Search in sources :

Example 56 with ISeries

use of org.eclipse.swtchart.ISeries in project swtchart by eclipse.

the class SeriesSet method createSeries.

/*
	 * @see ISeriesSet#createSeries(ISeries.SeriesType, String)
	 */
public ISeries createSeries(SeriesType type, String id) {
    if (id == null) {
        SWT.error(SWT.ERROR_NULL_ARGUMENT);
        // to suppress warning...
        return null;
    }
    String trimmedId = id.trim();
    if ("".equals(trimmedId)) {
        SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }
    Series series = null;
    if (type == SeriesType.BAR) {
        series = new BarSeries(chart, trimmedId);
    } else if (type == SeriesType.LINE) {
        series = new LineSeries(chart, trimmedId);
    } else {
        SWT.error(SWT.ERROR_INVALID_ARGUMENT);
        // to suppress warning...
        return null;
    }
    Series oldSeries = seriesMap.get(trimmedId);
    if (oldSeries != null) {
        oldSeries.dispose();
    }
    int[] xAxisIds = chart.getAxisSet().getXAxisIds();
    int[] yAxisIds = chart.getAxisSet().getYAxisIds();
    series.setXAxisId(xAxisIds[0]);
    series.setYAxisId(yAxisIds[0]);
    seriesMap.put(trimmedId, series);
    Axis axis = (Axis) chart.getAxisSet().getXAxis(xAxisIds[0]);
    if (axis != null) {
        updateStackAndRiserData();
    }
    // legend will be shown if there is previously no series.
    chart.updateLayout();
    return series;
}
Also used : ISeries(org.eclipse.swtchart.ISeries) IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis)

Example 57 with ISeries

use of org.eclipse.swtchart.ISeries in project swtchart by eclipse.

the class SeriesSet method updateStackAndRiserData.

/**
 * Updates the stack and riser data for given axes.
 *
 * @param xAxis
 *            the X axis
 * @param yAxis
 *            the Y axis
 */
private void updateStackAndRiserData(IAxis xAxis, IAxis yAxis) {
    int riserCnt = 0;
    int stackRiserPosition = -1;
    double[] stackBarSeries = null;
    double[] stackLineSeries = null;
    if (((Axis) xAxis).isValidCategoryAxis()) {
        String[] categorySeries = xAxis.getCategorySeries();
        if (categorySeries != null) {
            int size = categorySeries.length;
            stackBarSeries = new double[size];
            stackLineSeries = new double[size];
        }
    }
    for (ISeries series : getSeries()) {
        if (series.getXAxisId() != xAxis.getId() || series.getYAxisId() != yAxis.getId() || !series.isVisible()) {
            continue;
        }
        if (series.isStackEnabled() && !chart.getAxisSet().getYAxis(series.getYAxisId()).isLogScaleEnabled() && ((Axis) xAxis).isValidCategoryAxis()) {
            if (series.getType() == SeriesType.BAR) {
                if (stackRiserPosition == -1) {
                    stackRiserPosition = riserCnt;
                    riserCnt++;
                }
                ((BarSeries) series).setRiserIndex(((Axis) xAxis).getNumRisers() + stackRiserPosition);
                setStackSeries(stackBarSeries, series);
            } else if (series.getType() == SeriesType.LINE) {
                setStackSeries(stackLineSeries, series);
            }
        } else {
            if (series.getType() == SeriesType.BAR) {
                ((BarSeries) series).setRiserIndex(((Axis) xAxis).getNumRisers() + riserCnt++);
            }
        }
    }
    ((Axis) xAxis).setNumRisers(((Axis) xAxis).getNumRisers() + riserCnt);
}
Also used : ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis)

Example 58 with ISeries

use of org.eclipse.swtchart.ISeries in project tracecompass by tracecompass.

the class SWTBotCustomChartUtils method assertSeriesTitle.

/**
 * Verify the title of the series. These titles are shown in the legend if
 * there is more than one serie
 *
 * @param customChart
 *            The chart to verify
 * @param titles
 *            The list of series titles
 */
