Search in sources :

Example 51 with IAxis

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

the class RangeSelector method createControl.

private void createControl() {
    setLayout(new GridLayout(9, false));
    // 
    textStartX = new Text(this, SWT.BORDER);
    textStartX.setText("");
    textStartX.setLayoutData(getTextGridData());
    // 
    textStopX = new Text(this, SWT.BORDER);
    textStopX.setText("");
    textStopX.setLayoutData(getTextGridData());
    // 
    comboScaleX = new Combo(this, SWT.READ_ONLY);
    comboScaleX.setLayoutData(getComboGridData());
    comboScaleX.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = comboScaleX.getSelectionIndex();
            BaseChart baseChart = scrollableChart.getBaseChart();
            IAxis xAxis = baseChart.getAxisSet().getXAxis(selectionIndex);
            Range rangeX = xAxis.getRange();
            if (rangeX != null) {
                DecimalFormat decimalFormatX = baseChart.getDecimalFormat(IExtendedChart.X_AXIS, selectionIndex);
                textStartX.setText(decimalFormatX.format(rangeX.lower));
                textStopX.setText(decimalFormatX.format(rangeX.upper));
            }
        }
    });
    // 
    textStartY = new Text(this, SWT.BORDER);
    textStartY.setText("");
    textStartY.setLayoutData(getTextGridData());
    // 
    textStopY = new Text(this, SWT.BORDER);
    textStopY.setText("");
    textStopY.setLayoutData(getTextGridData());
    // 
    comboScaleY = new Combo(this, SWT.READ_ONLY);
    comboScaleY.setLayoutData(getComboGridData());
    comboScaleY.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = comboScaleY.getSelectionIndex();
            BaseChart baseChart = scrollableChart.getBaseChart();
            IAxis yAxis = baseChart.getAxisSet().getYAxis(selectionIndex);
            Range rangeY = yAxis.getRange();
            if (rangeY != null) {
                DecimalFormat decimalFormatY = baseChart.getDecimalFormat(IExtendedChart.Y_AXIS, selectionIndex);
                textStartY.setText(decimalFormatY.format(rangeY.lower));
                textStopY.setText(decimalFormatY.format(rangeY.upper));
            }
        }
    });
    // 
    Button buttonSetRange = new Button(this, SWT.PUSH);
    if (Activator.getDefault() != null) {
        buttonSetRange.setText("");
        buttonSetRange.setImage(Activator.getDefault().getImage(Activator.ICON_SET_RANGE));
    } else {
        buttonSetRange.setText("Set");
    }
    buttonSetRange.setToolTipText("Set the current selection.");
    buttonSetRange.setLayoutData(getButtonGridData());
    buttonSetRange.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                setRange();
            } catch (Exception e1) {
                System.out.println(e1);
            }
        }
    });
    // 
    Button buttonResetRange = new Button(this, SWT.PUSH);
    if (Activator.getDefault() != null) {
        buttonResetRange.setText("");
        buttonResetRange.setImage(Activator.getDefault().getImage(Activator.ICON_RESET));
    } else {
        buttonResetRange.setText("Reset");
    }
    buttonResetRange.setToolTipText("Reset the range.");
    buttonResetRange.setLayoutData(getButtonGridData());
    buttonResetRange.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                resetRange();
            } catch (Exception e1) {
                System.out.println(e1);
            }
        }
    });
    // 
    Button buttonHide = new Button(this, SWT.PUSH);
    if (Activator.getDefault() != null) {
        buttonHide.setText("");
        buttonHide.setImage(Activator.getDefault().getImage(Activator.ICON_HIDE));
    } else {
        buttonHide.setText("Hide");
    }
    buttonHide.setToolTipText("Hide the range selector UI.");
    buttonHide.setLayoutData(getButtonGridData());
    buttonHide.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            GridData gridData = (GridData) getLayoutData();
            gridData.exclude = true;
            setVisible(false);
            Composite parent = getParent();
            parent.layout(false);
            parent.redraw();
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DecimalFormat(java.text.DecimalFormat) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Range(org.eclipse.swtchart.Range) IAxis(org.eclipse.swtchart.IAxis) ParseException(java.text.ParseException) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData)

