Search in sources :

Example 31 with IAxis

use of org.eclipse.swtchart.IAxis in project tracecompass by tracecompass.

the class AbstractSegmentStoreDensityViewer method clearContent.

/**
 * Clears the view content.
 */
private void clearContent() {
    final Chart chart = fChart;
    if (!chart.isDisposed()) {
        ISeriesSet set = chart.getSeriesSet();
        ISeries<?>[] series = set.getSeries();
        for (int i = 0; i < series.length; i++) {
            set.deleteSeries(series[i].getId());
        }
        for (IAxis axis : chart.getAxisSet().getAxes()) {
            axis.setRange(new Range(0, 1));
        }
        chart.redraw();
    }
}
Also used : ISeriesSet(org.eclipse.swtchart.ISeriesSet) 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) ISeries(org.eclipse.swtchart.ISeries) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis)

Example 32 with IAxis

use of org.eclipse.swtchart.IAxis 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 33 with IAxis

use of org.eclipse.swtchart.IAxis in project tracecompass by tracecompass.

the class SWTBotCustomChartUtils method assertCategoriesAxis.

/**
 * Verify the categories of an axis correspond to the excpected values. This
 * method should be called on axis using discrete string values.
 *
 * @param chart
 *            The chart to verify
 * @param axisType
 *            The axis to test for
 * @param categories
 *            The expected categories
 */
public static void assertCategoriesAxis(Chart chart, AxisType axisType, String[] categories) {
    IAxis axis = (axisType == AxisType.X ? chart.getAxisSet().getXAxes()[0] : chart.getAxisSet().getYAxes()[0]);
    assertTrue(axis.isCategoryEnabled());
    String[] categorySeries = axis.getCategorySeries();
    assertArrayEquals(categories, categorySeries);
}
Also used : IAxis(org.eclipse.swtchart.IAxis)

Example 34 with IAxis

use of org.eclipse.swtchart.IAxis in project olca-app by GreenDelta.

the class ContributionChart method create.

public static ContributionChart create(Composite parent, FormToolkit tk) {
    Composite comp = UI.formComposite(parent, tk);
    UI.gridLayout(comp, 2);
    UI.gridData(comp, true, true);
    // create and configure the chart
    Chart chart = new Chart(comp, SWT.NONE);
    GridData gdata = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    gdata.heightHint = 300;
    gdata.widthHint = 700;
    chart.setLayoutData(gdata);
    chart.setOrientation(SWT.HORIZONTAL);
    chart.getLegend().setVisible(false);
    // we set a white title just to fix the problem
    // that the y-axis is cut sometimes
    chart.getTitle().setText(".");
    chart.getTitle().setFont(UI.defaultFont());
    chart.getTitle().setForeground(Colors.white());
    chart.getTitle().setVisible(true);
    // configure the x-axis with one category
    IAxis x = chart.getAxisSet().getXAxis(0);
    x.getTitle().setVisible(false);
    x.getTick().setForeground(Colors.darkGray());
    x.enableCategory(true);
    x.setCategorySeries(new String[] { "" });
    // configure the y-axis
    IAxis y = chart.getAxisSet().getYAxis(0);
    y.getTitle().setVisible(false);
    y.getTick().setForeground(Colors.darkGray());
    y.getGrid().setStyle(LineStyle.NONE);
    y.getTick().setFormat(new DecimalFormat("0.0E0#", new DecimalFormatSymbols(Locale.US)));
    y.getTick().setTickMarkStepHint(10);
    return new ContributionChart(chart, new ChartLegend(comp));
}
Also used : Composite(org.eclipse.swt.widgets.Composite) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) GridData(org.eclipse.swt.layout.GridData) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis)

Example 35 with IAxis

use of org.eclipse.swtchart.IAxis in project netxms by netxms.

the class LineChart method adjustYAxis.

public void adjustYAxis(boolean repaint) {
    zoomedToSelectionY = false;
    final IAxis yAxis = getAxisSet().getYAxis(0);
    yAxis.adjustRange();
    final Range range = yAxis.getRange();
    if (!configuration.isModifyYBase() && (range.lower > 0))
        range.lower = 0;
    else if (range.lower < 0)
        range.lower = -adjustRange(Math.abs(range.lower));
    range.upper = adjustRange(range.upper);
    yAxis.setRange(range);
    if (repaint)
        redraw();
}
Also used : Range(org.eclipse.swtchart.Range) IAxis(org.eclipse.swtchart.IAxis)

Aggregations

IAxis (org.eclipse.swtchart.IAxis)64 Point (org.eclipse.swt.graphics.Point)27 Range (org.eclipse.swtchart.Range)19 IAxisSet (org.eclipse.swtchart.IAxisSet)10 Chart (org.eclipse.swtchart.Chart)7 ISeries (org.eclipse.swtchart.ISeries)7 MouseEvent (org.eclipse.swt.events.MouseEvent)5 ILineSeries (org.eclipse.swtchart.ILineSeries)5 Color (org.eclipse.swt.graphics.Color)4 GridData (org.eclipse.swt.layout.GridData)4 DecimalFormat (java.text.DecimalFormat)3 PaintEvent (org.eclipse.swt.events.PaintEvent)3 PaintListener (org.eclipse.swt.events.PaintListener)3 GC (org.eclipse.swt.graphics.GC)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Composite (org.eclipse.swt.widgets.Composite)3 IBarSeries (org.eclipse.swtchart.IBarSeries)3 ITitle (org.eclipse.swtchart.ITitle)3 Axis (org.eclipse.swtchart.internal.axis.Axis)3 StyleRange (org.eclipse.swt.custom.StyleRange)2