Search in sources :

Example 16 with Range

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

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

the class BarSeries method getBoundsForCompressedSeries.

/**
 * Gets the array of bar rectangles for compressed series.
 *
 * @return the array of bar rectangles for compressed series
 */
private Rectangle[] getBoundsForCompressedSeries() {
    Axis xAxis = (Axis) chart.getAxisSet().getXAxis(xAxisId);
    Axis yAxis = (Axis) chart.getAxisSet().getYAxis(yAxisId);
    // get x and y series
    double[] xseries = compressor.getCompressedXSeries();
    double[] yseries = compressor.getCompressedYSeries();
    int[] indexes = compressor.getCompressedIndexes();
    if (xAxis.isValidCategoryAxis()) {
        for (int i = 0; i < xseries.length; i++) {
            xseries[i] = indexes[i];
        }
    }
    Rectangle[] rectangles = new Rectangle[xseries.length];
    Range xRange = xAxis.getRange();
    Range yRange = yAxis.getRange();
    for (int i = 0; i < xseries.length; i++) {
        int x = xAxis.getPixelCoordinate(xseries[i]);
        int y = yAxis.getPixelCoordinate(isValidStackSeries() ? stackSeries[indexes[i]] : yseries[i]);
        double baseYCoordinate = yAxis.getRange().lower > 0 ? yAxis.getRange().lower : 0;
        double riserwidth = getRiserWidth(xseries, i, xAxis, xRange.lower, xRange.upper);
        double riserHeight = Math.abs(yAxis.getPixelCoordinate(yseries[i], yRange.lower, yRange.upper) - yAxis.getPixelCoordinate(yAxis.isLogScaleEnabled() ? yRange.lower : baseYCoordinate, yRange.lower, yRange.upper));
        // adjust riser x coordinate and riser width for multiple series
        int riserCnt = xAxis.getNumRisers();
        if (riserCnt > 1) {
            if (xAxis.isHorizontalAxis()) {
                x = (int) (x - riserwidth / 2d + riserwidth / riserCnt * (riserIndex + 0.5));
            } else {
                x = (int) (x - riserwidth / 2d + riserwidth / riserCnt * (riserCnt - riserIndex - 0.5));
            }
            riserwidth /= riserCnt;
        }
        if (xAxis.isHorizontalAxis()) {
            // adjust coordinate for negative series
            if (y > yAxis.getPixelCoordinate(0)) {
                y = yAxis.getPixelCoordinate(0);
            }
            int width = (int) Math.ceil(riserwidth);
            width = (width == 0) ? 1 : width;
            rectangles[i] = getVisibleRectangle((int) Math.floor(x - riserwidth / 2d), y, width, (int) riserHeight);
        } else {
            // adjust coordinate for negative series
            if (y < yAxis.getPixelCoordinate(0)) {
                y = yAxis.getPixelCoordinate(0);
            }
            int height = (int) Math.ceil(riserwidth);
            height = (height == 0) ? 1 : height;
            rectangles[i] = getVisibleRectangle((int) (y - riserHeight), (int) Math.floor(x - riserwidth / 2d), (int) riserHeight, height);
        }
    }
    return rectangles;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Range(org.eclipse.swtchart.Range) Axis(org.eclipse.swtchart.internal.axis.Axis) Point(org.eclipse.swt.graphics.Point)

Example 18 with Range

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

the class LineChart method setRange.

/**
 * Sets the axis range.
 *
 * @param range
 *            the axis range in pixels
 * @param axis
 *            the axis to set range
 */
private void setRange(Point range, IAxis axis) {
    double min = axis.getDataCoordinate(range.x);
    double max = axis.getDataCoordinate(range.y);
    axis.setRange(new Range(min, max));
}
Also used : Range(org.eclipse.swtchart.Range)

Example 19 with Range

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

the class LineChart method setTimeRange.

/**
 * Set time range
 *
 * @param from start time
 * @param to end time
 */
public void setTimeRange(final Date from, final Date to) {
    if (zoomedToSelectionX) {
        delayedRangeFrom = from;
        delayedRangeTo = to;
        return;
    }
    delayedRangeFrom = null;
    delayedRangeTo = null;
    timeFrom = from.getTime();
    timeTo = to.getTime();
    getAxisSet().getXAxis(0).setRange(new Range(timeFrom, timeTo));
    int seconds = (int) ((timeTo - timeFrom) / 1000);
    DateFormat format;
    int angle;
    if (seconds <= 600) {
        format = DateFormatFactory.getTimeFormat();
        angle = 0;
    } else if (seconds <= 86400) {
        format = DateFormatFactory.getShortTimeFormat();
        angle = 0;
    } else if (seconds <= 86400 * 7) {
        format = new SimpleDateFormat("E " + DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT));
        angle = 0;
    } else {
        format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
        angle = 45;
    }
    IAxisTick xTick = getAxisSet().getXAxis(0).getTick();
    xTick.setFormat(format);
    xTick.setTickLabelAngle(angle);
}
Also used : IAxisTick(org.eclipse.swtchart.IAxisTick) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Range(org.eclipse.swtchart.Range) SimpleDateFormat(java.text.SimpleDateFormat) DataPoint(org.netxms.nxmc.modules.charts.api.DataPoint) Point(org.eclipse.swt.graphics.Point)

