Search in sources :

Example 1 with Axis

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

the class Series method draw.

/**
 * Draws series.
 *
 * @param gc
 *            the graphics context
 * @param width
 *            the width to draw series
 * @param height
 *            the height to draw series
 */
public void draw(GC gc, int width, int height) {
    if (!visible || width < 0 || height < 0 || xSeries.length == 0 || ySeries.length == 0) {
        return;
    }
    Axis xAxis = (Axis) chart.getAxisSet().getXAxis(getXAxisId());
    Axis yAxis = (Axis) chart.getAxisSet().getYAxis(getYAxisId());
    if (xAxis == null || yAxis == null) {
        return;
    }
    draw(gc, width, height, xAxis, yAxis);
}
Also used : IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis)

Example 2 with Axis

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

the class ChartLayout method adjustForRotatedTickLabels.

/**
 * Adjust the axis size for rotated tick labels.
 *
 * @param r
 *            the rectangle to layout
 */
private void adjustForRotatedTickLabels(Rectangle r) {
    for (IAxis axis : horizontalAxes) {
        double angle = axis.getTick().getTickLabelAngle();
        if (angle == 0 || !axis.getTick().isVisible()) {
            continue;
        }
        // update tick label height
        int tickLabelMaxLength = ((Axis) axis).getTick().getAxisTickLabels().getTickLabelMaxLength();
        AxisLayoutData layoutData = axisLayoutDataMap.get(axis);
        int height = Axis.MARGIN + (int) (tickLabelMaxLength * Math.sin(Math.toRadians(angle)) + Util.getExtentInGC(layoutData.axisTickLabels.getFont(), null).y * Math.cos(Math.toRadians(angle)));
        int delta = height - layoutData.tickLabelsLayoutdata.heightHint;
        layoutData.tickLabelsLayoutdata.heightHint = height;
        // update axis height
        if (axis.getPosition() == Position.Primary) {
            bottomAxisHeight += delta;
        } else {
            topAxisHeight += delta;
        }
        // update plot area height
        computePlotAreaSize(r);
        updateVerticalAxisTick();
    }
}
Also used : IAxis(org.eclipse.swtchart.IAxis) Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis)

Example 3 with Axis

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

the class ChartLayout method parseControls.

/**
 * Parses the controls on given composite.
 *
 * @param composite
 *            the composite
 * @return true if all children found
 */
private boolean parseControls(Composite composite) {
    for (Control child : composite.getChildren()) {
        if (child instanceof Legend) {
            legend = (Legend) child;
        } else if (child instanceof PlotArea) {
            plot = (PlotArea) child;
        }
    }
    if (composite instanceof Chart) {
        IAxisSet axisSet = ((Chart) composite).getAxisSet();
        if (axisSet != null) {
            axes = (Axis[]) axisSet.getAxes();
            if (((Chart) composite).getOrientation() == SWT.HORIZONTAL) {
                horizontalAxes = (Axis[]) axisSet.getXAxes();
                verticalAxes = (Axis[]) axisSet.getYAxes();
            } else {
                verticalAxes = (Axis[]) axisSet.getXAxes();
                horizontalAxes = (Axis[]) axisSet.getYAxes();
            }
        }
        title = (ChartTitle) ((Chart) composite).getTitle();
    }
    if (title == null || legend == null || plot == null || axes == null) {
        // the initialization of chart is not completed yet
        return false;
    }
    return true;
}
Also used : Control(org.eclipse.swt.widgets.Control) IAxisSet(org.eclipse.swtchart.IAxisSet) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis)

Example 4 with Axis

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

the class BarSeries method getBoundsForCompressedSeries.

/**
 * Gets the array of bar rectangles for compressed series.
 *
 * @return the array of bar rectangles for compressed series
 */
