Search in sources :

Example 26 with ISeries

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

the class ExchangeRatesListTab method refreshChart.

private void refreshChart(ExchangeRateTimeSeries series) {
    try {
        chart.suspendUpdate(true);
        for (ISeries s : chart.getSeriesSet().getSeries()) chart.getSeriesSet().deleteSeries(s.getId());
        if (series == null || series.getRates().isEmpty()) {
            chart.getTitle().setText(Messages.LabelCurrencies);
            return;
        }
        List<ExchangeRate> rates = series.getRates();
        LocalDate[] dates = new LocalDate[rates.size()];
        double[] values = new double[rates.size()];
        int ii = 0;
        for (ExchangeRate rate : rates) {
            dates[ii] = rate.getTime();
            values[ii] = rate.getValue().doubleValue();
            ii++;
        }
        Optional<ExchangeRateProvider> provider = series.getProvider();
        String title = // $NON-NLS-1$
        MessageFormat.format(// $NON-NLS-1$
        "{0}/{1} ({2})", series.getBaseCurrency(), series.getTermCurrency(), // $NON-NLS-1$
        provider.isPresent() ? provider.get().getName() : "-");
        chart.getTitle().setText(title);
        chart.addDateSeries(dates, values, Colors.ICON_BLUE, title);
        chart.adjustRange();
    } finally {
        chart.suspendUpdate(false);
        chart.redraw();
    }
}
Also used : ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) ExchangeRateProvider(name.abuchen.portfolio.money.ExchangeRateProvider) ISeries(org.swtchart.ISeries) LocalDate(java.time.LocalDate)

Example 27 with ISeries

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

the class PerformanceChartView method updateChart.

private void updateChart() {
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        updateTitle(Messages.LabelPerformanceChart + " (" + picker.getConfigurationName() + ")");
        chart.suspendUpdate(true);
        chart.getTitle().setText(getTitle());
        for (ISeries s : chart.getSeriesSet().getSeries()) chart.getSeriesSet().deleteSeries(s.getId());
        setChartSeries();
        chart.adjustRange();
    } finally {
        chart.suspendUpdate(false);
    }
    chart.redraw();
    // re-layout in case chart legend changed
    chart.getParent().layout(true);
}
Also used : ISeries(org.swtchart.ISeries)

Example 28 with ISeries

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

the class ActivityWidget method update.

@Override
public void update(List<TransactionPair<?>> transactions) {
    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());
        ChartType chartType = get(ChartTypeConfig.class).getValue();
        // $NON-NLS-1$ //$NON-NLS-2$
        toolTip.setDefaultValueFormat(new DecimalFormat(chartType == ChartType.COUNT ? "#" : "#,##0.00"));
        IAxis xAxis = chart.getAxisSet().getXAxis(0);
        Interval interval = get(ReportingPeriodConfig.class).getReportingPeriod().toInterval(LocalDate.now());
        List<YearMonth> yearMonths = interval.getYearMonths();
        chart.setData(yearMonths);
        xAxis.setCategorySeries(yearMonths.stream().map(ym -> String.valueOf(ym.getMonthValue())).collect(Collectors.toList()).toArray(new String[0]));
        createSeries(chartType, interval, transactions, yearMonths, PortfolioTransaction.Type.BUY, Colors.ICON_BLUE);
        createSeries(chartType, interval, transactions, yearMonths, PortfolioTransaction.Type.DELIVERY_INBOUND, Colors.brighter(Colors.ICON_BLUE));
        createSeries(chartType, interval, transactions, yearMonths, PortfolioTransaction.Type.SELL, Colors.ICON_ORANGE);
        createSeries(chartType, interval, transactions, yearMonths, PortfolioTransaction.Type.DELIVERY_OUTBOUND, Colors.brighter(Colors.ICON_ORANGE));
    } finally {
        chart.suspendUpdate(false);
    }
    try {
        chart.setRedraw(false);
        chart.getAxisSet().adjustRange();
    } finally {
        chart.setRedraw(true);
    }
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Values(name.abuchen.portfolio.money.Values) IPlotArea(org.swtchart.IPlotArea) CacheKey(name.abuchen.portfolio.ui.util.CacheKey) IAxis(org.swtchart.IAxis) ICustomPaintListener(org.swtchart.ICustomPaintListener) LineStyle(org.swtchart.LineStyle) PlainChart(name.abuchen.portfolio.ui.util.chart.PlainChart) ISeries(org.swtchart.ISeries) TimelineChartToolTip(name.abuchen.portfolio.ui.util.chart.TimelineChartToolTip) Supplier(java.util.function.Supplier) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) ArrayList(java.util.ArrayList) Widget(name.abuchen.portfolio.model.Dashboard.Widget) PaintEvent(org.eclipse.swt.events.PaintEvent) Chart(org.swtchart.Chart) TextUtil(name.abuchen.portfolio.util.TextUtil) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) Interval(name.abuchen.portfolio.util.Interval) GridData(org.eclipse.swt.layout.GridData) UIConstants(name.abuchen.portfolio.ui.UIConstants) Pair(name.abuchen.portfolio.util.Pair) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) Dashboard(name.abuchen.portfolio.model.Dashboard) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) TransactionPair(name.abuchen.portfolio.model.TransactionPair) DecimalFormat(java.text.DecimalFormat) Collectors(java.util.stream.Collectors) IBarSeries(org.swtchart.IBarSeries) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) List(java.util.List) Position(org.swtchart.IAxis.Position) Colors(name.abuchen.portfolio.ui.util.Colors) Color(org.eclipse.swt.graphics.Color) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) YearMonth(java.time.YearMonth) SeriesType(org.swtchart.ISeries.SeriesType) Optional(java.util.Optional) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) DecimalFormat(java.text.DecimalFormat) ISeries(org.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point) IAxis(org.swtchart.IAxis) YearMonth(java.time.YearMonth) GridData(org.eclipse.swt.layout.GridData) Interval(name.abuchen.portfolio.util.Interval)