Example 20 with Range

use of org.eclipse.swtchart.Range in project org.eclipse.linuxtools by eclipse-linuxtools.

the class PieChartPaintListener method getSliceIndexFromPosition.

/**
 * Given a set of 2D pixel coordinates (typically those of a mouse cursor), return the
 * index of the given pie's slice that those coordinates reside in.
 * @param chartnum The id of the chart.
 * @param x The x-coordinate to test.
 * @param y The y-coordinate to test.
 * @return The slice that contains the point with coordinates (x,y).
 * @since 2.0
 */
public int getSliceIndexFromPosition(int chartnum, int x, int y) {
    Range range = chart.getAxisSet().getXAxis(0).getRange();
    chartnum -= (int) range.lower;
    if (chartnum >= pieCenters.length || chartnum < 0) {
        return -1;
    }
    // Only continue if the point is inside the pie circle
    double rad = Math.sqrt(Math.pow(pieCenters[chartnum].x - x, 2) + Math.pow(pieCenters[chartnum].y - y, 2));
    if (2 * rad > pieWidth) {
        return -1;
    }
    // Angle is relative to 12:00 position, increases clockwise
    double angle = Math.acos((pieCenters[chartnum].y - y) / rad) / Math.PI * 180.0;
    if (x - pieCenters[chartnum].x < 0) {
        angle = 360 - angle;
    }
    if (pieSliceAngles[chartnum].length == 0 || angle < pieSliceAngles[chartnum][0]) {
        return 0;
    }
    for (int s = 0; s < pieSliceAngles[chartnum].length - 1; s++) {
        if (pieSliceAngles[chartnum][s] <= angle && angle < pieSliceAngles[chartnum][s + 1]) {
            return s + 1;
        }
    }
    return pieSliceAngles[chartnum].length;
}
Also used : Range(org.eclipse.swtchart.Range) Point(org.eclipse.swt.graphics.Point)

Aggregations

Range (org.eclipse.swtchart.Range)53 IAxis (org.eclipse.swtchart.IAxis)20 Point (org.eclipse.swt.graphics.Point)13 ISeries (org.eclipse.swtchart.ISeries)9 GridData (org.eclipse.swt.layout.GridData)5 IAxisSet (org.eclipse.swtchart.IAxisSet)5 DecimalFormat (java.text.DecimalFormat)4 StyleRange (org.eclipse.swt.custom.StyleRange)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 Event (org.eclipse.swt.widgets.Event)4 MouseEvent (org.eclipse.swt.events.MouseEvent)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 Chart (org.eclipse.swtchart.Chart)3 ISeriesSet (org.eclipse.swtchart.ISeriesSet)3 AxisRange (org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange)3 ParseException (java.text.ParseException)2 PaintEvent (org.eclipse.swt.events.PaintEvent)2 PaintListener (org.eclipse.swt.events.PaintListener)2 Color (org.eclipse.swt.graphics.Color)2