Search in sources :

Example 1 with ICompress

use of org.eclipse.swtchart.internal.compress.ICompress 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 2 with ICompress

use of org.eclipse.swtchart.internal.compress.ICompress 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

Point (org.eclipse.swt.graphics.Point)2 ISeries (org.eclipse.swtchart.ISeries)2 ICompress (org.eclipse.swtchart.internal.compress.ICompress)2 IAxis (org.eclipse.swtchart.IAxis)1 Range (org.eclipse.swtchart.Range)1 CompressConfig (org.eclipse.swtchart.internal.compress.CompressConfig)1