Example 29 with ISeries

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

the class AccountBalanceChart method updateChart.

public void updateChart(Account account, ExchangeRateProviderFactory exchangeRateProviderFactory) {
    try {
        suspendUpdate(true);
        for (ISeries s : getSeriesSet().getSeries()) getSeriesSet().deleteSeries(s.getId());
        if (account == null)
            return;
        List<AccountTransaction> tx = account.getTransactions();
        if (tx.isEmpty())
            return;
        LocalDate now = LocalDate.now();
        LocalDate start = tx.get(0).getDateTime().toLocalDate();
        LocalDate end = tx.get(tx.size() - 1).getDateTime().toLocalDate();
        CurrencyConverter converter = new CurrencyConverterImpl(exchangeRateProviderFactory, account.getCurrencyCode());
        Collections.sort(tx, Transaction.BY_DATE);
        if (now.isAfter(end))
            end = now;
        if (now.isBefore(start))
            start = now;
        int days = (int) ChronoUnit.DAYS.between(start, end) + 2;
        LocalDate[] dates = new LocalDate[days];
        double[] values = new double[days];
        dates[0] = start.minusDays(1);
        values[0] = 0d;
        for (int ii = 1; ii < dates.length; ii++) {
            values[ii] = // 
            AccountSnapshot.create(account, converter, start).getFunds().getAmount() / Values.Amount.divider();
            dates[ii] = start;
            start = start.plusDays(1);
        }
        addDateSeries(dates, values, Colors.CASH, account.getName());
    } finally {
        adjustRange();
        suspendUpdate(false);
    }
}
Also used : AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) ISeries(org.swtchart.ISeries) LocalDate(java.time.LocalDate) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 30 with ISeries

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

the class TimelineChartToolTip method createComposite.

@Override
protected void createComposite(Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    RowLayout layout = new RowLayout(SWT.VERTICAL);
    layout.center = true;
    container.setLayout(layout);
    Composite data = new Composite(container, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(data);
    Label left = new Label(data, SWT.NONE);
    left.setText(categoryEnabled ? getChart().getAxisSet().getXAxis(0).getTitle().getText() : Messages.ColumnDate);
    Label right = new Label(data, SWT.NONE);
    right.setText(formatXAxisData(getFocusedObject()));
    List<Pair<ISeries, Double>> values = computeValues(getChart().getSeriesSet().getSeries());
    if (reverseLabels)
        Collections.reverse(values);
    if (isAltPressed())
        Collections.sort(values, (l, r) -> r.getValue().compareTo(l.getValue()));
    for (Pair<ISeries, Double> value : values) {
        ISeries series = value.getKey();
        Color color = series instanceof ILineSeries ? ((ILineSeries) series).getLineColor() : ((IBarSeries) series).getBarColor();
        ColoredLabel cl = new ColoredLabel(data, SWT.NONE);
        cl.setBackdropColor(color);
        cl.setText(series.getId());
        GridDataFactory.fillDefaults().grab(true, false).applyTo(cl);
        right = new Label(data, SWT.RIGHT);
        DecimalFormat valueFormat = overrideValueFormat.getOrDefault(series.getId(), defaultValueFormat);
        right.setText(valueFormat.format(value.getRight()));
        GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(right);
    }
    Object focus = getFocusedObject();
    extraInfoProvider.forEach(provider -> provider.accept(container, focus));
    Label hint = new Label(data, SWT.NONE);
    hint.setText(Messages.TooltipHintPressAlt);
    hint.setFont(this.resourceManager.createFont(FontDescriptor.createFrom(data.getFont()).increaseHeight(-3).withStyle(SWT.ITALIC)));
    GridDataFactory.fillDefaults().span(2, 1).applyTo(hint);
}
Also used : Arrays(java.util.Arrays) Values(name.abuchen.portfolio.money.Values) Date(java.util.Date) IAxis(org.swtchart.IAxis) HashMap(java.util.HashMap) JFaceResources(org.eclipse.jface.resource.JFaceResources) ISeries(org.swtchart.ISeries) Function(java.util.function.Function) Event(org.eclipse.swt.widgets.Event) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Chart(org.swtchart.Chart) Calendar(java.util.Calendar) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) ILineSeries(org.swtchart.ILineSeries) Pair(name.abuchen.portfolio.util.Pair) FontDescriptor(org.eclipse.jface.resource.FontDescriptor) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel) DecimalFormat(java.text.DecimalFormat) Set(java.util.Set) IBarSeries(org.swtchart.IBarSeries) ZoneId(java.time.ZoneId) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) List(java.util.List) RowLayout(org.eclipse.swt.layout.RowLayout) Color(org.eclipse.swt.graphics.Color) SWT(org.eclipse.swt.SWT) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) Collections(java.util.Collections) Label(org.eclipse.swt.widgets.Label) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) ILineSeries(org.swtchart.ILineSeries) DecimalFormat(java.text.DecimalFormat) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel) Label(org.eclipse.swt.widgets.Label) ISeries(org.swtchart.ISeries) RowLayout(org.eclipse.swt.layout.RowLayout) ColoredLabel(name.abuchen.portfolio.ui.util.swt.ColoredLabel) Pair(name.abuchen.portfolio.util.Pair)

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