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;
}
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);
}
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());
}
}
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);
}
}
}
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);
}
}
}
Aggregations