use of org.eclipse.swtchart.Range in project swtchart by eclipse.
the class SeriesSet method compressAllSeries.
/**
* Compresses all series data.
*/
public void compressAllSeries() {
if (!chart.isCompressEnabled()) {
return;
}
CompressConfig config = new CompressConfig();
final int PRECISION = 2;
Point p = chart.getPlotArea().getSize();
int width = p.x * PRECISION;
int height = p.y * PRECISION;
config.setSizeInPixel(width, height);
for (ISeries series : getSeries()) {
int xAxisId = series.getXAxisId();
int yAxisId = series.getYAxisId();
IAxis xAxis = chart.getAxisSet().getXAxis(xAxisId);
IAxis yAxis = chart.getAxisSet().getYAxis(yAxisId);
if (xAxis == null || yAxis == null) {
continue;
}
Range xRange = xAxis.getRange();
Range yRange = yAxis.getRange();
if (xRange == null || yRange == null) {
continue;
}
double xMin = xRange.lower;
double xMax = xRange.upper;
double yMin = yRange.lower;
double yMax = yRange.upper;
config.setXLogScale(xAxis.isLogScaleEnabled());
config.setYLogScale(yAxis.isLogScaleEnabled());
double lower = xMin - (xMax - xMin) * 0.015;
double upper = xMax + (xMax - xMin) * 0.015;
if (xAxis.isLogScaleEnabled()) {
lower = ((Series) series).getXRange().lower;
}
config.setXRange(lower, upper);
lower = yMin - (yMax - yMin) * 0.015;
upper = yMax + (yMax - yMin) * 0.015;
if (yAxis.isLogScaleEnabled()) {
lower = ((Series) series).getYRange().lower;
}
config.setYRange(lower, upper);
ICompress compressor = ((Series) series).getCompressor();
compressor.compress(config);
}
}
use of org.eclipse.swtchart.Range in project swtchart by eclipse.
the class BarSeries method getBoundsForCompressedSeries.
/**
* Gets the array of bar rectangles for compressed series.
*
* @return the array of bar rectangles for compressed series
*/
private Rectangle[] getBoundsForCompressedSeries() {
Axis xAxis = (Axis) chart.getAxisSet().getXAxis(xAxisId);
Axis yAxis = (Axis) chart.getAxisSet().getYAxis(yAxisId);
// get x and y series
double[] xseries = compressor.getCompressedXSeries();
double[] yseries = compressor.getCompressedYSeries();
int[] indexes = compressor.getCompressedIndexes();
if (xAxis.isValidCategoryAxis()) {
for (int i = 0; i < xseries.length; i++) {
xseries[i] = indexes[i];
}
}
Rectangle[] rectangles = new Rectangle[xseries.length];
Range xRange = xAxis.getRange();
Range yRange = yAxis.getRange();
for (int i = 0; i < xseries.length; i++) {
int x = xAxis.getPixelCoordinate(xseries[i]);
int y = yAxis.getPixelCoordinate(isValidStackSeries() ? stackSeries[indexes[i]] : yseries[i]);
double baseYCoordinate = yAxis.getRange().lower > 0 ? yAxis.getRange().lower : 0;
double riserwidth = getRiserWidth(xseries, i, xAxis, xRange.lower, xRange.upper);
double riserHeight = Math.abs(yAxis.getPixelCoordinate(yseries[i], yRange.lower, yRange.upper) - yAxis.getPixelCoordinate(yAxis.isLogScaleEnabled() ? yRange.lower : baseYCoordinate, yRange.lower, yRange.upper));
// adjust riser x coordinate and riser width for multiple series
int riserCnt = xAxis.getNumRisers();
if (riserCnt > 1) {
if (xAxis.isHorizontalAxis()) {
x = (int) (x - riserwidth / 2d + riserwidth / riserCnt * (riserIndex + 0.5));
} else {
x = (int) (x - riserwidth / 2d + riserwidth / riserCnt * (riserCnt - riserIndex - 0.5));
}
riserwidth /= riserCnt;
}
if (xAxis.isHorizontalAxis()) {
// adjust coordinate for negative series
if (y > yAxis.getPixelCoordinate(0)) {
y = yAxis.getPixelCoordinate(0);
}
int width = (int) Math.ceil(riserwidth);
width = (width == 0) ? 1 : width;
rectangles[i] = getVisibleRectangle((int) Math.floor(x - riserwidth / 2d), y, width, (int) riserHeight);
} else {
// adjust coordinate for negative series
if (y < yAxis.getPixelCoordinate(0)) {
y = yAxis.getPixelCoordinate(0);
}
int height = (int) Math.ceil(riserwidth);
height = (height == 0) ? 1 : height;
rectangles[i] = getVisibleRectangle((int) (y - riserHeight), (int) Math.floor(x - riserwidth / 2d), (int) riserHeight, height);
}
}
return rectangles;
}
use of org.eclipse.swtchart.Range in project netxms by netxms.
the class LineChart method setRange.
/**
* Sets the axis range.
*
* @param range
* the axis range in pixels
* @param axis
* the axis to set range
*/
private void setRange(Point range, IAxis axis) {
double min = axis.getDataCoordinate(range.x);
double max = axis.getDataCoordinate(range.y);
axis.setRange(new Range(min, max));
}
use of org.eclipse.swtchart.Range in project netxms by netxms.
the class LineChart method setTimeRange.
/**
* Set time range
*
* @param from start time
* @param to end time
*/
public void setTimeRange(final Date from, final Date to) {
if (zoomedToSelectionX) {
delayedRangeFrom = from;
delayedRangeTo = to;
return;
}
delayedRangeFrom = null;
delayedRangeTo = null;
timeFrom = from.getTime();
timeTo = to.getTime();
getAxisSet().getXAxis(0).setRange(new Range(timeFrom, timeTo));
int seconds = (int) ((timeTo - timeFrom) / 1000);
DateFormat format;
int angle;
if (seconds <= 600) {
format = DateFormatFactory.getTimeFormat();
angle = 0;
} else if (seconds <= 86400) {
format = DateFormatFactory.getShortTimeFormat();
angle = 0;
} else if (seconds <= 86400 * 7) {
format = new SimpleDateFormat("E " + DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT));
angle = 0;
} else {
format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
angle = 45;
}
IAxisTick xTick = getAxisSet().getXAxis(0).getTick();
xTick.setFormat(format);
xTick.setTickLabelAngle(angle);
}
use of org.eclipse.swtchart.Range in project org.eclipse.linuxtools by eclipse-linuxtools.
the class PieChartPaintListener method getSliceIndexFromPosition.
/**
* Given a set of 2D pixel coordinates (typically those of a mouse cursor), return the
* index of the given pie's slice that those coordinates reside in.
* @param chartnum The id of the chart.
* @param x The x-coordinate to test.
* @param y The y-coordinate to test.
* @return The slice that contains the point with coordinates (x,y).
* @since 2.0
*/
public int getSliceIndexFromPosition(int chartnum, int x, int y) {
Range range = chart.getAxisSet().getXAxis(0).getRange();
chartnum -= (int) range.lower;
if (chartnum >= pieCenters.length || chartnum < 0) {
return -1;
}
// Only continue if the point is inside the pie circle
double rad = Math.sqrt(Math.pow(pieCenters[chartnum].x - x, 2) + Math.pow(pieCenters[chartnum].y - y, 2));
if (2 * rad > pieWidth) {
return -1;
}
// Angle is relative to 12:00 position, increases clockwise
double angle = Math.acos((pieCenters[chartnum].y - y) / rad) / Math.PI * 180.0;
if (x - pieCenters[chartnum].x < 0) {
angle = 360 - angle;
}
if (pieSliceAngles[chartnum].length == 0 || angle < pieSliceAngles[chartnum][0]) {
return 0;
}
for (int s = 0; s < pieSliceAngles[chartnum].length - 1; s++) {
if (pieSliceAngles[chartnum][s] <= angle && angle < pieSliceAngles[chartnum][s + 1]) {
return s + 1;
}
}
return pieSliceAngles[chartnum].length;
}
Aggregations