Example 52 with IAxis

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

the class AbstractExtendedChart method adjustSecondaryYAxes.

@Override
public void adjustSecondaryYAxes() {
    IAxisSet axisSet = getAxisSet();
    IAxis yAxis = axisSet.getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
    Range range = yAxis.getRange();
    for (int id : axisSet.getYAxisIds()) {
        if (id != BaseChart.ID_PRIMARY_Y_AXIS) {
            IAxis axis = axisSet.getYAxis(id);
            IAxisSettings axisSettings = yAxisSettingsMap.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 y axes range: " + start + "\t" + end);
                }
            }
        }
    }
}
Also used : IAxisSet(org.eclipse.swtchart.IAxisSet) Range(org.eclipse.swtchart.Range) IAxis(org.eclipse.swtchart.IAxis)

Example 53 with IAxis

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

the class BaseChart method handleSelection.

private void handleSelection(double[] selection) {
    double xStart = selection[0];
    double xStop = selection[1];
    double yStart = selection[2];
    double yStop = selection[3];
    IAxis xAxis = getAxisSet().getXAxis(ID_PRIMARY_X_AXIS);
    IAxis yAxis = getAxisSet().getYAxis(ID_PRIMARY_Y_AXIS);
    setRange(xAxis, xStart, xStop, false);
    setRange(yAxis, yStart, yStop, false);
}
Also used : IAxis(org.eclipse.swtchart.IAxis)

Example 54 with IAxis

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

the class Series method setYSeries.

/*
	 * @see ISeries#setYSeries(double[])
	 */
public void setYSeries(double[] series) {
    if (series == null) {
        SWT.error(SWT.ERROR_NULL_ARGUMENT);
        // to suppress warning...
        return;
    }
    ySeries = new double[series.length];
    System.arraycopy(series, 0, ySeries, 0, series.length);
    if (ySeries.length == 0) {
        return;
    }
    // find the min and max value of y series
    minY = ySeries[0];
    maxY = ySeries[0];
    for (int i = 1; i < ySeries.length; i++) {
        if (minY > ySeries[i]) {
            minY = ySeries[i];
        }
        if (maxY < ySeries[i]) {
            maxY = ySeries[i];
        }
    }
    if (xSeries.length != series.length) {
        xSeries = new double[series.length];
        for (int i = 0; i < series.length; i++) {
            xSeries[i] = i;
        }
        minX = xSeries[0];
        maxX = xSeries[xSeries.length - 1];
        isXMonotoneIncreasing = true;
    }
    setCompressor();
    compressor.setXSeries(xSeries);
    compressor.setYSeries(ySeries);
    if (minX <= 0) {
        IAxis axis = chart.getAxisSet().getXAxis(xAxisId);
        if (axis != null) {
            axis.enableLogScale(false);
        }
    }
    if (minY <= 0) {
        IAxis axis = chart.getAxisSet().getYAxis(yAxisId);
        if (axis != null) {
            axis.enableLogScale(false);
        }
        stackEnabled = false;
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis)

Example 55 with IAxis

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

the class Series method getPixelCoordinates.

/*
	 * @see ISeries#getPixelCoordinates(int)
	 */
public Point getPixelCoordinates(int index) {
    // get the horizontal and vertical axes
    IAxis hAxis;
    IAxis vAxis;
    if (chart.getOrientation() == SWT.HORIZONTAL) {
        hAxis = chart.getAxisSet().getXAxis(xAxisId);
        vAxis = chart.getAxisSet().getYAxis(yAxisId);
    } else if (chart.getOrientation() == SWT.VERTICAL) {
        hAxis = chart.getAxisSet().getYAxis(yAxisId);
        vAxis = chart.getAxisSet().getXAxis(xAxisId);
    } else {
        // $NON-NLS-1$
        throw new IllegalStateException("unknown chart orientation");
    }
    // get the pixel coordinates
    return new Point(getPixelCoordinate(hAxis, index), getPixelCoordinate(vAxis, index));
}
Also used : 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