Search in sources :

Example 1 with PieHiliteCalculator

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;
    }
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) PieSectionDataModel(org.knime.base.node.viz.pie.datamodel.PieSectionDataModel) PieHiliteCalculator(org.knime.base.node.viz.pie.datamodel.PieHiliteCalculator) Rectangle2D(java.awt.geom.Rectangle2D) Arc2D(java.awt.geom.Arc2D) Point(java.awt.Point)

Aggregations

Point (java.awt.Point)1 Arc2D (java.awt.geom.Arc2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 AggregationMethod (org.knime.base.node.viz.aggregation.AggregationMethod)1 PieHiliteCalculator (org.knime.base.node.viz.pie.datamodel.PieHiliteCalculator)1 PieSectionDataModel (org.knime.base.node.viz.pie.datamodel.PieSectionDataModel)1