Search in sources :

Example 1 with XYChartConsumer

use of org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYChartConsumer 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)

Example 2 with XYChartConsumer

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

the class SwtScatterChart method configureSeries.

@Override
protected void configureSeries(Map<@NonNull ISeries, Object[]> mapper) {
    XYChartConsumer chartConsumer = getChartConsumer();
    /* Obtain the X ranges if possible */
    NumericalConsumerAggregator xAggregator = (NumericalConsumerAggregator) chartConsumer.getXAggregator();
    if (xAggregator != null) {
        if (getModel().isXLogscale()) {
            fXRanges = clampInputDataRange(xAggregator.getChartRanges());
        } else {
            fXRanges = xAggregator.getChartRanges();
        }
    }
    /* Obtain the Y ranges if possible */
    NumericalConsumerAggregator yAggregator = (NumericalConsumerAggregator) chartConsumer.getYAggregator();
    if (yAggregator != null) {
        if (getModel().isYLogscale()) {
            fYRanges = clampInputDataRange(yAggregator.getChartRanges());
        } else {
            fYRanges = yAggregator.getChartRanges();
        }
    }
    /* Generate data for each SWT series */
    for (XYSeriesConsumer seriesConsumer : chartConsumer.getSeries()) {
        double[] xData;
        double[] yData;
        Object[] object = seriesConsumer.getConsumedElements().toArray();
        /* Generate data for the X axis */
        if (getXDescriptorsInfo().areNumerical()) {
            NumericalConsumer consumer = (NumericalConsumer) seriesConsumer.getXConsumer();
            List<Number> data = consumer.getData();
            int size = data.size();
            xData = new double[size];
            for (int i = 0; i < size; i++) {
                Number number = checkNotNull(data.get(i));
                xData[i] = fXRanges.getInternalValue(number).doubleValue();
            }
        } else {
            ScatterStringConsumer consumer = (ScatterStringConsumer) seriesConsumer.getXConsumer();
            List<String> list = consumer.getList();
            xData = new double[list.size()];
            for (int i = 0; i < xData.length; i++) {
                String str = list.get(i);
                xData[i] = checkNotNull(fXStringMap.get(str));
            }
        }
        /* Generate data for the Y axis */
        if (getYDescriptorsInfo().areNumerical()) {
            NumericalConsumer consumer = (NumericalConsumer) seriesConsumer.getYConsumer();
            List<Number> data = consumer.getData();
            yData = new double[data.size()];
            for (int i = 0; i < yData.length; i++) {
                Number number = checkNotNull(data.get(i));
                yData[i] = fYRanges.getInternalValue(number).doubleValue();
            }
        } else {
            ScatterStringConsumer consumer = (ScatterStringConsumer) seriesConsumer.getYConsumer();
            List<String> list = consumer.getList();
            yData = new double[list.size()];
            for (int i = 0; i < yData.length; i++) {
                String str = list.get(i);
                yData[i] = checkNotNull(fYStringMap.get(str));
            }
        }
        /* 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) 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) ScatterStringConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.ScatterStringConsumer)

Example 3 with XYChartConsumer

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

the class SwtXYChartViewer method createChartConsumer.

/**
 * Create the main consumer for the chart. For each series, it create the
 * series consumer. It also needs the X and Y aggregators.
 */
private final XYChartConsumer createChartConsumer() {
    List<XYSeriesConsumer> series = new ArrayList<>();
    getData().getChartSeries().forEach(s -> {
        IDataConsumer xConsumer = getXConsumer(s);
        IDataConsumer yConsumer = getYConsumer(s);
        /* Create consumer for this series */
        series.add(new XYSeriesConsumer(s, xConsumer, yConsumer));
    });
    /* Get the aggregators */
    IConsumerAggregator xAggregator = getXAggregator();
    IConsumerAggregator yAggregator = getYAggregator();
    /* Create the chart consumer */
    return new XYChartConsumer(series, xAggregator, yAggregator);
}
Also used : IDataConsumer(org.eclipse.tracecompass.internal.tmf.chart.core.consumer.IDataConsumer) IConsumerAggregator(org.eclipse.tracecompass.internal.tmf.chart.core.aggregator.IConsumerAggregator) XYSeriesConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYSeriesConsumer) ArrayList(java.util.ArrayList) XYChartConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYChartConsumer)

Example 4 with XYChartConsumer

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

the class SwtXYChartViewer method populate.

/**
 * This method is called after the constructor by the factory constructor.
 * While everything could be put in the constructor directly, splitting the
 * constructor simply makes the code cleaner by reducing the number of null
 * checks.
 */
protected final void populate() {
    /* Create the consumer for the data */
    XYChartConsumer chartConsumer = createChartConsumer();
    fChartConsumer = chartConsumer;
    /* Process all the objects from the stream of data */
    fData.getDataProvider().getSource().forEach(chartConsumer::accept);
    chartConsumer.finish();
    /* Create the SWT series */
    createChartSeries();
    configureSeries(fObjectMap);
    /* Adjust the chart range */
    getChart().getAxisSet().adjustRange();
    /* Configure axes */
    configureAxes();
    Arrays.stream(getChart().getAxisSet().getXAxes()).forEach(a -> a.enableLogScale(getModel().isXLogscale()));
    Arrays.stream(getChart().getAxisSet().getYAxes()).forEach(a -> a.enableLogScale(getModel().isYLogscale()));
    for (IAxis yAxis : getChart().getAxisSet().getYAxes()) {
        /*
             * SWTChart workaround: SWTChart fiddles with tick mark visibility
             * based on the fact that it can parse the label to double or not.
             *
             * If the label happens to be a double, it checks for the presence
             * of that value in its own tick labels to decide if it should add
             * it or not. If it happens that the parsed value is already present
             * in its map, the tick gets a visibility of false.
             *
             * The X axis does not have this problem since SWTCHART checks on
             * label angle, and if it is != 0 simply does no logic regarding
             * visibility. So simply set a label angle of 1 to the axis.
             */
        yAxis.getTick().setTickLabelAngle(1);
    }
    /* Update the titles */
    fXTitle = generateTitle(getXDescriptors(), getChart().getAxisSet().getXAxis(0));
    fYTitle = generateTitle(getYDescriptors(), getChart().getAxisSet().getYAxis(0));
    /* Refresh the titles to fit the current chart size */
    refreshDisplayTitles();
    refreshDisplayLabels();
}
Also used : XYChartConsumer(org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYChartConsumer) IAxis(org.eclipse.swtchart.IAxis)

Aggregations

XYChartConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYChartConsumer)4 XYSeriesConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYSeriesConsumer)3 Point (org.eclipse.swt.graphics.Point)2 DoubleArraySeriesModel (org.eclipse.swtchart.model.DoubleArraySeriesModel)2 NumericalConsumer (org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer)2 NumericalConsumerAggregator (org.eclipse.tracecompass.internal.tmf.chart.ui.aggregator.NumericalConsumerAggregator)2 ArrayList (java.util.ArrayList)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 IAxis (org.eclipse.swtchart.IAxis)1 IConsumerAggregator (org.eclipse.tracecompass.internal.tmf.chart.core.aggregator.IConsumerAggregator)1 IDataConsumer (org.eclipse.tracecompass.internal.tmf.chart.core.consumer.IDataConsumer)1 BarStringConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.BarStringConsumer)1 ScatterStringConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.ScatterStringConsumer)1