Search in sources :

Example 1 with ICircularSeries

use of org.eclipse.swtchart.ICircularSeries in project portfolio by buchen.

the class PieChart method renderLabels.

protected void renderLabels(PaintEvent e) {
    for (ISeries<?> series : getSeriesSet().getSeries()) {
        if (series instanceof ICircularSeries) {
            IAxis xAxis = getAxisSet().getXAxis(series.getXAxisId());
            IAxis yAxis = getAxisSet().getYAxis(series.getYAxisId());
            List<Node> nodes = ((ICircularSeries<?>) series).getRootNode().getChildren();
            if (!nodes.isEmpty()) {
                for (Node node : nodes) {
                    renderNodeLabel(node, (ICircularSeries<?>) series, e.gc, xAxis, yAxis);
                }
            }
        }
    }
}
Also used : Node(org.eclipse.swtchart.model.Node) ICircularSeries(org.eclipse.swtchart.ICircularSeries) IAxis(org.eclipse.swtchart.IAxis)

Example 2 with ICircularSeries

use of org.eclipse.swtchart.ICircularSeries in project portfolio by buchen.

the class PieChart method getNodeAt.

/**
 * Find the node at position
 */
public Node getNodeAt(int x, int y) {
    Node node = null;
    for (ISeries<?> series : getSeriesSet().getSeries()) {
        if (!(series instanceof ICircularSeries)) {
            continue;
        }
        ICircularSeries<?> circularSeries = (ICircularSeries<?>) series;
        double primaryValueX = getSelectedPrimaryAxisValue(x, PieChart.Orientation.X_AXIS);
        double primaryValueY = getSelectedPrimaryAxisValue(y, PieChart.Orientation.Y_AXIS);
        node = circularSeries.getPieSliceFromPosition(primaryValueX, primaryValueY);
        circularSeries.setHighlightedNode(node);
    }
    return node;
}
Also used : Node(org.eclipse.swtchart.model.Node) ICircularSeries(org.eclipse.swtchart.ICircularSeries)

Example 3 with ICircularSeries

use of org.eclipse.swtchart.ICircularSeries in project portfolio by buchen.

the class HoldingsPieChartSWT method updateChart.

private void updateChart() {
    List<Double> values = new ArrayList<>();
    List<String> labels = new ArrayList<>();
    nodeDataMap.clear();
    // 
    snapshot.getAssetPositions().filter(// 
    p -> p.getValuation().getAmount() > 0).sorted(// 
    (l, r) -> Long.compare(r.getValuation().getAmount(), l.getValuation().getAmount())).forEach(p -> {
        String nodeId = JSONObject.escape(p.getDescription());
        labels.add(nodeId);
        values.add(p.getValuation().getAmount() / Values.Amount.divider());
        NodeData data = new NodeData();
        data.position = p;
        data.percentage = p.getShare();
        data.percentageString = Values.Percent2.format(p.getShare());
        data.shares = Values.Share.format(p.getPosition().getShares());
        data.value = Values.Money.format(p.getValuation());
        data.valueSingle = Values.Money.format(p.getValuation().multiply((long) Values.Share.divider()).divide(p.getPosition().getShares()));
        nodeDataMap.put(nodeId, data);
    });
    ICircularSeries<?> circularSeries = (ICircularSeries<?>) chart.getSeriesSet().getSeries(Messages.LabelStatementOfAssetsHoldings);
    if (circularSeries == null) {
        circularSeries = createSeries(values, labels);
    } else {
        if (hasDataSetChanged(labels)) {
            // refresh values only for smoother update
            ListIterator<String> iter = labels.listIterator();
            while (iter.hasNext()) {
                int idx = iter.nextIndex();
                String label = iter.next();
                Node node = circularSeries.getNodeById(label);
                if (node != null) {
                    node.setValue(values.get(idx));
                }
            }
        } else {
            circularSeries = createSeries(values, labels);
        }
    }
    setColors(circularSeries, values.size());
    chart.redraw();
}
Also used : Values(name.abuchen.portfolio.money.Values) ListIterator(java.util.ListIterator) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) Map(java.util.Map) AbstractFinanceView(name.abuchen.portfolio.ui.editor.AbstractFinanceView) PieChart(name.abuchen.portfolio.ui.util.chart.PieChart) FontDescriptor(org.eclipse.jface.resource.FontDescriptor) Node(org.eclipse.swtchart.model.Node) ICircularSeries(org.eclipse.swtchart.ICircularSeries) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) List(java.util.List) RowLayout(org.eclipse.swt.layout.RowLayout) JSONObject(org.json.simple.JSONObject) Colors(name.abuchen.portfolio.ui.util.Colors) Color(org.eclipse.swt.graphics.Color) SWT(org.eclipse.swt.SWT) SeriesType(org.eclipse.swtchart.ISeries.SeriesType) IPieChart(name.abuchen.portfolio.ui.views.IPieChart) Collections(java.util.Collections) Label(org.eclipse.swt.widgets.Label) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Control(org.eclipse.swt.widgets.Control) Node(org.eclipse.swtchart.model.Node) ArrayList(java.util.ArrayList) ICircularSeries(org.eclipse.swtchart.ICircularSeries)

