Search in sources :

Example 16 with IAxis

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

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

the class ChartLayout method computeAxisSize.

/**
 * Computes the size of axes updating tick labels.
 *
 * @param r
 *            the rectangle to layout
 */
private void computeAxisSize(Rectangle r) {
    // update vertical axis tick labels
    updateVerticalAxisTick();
    // compute axis width
    for (IAxis axis : verticalAxes) {
        int tickAreaWidth = Axis.MARGIN;
        if (axis.getTick().isVisible()) {
            tickAreaWidth = ((Axis) axis).getTick().getAxisTickLabels().getTickLabelMaxLength();
        }
        AxisLayoutData axisLayout = axisLayoutDataMap.get(axis);
        axisLayout.tickLabelsLayoutdata.widthHint += tickAreaWidth;
        if (axis.getPosition() == Position.Primary) {
            leftAxisWidth += tickAreaWidth;
        } else {
            rightAxisWidth += tickAreaWidth;
        }
    }
    // compute axis height
    for (IAxis axis : horizontalAxes) {
        if (axis.getTick().isVisible()) {
            continue;
        }
        if (axis.getPosition() == Position.Primary) {
            bottomAxisHeight += Axis.MARGIN;
        } else {
            topAxisHeight += Axis.MARGIN;
        }
    }
    // update plot area width
    computePlotAreaSize(r);
    // update horizontal axis tick labels
    updateHorizontalAxisTick();
}
Also used : IAxis(org.eclipse.swtchart.IAxis) Point(org.eclipse.swt.graphics.Point)

Example 18 with IAxis

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

the class SeriesSet method compressAllSeries.

/**
 * Compresses all series data.
 */
public void compressAllSeries() {
    if (!chart.isCompressEnabled()) {
        return;
    }
    CompressConfig config = new CompressConfig();
    final int PRECISION = 2;
    Point p = chart.getPlotArea().getSize();
    int width = p.x * PRECISION;
    int height = p.y * PRECISION;
    config.setSizeInPixel(width, height);
    for (ISeries series : getSeries()) {
        int xAxisId = series.getXAxisId();
        int yAxisId = series.getYAxisId();
        IAxis xAxis = chart.getAxisSet().getXAxis(xAxisId);
        IAxis yAxis = chart.getAxisSet().getYAxis(yAxisId);
        if (xAxis == null || yAxis == null) {
            continue;
        }
        Range xRange = xAxis.getRange();
        Range yRange = yAxis.getRange();
        if (xRange == null || yRange == null) {
            continue;
        }
        double xMin = xRange.lower;
        double xMax = xRange.upper;
        double yMin = yRange.lower;
        double yMax = yRange.upper;
        config.setXLogScale(xAxis.isLogScaleEnabled());
        config.setYLogScale(yAxis.isLogScaleEnabled());
        double lower = xMin - (xMax - xMin) * 0.015;
        double upper = xMax + (xMax - xMin) * 0.015;
        if (xAxis.isLogScaleEnabled()) {
            lower = ((Series) series).getXRange().lower;
        }
        config.setXRange(lower, upper);
        lower = yMin - (yMax - yMin) * 0.015;
        upper = yMax + (yMax - yMin) * 0.015;
        if (yAxis.isLogScaleEnabled()) {
            lower = ((Series) series).getYRange().lower;
        }
        config.setYRange(lower, upper);
        ICompress compressor = ((Series) series).getCompressor();
        compressor.compress(config);
    }
}
Also used : ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) Range(org.eclipse.swtchart.Range) CompressConfig(org.eclipse.swtchart.internal.compress.CompressConfig) ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis) ICompress(org.eclipse.swtchart.internal.compress.ICompress)

Example 19 with IAxis

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

the class LineChart method endSelection.

/**
 * Selection end handler
 */
private void endSelection() {
    if (!selectionActive)
        return;
    selectionActive = false;
    final IPlotArea plotArea = getPlotArea();
    plotArea.removeMouseMoveListener(moveListener);
    if (selection.isUsableSize()) {
        for (IAxis axis : getAxisSet().getAxes()) {
            Point range = null;
            if ((getOrientation() == SWT.HORIZONTAL && axis.getDirection() == Direction.X) || (getOrientation() == SWT.VERTICAL && axis.getDirection() == Direction.Y)) {
                range = selection.getHorizontalRange();
            } else {
                range = selection.getVerticalRange();
            }
            if (range != null && range.x != range.y) {
                setRange(range, axis);
            }
        }
        zoomedToSelectionX = true;
        zoomedToSelectionY = true;
    }
    selection.dispose();
    redraw();
}
Also used : IPlotArea(org.eclipse.swtchart.IPlotArea) DataPoint(org.netxms.nxmc.modules.charts.api.DataPoint) Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis)

Example 20 with IAxis

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

the class PieChart method renderLabels.

protected void renderLabels(PaintEvent e) {
    for (ISeries<?> series : getSeriesSet().getSeries()) {
        if (series instanceof ICircularSeries) {
            IAxis xAxis = getAxisSet().getXAxis(series.getXAxisId());
            IAxis yAxis = getAxisSet().getYAxis(series.getYAxisId());
            List<Node> nodes = ((ICircularSeries<?>) series).getRootNode().getChildren();
            if (!nodes.isEmpty()) {
                for (Node node : nodes) {
                    renderNodeLabel(node, (ICircularSeries<?>) series, e.gc, xAxis, yAxis);
                }
            }
        }
    }
}
Also used : Node(org.eclipse.swtchart.model.Node) ICircularSeries(org.eclipse.swtchart.ICircularSeries) 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