use of org.swtchart.ISeries in project netxms by netxms.
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.swtchart.ISeries in project netxms by netxms.
the class SeriesSet method updateCompressor.
/**
* Updates the compressor associated with the given axis.
* <p>
* In most cases, compressor is updated when series is changed. However, there is a case that compressor has to be updated with
* the changes in axis.
*
* @param axis the axis
*/
public void updateCompressor(Axis axis) {
for (ISeries series : getSeries()) {
int axisId = (axis.getDirection() == Direction.X) ? series.getXAxisId() : series.getYAxisId();
if (axisId != axis.getId()) {
continue;
}
ICompress compressor = ((Series) series).getCompressor();
if (axis.isValidCategoryAxis()) {
String[] categorySeries = axis.getCategorySeries();
if (categorySeries == null) {
continue;
}
double[] xSeries = new double[categorySeries.length];
for (int i = 0; i < xSeries.length; i++) {
xSeries[i] = i;
}
compressor.setXSeries(xSeries);
} else if (((Series) series).getXSeries() != null) {
compressor.setXSeries(((Series) series).getXSeries());
}
}
compressAllSeries();
}
use of org.swtchart.ISeries in project netxms by netxms.
the class SeriesSet method setStackSeries.
/**
* Sets the stack series.
*
* @param stackSeries the stack series
* @param series the series
*/
private void setStackSeries(double[] stackSeries, ISeries series) {
double[] ySeries = series.getYSeries();
if (ySeries == null || stackSeries == null) {
return;
}
for (int i = 0; i < stackSeries.length; i++) {
if (i >= ySeries.length) {
break;
}
stackSeries[i] = new BigDecimal(Double.valueOf(stackSeries[i]).toString()).add(new BigDecimal(Double.valueOf(ySeries[i]).toString())).doubleValue();
}
double[] copiedStackSeries = new double[stackSeries.length];
System.arraycopy(stackSeries, 0, copiedStackSeries, 0, stackSeries.length);
((Series) series).setStackSeries(copiedStackSeries);
}
use of org.swtchart.ISeries in project portfolio by buchen.
the class ChartWidget method update.
@Override
public void update(Object object) {
title.setText(TextUtil.tooltip(getWidget().getLabel()));
try {
chart.suspendUpdate(true);
GridData data = (GridData) chart.getLayoutData();
int oldHeight = data.heightHint;
int newHeight = get(ChartHeightConfig.class).getPixel();
if (oldHeight != newHeight) {
data.heightHint = newHeight;
title.getParent().layout(true);
title.getParent().getParent().layout(true);
}
chart.getTitle().setText(title.getText());
for (ISeries s : chart.getSeriesSet().getSeries()) chart.getSeriesSet().deleteSeries(s.getId());
List<DataSeries> series = Lists.reverse(new DataSeriesSerializer().fromString(dataSeriesSet, get(ChartConfig.class).getData()));
Interval reportingPeriod = get(ReportingPeriodConfig.class).getReportingPeriod().toInterval(LocalDate.now());
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 portfolio by buchen.
the class StatementOfAssetsHistoryView method updateChart.
private void updateChart() {
try {
// $NON-NLS-1$ //$NON-NLS-2$
updateTitle(Messages.LabelStatementOfAssetsHistory + " (" + configurator.getConfigurationName() + ")");
chart.suspendUpdate(true);
chart.getTitle().setText(getTitle());
for (ISeries s : chart.getSeriesSet().getSeries()) chart.getSeriesSet().deleteSeries(s.getId());
Interval interval = getReportingPeriod().toInterval(LocalDate.now());
Lists.reverse(configurator.getSelectedDataSeries()).forEach(series -> seriesBuilder.build(series, interval));
chart.adjustRange();
} finally {
chart.suspendUpdate(false);
}
chart.redraw();
}
Aggregations