Example 4 with ICircularSeries

use of org.eclipse.swtchart.ICircularSeries in project portfolio by buchen.

the class TaxonomyDonutSWT method updateChart.

private void updateChart() {
    nodeDataMap.clear();
    TaxonomyNode node = chartPage.getModel().getVirtualRootNode();
    ICircularSeries<?> circularSeries = (ICircularSeries<?>) chart.getSeriesSet().createSeries(ChartType.DONUT == chartType ? SeriesType.DOUGHNUT : SeriesType.PIE, node.getName());
    circularSeries.setHighlightColor(Colors.GREEN);
    circularSeries.setBorderColor(Colors.WHITE);
    Money total = getModel().getChartRenderingRootNode().getActual();
    Node rootNode = circularSeries.getRootNode();
    Map<String, Color> colors = new HashMap<>();
    addNodes(nodeDataMap, colors, rootNode, node, node.getChildren(), total);
    for (Map.Entry<String, Color> entry : colors.entrySet()) {
        circularSeries.setColor(entry.getKey(), entry.getValue());
    }
    chart.redraw();
}
Also used : Money(name.abuchen.portfolio.money.Money) HashMap(java.util.HashMap) Node(org.eclipse.swtchart.model.Node) Color(org.eclipse.swt.graphics.Color) ICircularSeries(org.eclipse.swtchart.ICircularSeries) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ICircularSeries

use of org.eclipse.swtchart.ICircularSeries in project portfolio by buchen.

the class TaxonomyPieChartSWT method updateChart.

private void updateChart() {
    nodeDataMap.clear();
    TaxonomyNode taxRoot = getModel().getVirtualRootNode();
    ICircularSeries<?> circularSeries = (ICircularSeries<?>) chart.getSeriesSet().createSeries(ChartType.DONUT == chartType ? SeriesType.DOUGHNUT : SeriesType.PIE, taxRoot.getName());
    circularSeries.setHighlightColor(Colors.GREEN);
    circularSeries.setBorderColor(Colors.WHITE);
    Node rootNode = circularSeries.getRootNode();
    Map<String, Color> colors = new HashMap<>();
    addNodes(nodeDataMap, colors, rootNode, taxRoot, taxRoot.getChildren(), taxRoot.getActual(), getModel().isSecuritiesInPieChartExcluded());
    for (Map.Entry<String, Color> entry : colors.entrySet()) {
        circularSeries.setColor(entry.getKey(), entry.getValue());
    }
    chart.redraw();
}
Also used : HashMap(java.util.HashMap) Node(org.eclipse.swtchart.model.Node) Color(org.eclipse.swt.graphics.Color) ICircularSeries(org.eclipse.swtchart.ICircularSeries) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ICircularSeries (org.eclipse.swtchart.ICircularSeries)5 Node (org.eclipse.swtchart.model.Node)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Color (org.eclipse.swt.graphics.Color)3 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Money (name.abuchen.portfolio.money.Money)1 Values (name.abuchen.portfolio.money.Values)1 AssetPosition (name.abuchen.portfolio.snapshot.AssetPosition)1 ClientSnapshot (name.abuchen.portfolio.snapshot.ClientSnapshot)1 Messages (name.abuchen.portfolio.ui.Messages)1 AbstractFinanceView (name.abuchen.portfolio.ui.editor.AbstractFinanceView)1 Colors (name.abuchen.portfolio.ui.util.Colors)1 PieChart (name.abuchen.portfolio.ui.util.chart.PieChart)1 IPieChart (name.abuchen.portfolio.ui.views.IPieChart)1 GridLayoutFactory (org.eclipse.jface.layout.GridLayoutFactory)1 FontDescriptor (org.eclipse.jface.resource.FontDescriptor)1