Search in sources :

Example 21 with ISeries

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

Example 22 with ISeries

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

Example 23 with ISeries

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);
}
Also used : ISeries(org.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) BigDecimal(java.math.BigDecimal)

Example 24 with ISeries

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();
}
Also used : DataSeriesSerializer(name.abuchen.portfolio.ui.views.dataseries.DataSeriesSerializer) GridData(org.eclipse.swt.layout.GridData) DataSeries(name.abuchen.portfolio.ui.views.dataseries.DataSeries) ISeries(org.swtchart.ISeries) Interval(name.abuchen.portfolio.util.Interval)

Example 25 with ISeries

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();
}
Also used : ISeries(org.swtchart.ISeries) Interval(name.abuchen.portfolio.util.Interval)

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