Search in sources :

Example 46 with IAxis

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

the class ScrollableChart method setSliderSelection.

private void setSliderSelection(boolean calculateIncrement) {
    IAxis xAxis = baseChart.getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
    IAxis yAxis = baseChart.getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
    // 
    if (xAxis != null && yAxis != null) {
        /*
			 * Take care of Horizontal or Vertical orientation.
			 */
        int minX = (int) baseChart.getMinX();
        int maxX = (int) baseChart.getMaxX();
        int minY = (int) baseChart.getMinY();
        int maxY = (int) baseChart.getMaxY();
        // 
        int minSelectionX = (int) xAxis.getRange().lower;
        int maxSelectionX = (int) xAxis.getRange().upper;
        int thumbSelectionX = (int) (maxSelectionX - minSelectionX);
        // 
        int minSelectionY = (int) yAxis.getRange().lower;
        int maxSelectionY = (int) yAxis.getRange().upper;
        int thumbSelectionY = (int) (maxSelectionY - minSelectionY);
        // 
        boolean isHorizontal = isOrientationHorizontal();
        // 
        sliderVertical.setMinimum((isHorizontal) ? minY : minX);
        sliderVertical.setMaximum((isHorizontal) ? maxY : maxX);
        sliderVertical.setThumb((isHorizontal) ? thumbSelectionY : thumbSelectionX);
        sliderVertical.setSelection((isHorizontal) ? minSelectionY : minSelectionX);
        // 
        sliderHorizontal.setMinimum((isHorizontal) ? minX : minY);
        sliderHorizontal.setMaximum((isHorizontal) ? maxX : maxY);
        sliderHorizontal.setThumb((isHorizontal) ? thumbSelectionX : thumbSelectionY);
        sliderHorizontal.setSelection((isHorizontal) ? minSelectionX : minSelectionY);
        /*
			 * Calculate the increment.
			 */
        if (calculateIncrement) {
            int thumbX = maxX - minX;
            int thumbY = maxY - minY;
            int incrementX = calculateIncrement(thumbX, baseChart.getSeriesMaxDataPoints());
            int incrementY = calculateIncrement(thumbY, baseChart.getSeriesMaxDataPoints());
            sliderVertical.setIncrement((isHorizontal) ? incrementY : incrementX);
            sliderHorizontal.setPageIncrement((isHorizontal) ? incrementX : incrementY);
        }
        /*
			 * Set the range info and update linked charts.
			 */
        displayRangeInfo(xAxis, yAxis);
    }
}
Also used : IAxis(org.eclipse.swtchart.IAxis) Point(org.eclipse.swt.graphics.Point)

Example 47 with IAxis

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

the class ScrollableChart method addPrimaryAxisX.

private void addPrimaryAxisX(IChartSettings chartSettings) {
    IAxisSet axisSet = baseChart.getAxisSet();
    IAxis xAxisPrimary = axisSet.getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
    IPrimaryAxisSettings primaryAxisSettings = chartSettings.getPrimaryAxisSettingsX();
    setAxisSettings(xAxisPrimary, primaryAxisSettings);
    baseChart.putXAxisSettings(BaseChart.ID_PRIMARY_X_AXIS, primaryAxisSettings);
}
Also used : IAxisSet(org.eclipse.swtchart.IAxisSet) IAxis(org.eclipse.swtchart.IAxis)

Example 48 with IAxis

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

the class ScrollableChart method createSliderVertical.

private void createSliderVertical(Composite parent) {
    sliderVertical = new Slider(parent, SWT.VERTICAL);
    sliderVertical.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    // See Bug #511257
    sliderVertical.setOrientation(SWT.RIGHT_TO_LEFT);
    sliderVertical.setVisible(true);
    sliderVertical.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            IAxis xAxis = baseChart.getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
            IAxis yAxis = baseChart.getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
            // 
            if (xAxis != null && yAxis != null) {
                Range range = calculateShiftedRange(yAxis.getRange(), sliderVertical);
                if (isOrientationHorizontal()) {
                    yAxis.setRange(range);
                    baseChart.adjustMinMaxRange(yAxis);
                    adjustSecondaryYAxes();
                } else {
                    xAxis.setRange(range);
                    baseChart.adjustMinMaxRange(xAxis);
                    adjustSecondaryXAxes();
                }
                // 
                displayRangeInfo(xAxis, yAxis);
                fireUpdateCustomRangeSelectionHandlers(event);
                baseChart.redraw();
            }
        }
    });
}
Also used : PaintListener(org.eclipse.swt.events.PaintListener) Listener(org.eclipse.swt.widgets.Listener) Slider(org.eclipse.swt.widgets.Slider) GridData(org.eclipse.swt.layout.GridData) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) Range(org.eclipse.swtchart.Range) StyleRange(org.eclipse.swt.custom.StyleRange) IAxis(org.eclipse.swtchart.IAxis)

