Search in sources :

Example 11 with ISeries

use of org.swtchart.ISeries in project netxms-ocilib by stevemqeen.

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();
}
Also used : ISeries(org.swtchart.ISeries) ISeries(org.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) ICompress(org.swtchart.internal.compress.ICompress)

Example 12 with ISeries

use of org.swtchart.ISeries in project netxms-ocilib by stevemqeen.

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);
}
Also used : ArrayList(java.util.ArrayList) ISeries(org.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) IAxis(org.swtchart.IAxis) Axis(org.swtchart.internal.axis.Axis) Date(java.util.Date)

Example 13 with ISeries

use of org.swtchart.ISeries in project netxms-ocilib by stevemqeen.

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);
    }
}
Also used : ISeries(org.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) Range(org.swtchart.Range) CompressConfig(org.swtchart.internal.compress.CompressConfig) ISeries(org.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) IAxis(org.swtchart.IAxis) ICompress(org.swtchart.internal.compress.ICompress)

Example 14 with ISeries

use of org.swtchart.ISeries in project netxms-ocilib by stevemqeen.

the class Legend method sort.

/**
 * Sorts the given series array. For instance, if there are two stack series in horizontal orientation, the top of stack series
 * should appear at top of legend.
 * <p>
 * If there are multiple x axes, the given series array will be sorted with x axis first. And then, the series in each x axis
 * will be sorted with {@link Legend#sort(List, boolean, boolean)}.
 *
 * @param seriesArray the series array
 * @return the sorted series array
 */
private ISeries[] sort(ISeries[] seriesArray) {
    // create a map between axis id and series list
    Map<Integer, List<ISeries>> map = new HashMap<Integer, List<ISeries>>();
    for (ISeries series : seriesArray) {
        int axisId = series.getXAxisId();
        List<ISeries> list = map.get(axisId);
        if (list == null) {
            list = new ArrayList<ISeries>();
        }
        list.add(series);
        map.put(axisId, list);
    }
    // sort an each series list
    List<ISeries> sortedArray = new ArrayList<ISeries>();
    boolean isVertical = chart.getOrientation() == SWT.VERTICAL;
    for (Entry<Integer, List<ISeries>> entry : map.entrySet()) {
        boolean isCategoryEnabled = chart.getAxisSet().getXAxis(entry.getKey()).isCategoryEnabled();
        sortedArray.addAll(sort(entry.getValue(), isCategoryEnabled, isVertical));
    }
    return sortedArray.toArray(new ISeries[0]);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ISeries(org.swtchart.ISeries)

Example 15 with ISeries

use of org.swtchart.ISeries in project netxms-ocilib by stevemqeen.

the class Legend method paintControl.

/*
    * @see PaintListener#paintControl(PaintEvent)
    */
public void paintControl(PaintEvent e) {
    if (!visible) {
        return;
    }
    GC gc = e.gc;
    gc.setFont(getFont());
    ISeries[] seriesArray = chart.getSeriesSet().getSeries();
    if (seriesArray.length == 0) {
        return;
    }
    // draw content
    for (int i = 0; i < seriesArray.length; i++) {
        // draw plot line, symbol etc
        Rectangle r = cellBounds.get(seriesArray[i].getId());
        drawSymbol(gc, (Series) seriesArray[i], new Rectangle(r.x + MARGIN, r.y + MARGIN, SYMBOL_WIDTH, r.height - MARGIN * 2));
        // draw plot id
        gc.setBackground(getBackground());
        gc.setForeground(getForeground());
        gc.drawText(seriesArray[i].getName(), r.x + SYMBOL_WIDTH + MARGIN * 2, r.y, true);
        if (extended) {
            drawExtendedInfo(gc, (Series) seriesArray[i], r);
        }
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) GC(org.eclipse.swt.graphics.GC) ISeries(org.swtchart.ISeries)

Aggregations

ISeries (org.swtchart.ISeries)68 Point (org.eclipse.swt.graphics.Point)27 IAxis (org.swtchart.IAxis)17 Date (java.util.Date)15 ArrayList (java.util.ArrayList)11 Range (org.swtchart.Range)10 LocalDate (java.time.LocalDate)7 HashMap (java.util.HashMap)5 GC (org.eclipse.swt.graphics.GC)5 IBarSeries (org.swtchart.IBarSeries)5 ILineSeries (org.swtchart.ILineSeries)5 DecimalFormat (java.text.DecimalFormat)4 List (java.util.List)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 DataPoint (org.netxms.ui.eclipse.charts.api.DataPoint)4 Series (org.swtchart.internal.series.Series)4 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)3 Interval (name.abuchen.portfolio.util.Interval)3 Pair (name.abuchen.portfolio.util.Pair)3 Color (org.eclipse.swt.graphics.Color)3