Search in sources :

Example 1 with ILegend

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

the class ScrollableChart method toggleSeriesLegendVisibility.

public void toggleSeriesLegendVisibility() {
    ILegend legend = baseChart.getLegend();
    legend.setVisible(!legend.isVisible());
    baseChart.redraw();
}
Also used : ILegend(org.eclipse.swtchart.ILegend)

Example 2 with ILegend

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

the class ScrollableChart method modifyChart.

private void modifyChart() {
    IChartSettings chartSettings = baseChart.getChartSettings();
    setSliderVisibility(chartSettings);
    setRangeInfoVisibility(chartSettings);
    // 
    ITitle title = baseChart.getTitle();
    title.setText(chartSettings.getTitle());
    title.setVisible(chartSettings.isTitleVisible());
    title.setForeground(chartSettings.getTitleColor());
    // 
    ILegend legend = baseChart.getLegend();
    legend.setPosition(chartSettings.getLegendPosition());
    legend.setVisible(chartSettings.isLegendVisible());
    // 
    setBackground(chartSettings.getBackground());
    baseChart.setOrientation(chartSettings.getOrientation());
    baseChart.setBackground(chartSettings.getBackgroundChart());
    baseChart.setBackgroundInPlotArea(chartSettings.getBackgroundPlotArea());
    baseChart.enableCompress(chartSettings.isEnableCompress());
    baseChart.setRangeRestriction(chartSettings.getRangeRestriction());
    /*
		 * Primary and Secondary axes
		 */
    addPrimaryAxisX(chartSettings);
    addPrimaryAxisY(chartSettings);
    addSecondaryAxesX(chartSettings);
    addSecondaryAxesY(chartSettings);
    /*
		 * Range Info
		 */
    rangeSelector.resetRanges();
    /*
		 * Additional actions.
		 */
    setCustomPaintListener();
    updateRangeHintPaintListener();
    setMenuItems();
    setEventProcessors();
}
Also used : ILegend(org.eclipse.swtchart.ILegend) ITitle(org.eclipse.swtchart.ITitle)

Example 3 with ILegend

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

Aggregations

ILegend (org.eclipse.swtchart.ILegend)3 IAxis (org.eclipse.swtchart.IAxis)1 ITitle (org.eclipse.swtchart.ITitle)1 Range (org.eclipse.swtchart.Range)1 DoubleArraySeriesModel (org.eclipse.swtchart.model.DoubleArraySeriesModel)1 SegmentStoreWithRange (org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider.SegmentStoreWithRange)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