use of org.swtchart.internal.axis.Axis in project netxms by netxms.
the class SeriesSet method updateStackAndRiserData.
/**
* Updates the stack and riser data for given axes.
*
* @param xAxis the X axis
* @param yAxis the Y axis
*/
private void updateStackAndRiserData(IAxis xAxis, IAxis yAxis) {
int riserCnt = 0;
int stackRiserPosition = -1;
double[] stackBarSeries = null;
double[] stackLineSeries = null;
double[] invertedStackLineSeries = null;
if (((Axis) xAxis).isValidCategoryAxis()) {
String[] categorySeries = xAxis.getCategorySeries();
if (categorySeries != null) {
int size = categorySeries.length;
stackBarSeries = new double[size];
stackLineSeries = new double[size];
invertedStackLineSeries = new double[size];
}
} else {
// Build combined time series
// Time stamps in series are reversed - latest value first
List<Date> combinedTimeSeries = new ArrayList<Date>();
for (ISeries series : getSeries()) {
if (!series.isStackEnabled())
continue;
for (Date d : series.getXDateSeries()) {
int i;
for (i = 0; i < combinedTimeSeries.size(); i++) {
if (combinedTimeSeries.get(i).getTime() == d.getTime())
break;
if (combinedTimeSeries.get(i).getTime() < d.getTime()) {
combinedTimeSeries.add(i, d);
break;
}
}
if (i == combinedTimeSeries.size())
combinedTimeSeries.add(d);
}
}
// insert missing values
for (ISeries series : getSeries()) {
if (!series.isStackEnabled())
continue;
double[] ySeries = new double[combinedTimeSeries.size()];
int combinedIndex = 0;
double lastValue = 0;
long lastTimestamp = 0;
for (int i = 0; i < series.getYSeries().length; i++) {
Date currentTimestamp = series.getXDateSeries()[i];
double currentValue = series.getYSeries()[i];
long currentCombinedTimestamp = combinedTimeSeries.get(combinedIndex).getTime();
while (currentCombinedTimestamp > currentTimestamp.getTime()) {
if (lastTimestamp != 0) {
// do linear interpolation for missed value
ySeries[combinedIndex] = lastValue + (currentValue - lastValue) * ((double) (lastTimestamp - currentCombinedTimestamp) / (double) (lastTimestamp - currentTimestamp.getTime()));
} else {
ySeries[combinedIndex] = currentValue;
}
combinedIndex++;
currentCombinedTimestamp = combinedTimeSeries.get(combinedIndex).getTime();
}
ySeries[combinedIndex++] = currentValue;
lastTimestamp = currentTimestamp.getTime();
lastValue = currentValue;
}
while (combinedIndex < ySeries.length) ySeries[combinedIndex++] = lastValue;
series.setXDateSeries(combinedTimeSeries.toArray(new Date[combinedTimeSeries.size()]));
series.setYSeries(ySeries);
}
stackLineSeries = new double[combinedTimeSeries.size()];
invertedStackLineSeries = new double[combinedTimeSeries.size()];
}
for (ISeries series : getSeries()) {
if (series.getXAxisId() != xAxis.getId() || series.getYAxisId() != yAxis.getId() || !series.isVisible()) {
continue;
}
if (series.isStackEnabled() && !chart.getAxisSet().getYAxis(series.getYAxisId()).isLogScaleEnabled()) {
if (series.getType() == SeriesType.BAR) {
if (stackRiserPosition == -1) {
stackRiserPosition = riserCnt;
riserCnt++;
}
((BarSeries) series).setRiserIndex(((Axis) xAxis).getNumRisers() + stackRiserPosition);
setStackSeries(stackBarSeries, series);
} else if (series.getType() == SeriesType.LINE) {
setStackSeries(series.isInverted() ? invertedStackLineSeries : stackLineSeries, series);
}
} else {
if (series.getType() == SeriesType.BAR) {
((BarSeries) series).setRiserIndex(((Axis) xAxis).getNumRisers() + riserCnt++);
}
}
}
((Axis) xAxis).setNumRisers(((Axis) xAxis).getNumRisers() + riserCnt);
}
use of org.swtchart.internal.axis.Axis in project netxms by netxms.
the class SeriesSet method createSeries.
/* (non-Javadoc)
* @see org.swtchart.ISeriesSet#createSeries(org.swtchart.ISeries.SeriesType, java.lang.String, boolean)
*/
@Override
public ISeries createSeries(SeriesType type, String id, boolean updateChart) {
if (id == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
// to suppress warning...
return null;
}
String identifier = id.trim();
if ("".equals(identifier)) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
Series series = null;
if (type == SeriesType.BAR) {
series = new BarSeries(chart, identifier);
} else if (type == SeriesType.LINE) {
series = new LineSeries(chart, identifier);
} else {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
// to suppress warning...
return null;
}
Series oldSeries = seriesMap.get(identifier);
if (oldSeries != null) {
oldSeries.dispose();
}
int[] xAxisIds = chart.getAxisSet().getXAxisIds();
int[] yAxisIds = chart.getAxisSet().getYAxisIds();
series.setXAxisId(xAxisIds[0]);
series.setYAxisId(yAxisIds[0]);
seriesMap.put(identifier, series);
if (updateChart) {
Axis axis = (Axis) chart.getAxisSet().getXAxis(xAxisIds[0]);
if (axis != null) {
updateStackAndRiserData();
}
}
// legend will be shown if there is previously no series.
chart.updateLayout();
return series;
}
Aggregations