Search in sources :

Example 61 with ISeries

use of org.swtchart.ISeries in project portfolio by buchen.

the class SecuritiesChart method updateChart.

private void updateChart() {
    chart.setRedraw(false);
    try {
        // delete all line series (quotes + possibly moving average)
        ISeries[] series = chart.getSeriesSet().getSeries();
        for (ISeries s : series) chart.getSeriesSet().deleteSeries(s.getId());
        chart.clearMarkerLines();
        chart.clearNonTradingDayMarker();
        customPaintListeners.clear();
        customBehindPaintListener.clear();
        customTooltipEvents.clear();
        if (security == null || security.getPrices().isEmpty()) {
            // $NON-NLS-1$
            chart.getTitle().setText(security == null ? "..." : security.getName());
            chart.redraw();
            return;
        }
        chart.getTitle().setText(security.getName());
        boolean showAreaRelativeToFirstQuote = chartConfig.contains(ChartDetails.CLOSING) || chartConfig.contains(ChartDetails.PURCHASEPRICE);
        // determine the interval to be shown in the chart
        ChartInterval chartInterval = intervalOption.getInverval(client, converter, security);
        // determine index range for given interval in prices list
        List<SecurityPrice> prices = security.getPricesIncludingLatest();
        ChartRange range = ChartRange.createFor(prices, chartInterval);
        if (range == null) {
            chart.redraw();
            return;
        }
        // prepare value arrays
        LocalDate[] dates = new LocalDate[range.size];
        double[] values = new double[range.size];
        double[] valuesRelative = new double[range.size];
        double[] valuesRelativePositive = new double[range.size];
        double[] valuesRelativeNegative = new double[range.size];
        double[] valuesZeroLine = new double[range.size];
        double firstQuote = 0;
        // Disable SWT antialias for more than 1000 records due to SWT
        // performance issue in Drawing
        swtAntialias = range.size > 1000 ? SWT.OFF : SWT.ON;
        if (!chartConfig.contains(ChartDetails.PURCHASEPRICE)) {
            SecurityPrice p2 = prices.get(range.start);
            firstQuote = (p2.getValue() / Values.Quote.divider());
        } else {
            Optional<Double> purchasePrice = getLatestPurchasePrice();
            if (purchasePrice.isPresent())
                firstQuote = purchasePrice.get();
            else
                showAreaRelativeToFirstQuote = false;
        }
        addChartMarkerBackground(chartInterval, range);
        for (int ii = 0; ii < range.size; ii++) {
            SecurityPrice p = prices.get(ii + range.start);
            dates[ii] = p.getDate();
            values[ii] = p.getValue() / Values.Quote.divider();
            if (showAreaRelativeToFirstQuote) {
                valuesRelative[ii] = (p.getValue() / Values.Quote.divider()) - firstQuote;
                valuesZeroLine[ii] = 0;
                if (valuesRelative[ii] >= 0) {
                    valuesRelativePositive[ii] = valuesRelative[ii];
                    valuesRelativeNegative[ii] = 0;
                } else {
                    valuesRelativePositive[ii] = 0;
                    valuesRelativeNegative[ii] = valuesRelative[ii];
                }
            }
        }
        Date[] javaDates = TimelineChart.toJavaUtilDate(dates);
        if (showAreaRelativeToFirstQuote) {
            ILineSeries lineSeries2ndNegative = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$
            Messages.LabelChartDetailChartDevelopmentClosing + "Negative");
            lineSeries2ndNegative.setSymbolType(PlotSymbolType.NONE);
            lineSeries2ndNegative.setYAxisId(1);
            configureSeriesPainter(lineSeries2ndNegative, javaDates, valuesRelativeNegative, colorAreaNegative, 1, LineStyle.SOLID, true, false);
            ILineSeries lineSeries2ndPositive = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$
            Messages.LabelChartDetailChartDevelopmentClosing + "Positive");
            lineSeries2ndPositive.setSymbolType(PlotSymbolType.NONE);
            lineSeries2ndPositive.setYAxisId(1);
            configureSeriesPainter(lineSeries2ndPositive, javaDates, valuesRelativePositive, colorAreaPositive, 1, LineStyle.SOLID, true, false);
        }
        ILineSeries lineSeries = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, Messages.ColumnQuote);
        lineSeries.setSymbolType(PlotSymbolType.NONE);
        configureSeriesPainter(lineSeries, javaDates, values, colorQuote, 2, LineStyle.SOLID, !showAreaRelativeToFirstQuote, false);
        chart.adjustRange();
        addChartMarkerForeground(chartInterval);
        chart.adjustRange();
        IAxis yAxis1st = chart.getAxisSet().getYAxis(0);
        IAxis yAxis2nd = chart.getAxisSet().getYAxis(1);
        yAxis2nd.setRange(new Range(yAxis1st.getRange().lower - firstQuote, yAxis1st.getRange().upper - firstQuote));
        yAxis1st.enableLogScale(chartConfig.contains(ChartDetails.SCALING_LOG));
        yAxis2nd.enableLogScale(chartConfig.contains(ChartDetails.SCALING_LOG));
        yAxis1st.getTick().setVisible(true);
        if (chartConfig.contains(ChartDetails.SHOW_MISSING_TRADING_DAYS)) {
            TradeCalendar tradeCalendar = TradeCalendarManager.getInstance(security);
            List<LocalDate> calendarDates = new ArrayList<>();
            for (LocalDate calendarDate = dates[0]; calendarDate.isBefore(dates[dates.length - 1]); calendarDate = calendarDate.plusDays(1)) calendarDates.add(calendarDate);
            for (LocalDate pricingDate : dates) calendarDates.remove(pricingDate);
            for (LocalDate targetDate : calendarDates) {
                if (!tradeCalendar.isHoliday(targetDate))
                    chart.addNonTradingDayMarker(targetDate, colorNonTradingDay);
            }
        }
    } finally {
        chart.setRedraw(true);
        chart.redraw();
    }
}
Also used : ILineSeries(org.swtchart.ILineSeries) TradeCalendar(name.abuchen.portfolio.util.TradeCalendar) ArrayList(java.util.ArrayList) Range(org.swtchart.Range) ISeries(org.swtchart.ISeries) LocalDate(java.time.LocalDate) Point(org.eclipse.swt.graphics.Point) Date(java.util.Date) LocalDate(java.time.LocalDate) IAxis(org.swtchart.IAxis) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice)

