use of org.knime.base.node.viz.pie.datamodel.PieHiliteCalculator in project knime-core by knime.
the class PiePlotter method setPieSections.
/**
* Calculates the size of all pie sections.
* @param vizModel the {@link PieVizModel} that provides visualisation
* information and the sections
*/
private void setPieSections(final PieVizModel vizModel) {
final Rectangle2D pieArea = vizModel.getPieArea();
final Rectangle2D explodedArea = vizModel.getExplodedArea();
final boolean explode = vizModel.explodeSelectedSections();
// final double explodePercentage = vizModel.getExplodeMargin();
final double totalVal = vizModel.getAbsAggregationValue();
final double arcPerVal = 360 / totalVal;
final AggregationMethod method = vizModel.getAggregationMethod();
final PieHiliteCalculator calculator = vizModel.getCalculator();
final List<PieSectionDataModel> pieSections = vizModel.getSections2Draw();
final int noOfSections = pieSections.size();
double startAngle = 0;
for (int i = 0; i < noOfSections; i++) {
final PieSectionDataModel section = pieSections.get(i);
final double value = Math.abs(section.getAggregationValue(method));
double arcAngle = value * arcPerVal;
// avoid a rounding gap
if (i == noOfSections - 1) {
arcAngle = 360 - startAngle;
}
if (arcAngle < PieVizModel.MINIMUM_ARC_ANGLE) {
LOGGER.debug("Pie section: " + vizModel.createLabel(section) + " angle " + arcAngle + " to small to display." + " Angle updated to set to minimum angle " + PieVizModel.MINIMUM_ARC_ANGLE);
arcAngle = PieVizModel.MINIMUM_ARC_ANGLE;
// skip this section
// section.setPieSection(null, calculator);
// continue;
}
final Rectangle2D bounds;
// explode selected sections
if (explode && section.isSelected()) {
bounds = GeometryUtil.getArcBounds(pieArea, explodedArea, startAngle, arcAngle, 1.0);
} else {
bounds = pieArea;
}
final Arc2D arc = new Arc2D.Double(bounds, startAngle, arcAngle, Arc2D.PIE);
section.setPieSection(arc, calculator);
startAngle += arcAngle;
}
}
Aggregations