Search in sources :

Example 16 with ISeries

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

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);
    }
}
Also used : Series(org.swtchart.internal.series.Series) ISeries(org.swtchart.ISeries) Range(org.swtchart.Range) ISeries(org.swtchart.ISeries)

Example 17 with ISeries

use of org.swtchart.ISeries in project netxms by netxms.

the class AxisSet method deleteAxis.

/**
 * Deletes the axis with the axis id for given direction.
 *
 * @param id
 *            the axis id
 * @param direction
 *            the direction
 */
private void deleteAxis(int id, Direction direction) {
    if (id == 0) {
        SWT.error(SWT.ERROR_CANNOT_BE_ZERO);
    }
    if (getAxisMap(direction).get(id) == null) {
        throw new IllegalArgumentException("Given axis id doesn't exist");
    }
    ((Axis) getAxis(id, direction)).dispose();
    getAxisMap(direction).remove(id);
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        if (direction == Direction.X) {
            if (series.getXAxisId() == id) {
                series.setXAxisId(0);
            }
        } else {
            if (series.getYAxisId() == id) {
                series.setYAxisId(0);
            }
        }
    }
    chart.updateLayout();
}
Also used : ISeries(org.swtchart.ISeries) IAxis(org.swtchart.IAxis)

Example 18 with ISeries

use of org.swtchart.ISeries in project netxms by netxms.

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 column headers
    if (extended) {
        gc.setBackground(getBackground());
        gc.setForeground(getForeground());
        gc.setFont(headerFont);
        final int shift = Util.getExtentInGC(getFont(), VALUE_PLACEHOLDER).x + EXT_COL_MARGIN;
        Rectangle r = cellBounds.get(HEADER_ID);
        int x = r.x + extendedInfoOffset + MARGIN * 2;
        gc.drawText("Curr", x, r.y, true);
        x += shift;
        gc.drawText("Min", x, r.y, true);
        x += shift;
        gc.drawText("Avg", x, r.y, true);
        x += shift;
        gc.drawText("Max", x, r.y, true);
        gc.setFont(getFont());
    }
    // 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)

Example 19 with ISeries

use of org.swtchart.ISeries in project netxms by netxms.

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 20 with ISeries

use of org.swtchart.ISeries in project netxms by netxms.

the class Legend method updateLayoutData.

/**
 * Update the layout data.
 */
public void updateLayoutData() {
    if (!visible) {
        setLayoutData(new ChartLayoutData(0, 0));
        return;
    }
    extendedInfoOffset = 0;
    int width = 0;
    int height = 0;
    ISeries[] seriesArray = sort(chart.getSeriesSet().getSeries());
    Rectangle r = chart.getClientArea();
    final int titleHeight = ((Composite) chart.getTitle()).getSize().y;
    final int cellHeight = Util.getExtentInGC(getFont(), "fgdl0").y;
    final int cellExtraWidth = extended ? (Util.getExtentInGC(getFont(), VALUE_PLACEHOLDER).x + EXT_COL_MARGIN) * 4 : 0;
    if (position == SWT.RIGHT || position == SWT.LEFT) {
        int columns = 1;
        int yPosition = extended ? (cellHeight + MARGIN * 2) : MARGIN;
        int maxCellWidth = 0;
        for (ISeries series : seriesArray) {
            int textWidth = Util.getExtentInGC(getFont(), series.getName()).x;
            int cellWidth = textWidth + SYMBOL_WIDTH + MARGIN * 3;
            maxCellWidth = Math.max(maxCellWidth, cellWidth);
            if (extendedInfoOffset < cellWidth + EXT_COL_MARGIN) {
                extendedInfoOffset = cellWidth + EXT_COL_MARGIN;
            }
            if (yPosition + cellHeight < r.height - titleHeight || yPosition == MARGIN) {
                yPosition += cellHeight + MARGIN;
            } else {
                columns++;
                yPosition = cellHeight + MARGIN * 2;
            }
            cellBounds.put(series.getId(), new Rectangle(maxCellWidth * (columns - 1), yPosition - cellHeight - MARGIN, cellWidth + cellExtraWidth, cellHeight));
            height = Math.max(yPosition, height);
        }
        width = maxCellWidth * columns;
    } else if (position == SWT.TOP || position == SWT.BOTTOM) {
        int rows = 1;
        int xPosition = 0;
        final int topOffset = extended ? (cellHeight + MARGIN * 2) : MARGIN;
        for (ISeries series : seriesArray) {
            int textWidth = Util.getExtentInGC(getFont(), series.getName()).x;
            int cellWidth = textWidth + SYMBOL_WIDTH + MARGIN * 3;
            if ((!extended && (xPosition + cellWidth < r.width)) || (xPosition == 0)) {
                xPosition += cellWidth;
            } else {
                rows++;
                xPosition = cellWidth;
            }
            cellBounds.put(series.getId(), new Rectangle(xPosition - cellWidth, (cellHeight + MARGIN) * (rows - 1) + topOffset, cellWidth + cellExtraWidth, cellHeight));
            width = Math.max(xPosition, width);
            if (extendedInfoOffset < cellWidth + EXT_COL_MARGIN) {
                extendedInfoOffset = cellWidth + EXT_COL_MARGIN;
            }
        }
        height = (cellHeight + MARGIN) * rows + MARGIN;
    }
    if (extended) {
        width += cellExtraWidth;
        height += cellHeight + MARGIN;
        cellBounds.put(HEADER_ID, new Rectangle(0, MARGIN, cellExtraWidth, cellHeight));
        // extendedInfoOffset was updated multiple times during calculation
        for (Entry<String, Rectangle> e : cellBounds.entrySet()) {
            if (e.getKey().equals(HEADER_ID))
                continue;
            e.getValue().width = width;
        }
    }
    setLayoutData(new ChartLayoutData(width, height));
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) 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