Search in sources :

Example 1 with PlainChart

use of name.abuchen.portfolio.ui.util.chart.PlainChart in project portfolio by buchen.

the class AbstractChartTab method createControl.

@Override
public Control createControl(Composite parent) {
    resources = new LocalResourceManager(JFaceResources.getResources(), parent);
    chart = new PlainChart(parent, SWT.NONE);
    // $NON-NLS-1$
    chart.setData(UIConstants.CSS.CLASS_NAME, "chart");
    chart.getTitle().setVisible(false);
    chart.getLegend().setPosition(SWT.BOTTOM);
    IAxis xAxis = chart.getAxisSet().getXAxis(0);
    xAxis.getTitle().setVisible(false);
    xAxis.getTitle().setText(Messages.ColumnMonth);
    IAxis yAxis = chart.getAxisSet().getYAxis(0);
    yAxis.getTitle().setVisible(false);
    yAxis.setPosition(Position.Secondary);
    xAxis.enableCategory(true);
    // format symbols returns 13 values as some calendars have 13 months
    xAxis.setCategorySeries(Arrays.copyOfRange(new DateFormatSymbols().getMonths(), 0, 12));
    createSeries();
    chart.getAxisSet().adjustRange();
    // if max/min value of range is more than 1000, formatting is #.#k
    Range r = yAxis.getRange();
    if (r.lower < -1000.0 || r.upper > 1000.0) {
        yAxis.getTick().setFormat(new ThousandsNumberFormat());
    }
    attachTooltipTo(chart);
    model.addUpdateListener(this::updateChart);
    return chart;
}
Also used : ThousandsNumberFormat(name.abuchen.portfolio.ui.util.chart.TimelineChart.ThousandsNumberFormat) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) DateFormatSymbols(java.text.DateFormatSymbols) PlainChart(name.abuchen.portfolio.ui.util.chart.PlainChart) Range(org.swtchart.Range) IAxis(org.swtchart.IAxis)

Example 2 with PlainChart

use of name.abuchen.portfolio.ui.util.chart.PlainChart in project portfolio by buchen.

the class ActivityWidget method createControl.

@Override
public Composite createControl(Composite parent, DashboardResources resources) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).margins(5, 5).applyTo(container);
    container.setBackground(parent.getBackground());
    title = new Label(container, SWT.NONE);
    title.setBackground(container.getBackground());
    title.setText(TextUtil.tooltip(getWidget().getLabel()));
    GridDataFactory.fillDefaults().grab(true, false).applyTo(title);
    chart = new PlainChart(container, SWT.NONE);
    // $NON-NLS-1$
    chart.setData(UIConstants.CSS.CLASS_NAME, "chart");
    getDashboardData().getStylingEngine().style(chart);
    chart.setBackground(container.getBackground());
    chart.getTitle().setVisible(false);
    chart.getTitle().setText(title.getText());
    chart.getLegend().setVisible(false);
    toolTip = new TimelineChartToolTip(chart);
    toolTip.enableCategory(true);
    toolTip.reverseLabels(true);
    // $NON-NLS-1$
    toolTip.setDefaultValueFormat(new DecimalFormat("#"));
    toolTip.setXAxisFormat(obj -> {
        Integer index = (Integer) obj;
        @SuppressWarnings("unchecked") List<YearMonth> yearMonths = (List<YearMonth>) chart.getData();
        return yearMonths.get(index).toString();
    });
    int yHint = get(ChartHeightConfig.class).getPixel();
    GridDataFactory.fillDefaults().hint(SWT.DEFAULT, yHint).grab(true, false).applyTo(chart);
    // configure axis
    IAxis xAxis = chart.getAxisSet().getXAxis(0);
    xAxis.getTick().setVisible(true);
    xAxis.getTitle().setVisible(false);
    xAxis.getTitle().setText(Messages.ColumnMonth);
    xAxis.getGrid().setStyle(LineStyle.NONE);
    xAxis.enableCategory(true);
    IAxis yAxis = chart.getAxisSet().getYAxis(0);
    yAxis.getTitle().setVisible(false);
    yAxis.setPosition(Position.Secondary);
    chart.getPlotArea().addTraverseListener(event -> event.doit = true);
    ((IPlotArea) chart.getPlotArea()).addCustomPaintListener(new TimeGridPaintListener(chart));
    container.layout();
    return container;
}
Also used : TimelineChartToolTip(name.abuchen.portfolio.ui.util.chart.TimelineChartToolTip) Composite(org.eclipse.swt.widgets.Composite) DecimalFormat(java.text.DecimalFormat) Label(org.eclipse.swt.widgets.Label) Point(org.eclipse.swt.graphics.Point) IAxis(org.swtchart.IAxis) YearMonth(java.time.YearMonth) IPlotArea(org.swtchart.IPlotArea) ArrayList(java.util.ArrayList) List(java.util.List) PlainChart(name.abuchen.portfolio.ui.util.chart.PlainChart)

Aggregations

PlainChart (name.abuchen.portfolio.ui.util.chart.PlainChart)2 IAxis (org.swtchart.IAxis)2 DateFormatSymbols (java.text.DateFormatSymbols)1 DecimalFormat (java.text.DecimalFormat)1 YearMonth (java.time.YearMonth)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ThousandsNumberFormat (name.abuchen.portfolio.ui.util.chart.TimelineChart.ThousandsNumberFormat)1 TimelineChartToolTip (name.abuchen.portfolio.ui.util.chart.TimelineChartToolTip)1 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)1 Point (org.eclipse.swt.graphics.Point)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 IPlotArea (org.swtchart.IPlotArea)1 Range (org.swtchart.Range)1