Search in sources :

Example 56 with IAxis

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

the class SeriesSet method updateStackAndRiserData.

/**
 * Updates the stack and riser data for given axes.
 *
 * @param xAxis
 *            the X axis
 * @param yAxis
 *            the Y axis
 */
private void updateStackAndRiserData(IAxis xAxis, IAxis yAxis) {
    int riserCnt = 0;
    int stackRiserPosition = -1;
    double[] stackBarSeries = null;
    double[] stackLineSeries = null;
    if (((Axis) xAxis).isValidCategoryAxis()) {
        String[] categorySeries = xAxis.getCategorySeries();
        if (categorySeries != null) {
            int size = categorySeries.length;
            stackBarSeries = new double[size];
            stackLineSeries = new double[size];
        }
    }
    for (ISeries series : getSeries()) {
        if (series.getXAxisId() != xAxis.getId() || series.getYAxisId() != yAxis.getId() || !series.isVisible()) {
            continue;
        }
        if (series.isStackEnabled() && !chart.getAxisSet().getYAxis(series.getYAxisId()).isLogScaleEnabled() && ((Axis) xAxis).isValidCategoryAxis()) {
            if (series.getType() == SeriesType.BAR) {
                if (stackRiserPosition == -1) {
                    stackRiserPosition = riserCnt;
                    riserCnt++;
                }
                ((BarSeries) series).setRiserIndex(((Axis) xAxis).getNumRisers() + stackRiserPosition);
                setStackSeries(stackBarSeries, series);
            } else if (series.getType() == SeriesType.LINE) {
                setStackSeries(stackLineSeries, series);
            }
        } else {
            if (series.getType() == SeriesType.BAR) {
                ((BarSeries) series).setRiserIndex(((Axis) xAxis).getNumRisers() + riserCnt++);
            }
        }
    }
    ((Axis) xAxis).setNumRisers(((Axis) xAxis).getNumRisers() + riserCnt);
}
Also used : ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis)

Example 57 with IAxis

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

the class SWTBotCustomChartUtils method assertAxisRange.

/**
 * Verify that the internal range of the axis corresponds to the expected
 * values. This method should be called on axis using numerical or time
 * stamp formatters
 *
 * @param chart
 *            The chart to verify
 * @param axisType
 *            The axis to test for
 * @param min
 *            The minimum range value
 * @param max
 *            The maximum range value
 */
public static void assertAxisRange(Chart chart, AxisType axisType, Number min, Number max) {
    IAxis axis = (axisType == AxisType.X ? chart.getAxisSet().getXAxes()[0] : chart.getAxisSet().getYAxes()[0]);
    Format format = axis.getTick().getFormat();
    // Get the range map for the format, it has to have one
    ChartRangeMap map = null;
    if (format instanceof ChartTimeStampFormat) {
        map = ((ChartTimeStampFormat) format).getRangeMap();
    } else if (format instanceof ChartDecimalUnitFormat) {
        map = ((ChartDecimalUnitFormat) format).getRangeMap();
    }
    assertNotNull(map);
    ChartRange inputDataRange = map.getInputDataRange();
    assertEquals(min.doubleValue(), inputDataRange.getMinimum().doubleValue(), 1);
    assertEquals(max.doubleValue(), inputDataRange.getMaximum().doubleValue(), 1);
}
Also used : ChartDecimalUnitFormat(org.eclipse.tracecompass.internal.tmf.chart.ui.format.ChartDecimalUnitFormat) Format(java.text.Format) ChartDecimalUnitFormat(org.eclipse.tracecompass.internal.tmf.chart.ui.format.ChartDecimalUnitFormat) ChartTimeStampFormat(org.eclipse.tracecompass.internal.tmf.chart.ui.format.ChartTimeStampFormat) ChartTimeStampFormat(org.eclipse.tracecompass.internal.tmf.chart.ui.format.ChartTimeStampFormat) ChartRangeMap(org.eclipse.tracecompass.internal.tmf.chart.ui.data.ChartRangeMap) IAxis(org.eclipse.swtchart.IAxis) ChartRange(org.eclipse.tracecompass.internal.tmf.chart.ui.data.ChartRange)

Example 58 with IAxis

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

the class SWTBotCustomChartUtils method assertAxisLogscale.

/**
 * Verify an axis log scale status
 *
 * @param chart
 *            The chart to verify
 * @param axisType
 *            The axis to test for
 * @param logscale
 *            <code>true</code> if this axis should be logscale,
 *            <code>false</code> otherwise
 */
public static void assertAxisLogscale(Chart chart, AxisType axisType, boolean logscale) {
    IAxis axis = (axisType == AxisType.X ? chart.getAxisSet().getXAxes()[0] : chart.getAxisSet().getYAxes()[0]);
    assertEquals("Log scale", logscale, axis.isLogScaleEnabled());
}
Also used : IAxis(org.eclipse.swtchart.IAxis)

Example 59 with IAxis

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

the class TmfXYChartViewer method getPointAreaWidth.

/**
 * Get the width of the point area. We consider the point area to be from where
 * the first point could be drawn to where the last point could be drawn. The
 * point area differs from the plot area because there might be a gap between
 * where the plot area start and where the fist point is drawn. This also
 * matches the width that the use can select.
 *
 * @return the width in pixels
 */
public int getPointAreaWidth() {
    IAxis[] xAxes = getSwtChart().getAxisSet().getXAxes();
    if (xAxes.length > 0) {
        IAxis axis = xAxes[0];
        int x1 = getPointAreaOffset();
        int x2 = axis.getPixelCoordinate(axis.getRange().upper);
        x2 = getSwtChart().toControl(((Composite) fSwtChart.getPlotArea()).toDisplay(x2, 0)).x;
        int width = x2 - x1;
        return width;
    }
    return getSwtChart().getPlotArea().getSize().x;
}
Also used : IAxis(org.eclipse.swtchart.IAxis) Point(org.eclipse.swt.graphics.Point)

Example 60 with IAxis

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

the class TmfXYChartViewer method getPointAreaOffset.

/**
 * Get the offset of the point area, relative to the XY chart viewer control. We
 * consider the point area to be from where the first point could be drawn to
 * where the last point could be drawn.
 *
 * @return the offset in pixels
 */
public int getPointAreaOffset() {
    int pixelCoordinate = 0;
    IAxis[] xAxes = getSwtChart().getAxisSet().getXAxes();
    if (xAxes.length > 0) {
        IAxis axis = xAxes[0];
        pixelCoordinate = axis.getPixelCoordinate(axis.getRange().lower);
    }
    return getSwtChart().toControl(((Composite) fSwtChart.getPlotArea()).toDisplay(pixelCoordinate, 0)).x;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Point(org.eclipse.swt.graphics.Point) 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