Search in sources :

Example 6 with IAxis

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

the class AbstractExtendedChart method adjustSecondaryXAxes.

@Override
public void adjustSecondaryXAxes() {
    IAxisSet axisSet = getAxisSet();
    IAxis xAxis = axisSet.getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
    Range range = xAxis.getRange();
    for (int id : axisSet.getXAxisIds()) {
        if (id != BaseChart.ID_PRIMARY_X_AXIS) {
            IAxis axis = axisSet.getXAxis(id);
            IAxisSettings axisSettings = xAxisSettingsMap.get(id);
            if (axis != null && axisSettings instanceof ISecondaryAxisSettings) {
                IAxisScaleConverter axisScaleConverter = ((ISecondaryAxisSettings) axisSettings).getAxisScaleConverter();
                axisScaleConverter.setChartDataCoordinates(this);
                double start = axisScaleConverter.convertToSecondaryUnit(range.lower);
                double end = axisScaleConverter.convertToSecondaryUnit(range.upper);
                if (end > start) {
                    Range adjustedRange = new Range(start, end);
                    axis.setRange(adjustedRange);
                } else {
                    System.out.println("Can't set secondary x axes range: " + start + "\t" + end);
                }
            }
        }
    }
}
Also used : IAxisSet(org.eclipse.swtchart.IAxisSet) Range(org.eclipse.swtchart.Range) IAxis(org.eclipse.swtchart.IAxis)

Example 7 with IAxis

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

the class InteractiveChart method handleSelectionEvent.

/**
 * Handles the selection event.
 *
 * @param event
 *            the event
 */
private void handleSelectionEvent(Event event) {
    if (!(event.widget instanceof MenuItem)) {
        return;
    }
    MenuItem menuItem = (MenuItem) event.widget;
    if (menuItem.getText().equals(Messages.ADJUST_AXIS_RANGE)) {
        getAxisSet().adjustRange();
    } else if (menuItem.getText().equals(Messages.ADJUST_X_AXIS_RANGE)) {
        for (IAxis axis : getAxisSet().getXAxes()) {
            axis.adjustRange();
        }
    } else if (menuItem.getText().equals(Messages.ADJUST_Y_AXIS_RANGE)) {
        for (IAxis axis : getAxisSet().getYAxes()) {
            axis.adjustRange();
        }
    } else if (menuItem.getText().equals(Messages.ZOOMIN)) {
        getAxisSet().zoomIn();
    } else if (menuItem.getText().equals(Messages.ZOOMIN_X)) {
        for (IAxis axis : getAxisSet().getXAxes()) {
            axis.zoomIn();
        }
    } else if (menuItem.getText().equals(Messages.ZOOMIN_Y)) {
        for (IAxis axis : getAxisSet().getYAxes()) {
            axis.zoomIn();
        }
    } else if (menuItem.getText().equals(Messages.ZOOMOUT)) {
        getAxisSet().zoomOut();
    } else if (menuItem.getText().equals(Messages.ZOOMOUT_X)) {
        for (IAxis axis : getAxisSet().getXAxes()) {
            axis.zoomOut();
        }
    } else if (menuItem.getText().equals(Messages.ZOOMOUT_Y)) {
        for (IAxis axis : getAxisSet().getYAxes()) {
            axis.zoomOut();
        }
    } else if (menuItem.getText().equals(Messages.SAVE_AS)) {
        openSaveAsDialog();
    } else if (menuItem.getText().equals(Messages.PROPERTIES)) {
        openPropertiesDialog();
    }
    redraw();
}
Also used : MenuItem(org.eclipse.swt.widgets.MenuItem) IAxis(org.eclipse.swtchart.IAxis)

Example 8 with IAxis

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

the class BaseChart method getShiftValue.

public double getShiftValue(int positionStart, int positionStop, String orientation) {
    double shiftValue = 0.0d;
    double start;
    double stop;
    int length;
    /*
		 * Get the axis.
		 */
    if (orientation.equals(IExtendedChart.X_AXIS)) {
        IAxis axis = getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
        start = axis.getRange().lower;
        stop = axis.getRange().upper;
        length = getPlotArea().getBounds().width;
    } else {
        IAxis axis = getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
        start = axis.getRange().lower;
        stop = axis.getRange().upper;
        length = getPlotArea().getBounds().height;
    }
    // 
    if (positionStart > 0 && positionStop > 0 && positionStart < length && positionStop < length) {
        // 
        double delta = stop - start;
        double percentageStart;
        double percentageStop;
        // 
        if (orientation.equals(IExtendedChart.X_AXIS)) {
            percentageStart = ((100.0d / length) * positionStart) / 100.0d;
            percentageStop = ((100.0d / length) * positionStop) / 100.0d;
        } else {
            percentageStart = (100.0d - ((100.0d / length) * positionStart)) / 100.0d;
            percentageStop = (100.0d - ((100.0d / length) * positionStop)) / 100.0d;
        }
        // 
        shiftValue = (start + delta * percentageStop) - (start + delta * percentageStart);
    }
    return shiftValue;
}
Also used : Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis)

Example 9 with IAxis

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

the class BaseChart method getSelectedPrimaryAxisValue.

public double getSelectedPrimaryAxisValue(int position, String orientation) {
    double primaryValue = 0.0d;
    double start;
    double stop;
    int length;
    // 
    if (orientation.equals(IExtendedChart.X_AXIS)) {
        IAxis axis = getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
        start = axis.getRange().lower;
        stop = axis.getRange().upper;
        length = getPlotArea().getBounds().width;
    } else {
        IAxis axis = getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
        start = axis.getRange().lower;
        stop = axis.getRange().upper;
        length = getPlotArea().getBounds().height;
    }
    // 
    if (position <= 0) {
        primaryValue = start;
    } else if (position > length) {
        primaryValue = stop;
    } else {
        double delta = stop - start;
        double percentage;
        if (orientation.equals(IExtendedChart.X_AXIS)) {
            percentage = ((100.0d / length) * position) / 100.0d;
        } else {
            percentage = (100.0d - ((100.0d / length) * position)) / 100.0d;
        }
        primaryValue = start + delta * percentage;
    }
    return primaryValue;
}
Also used : Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis)

Example 10 with IAxis

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

the class BaseChart method getAxisLabels.

public String[] getAxisLabels(String axisOrientation) {
    IAxis[] axes = getAxes(axisOrientation);
    int size = axes.length;
    String[] items = new String[size];
    // 
    for (int i = 0; i < size; i++) {
        /*
			 * Get the label.
			 */
        String label;
        IAxisSettings axisSettings = getAxisSettings(axisOrientation, i);
        if (axisSettings != null) {
            label = axisSettings.getLabel();
        } else {
            label = "not set";
        }
        items[i] = label;
    }
    return items;
}
Also used : IAxis(org.eclipse.swtchart.IAxis) Point(org.eclipse.swt.graphics.Point)

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