Search in sources :

Example 1 with Series

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

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 : ISeries(org.eclipse.swtchart.ISeries) Series(org.eclipse.swtchart.internal.series.Series) Range(org.eclipse.swtchart.Range) ISeries(org.eclipse.swtchart.ISeries)

Example 2 with Series

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

the class PlotArea method paintControl.

/*
	 * @see PaintListener#paintControl(PaintEvent)
	 */
public void paintControl(PaintEvent e) {
    Point p = getSize();
    GC gc = e.gc;
    // draw the plot area background
    Color oldBackground = gc.getBackground();
    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);
        }
    }
    e.gc.setBackground(oldBackground);
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) ILineSeries(org.eclipse.swtchart.ILineSeries) ISeries(org.eclipse.swtchart.ISeries) Series(org.eclipse.swtchart.internal.series.Series) ICustomPaintListener(org.eclipse.swtchart.ICustomPaintListener) IBarSeries(org.eclipse.swtchart.IBarSeries) Color(org.eclipse.swt.graphics.Color) ILineSeries(org.eclipse.swtchart.ILineSeries) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) ISeries(org.eclipse.swtchart.ISeries) IAxis(org.eclipse.swtchart.IAxis)

Aggregations

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