Search in sources :

Example 1 with DataSeries

use of name.abuchen.portfolio.ui.views.dataseries.DataSeries in project portfolio by buchen.

the class PerformanceHeatmapWidget method fillTable.

private void fillTable() {
    // fill the table lines according to the supplied period
    // calculate the performance with a temporary reporting period
    // calculate the color interpolated between red and green with yellow as
    // the median
    Interval interval = get(ReportingPeriodConfig.class).getReportingPeriod().toInterval();
    DoubleFunction<Color> coloring = buildColorFunction();
    addHeaderRow();
    DataSeries dataSeries = get(DataSeriesConfig.class).getDataSeries();
    // adapt interval to include the first and last month fully
    Interval calcInterval = Interval.of(interval.getStart().getDayOfMonth() == interval.getStart().lengthOfMonth() ? interval.getStart() : interval.getStart().withDayOfMonth(1).minusDays(1), interval.getEnd().withDayOfMonth(interval.getEnd().lengthOfMonth()));
    PerformanceIndex performanceIndex = getDashboardData().calculate(dataSeries, new ReportingPeriod.FromXtoY(calcInterval));
    Interval actualInterval = performanceIndex.getActualInterval();
    for (Integer year : actualInterval.iterYears()) {
        // year
        Cell cell = new Cell(table, () -> {
            int numColumns = getDashboardData().getDashboard().getColumns().size();
            return numColumns > 2 ? String.valueOf(year % 100) : String.valueOf(year);
        });
        GridDataFactory.fillDefaults().grab(true, false).applyTo(cell);
        // monthly data
        for (LocalDate month = LocalDate.of(year, 1, 1); month.getYear() == year; month = month.plusMonths(1)) {
            if (actualInterval.contains(month)) {
                cell = createCell(performanceIndex, month, coloring);
                InfoToolTip.attach(cell, Messages.PerformanceHeatmapToolTip);
            } else {
                // $NON-NLS-1$
                cell = new Cell(table, () -> "");
            }
            GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(cell);
        }
    }
    table.layout(true);
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Color(org.eclipse.swt.graphics.Color) DataSeries(name.abuchen.portfolio.ui.views.dataseries.DataSeries) LocalDate(java.time.LocalDate) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Point(org.eclipse.swt.graphics.Point) Interval(name.abuchen.portfolio.util.Interval)

Example 2 with DataSeries

use of name.abuchen.portfolio.ui.views.dataseries.DataSeries in project portfolio by buchen.

the class ChartWidget method update.

@Override
public void update() {
    title.setText(getWidget().getLabel());
    try {
        chart.suspendUpdate(true);
        chart.getTitle().setText(title.getText());
        for (ISeries s : chart.getSeriesSet().getSeries()) chart.getSeriesSet().deleteSeries(s.getId());
        List<DataSeries> series = new DataSeriesSerializer().fromString(dataSeriesSet, get(ChartConfig.class).getData());
        ReportingPeriod reportingPeriod = get(ReportingPeriodConfig.class).getReportingPeriod();
        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 : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) DataSeriesSerializer(name.abuchen.portfolio.ui.views.dataseries.DataSeriesSerializer) DataSeries(name.abuchen.portfolio.ui.views.dataseries.DataSeries) ISeries(org.swtchart.ISeries)

Example 3 with DataSeries

use of name.abuchen.portfolio.ui.views.dataseries.DataSeries in project portfolio by buchen.

the class DataSeriesConfig method doAddSeries.

private void doAddSeries(boolean showOnlyBenchmark) {
    List<DataSeries> list = delegate.getDashboardData().getDataSeriesSet().getAvailableSeries().stream().filter(ds -> ds.isBenchmark() == showOnlyBenchmark).collect(Collectors.toList());
    ListSelectionDialog dialog = new ListSelectionDialog(Display.getDefault().getActiveShell(), new DataSeriesLabelProvider());
    dialog.setTitle(Messages.ChartSeriesPickerTitle);
    dialog.setMessage(Messages.ChartSeriesPickerTitle);
    dialog.setElements(list);
    dialog.setMultiSelection(false);
    if (dialog.open() != ListSelectionDialog.OK)
        return;
    Object[] result = dialog.getResult();
    if (result == null || result.length == 0)
        return;
    dataSeries = (DataSeries) result[0];
    delegate.getWidget().getConfiguration().put(Dashboard.Config.DATA_SERIES.name(), dataSeries.getUUID());
    // construct label to indicate the data series (user can manually change
    // the label later)
    // $NON-NLS-1$
    String label = WidgetFactory.valueOf(delegate.getWidget().getType()).getLabel() + ", " + dataSeries.getLabel();
    delegate.getWidget().setLabel(label);
    delegate.getClient().markDirty();
}
Also used : Separator(org.eclipse.jface.action.Separator) Dashboard(name.abuchen.portfolio.model.Dashboard) MenuManager(org.eclipse.jface.action.MenuManager) DataSeries(name.abuchen.portfolio.ui.views.dataseries.DataSeries) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Display(org.eclipse.swt.widgets.Display) Collectors(java.util.stream.Collectors) List(java.util.List) IMenuManager(org.eclipse.jface.action.IMenuManager) Messages(name.abuchen.portfolio.ui.Messages) ListSelectionDialog(name.abuchen.portfolio.ui.dialogs.ListSelectionDialog) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) DataSeriesLabelProvider(name.abuchen.portfolio.ui.views.dataseries.DataSeriesLabelProvider) DataSeries(name.abuchen.portfolio.ui.views.dataseries.DataSeries) ListSelectionDialog(name.abuchen.portfolio.ui.dialogs.ListSelectionDialog) DataSeriesLabelProvider(name.abuchen.portfolio.ui.views.dataseries.DataSeriesLabelProvider)

Aggregations

DataSeries (name.abuchen.portfolio.ui.views.dataseries.DataSeries)3 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)2 LocalDate (java.time.LocalDate)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Dashboard (name.abuchen.portfolio.model.Dashboard)1 PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)1 Messages (name.abuchen.portfolio.ui.Messages)1 ListSelectionDialog (name.abuchen.portfolio.ui.dialogs.ListSelectionDialog)1 LabelOnly (name.abuchen.portfolio.ui.util.LabelOnly)1 SimpleAction (name.abuchen.portfolio.ui.util.SimpleAction)1 DataSeriesLabelProvider (name.abuchen.portfolio.ui.views.dataseries.DataSeriesLabelProvider)1 DataSeriesSerializer (name.abuchen.portfolio.ui.views.dataseries.DataSeriesSerializer)1 Interval (name.abuchen.portfolio.util.Interval)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 Separator (org.eclipse.jface.action.Separator)1 Color (org.eclipse.swt.graphics.Color)1 Point (org.eclipse.swt.graphics.Point)1 Display (org.eclipse.swt.widgets.Display)1