Example 49 with IAxis

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

the class ScrollableChart method createSliderHorizontal.

private void createSliderHorizontal(Composite parent) {
    sliderHorizontal = new Slider(parent, SWT.HORIZONTAL);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    sliderHorizontal.setLayoutData(gridData);
    sliderHorizontal.setOrientation(SWT.LEFT_TO_RIGHT);
    sliderHorizontal.setVisible(true);
    sliderHorizontal.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            IAxis xAxis = baseChart.getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
            IAxis yAxis = baseChart.getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
            // 
            if (xAxis != null && yAxis != null) {
                Range range = calculateShiftedRange(xAxis.getRange(), sliderHorizontal);
                if (isOrientationHorizontal()) {
                    xAxis.setRange(range);
                    baseChart.adjustMinMaxRange(xAxis);
                    adjustSecondaryXAxes();
                } else {
                    yAxis.setRange(range);
                    baseChart.adjustMinMaxRange(yAxis);
                    adjustSecondaryYAxes();
                }
                // 
                displayRangeInfo(xAxis, yAxis);
                fireUpdateCustomRangeSelectionHandlers(event);
                baseChart.redraw();
            }
        }
    });
}
Also used : PaintListener(org.eclipse.swt.events.PaintListener) Listener(org.eclipse.swt.widgets.Listener) Slider(org.eclipse.swt.widgets.Slider) GridData(org.eclipse.swt.layout.GridData) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) Range(org.eclipse.swtchart.Range) StyleRange(org.eclipse.swt.custom.StyleRange) IAxis(org.eclipse.swtchart.IAxis)

Example 50 with IAxis

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

the class ScrollableChart method addSecondaryAxesX.

private void addSecondaryAxesX(IChartSettings chartSettings) {
    IAxisSet axisSet = baseChart.getAxisSet();
    for (int id : axisSet.getXAxisIds()) {
        if (id != BaseChart.ID_PRIMARY_X_AXIS) {
            axisSet.deleteXAxis(id);
        }
    }
    /*
		 * Remove all items except the primary axis settings.
		 */
    baseChart.removeXAxisSettings();
    /*
		 * Add the axis settings.
		 */
    for (ISecondaryAxisSettings secondaryAxisSettings : chartSettings.getSecondaryAxisSettingsListX()) {
        int xAxisId = axisSet.createXAxis();
        IAxis xAxisSecondary = axisSet.getXAxis(xAxisId);
        setAxisSettings(xAxisSecondary, secondaryAxisSettings);
        baseChart.putXAxisSettings(xAxisId, secondaryAxisSettings);
    }
}
Also used : IAxisSet(org.eclipse.swtchart.IAxisSet) Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis)

Aggregations

IAxis (org.eclipse.swtchart.IAxis)64 Point (org.eclipse.swt.graphics.Point)27 Range (org.eclipse.swtchart.Range)19 IAxisSet (org.eclipse.swtchart.IAxisSet)10 Chart (org.eclipse.swtchart.Chart)7 ISeries (org.eclipse.swtchart.ISeries)7 MouseEvent (org.eclipse.swt.events.MouseEvent)5 ILineSeries (org.eclipse.swtchart.ILineSeries)5 Color (org.eclipse.swt.graphics.Color)4 GridData (org.eclipse.swt.layout.GridData)4 DecimalFormat (java.text.DecimalFormat)3 PaintEvent (org.eclipse.swt.events.PaintEvent)3 PaintListener (org.eclipse.swt.events.PaintListener)3 GC (org.eclipse.swt.graphics.GC)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Composite (org.eclipse.swt.widgets.Composite)3 IBarSeries (org.eclipse.swtchart.IBarSeries)3 ITitle (org.eclipse.swtchart.ITitle)3 Axis (org.eclipse.swtchart.internal.axis.Axis)3 StyleRange (org.eclipse.swt.custom.StyleRange)2