private Rectangle[] getBoundsForCompressedSeries() {
    Axis xAxis = (Axis) chart.getAxisSet().getXAxis(xAxisId);
    Axis yAxis = (Axis) chart.getAxisSet().getYAxis(yAxisId);
    // get x and y series
    double[] xseries = compressor.getCompressedXSeries();
    double[] yseries = compressor.getCompressedYSeries();
    int[] indexes = compressor.getCompressedIndexes();
    if (xAxis.isValidCategoryAxis()) {
        for (int i = 0; i < xseries.length; i++) {
            xseries[i] = indexes[i];
        }
    }
    Rectangle[] rectangles = new Rectangle[xseries.length];
    Range xRange = xAxis.getRange();
    Range yRange = yAxis.getRange();
    for (int i = 0; i < xseries.length; i++) {
        int x = xAxis.getPixelCoordinate(xseries[i]);
        int y = yAxis.getPixelCoordinate(isValidStackSeries() ? stackSeries[indexes[i]] : yseries[i]);
        double baseYCoordinate = yAxis.getRange().lower > 0 ? yAxis.getRange().lower : 0;
        double riserwidth = getRiserWidth(xseries, i, xAxis, xRange.lower, xRange.upper);
        double riserHeight = Math.abs(yAxis.getPixelCoordinate(yseries[i], yRange.lower, yRange.upper) - yAxis.getPixelCoordinate(yAxis.isLogScaleEnabled() ? yRange.lower : baseYCoordinate, yRange.lower, yRange.upper));
        // adjust riser x coordinate and riser width for multiple series
        int riserCnt = xAxis.getNumRisers();
        if (riserCnt > 1) {
            if (xAxis.isHorizontalAxis()) {
                x = (int) (x - riserwidth / 2d + riserwidth / riserCnt * (riserIndex + 0.5));
            } else {
                x = (int) (x - riserwidth / 2d + riserwidth / riserCnt * (riserCnt - riserIndex - 0.5));
            }
            riserwidth /= riserCnt;
        }
        if (xAxis.isHorizontalAxis()) {
            // adjust coordinate for negative series
            if (y > yAxis.getPixelCoordinate(0)) {
                y = yAxis.getPixelCoordinate(0);
            }
            int width = (int) Math.ceil(riserwidth);
            width = (width == 0) ? 1 : width;
            rectangles[i] = getVisibleRectangle((int) Math.floor(x - riserwidth / 2d), y, width, (int) riserHeight);
        } else {
            // adjust coordinate for negative series
            if (y < yAxis.getPixelCoordinate(0)) {
                y = yAxis.getPixelCoordinate(0);
            }
            int height = (int) Math.ceil(riserwidth);
            height = (height == 0) ? 1 : height;
            rectangles[i] = getVisibleRectangle((int) (y - riserHeight), (int) Math.floor(x - riserwidth / 2d), (int) riserHeight, height);
        }
    }
    return rectangles;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Range(org.eclipse.swtchart.Range) Axis(org.eclipse.swtchart.internal.axis.Axis) Point(org.eclipse.swt.graphics.Point)

Example 5 with Axis

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

the class ChartLayout method initAxisSize.

/**
 * Initializes the size of axes.
 */
private void initAxisSize() {
    axisLayoutDataMap.clear();
    for (Axis axis : axes) {
        AxisLayoutData layoutData = new AxisLayoutData(axis);
        if (layoutData.titleLayoutdata == null || layoutData.tickLabelsLayoutdata == null || layoutData.tickMarksLayoutdata == null) {
            continue;
        }
        axisLayoutDataMap.put(axis, layoutData);
        Position position = axis.getPosition();
        if (position == Position.Primary && axis.isHorizontalAxis()) {
            bottomAxisHeight += layoutData.titleLayoutdata.heightHint + layoutData.tickLabelsLayoutdata.heightHint + layoutData.tickMarksLayoutdata.heightHint;
        } else if (position == Position.Secondary && axis.isHorizontalAxis()) {
            topAxisHeight += layoutData.titleLayoutdata.heightHint + layoutData.tickLabelsLayoutdata.heightHint + layoutData.tickMarksLayoutdata.heightHint;
        } else if (position == Position.Primary && !axis.isHorizontalAxis()) {
            leftAxisWidth += layoutData.titleLayoutdata.widthHint + layoutData.tickLabelsLayoutdata.widthHint + layoutData.tickMarksLayoutdata.widthHint;
        } else if (position == Position.Secondary && !axis.isHorizontalAxis()) {
            rightAxisWidth += layoutData.titleLayoutdata.widthHint + layoutData.tickLabelsLayoutdata.widthHint + layoutData.tickMarksLayoutdata.widthHint;
        }
    }
}
Also used : Position(org.eclipse.swtchart.IAxis.Position) 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