Search in sources :

Example 16 with ISeries

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

the class Legend method paintControl.

/*
	 * @see PaintListener#paintControl(PaintEvent)
	 */
public void paintControl(PaintEvent e) {
    if (!visible) {
        return;
    }
    GC gc = e.gc;
    gc.setFont(getFont());
    ISeries[] seriesArray = chart.getSeriesSet().getSeries();
    if (seriesArray.length == 0) {
        return;
    }
    // draw frame
    gc.fillRectangle(0, 0, getSize().x - 1, getSize().y - 1);
    gc.setLineStyle(SWT.LINE_SOLID);
    gc.setLineWidth(1);
    gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
    gc.drawRectangle(0, 0, getSize().x - 1, getSize().y - 1);
    // draw content
    for (int i = 0; i < seriesArray.length; i++) {
        if (!seriesArray[i].isVisibleInLegend()) {
            continue;
        }
        // draw plot line, symbol etc
        String id = seriesArray[i].getId();
        Rectangle r = cellBounds.get(id);
        drawSymbol(gc, (Series) seriesArray[i], new Rectangle(r.x + MARGIN, r.y + MARGIN, SYMBOL_WIDTH, r.height - MARGIN * 2));
        // draw label
        String label = getLegendLabel(seriesArray[i]);
        gc.setBackground(getBackground());
        gc.setForeground(getForeground());
        gc.drawText(label, r.x + SYMBOL_WIDTH + MARGIN * 2, r.y, true);
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) GC(org.eclipse.swt.graphics.GC) ISeries(org.eclipse.swtchart.ISeries)

Example 17 with ISeries

use of org.eclipse.swtchart.ISeries 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 18 with ISeries

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

the class SeriesSet method setStackSeries.

/**
 * Sets the stack series.
 *
 * @param stackSeries
 *            the stack series
 * @param series
 *            the series
 */
private static void setStackSeries(double[] stackSeries, ISeries series) {
    double[] ySeries = series.getYSeries();
    if (ySeries == null || stackSeries == null) {
        return;
    }
    for (int i = 0; i < stackSeries.length; i++) {
        if (i >= ySeries.length) {
            break;
        }
        stackSeries[i] = BigDecimal.valueOf(stackSeries[i]).add(BigDecimal.valueOf(ySeries[i])).doubleValue();
    }
    double[] copiedStackSeries = new double[stackSeries.length];
    System.arraycopy(stackSeries, 0, copiedStackSeries, 0, stackSeries.length);
    ((Series) series).setStackSeries(copiedStackSeries);
}
Also used : ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point)

Example 19 with ISeries

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

the class SeriesSet method getSeries.

/*
	 * @see ISeriesSet#getSeries()
	 */
public ISeries[] getSeries() {
    Set<String> keys = seriesMap.keySet();
    ISeries[] series = new ISeries[keys.size()];
    int i = 0;
    for (String key : keys) {
        series[i++] = seriesMap.get(key);
    }
    return series;
}
Also used : ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point)

Example 20 with ISeries

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

the class SeriesSet method updateCompressor.

/**
 * Updates the compressor associated with the given axis.
 * <p>
 * In most cases, compressor is updated when series is changed. However,
 * there is a case that compressor has to be updated with the changes in
 * axis.
 *
 * @param axis
 *            the axis
 */
public void updateCompressor(Axis axis) {
    for (ISeries series : getSeries()) {
        int axisId = (axis.getDirection() == Direction.X) ? series.getXAxisId() : series.getYAxisId();
        if (axisId != axis.getId()) {
            continue;
        }
        ICompress compressor = ((Series) series).getCompressor();
        if (axis.isValidCategoryAxis()) {
            String[] categorySeries = axis.getCategorySeries();
            if (categorySeries == null) {
                continue;
            }
            double[] xSeries = new double[categorySeries.length];
            for (int i = 0; i < xSeries.length; i++) {
                xSeries[i] = i;
            }
            compressor.setXSeries(xSeries);
        } else if (((Series) series).getXSeries() != null) {
            compressor.setXSeries(((Series) series).getXSeries());
        }
    }
    compressAllSeries();
}
Also used : ISeries(org.eclipse.swtchart.ISeries) ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) ICompress(org.eclipse.swtchart.internal.compress.ICompress)

Aggregations

ISeries (org.eclipse.swtchart.ISeries)60 Point (org.eclipse.swt.graphics.Point)21 ISeriesSet (org.eclipse.swtchart.ISeriesSet)11 Chart (org.eclipse.swtchart.Chart)10 IAxis (org.eclipse.swtchart.IAxis)9 Range (org.eclipse.swtchart.Range)9 BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)8 Color (org.eclipse.swt.graphics.Color)5 IBarSeries (org.eclipse.swtchart.IBarSeries)5 ILineSeries (org.eclipse.swtchart.ILineSeries)5 IAxisSettings (org.eclipse.swtchart.extensions.core.IAxisSettings)5 Rectangle (org.eclipse.swt.graphics.Rectangle)4 MouseEvent (org.eclipse.swt.events.MouseEvent)3 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)3 GC (org.eclipse.swt.graphics.GC)3 Test (org.junit.Test)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2