Search in sources :

Example 6 with Axis

use of org.eclipse.swtchart.internal.axis.Axis in project swtchart by eclipse.

the class ChartLayout method adjustForMostLeftRightTickLabel.

/**
 * Adjust the axis size for most left/right tick label.
 *
 * @param r
 *            the rectangle to layout
 */
private void adjustForMostLeftRightTickLabel(Rectangle r) {
    // get axis margin hint
    int rightAxisMarginHint = 0;
    int leftAxisMarginHint = 0;
    for (IAxis axis : horizontalAxes) {
        if (!axis.getTick().isVisible()) {
            continue;
        }
        rightAxisMarginHint = Math.max(rightAxisMarginHint, ((Axis) axis).getTick().getAxisTickLabels().getRightMarginHint(plotAreaWidth));
        leftAxisMarginHint = Math.max(leftAxisMarginHint, ((Axis) axis).getTick().getAxisTickLabels().getLeftMarginHint(plotAreaWidth));
    }
    // have space to draw most right tick label on horizontal axis
    if ((legendWidth == 0 || legend.getPosition() != SWT.RIGHT) && rightAxisWidth < rightAxisMarginHint) {
        rightAxisWidth = rightAxisMarginHint;
        computePlotAreaSize(r);
        updateHorizontalAxisTick();
    }
    // have space to draw most left tick label on horizontal axis
    if ((legendWidth == 0 || legend.getPosition() != SWT.LEFT) && leftAxisWidth < leftAxisMarginHint) {
        leftAxisWidth = leftAxisMarginHint;
        computePlotAreaSize(r);
        updateHorizontalAxisTick();
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis) IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis)

Example 7 with Axis

use of org.eclipse.swtchart.internal.axis.Axis in project swtchart by eclipse.

the class ChartLayout method layoutAxes.

/**
 * Layouts the axes.
 *
 * @param r
 *            the rectangle to layout
 */
private void layoutAxes(Rectangle r) {
    bottomAxisOffset = 0;
    topAxisOffset = 0;
    leftAxisOffset = 0;
    rightAxisOffset = 0;
    for (Axis axis : axes) {
        AxisLayoutData layoutData = axisLayoutDataMap.get(axis);
        Position position = axis.getPosition();
        if (position == Position.Primary && axis.isHorizontalAxis()) {
            layoutBottomAxis(r, layoutData);
        } else if (position == Position.Secondary && axis.isHorizontalAxis()) {
            layoutTopAxis(r, layoutData);
        } else if (position == Position.Primary && !axis.isHorizontalAxis()) {
            layoutLeftAxis(r, layoutData);
        } else if (position == Position.Secondary && !axis.isHorizontalAxis()) {
            layoutRightAxis(r, layoutData);
        }
    }
}
Also used : Position(org.eclipse.swtchart.IAxis.Position) IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis)

Example 8 with Axis

use of org.eclipse.swtchart.internal.axis.Axis in project swtchart by eclipse.

the class Series method getYRange.

/**
 * Gets the Y range of series.
 *
 * @return the Y range of series
 */
public Range getYRange() {
    double min = minY;
    double max = maxY;
    Axis xAxis = (Axis) chart.getAxisSet().getXAxis(xAxisId);
    if (isValidStackSeries() && xAxis.isValidCategoryAxis()) {
        for (int i = 0; i < stackSeries.length; i++) {
            if (max < stackSeries[i]) {
                max = stackSeries[i];
            }
        }
    }
    return new Range(min, max);
}
Also used : Range(org.eclipse.swtchart.Range) IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis) Point(org.eclipse.swt.graphics.Point)

Example 9 with Axis

use of org.eclipse.swtchart.internal.axis.Axis in project swtchart by eclipse.

the class BarSeries method getBounds.

/*
	 * @see IBarSeries#getBounds()
	 */
public Rectangle[] getBounds() {
    Rectangle[] compressedBounds = getBoundsForCompressedSeries();
    if (((Axis) chart.getAxisSet().getXAxis(xAxisId)).isValidCategoryAxis()) {
        return compressedBounds;
    }
    Rectangle[] rs = new Rectangle[xSeries.length];
    double[] comporessedXSeries = compressor.getCompressedXSeries();
    int cnt = 0;
    for (int i = 0; i < xSeries.length; i++) {
        if (cnt < comporessedXSeries.length && comporessedXSeries[cnt] == xSeries[i]) {
            if (compressedBounds[cnt].width != 0 && compressedBounds[cnt].height != 0) {
                rs[i] = compressedBounds[cnt];
            }
            cnt++;
        }
    }
    return rs;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Axis(org.eclipse.swtchart.internal.axis.Axis) Point(org.eclipse.swt.graphics.Point)

Example 10 with Axis

use of org.eclipse.swtchart.internal.axis.Axis in project swtchart by eclipse.

the class SeriesSet method createSeries.

/*
	 * @see ISeriesSet#createSeries(ISeries.SeriesType, String)
	 */
public ISeries createSeries(SeriesType type, String id) {
    if (id == null) {
        SWT.error(SWT.ERROR_NULL_ARGUMENT);
        // to suppress warning...
        return null;
    }
    String trimmedId = id.trim();
    if ("".equals(trimmedId)) {
        SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }
    Series series = null;
    if (type == SeriesType.BAR) {
        series = new BarSeries(chart, trimmedId);
    } else if (type == SeriesType.LINE) {
        series = new LineSeries(chart, trimmedId);
    } else {
        SWT.error(SWT.ERROR_INVALID_ARGUMENT);
        // to suppress warning...
        return null;
    }
    Series oldSeries = seriesMap.get(trimmedId);
    if (oldSeries != null) {
        oldSeries.dispose();
    }
    int[] xAxisIds = chart.getAxisSet().getXAxisIds();
    int[] yAxisIds = chart.getAxisSet().getYAxisIds();
    series.setXAxisId(xAxisIds[0]);
    series.setYAxisId(yAxisIds[0]);
    seriesMap.put(trimmedId, series);
    Axis axis = (Axis) chart.getAxisSet().getXAxis(xAxisIds[0]);
    if (axis != null) {
        updateStackAndRiserData();
    }
    // legend will be shown if there is previously no series.
    chart.updateLayout();
    return series;
}
Also used : ISeries(org.eclipse.swtchart.ISeries) IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis)

Aggregations

Axis (org.eclipse.swtchart.internal.axis.Axis)11 IAxis (org.eclipse.swtchart.IAxis)9 Point (org.eclipse.swt.graphics.Point)6 Rectangle (org.eclipse.swt.graphics.Rectangle)2 Position (org.eclipse.swtchart.IAxis.Position)2 ISeries (org.eclipse.swtchart.ISeries)2 Range (org.eclipse.swtchart.Range)2 Control (org.eclipse.swt.widgets.Control)1 Chart (org.eclipse.swtchart.Chart)1 IAxisSet (org.eclipse.swtchart.IAxisSet)1