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();
}
});
}
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);
}
}
}
}
}
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);
}
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;
}
}
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));
}
Aggregations