use of eu.hansolo.tilesfx.events.TreeNodeEvent in project tilesfx by HanSolo.
the class SunburstChart method createSegment.
private Path createSegment(final double START_ANGLE, final double END_ANGLE, final double INNER_RADIUS, final double OUTER_RADIUS, final Color FILL, final Color STROKE, final TreeNode NODE) {
double startAngleRad = Math.toRadians(START_ANGLE + 90);
double endAngleRad = Math.toRadians(END_ANGLE + 90);
boolean largeAngle = Math.abs(END_ANGLE - START_ANGLE) > 180.0;
double x1 = centerX + INNER_RADIUS * Math.sin(startAngleRad);
double y1 = centerY - INNER_RADIUS * Math.cos(startAngleRad);
double x2 = centerX + OUTER_RADIUS * Math.sin(startAngleRad);
double y2 = centerY - OUTER_RADIUS * Math.cos(startAngleRad);
double x3 = centerX + OUTER_RADIUS * Math.sin(endAngleRad);
double y3 = centerY - OUTER_RADIUS * Math.cos(endAngleRad);
double x4 = centerX + INNER_RADIUS * Math.sin(endAngleRad);
double y4 = centerY - INNER_RADIUS * Math.cos(endAngleRad);
MoveTo moveTo1 = new MoveTo(x1, y1);
LineTo lineTo2 = new LineTo(x2, y2);
ArcTo arcTo3 = new ArcTo(OUTER_RADIUS, OUTER_RADIUS, 0, x3, y3, largeAngle, true);
LineTo lineTo4 = new LineTo(x4, y4);
ArcTo arcTo1 = new ArcTo(INNER_RADIUS, INNER_RADIUS, 0, x1, y1, largeAngle, false);
Path path = new Path(moveTo1, lineTo2, arcTo3, lineTo4, arcTo1);
path.setFill(FILL);
path.setStroke(STROKE);
String tooltipText = new StringBuilder(NODE.getData().getName()).append("\n").append(String.format(Locale.US, formatString, NODE.getData().getValue())).toString();
Tooltip.install(path, new Tooltip(tooltipText));
path.setOnMousePressed(new WeakEventHandler<>(e -> NODE.getTreeRoot().fireTreeNodeEvent(new TreeNodeEvent(NODE, EventType.NODE_SELECTED))));
return path;
}
Aggregations