use of org.eclipse.swtchart.model.Node 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);
}
}
}
}
}
use of org.eclipse.swtchart.model.Node 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;
}
use of org.eclipse.swtchart.model.Node in project portfolio by buchen.
the class PieChart method renderNodeLabel.
protected void renderNodeLabel(Node node, ICircularSeries<?> series, GC gc, IAxis xAxis, IAxis yAxis) {
// children drawn first as parent overrides it's section of drawing
if (!node.getChildren().isEmpty()) {
for (Node childNode : node.getChildren()) {
renderNodeLabel(childNode, series, gc, xAxis, yAxis);
}
}
if (!node.isVisible())
return;
int level = node.getLevel() - series.getRootNode().getLevel() + (chartType == IPieChart.ChartType.PIE ? 0 : 1);
Font oldFont = gc.getFont();
gc.setForeground(Colors.WHITE);
int angleStart = node.getAngleBounds().x;
int angleWidth = (int) (node.getAngleBounds().y * 0.5);
Point outerEnd = calcPixelCoord(xAxis, yAxis, level * 0.85, angleStart + angleWidth);
FontDescriptor boldDescriptor = FontDescriptor.createFrom(gc.getFont()).setHeight(9);
gc.setFont(boldDescriptor.createFont(getDisplay()));
String label = labelProvider.getLabel(node);
if (label != null) {
Point textSize = gc.textExtent(label);
gc.drawString(label, outerEnd.x - (textSize.x / 2), outerEnd.y - (textSize.y / 2), true);
}
gc.setFont(oldFont);
}
use of org.eclipse.swtchart.model.Node in project portfolio by buchen.
the class HoldingsPieChartSWT method createControl.
@Override
public Control createControl(Composite parent) {
chart = new PieChart(parent, IPieChart.ChartType.DONUT, this::getNodeLabel);
// set customized tooltip builder
chart.getToolTip().setToolTipBuilder((container, currentNode) -> {
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 assetLabel = new Label(data, SWT.NONE);
FontDescriptor boldDescriptor = FontDescriptor.createFrom(assetLabel.getFont()).setStyle(SWT.BOLD);
assetLabel.setFont(boldDescriptor.createFont(assetLabel.getDisplay()));
assetLabel.setText(currentNode.getId());
NodeData nodeData = nodeDataMap.get(currentNode.getId());
if (nodeData != null) {
Label right = new Label(data, SWT.NONE);
// $NON-NLS-1$ //$NON-NLS-2$
right.setText("(" + nodeData.percentageString + ")");
Label info = new Label(container, SWT.NONE);
info.setText(// $NON-NLS-1$
String.format(// $NON-NLS-1$
"%s x %s = %s", nodeData.shares, nodeData.valueSingle, nodeData.value));
}
});
// Listen on mouse clicks to update information pane
((Composite) chart.getPlotArea()).addListener(SWT.MouseUp, event -> {
Node node = chart.getNodeAt(event.x, event.y);
if (node == null)
return;
NodeData nodeData = nodeDataMap.get(node.getId());
if (nodeData != null) {
financeView.setInformationPaneInput(nodeData.position.getInvestmentVehicle());
}
});
chart.getTitle().setVisible(false);
chart.getLegend().setPosition(SWT.RIGHT);
updateChart();
return chart;
}
use of org.eclipse.swtchart.model.Node 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();
}
Aggregations