use of org.eclipse.swtchart.Range in project swtchart by eclipse.
the class RangeSelector method adjustRanges.
public void adjustRanges(boolean redraw) {
BaseChart baseChart = scrollableChart.getBaseChart();
//
int indexX = (comboScaleX.getSelectionIndex() >= 0) ? comboScaleX.getSelectionIndex() : BaseChart.ID_PRIMARY_X_AXIS;
int indexY = (comboScaleY.getSelectionIndex() >= 0) ? comboScaleY.getSelectionIndex() : BaseChart.ID_PRIMARY_Y_AXIS;
IAxis xAxis = baseChart.getAxisSet().getXAxis(indexX);
IAxis yAxis = baseChart.getAxisSet().getYAxis(indexY);
Range rangeX = xAxis.getRange();
Range rangeY = yAxis.getRange();
//
DecimalFormat decimalFormatX = baseChart.getDecimalFormat(IExtendedChart.X_AXIS, indexX);
DecimalFormat decimalFormatY = baseChart.getDecimalFormat(IExtendedChart.Y_AXIS, indexY);
//
if (rangeX != null && rangeY != null) {
/*
* Update the text boxes.
*/
textStartX.setText(decimalFormatX.format(rangeX.lower));
textStopX.setText(decimalFormatX.format(rangeX.upper));
textStartY.setText(decimalFormatY.format(rangeY.lower));
textStopY.setText(decimalFormatY.format(rangeY.upper));
/*
* Redraw the base chart.
*/
if (redraw) {
baseChart.redraw();
}
}
}
use of org.eclipse.swtchart.Range in project swtchart by eclipse.
the class ScrollableChart method calculateShiftedRange.
private Range calculateShiftedRange(Range range, Slider slider) {
int selection = slider.getSelection();
double min = selection;
double max = (range.upper - range.lower) + selection;
return new Range(min, max);
}
use of org.eclipse.swtchart.Range in project swtchart by eclipse.
the class ZoomEvent method handleEvent.
@Override
public void handleEvent(BaseChart baseChart, Event event) {
IAxisSet axisSet = baseChart.getAxisSet();
IAxis xAxis = axisSet.getXAxis(BaseChart.ID_PRIMARY_X_AXIS);
IAxis yAxis = axisSet.getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
//
RangeRestriction rangeRestriction = baseChart.getRangeRestriction();
if (baseChart.isZoomXAndY(rangeRestriction)) {
/*
* X and Y zoom.
*/
baseChart.zoomX(xAxis, event);
baseChart.zoomY(yAxis, event);
} else {
/*
* X or Y zoom.
*/
if (rangeRestriction.isXZoomOnly()) {
baseChart.zoomX(xAxis, event);
} else if (rangeRestriction.isYZoomOnly()) {
baseChart.zoomY(yAxis, event);
}
}
/*
* Adjust the range if it shall not exceed the initial
* min and max values.
*/
if (rangeRestriction.isRestrictZoom()) {
/*
* Adjust the primary axes.
* The secondary axes are adjusted by setting the range.
*/
Range rangeX = xAxis.getRange();
Range rangeY = yAxis.getRange();
baseChart.setRange(xAxis, rangeX.lower, rangeX.upper, true);
baseChart.setRange(yAxis, rangeY.lower, rangeY.upper, true);
} else {
/*
* Update the secondary axes.
*/
baseChart.adjustSecondaryXAxes();
baseChart.adjustSecondaryYAxes();
}
//
baseChart.fireUpdateCustomRangeSelectionHandlers(event);
baseChart.redraw();
}
use of org.eclipse.swtchart.Range in project swtchart by eclipse.
the class Axis method adjustRange.
/**
* Adjusts the axis range to the series belonging to the axis.
*
* @param update
* true if updating chart layout
*/
public void adjustRange(boolean update) {
if (isValidCategoryAxis()) {
setRange(new Range(0, categorySeries.length - 1));
return;
}
double minimum = Double.NaN;
double maximum = Double.NaN;
for (ISeries series : chart.getSeriesSet().getSeries()) {
int axisId = direction == Direction.X ? series.getXAxisId() : series.getYAxisId();
if (!series.isVisible() || getId() != axisId) {
continue;
}
// get axis length
int length;
if (isHorizontalAxis) {
length = chart.getPlotArea().getSize().x;
} else {
length = chart.getPlotArea().getSize().y;
}
// get min and max value of series
Range range = ((Series) series).getAdjustedRange(this, length);
if (Double.isNaN(minimum) || range.lower < minimum) {
minimum = range.lower;
}
if (Double.isNaN(maximum) || range.upper > maximum) {
maximum = range.upper;
}
}
// set adjusted range
if (!Double.isNaN(minimum) && !Double.isNaN(maximum)) {
if (minimum == maximum) {
double margin = (minimum == 0) ? 1d : Math.abs(minimum / 2d);
minimum -= margin;
maximum += margin;
}
setRange(new Range(minimum, maximum), update);
}
}
use of org.eclipse.swtchart.Range in project swtchart by eclipse.
the class Axis method zoomIn.
/*
* @see IAxis#zoomIn(double)
*/
public void zoomIn(double coordinate) {
double lower = min;
double upper = max;
if (isValidCategoryAxis()) {
if (lower != upper) {
if ((min + max) / 2d < coordinate) {
lower = min + 1;
} else if (coordinate < (min + max) / 2d) {
upper = max - 1;
} else {
lower = min + 1;
upper = max - 1;
}
}
} else if (isLogScaleEnabled()) {
double digitMin = Math.log10(min);
double digitMax = Math.log10(max);
double digitCoordinate = Math.log10(coordinate);
lower = Math.pow(10, digitMin + 2 * SCROLL_RATIO * (digitCoordinate - digitMin));
upper = Math.pow(10, digitMax + 2 * SCROLL_RATIO * (digitCoordinate - digitMax));
} else {
lower = min + 2 * ZOOM_RATIO * (coordinate - min);
upper = max + 2 * ZOOM_RATIO * (coordinate - max);
}
setRange(new Range(lower, upper));
}
Aggregations