Search in sources :

Example 1 with Series

use of org.swtchart.internal.series.Series in project netxms by netxms.

the class Axis method adjustRange.

/**
 * Adjusts the axis range to the series belonging to the axis.
 *
 * @param update
 *           true if updating chart layout
 */
public void adjustRange(boolean update) {
    if (isValidCategoryAxis()) {
        setRange(new Range(0, categorySeries.length - 1));
        return;
    }
    double minimum = Double.NaN;
    double maximum = Double.NaN;
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        int axisId = direction == Direction.X ? series.getXAxisId() : series.getYAxisId();
        if (!series.isVisible() || getId() != axisId) {
            continue;
        }
        // get axis length
        int length;
        if (isHorizontalAxis) {
            length = chart.getPlotArea().getSize().x;
        } else {
            length = chart.getPlotArea().getSize().y;
        }
        // get min and max value of series
        Range range = ((Series) series).getAdjustedRange(this, length);
        if (Double.isNaN(minimum) || range.lower < minimum) {
            minimum = range.lower;
        }
        if (Double.isNaN(maximum) || range.upper > maximum) {
            maximum = range.upper;
        }
    }
    // set adjusted range
    if (!Double.isNaN(minimum) && !Double.isNaN(maximum)) {
        if (minimum == maximum) {
            double margin = (minimum == 0) ? 1d : Math.abs(minimum / 2d);
            minimum -= margin;
            maximum += margin;
        }
        setRange(new Range(minimum, maximum), update);
    }
}
Also used : Series(org.swtchart.internal.series.Series) ISeries(org.swtchart.ISeries) Range(org.swtchart.Range) ISeries(org.swtchart.ISeries)

Example 2 with Series

use of org.swtchart.internal.series.Series in project netxms by netxms.

the class PlotArea method paintControl.

/*
	 * @see PaintListener#paintControl(PaintEvent)
	 */
public void paintControl(PaintEvent e) {
    Point p = getSize();
    final GC gc = e.gc;
    // draw the plot area background
    gc.setBackground(getBackground());
    gc.fillRectangle(0, 0, p.x, p.y);
    // draw grid
    for (IAxis axis : chart.getAxisSet().getAxes()) {
        ((Grid) axis.getGrid()).draw(gc, p.x, p.y);
    }
    // draw behind series
    for (ICustomPaintListener listener : paintListeners) {
        if (listener.drawBehindSeries()) {
            listener.paintControl(e);
        }
    }
    // draw series. The line series should be drawn on bar series.
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        if (series instanceof IBarSeries) {
            ((Series) series).draw(gc, p.x, p.y);
        }
    }
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        if (series instanceof ILineSeries) {
            ((Series) series).draw(gc, p.x, p.y);
        }
    }
    // draw over series
    for (ICustomPaintListener listener : paintListeners) {
        if (!listener.drawBehindSeries()) {
            listener.paintControl(e);
        }
    }
}
Also used : Series(org.swtchart.internal.series.Series) ISeries(org.swtchart.ISeries) IBarSeries(org.swtchart.IBarSeries) ILineSeries(org.swtchart.ILineSeries) ICustomPaintListener(org.swtchart.ICustomPaintListener) IBarSeries(org.swtchart.IBarSeries) ILineSeries(org.swtchart.ILineSeries) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) ISeries(org.swtchart.ISeries) IAxis(org.swtchart.IAxis)

Aggregations

ISeries (org.swtchart.ISeries)2 Series (org.swtchart.internal.series.Series)2 GC (org.eclipse.swt.graphics.GC)1 Point (org.eclipse.swt.graphics.Point)1 IAxis (org.swtchart.IAxis)1 IBarSeries (org.swtchart.IBarSeries)1 ICustomPaintListener (org.swtchart.ICustomPaintListener)1 ILineSeries (org.swtchart.ILineSeries)1 Range (org.swtchart.Range)1