Example 62 with ISeries

use of org.swtchart.ISeries in project portfolio by buchen.

the class StackedChartViewer method rebuildChartSeries.

private void rebuildChartSeries(long[] totals, List<SeriesBuilder> series) {
    if (chart.isDisposed())
        return;
    try {
        chart.suspendUpdate(true);
        for (ISeries s : chart.getSeriesSet().getSeries()) chart.getSeriesSet().deleteSeries(s.getId());
        for (SeriesBuilder serie : series) {
            // 
            chart.addSeries(// 
            serie.node.getClassification().getPathName(false), // 
            serie.getValues(totals), getRenderer().getColorFor(serie.node));
        }
        chart.getAxisSet().adjustRange();
        chart.getAxisSet().getYAxis(0).setRange(new Range(-0.01, 1.01));
    } finally {
        chart.suspendUpdate(false);
        chart.redraw();
    }
    isDirty = false;
}
Also used : Range(org.swtchart.Range) ISeries(org.swtchart.ISeries)

Example 63 with ISeries

use of org.swtchart.ISeries in project portfolio by buchen.

the class AbstractChartTab method updateChart.

private void updateChart() {
    try {
        chart.suspendUpdate(true);
        for (ISeries s : chart.getSeriesSet().getSeries()) chart.getSeriesSet().deleteSeries(s.getId());
        createSeries();
        chart.getAxisSet().adjustRange();
    } finally {
        chart.suspendUpdate(false);
    }
    chart.redraw();
}
Also used : ISeries(org.swtchart.ISeries)

Example 64 with ISeries

use of org.swtchart.ISeries in project portfolio by buchen.

the class ScatterChartCSVExporter method writeToFile.

@Override
protected void writeToFile(File file) throws IOException {
    try (CSVPrinter printer = new CSVPrinter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8), STRATEGY)) {
        // write header
        printer.print(Messages.ColumnDataSeries);
        printer.print(chart.getAxisSet().getXAxis(0).getTitle().getText());
        printer.print(chart.getAxisSet().getYAxis(0).getTitle().getText());
        printer.println();
        // write body
        ISeries[] series = chart.getSeriesSet().getSeries();
        for (ISeries serie : series) {
            printer.print(serie.getId());
            printer.print(valueFormat.format(serie.getXSeries()[0]));
            printer.print(valueFormat.format(serie.getYSeries()[0]));
            printer.println();
        }
    }
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ISeries(org.swtchart.ISeries)

Example 65 with ISeries

use of org.swtchart.ISeries in project portfolio by buchen.

the class TimelineChartCSVExporter method writeToFile.

@Override
protected void writeToFile(File file) throws IOException {
    try (CSVPrinter printer = new CSVPrinter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8), STRATEGY)) {
        ISeries[] series = chart.getSeriesSet().getSeries();
        // write header
        printer.print(Messages.ColumnDate);
        for (ISeries s : series) printer.print(s.getId());
        printer.println();
        // write body
        Date[] dateSeries = series[0].getXDateSeries();
        SeriesAdapter[] adapters = new SeriesAdapter[series.length];
        for (int ii = 0; ii < series.length; ii++) {
            if (discontinousSeries.contains(series[ii].getId()))
                adapters[ii] = new DiscontinousAdapter(series[ii]);
            else
                adapters[ii] = new DefaultAdapter(series[ii]);
        }
        for (int line = 0; line < dateSeries.length; line++) {
            printer.print(dateFormat.format(dateSeries[line]));
            for (int col = 0; col < adapters.length; col++) printer.print(adapters[col].format(dateSeries[line], line));
            printer.println();
        }
    }
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ISeries(org.swtchart.ISeries) Date(java.util.Date)

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