use of org.swtchart.ISeries in project portfolio by buchen.
the class ChartWidget method update.
@Override
public void update() {
title.setText(getWidget().getLabel());
try {
chart.suspendUpdate(true);
chart.getTitle().setText(title.getText());
for (ISeries s : chart.getSeriesSet().getSeries()) chart.getSeriesSet().deleteSeries(s.getId());
List<DataSeries> series = new DataSeriesSerializer().fromString(dataSeriesSet, get(ChartConfig.class).getData());
ReportingPeriod reportingPeriod = get(ReportingPeriodConfig.class).getReportingPeriod();
switch(useCase) {
case STATEMENT_OF_ASSETS:
buildAssetSeries(series, reportingPeriod);
break;
case PERFORMANCE:
buildPerformanceSeries(series, reportingPeriod);
break;
case RETURN_VOLATILITY:
throw new UnsupportedOperationException();
default:
throw new IllegalArgumentException();
}
chart.adjustRange();
} finally {
chart.suspendUpdate(false);
}
chart.redraw();
}
use of org.swtchart.ISeries in project netxms by netxms.
the class LineChart method getSeriesAtPoint.
/**
* Get series at given point
*
* @param px
* @param py
* @return
*/
public ISeries getSeriesAtPoint(int px, int py) {
ISeries[] series = getSeriesSet().getSeries();
for (ISeries s : series) {
int size = s.getSize();
for (int i = 1; i < size; i++) {
Point p1 = s.getPixelCoordinates(i - 1);
Point p2 = s.getPixelCoordinates(i);
if ((px > p1.x + 2) || (px < p2.x - 2) || (py < Math.min(p1.y, p2.y) - 2) || (py > Math.max(p1.y, p2.y) + 2))
continue;
if (pointToLineDistance(px, py, p2, p1) <= ((ILineSeries) s).getLineWidth() * 3.0)
return s;
}
}
return null;
}
use of org.swtchart.ISeries in project netxms by netxms.
the class LineChart method getClosestDataPoint.
/**
* Get data point closest to given point in plot area
*
* @param px
* @param py
* @return
*/
public DataPoint getClosestDataPoint(int px, int py) {
IAxis xAxis = getAxisSet().getXAxis(0);
IAxis yAxis = getAxisSet().getYAxis(0);
double x = xAxis.getDataCoordinate(px);
double y = yAxis.getDataCoordinate(py);
double closestX = 0;
double closestY = 0;
double minDist = Double.MAX_VALUE;
ISeries closestSeries = null;
/* over all series */
ISeries[] series = getSeriesSet().getSeries();
for (ISeries s : series) {
double[] xS = s.getXSeries();
double[] yS = s.getYSeries();
/* check all data points */
for (int i = 0; i < xS.length; i++) {
/* compute distance to mouse position */
double newDist = Math.sqrt(Math.pow((x - xS[i]), 2) + Math.pow((y - yS[i]), 2));
/* if closer to mouse, remember */
if (newDist < minDist) {
minDist = newDist;
closestX = xS[i];
closestY = yS[i];
closestSeries = s;
}
}
}
return (closestSeries != null) ? new DataPoint(new Date((long) closestX), closestY, closestSeries) : null;
}
use of org.swtchart.ISeries in project netxms by netxms.
the class PlotArea method paintControl.
/*
* @see PaintListener#paintControl(PaintEvent)
*/
public void paintControl(PaintEvent e) {
Point p = getSize();
final GC gc = e.gc;
// draw the plot area background
gc.setBackground(getBackground());
gc.fillRectangle(0, 0, p.x, p.y);
// draw grid
for (IAxis axis : chart.getAxisSet().getAxes()) {
((Grid) axis.getGrid()).draw(gc, p.x, p.y);
}
// draw behind series
for (ICustomPaintListener listener : paintListeners) {
if (listener.drawBehindSeries()) {
listener.paintControl(e);
}
}
// draw series. The line series should be drawn on bar series.
for (ISeries series : chart.getSeriesSet().getSeries()) {
if (series instanceof IBarSeries) {
((Series) series).draw(gc, p.x, p.y);
}
}
for (ISeries series : chart.getSeriesSet().getSeries()) {
if (series instanceof ILineSeries) {
((Series) series).draw(gc, p.x, p.y);
}
}
// draw over series
for (ICustomPaintListener listener : paintListeners) {
if (!listener.drawBehindSeries()) {
listener.paintControl(e);
}
}
}
use of org.swtchart.ISeries in project netxms by netxms.
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);
}
}
Aggregations