Search in sources :

Example 1 with BarStringConsumer

use of org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.BarStringConsumer in project tracecompass by tracecompass.

the class SwtBarChart method configureSeries.

@Override
protected void configureSeries(Map<@NonNull ISeries, Object[]> mapper) {
    XYChartConsumer chartConsumer = getChartConsumer();
    NumericalConsumerAggregator aggregator = (NumericalConsumerAggregator) checkNotNull(chartConsumer.getYAggregator());
    /* Clamp the Y ranges */
    fYRanges = clampInputDataRange(checkNotNull(aggregator.getChartRanges()));
    /* Generate data for each SWT series */
    for (XYSeriesConsumer seriesConsumer : chartConsumer.getSeries()) {
        BarStringConsumer xconsumer = (BarStringConsumer) seriesConsumer.getXConsumer();
        NumericalConsumer yConsumer = (NumericalConsumer) seriesConsumer.getYConsumer();
        Object[] object = seriesConsumer.getConsumedElements().toArray();
        /* Generate categories for the X axis */
        Collection<@Nullable String> list = xconsumer.getList();
        /*
             * The categories are nullable, but swtchart does not support null
             * values, so we'll update the null values to an empty string
             */
        String @Nullable [] categories = list.toArray(new String[list.size()]);
        for (int i = 0; i < list.size(); i++) {
            if (categories[i] == null) {
                // $NON-NLS-1$
                categories[i] = "?";
            }
        }
        fCategories = categories;
        /* Generate numerical data for the Y axis */
        List<Number> data = yConsumer.getData();
        double[] xData = new double[data.size()];
        double[] yData = new double[data.size()];
        for (int i = 0; i < yData.length; i++) {
            Number number = checkNotNull(data.get(i));
            xData[i] = i;
            yData[i] = fYRanges.getInternalValue(number).doubleValue();
        }
        /* Set the data for the SWT series */
        ISeries<Integer> series = checkNotNull(getSeriesMap().get(seriesConsumer.getSeries()));
        series.setDataModel(new DoubleArraySeriesModel(xData, yData));
        /* Create a series mapper */
        mapper.put(series, checkNotNull(object));
    }
}
Also used : DoubleArraySeriesModel(org.eclipse.swtchart.model.DoubleArraySeriesModel) XYSeriesConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYSeriesConsumer) BarStringConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.BarStringConsumer) XYChartConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYChartConsumer) Point(org.eclipse.swt.graphics.Point) NumericalConsumerAggregator(org.eclipse.tracecompass.internal.tmf.chart.ui.aggregator.NumericalConsumerAggregator) NumericalConsumer(org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

Nullable (org.eclipse.jdt.annotation.Nullable)1 Point (org.eclipse.swt.graphics.Point)1 DoubleArraySeriesModel (org.eclipse.swtchart.model.DoubleArraySeriesModel)1 NumericalConsumer (org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer)1 NumericalConsumerAggregator (org.eclipse.tracecompass.internal.tmf.chart.ui.aggregator.NumericalConsumerAggregator)1 BarStringConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.BarStringConsumer)1 XYChartConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYChartConsumer)1 XYSeriesConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYSeriesConsumer)1