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