public static void assertSeriesTitle(Chart customChart, List<String> titles) {
    ISeriesSet seriesSet = customChart.getSeriesSet();
    assertNotNull(seriesSet);
    ISeries<?>[] series = seriesSet.getSeries();
    assertEquals(titles.size(), series.length);
    for (int i = 0; i < series.length; i++) {
        assertEquals("Series title " + i, titles.get(i), series[i].getId());
    }
}
Also used : ISeriesSet(org.eclipse.swtchart.ISeriesSet) ISeries(org.eclipse.swtchart.ISeries)

Example 59 with ISeries

use of org.eclipse.swtchart.ISeries in project tracecompass by tracecompass.

the class SwtBarChart method setSelection.

@Override
protected void setSelection(@NonNull Set<@NonNull Object> set) {
    super.setSelection(set);
    /* Set color of selected symbol */
    Iterator<Color> colorsIt = Iterators.cycle(COLORS);
    Iterator<Color> lightColorsIt = Iterators.cycle(COLORS_LIGHT);
    for (ISeries series : getChart().getSeriesSet().getSeries()) {
        /* Series color */
        Color lightColor = NonNullUtils.checkNotNull(lightColorsIt.next());
        Color color = NonNullUtils.checkNotNull(colorsIt.next());
        if (set.isEmpty()) {
            /* Put all symbols to the normal colors */
            ((IBarSeries) series).setBarColor(color);
        } else {
            /*
                 * Fill with light colors to represent the deselected state. The
                 * paint listener is then responsible for drawing the cross and
                 * the dark colors for the selection.
                 */
            ((IBarSeries) series).setBarColor(lightColor);
        }
    }
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) Color(org.eclipse.swt.graphics.Color) ISeries(org.eclipse.swtchart.ISeries)

Example 60 with ISeries

use of org.eclipse.swtchart.ISeries in project tracecompass by tracecompass.

the class SwtScatterChart method setSelection.

@Override
protected void setSelection(@NonNull Set<@NonNull Object> set) {
    super.setSelection(set);
    /* Set color of selected symbol */
    Iterator<Color> colorsIt = Iterators.cycle(COLORS);
    Iterator<Color> lightColorsIt = Iterators.cycle(COLORS_LIGHT);
    for (ISeries series : getChart().getSeriesSet().getSeries()) {
        /* Series color */
        Color lightColor = NonNullUtils.checkNotNull(lightColorsIt.next());
        Color color = NonNullUtils.checkNotNull(colorsIt.next());
        if (set.isEmpty()) {
            /* Put all symbols to the normal colors */
            ((ILineSeries) series).setSymbolColor(color);
        } else {
            /*
                 * Fill with light colors to represent the deselected state. The
                 * paint listener is then responsible for drawing the cross and
                 * the dark colors for the selection.
                 */
            ((ILineSeries) series).setSymbolColor(lightColor);
        }
    }
}
Also used : Color(org.eclipse.swt.graphics.Color) ILineSeries(org.eclipse.swtchart.ILineSeries) ISeries(org.eclipse.swtchart.ISeries)

Aggregations

ISeries (org.eclipse.swtchart.ISeries)60 Point (org.eclipse.swt.graphics.Point)21 ISeriesSet (org.eclipse.swtchart.ISeriesSet)11 Chart (org.eclipse.swtchart.Chart)10 IAxis (org.eclipse.swtchart.IAxis)9 Range (org.eclipse.swtchart.Range)9 BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)8 Color (org.eclipse.swt.graphics.Color)5 IBarSeries (org.eclipse.swtchart.IBarSeries)5 ILineSeries (org.eclipse.swtchart.ILineSeries)5 IAxisSettings (org.eclipse.swtchart.extensions.core.IAxisSettings)5 Rectangle (org.eclipse.swt.graphics.Rectangle)4 MouseEvent (org.eclipse.swt.events.MouseEvent)3 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)3 GC (org.eclipse.swt.graphics.GC)3 Test (org.junit.Test)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2