Search in sources :

Example 1 with DoubleArraySeriesModel

use of org.eclipse.swtchart.model.DoubleArraySeriesModel in project tracecompass by tracecompass.

the class AbstractSegmentStoreDensityViewer method updateDisplay.

private synchronized void updateDisplay(String name, Iterable<ISegment> data) {
    ISeries<Integer> series = fSeriesType.equals(Type.BAR) ? createSeries() : createAreaSeries(name);
    int barWidth = 4;
    int preWidth = fOverrideNbPoints == 0 ? fChart.getPlotArea().getSize().x / barWidth : fOverrideNbPoints;
    if (!fSeriesType.equals(Type.BAR)) {
        preWidth += 2;
    }
    final int width = preWidth;
    double[] xOrigSeries = new double[width];
    double[] yOrigSeries = new double[width];
    // Set a positive value that is greater than 0 and less than 1.0
    Arrays.fill(yOrigSeries, Double.MIN_VALUE);
    Optional<ISegment> maxSegment = StreamSupport.stream(data.spliterator(), false).max(SegmentComparators.INTERVAL_LENGTH_COMPARATOR);
    long maxLength = Long.MIN_VALUE;
    if (maxSegment.isPresent()) {
        maxLength = maxSegment.get().getLength();
    } else {
        for (ISegment segment : data) {
            maxLength = Math.max(maxLength, segment.getLength());
        }
        if (maxLength == Long.MIN_VALUE) {
            maxLength = 1;
        }
    }
    double maxFactor = 1.0 / (maxLength + 1.0);
    long minX = Long.MAX_VALUE;
    for (ISegment segment : data) {
        double xBox = segment.getLength() * maxFactor * width;
        if (yOrigSeries[(int) xBox] < 1) {
            yOrigSeries[(int) xBox] = 1;
        } else {
            yOrigSeries[(int) xBox]++;
        }
        minX = Math.min(minX, segment.getLength());
    }
    double timeWidth = (double) maxLength / (double) width;
    for (int i = 0; i < width; i++) {
        xOrigSeries[i] = i * timeWidth;
        if (!fSeriesType.equals(Type.BAR)) {
            xOrigSeries[i] += timeWidth / 2;
        }
    }
    double maxY = Double.NEGATIVE_INFINITY;
    for (int i = 0; i < width; i++) {
        maxY = Math.max(maxY, yOrigSeries[i]);
    }
    if (minX == maxLength) {
        maxLength++;
        minX--;
    }
    series.setDataModel(new DoubleArraySeriesModel(xOrigSeries, yOrigSeries));
    final IAxis xAxis = fChart.getAxisSet().getXAxis(0);
    /*
         * adjustrange appears to bring origin back since we pad the series with
         * 0s, not interesting.
         */
    AxisRange currentDurationRange = fCurrentDurationRange;
    if (Double.isFinite(currentDurationRange.getLower()) && Double.isFinite(currentDurationRange.getUpper())) {
        xAxis.setRange(new Range(currentDurationRange.getLower(), currentDurationRange.getUpper()));
    } else {
        xAxis.adjustRange();
    }
    xAxis.getTick().setFormat(DENSITY_TIME_FORMATTER);
    ILegend legend = fChart.getLegend();
    legend.setVisible(fSegmentStoreProviders.size() > 1);
    legend.setPosition(SWT.BOTTOM);
    /*
         * Clamp range lower to 0.9 to make it log, 0.1 would be scientifically
         * accurate, but we cannot have partial counts.
         */
    for (ISeries<?> internalSeries : fChart.getSeriesSet().getSeries()) {
        maxY = Math.max(maxY, internalSeries.getDataModel().getMaxY().doubleValue());
    }
    fChart.getAxisSet().getYAxis(0).setRange(new Range(0.9, Math.max(1.0, maxY)));
    fChart.getAxisSet().getYAxis(0).enableLogScale(true);
    new Thread(() -> {
        for (ISegmentStoreDensityViewerDataListener l : fListeners) {
            l.chartUpdated();
        }
    }).start();
}
Also used : ILegend(org.eclipse.swtchart.ILegend) DoubleArraySeriesModel(org.eclipse.swtchart.model.DoubleArraySeriesModel) Range(org.eclipse.swtchart.Range) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) SegmentStoreWithRange(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider.SegmentStoreWithRange) AxisRange(org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange) IAxis(org.eclipse.swtchart.IAxis) AxisRange(org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment)

Example 2 with DoubleArraySeriesModel

use of org.eclipse.swtchart.model.DoubleArraySeriesModel 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 3 with DoubleArraySeriesModel

use of org.eclipse.swtchart.model.DoubleArraySeriesModel 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)

Aggregations

DoubleArraySeriesModel (org.eclipse.swtchart.model.DoubleArraySeriesModel)3 Point (org.eclipse.swt.graphics.Point)2 NumericalConsumer (org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer)2 NumericalConsumerAggregator (org.eclipse.tracecompass.internal.tmf.chart.ui.aggregator.NumericalConsumerAggregator)2 XYChartConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYChartConsumer)2 XYSeriesConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.XYSeriesConsumer)2 Nullable (org.eclipse.jdt.annotation.Nullable)1 IAxis (org.eclipse.swtchart.IAxis)1 ILegend (org.eclipse.swtchart.ILegend)1 Range (org.eclipse.swtchart.Range)1 SegmentStoreWithRange (org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider.SegmentStoreWithRange)1 BarStringConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.BarStringConsumer)1 ScatterStringConsumer (org.eclipse.tracecompass.internal.tmf.chart.ui.consumer.ScatterStringConsumer)1 ISegment (org.eclipse.tracecompass.segmentstore.core.ISegment)1 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)1 AxisRange (org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange)1