Search in sources :

Example 6 with Range

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

the class RangeSelector method adjustRanges.

public void adjustRanges(boolean redraw) {
    BaseChart baseChart = scrollableChart.getBaseChart();
    // 
    int indexX = (comboScaleX.getSelectionIndex() >= 0) ? comboScaleX.getSelectionIndex() : BaseChart.ID_PRIMARY_X_AXIS;
    int indexY = (comboScaleY.getSelectionIndex() >= 0) ? comboScaleY.getSelectionIndex() : BaseChart.ID_PRIMARY_Y_AXIS;
    IAxis xAxis = baseChart.getAxisSet().getXAxis(indexX);
    IAxis yAxis = baseChart.getAxisSet().getYAxis(indexY);
    Range rangeX = xAxis.getRange();
    Range rangeY = yAxis.getRange();
    // 
    DecimalFormat decimalFormatX = baseChart.getDecimalFormat(IExtendedChart.X_AXIS, indexX);
    DecimalFormat decimalFormatY = baseChart.getDecimalFormat(IExtendedChart.Y_AXIS, indexY);
    // 
    if (rangeX != null && rangeY != null) {
        /*
			 * Update the text boxes.
			 */
        textStartX.setText(decimalFormatX.format(rangeX.lower));
        textStopX.setText(decimalFormatX.format(rangeX.upper));
        textStartY.setText(decimalFormatY.format(rangeY.lower));
        textStopY.setText(decimalFormatY.format(rangeY.upper));
        /*
			 * Redraw the base chart.
			 */
        if (redraw) {
            baseChart.redraw();
        }
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) Range(org.eclipse.swtchart.Range) IAxis(org.eclipse.swtchart.IAxis)

Example 7 with Range

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

the class ScrollableChart method calculateShiftedRange.

private Range calculateShiftedRange(Range range, Slider slider) {
    int selection = slider.getSelection();
    double min = selection;
    double max = (range.upper - range.lower) + selection;
    return new Range(min, max);
}
Also used : Range(org.eclipse.swtchart.Range) StyleRange(org.eclipse.swt.custom.StyleRange) Point(org.eclipse.swt.graphics.Point)

Example 8 with Range

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

the class ZoomEvent method handleEvent.

@Override
public void handleEvent(BaseChart baseChart, Event event) {
    IAxisSet axisSet = baseChart.getAxisSet();
    IAxis xAxis = axisSet.getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
    IAxis yAxis = axisSet.getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
    // 
    RangeRestriction rangeRestriction = baseChart.getRangeRestriction();
    if (baseChart.isZoomXAndY(rangeRestriction)) {
        /*
			 * X and Y zoom.
			 */
        baseChart.zoomX(xAxis, event);
        baseChart.zoomY(yAxis, event);
    } else {
        /*
			 * X or Y zoom.
			 */
        if (rangeRestriction.isXZoomOnly()) {
            baseChart.zoomX(xAxis, event);
        } else if (rangeRestriction.isYZoomOnly()) {
            baseChart.zoomY(yAxis, event);
        }
    }
    /*
		 * Adjust the range if it shall not exceed the initial
		 * min and max values.
		 */
    if (rangeRestriction.isRestrictZoom()) {
        /*
			 * Adjust the primary axes.
			 * The secondary axes are adjusted by setting the range.
			 */
        Range rangeX = xAxis.getRange();
        Range rangeY = yAxis.getRange();
        baseChart.setRange(xAxis, rangeX.lower, rangeX.upper, true);
        baseChart.setRange(yAxis, rangeY.lower, rangeY.upper, true);
    } else {
        /*
			 * Update the secondary axes.
			 */
        baseChart.adjustSecondaryXAxes();
        baseChart.adjustSecondaryYAxes();
    }
    // 
    baseChart.fireUpdateCustomRangeSelectionHandlers(event);
    baseChart.redraw();
}
Also used : IAxisSet(org.eclipse.swtchart.IAxisSet) RangeRestriction(org.eclipse.swtchart.extensions.core.RangeRestriction) Range(org.eclipse.swtchart.Range) IAxis(org.eclipse.swtchart.IAxis)

Example 9 with Range

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

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

the class Axis method zoomIn.

/*
	 * @see IAxis#zoomIn(double)
	 */
public void zoomIn(double coordinate) {
    double lower = min;
    double upper = max;
    if (isValidCategoryAxis()) {
        if (lower != upper) {
            if ((min + max) / 2d < coordinate) {
                lower = min + 1;
            } else if (coordinate < (min + max) / 2d) {
                upper = max - 1;
            } else {
                lower = min + 1;
                upper = max - 1;
            }
        }
    } else if (isLogScaleEnabled()) {
        double digitMin = Math.log10(min);
        double digitMax = Math.log10(max);
        double digitCoordinate = Math.log10(coordinate);
        lower = Math.pow(10, digitMin + 2 * SCROLL_RATIO * (digitCoordinate - digitMin));
        upper = Math.pow(10, digitMax + 2 * SCROLL_RATIO * (digitCoordinate - digitMax));
    } else {
        lower = min + 2 * ZOOM_RATIO * (coordinate - min);
        upper = max + 2 * ZOOM_RATIO * (coordinate - max);
    }
    setRange(new Range(lower, upper));
}
Also used : Range(org.eclipse.swtchart.Range)

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