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();
}
}
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);
}
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);
}
}
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);
}
}
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);
}
Aggregations