Search in sources :

Example 1 with AggregationMethod

use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.

the class PieVizModel method createLabel.

/**
 * @param section the main section
 * @param subSection the sub section of interest
 * @return the label for the sub section including some section information
 */
public String createLabel(final PieSectionDataModel section, final PieSubSectionDataModel subSection) {
    if (section == null) {
        throw new NullPointerException("Section must not be null");
    }
    if (section.getElements().size() == 1) {
        // if the section contains only one label just draw the section label
        return createLabel(section);
    }
    if (subSection == null) {
        throw new NullPointerException("subSection must not be null");
    }
    final String name = section.getName();
    final AggregationMethod aggrMethod = getAggregationMethod();
    final double value = section.getAggregationValue(aggrMethod);
    final double totalValue = getAbsAggregationValue();
    final double scaledValue = m_valueScale.scale(value, totalValue);
    final String valuePart = GUIUtils.createLabel(scaledValue, NO_OF_LABEL_DIGITS, aggrMethod, m_valueScale);
    final double subValue = subSection.getAggregationValue(aggrMethod);
    final double scaledSubValue = m_valueScale.scale(subValue, totalValue);
    final String subValuePart = GUIUtils.createLabel(scaledSubValue, NO_OF_LABEL_DIGITS, aggrMethod, m_valueScale);
    final StringBuilder buf = new StringBuilder();
    if (name != null) {
        buf.append(name);
        buf.append(": ");
        buf.append(aggrMethod.getText());
        buf.append(' ');
    }
    buf.append(subValuePart);
    buf.append(" (");
    buf.append(valuePart);
    buf.append(')');
    return buf.toString();
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod)

Example 2 with AggregationMethod

use of org.knime.base.node.viz.aggregation.AggregationMethod 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)

Example 3 with AggregationMethod

use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.

the class PiePlotter method registerPropertiesChangeListener.

/**
 * Registers all histogram properties listener to the histogram
 * properties panel.
 */
private void registerPropertiesChangeListener() {
    m_props.addShowSectionOutlineChangedListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel != null) {
                vizModel.setDrawSectionOutline(e.getStateChange() == ItemEvent.SELECTED);
                final AbstractDrawingPane drawingPane = getPieDrawingPane();
                drawingPane.repaint();
            }
        }
    });
    m_props.addLabelDisplayListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel != null) {
                final P props = getPropertiesPanel();
                if (props != null) {
                    vizModel.setLabelDisplayPolicy(props.getLabelDisplayPolicy());
                    final AbstractDrawingPane drawingPane = getPieDrawingPane();
                    drawingPane.repaint();
                }
            }
        }
    });
    m_props.addValueScaleListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel != null) {
                final P props = getPropertiesPanel();
                if (props != null) {
                    vizModel.setValueScale(props.getValueScale());
                    final AbstractDrawingPane drawingPane = getPieDrawingPane();
                    drawingPane.repaint();
                }
            }
        }
    });
    m_props.addShowDetailsListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel != null) {
                if (vizModel.setShowDetails(e.getStateChange() == ItemEvent.SELECTED)) {
                    final AbstractDrawingPane drawingPane = getPieDrawingPane();
                    drawingPane.repaint();
                }
            }
        }
    });
    m_props.addPieSizeChangeListener(new ChangeListener() {

        public void stateChanged(final ChangeEvent e) {
            final JSlider source = (JSlider) e.getSource();
            final int pieSize = source.getValue();
            final PieVizModel vizModel = getVizModel();
            if (vizModel == null) {
                return;
            }
            if (vizModel.setPieSize((pieSize / 100.0))) {
                updatePaintModel();
            }
        }
    });
    m_props.addExplodeSizeChangeListener(new ChangeListener() {

        public void stateChanged(final ChangeEvent e) {
            final JSlider source = (JSlider) e.getSource();
            final int explodeSize = source.getValue();
            final PieVizModel vizModel = getVizModel();
            if (vizModel == null) {
                return;
            }
            if (vizModel.setExplodeSize((explodeSize / 100.0))) {
                updatePaintModel();
            }
        }
    });
    m_props.addAggrMethodListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel == null) {
                return;
            }
            final String methodName = e.getActionCommand();
            if (!AggregationMethod.valid(methodName)) {
                throw new IllegalArgumentException("No valid aggregation method");
            }
            final AggregationMethod aggrMethod = AggregationMethod.getMethod4Command(methodName);
            if (vizModel.setAggregationMethod(aggrMethod)) {
                updatePaintModel();
            }
        }
    });
    m_props.addShowMissingValSectionListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel == null) {
                return;
            }
            if (vizModel.setShowMissingValSection(e.getStateChange() == ItemEvent.SELECTED)) {
                // reset the details view if the missing section was selected
                final P properties = getPropertiesPanel();
                if (properties != null) {
                    properties.updateHTMLDetailsPanel(vizModel.getHTMLDetailData());
                }
                updatePaintModel();
            }
        }
    });
    m_props.addExplodeSelectedSectionListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            final PieVizModel vizModel = getVizModel();
            if (vizModel == null) {
                return;
            }
            if (vizModel.setExplodeSelectedSections(e.getStateChange() == ItemEvent.SELECTED)) {
                updatePaintModel();
            }
        }
    });
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) ItemEvent(java.awt.event.ItemEvent) PieVizModel(org.knime.base.node.viz.pie.datamodel.PieVizModel) ActionEvent(java.awt.event.ActionEvent) AbstractDrawingPane(org.knime.base.node.viz.plotter.AbstractDrawingPane) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) JSlider(javax.swing.JSlider) ItemListener(java.awt.event.ItemListener) ChangeListener(javax.swing.event.ChangeListener)

Example 4 with AggregationMethod

use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.

the class PieNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec spec = (DataTableSpec) inSpecs[0];
    if (spec == null) {
        throw new IllegalArgumentException("Table specification must not be null");
    }
    final String colName = m_pieColumn.getStringValue();
    if (colName == null || colName.length() < 1) {
        throw new InvalidSettingsException("Please select the pie column");
    }
    final DataColumnSpec pieCol = spec.getColumnSpec(colName);
    if (pieCol == null) {
        throw new InvalidSettingsException("Specified column name '" + colName + "' not found in input table");
    }
    if (!PieColumnFilter.validDomain(pieCol)) {
        throw new InvalidSettingsException("No valid pie column selected.");
    }
    final AggregationMethod method = AggregationMethod.getMethod4Command(m_aggrMethod.getStringValue());
    if (method == null) {
        throw new InvalidSettingsException("No valid aggregation method");
    }
    return new DataTableSpec[0];
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 5 with AggregationMethod

use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.

the class BinDataModel method setBarRectangle.

/**
 * Sets the rectangle for all bars in this bin.
 * @param baseLine the x coordinate of the base line (0) on the screen
 * @param barElementColors all element colors which define the order
 * the elements should be drawn
 * @param aggrColumns the aggregation column array which indicates
 * the order of the bars
 */
private void setBarRectangle(final int baseLine, final List<Color> barElementColors, final Collection<? extends ColorColumn> aggrColumns, final HistogramHiliteCalculator calculator) {
    if (m_binRectangle == null) {
        final Collection<BarDataModel> bars = m_bars.values();
        // also reset the bar rectangle
        for (final BarDataModel bar : bars) {
            bar.setBarRectangle(null, baseLine, barElementColors, calculator);
        }
        return;
    }
    final AggregationMethod aggrMethod = calculator.getAggrMethod();
    final HistogramLayout layout = calculator.getLayout();
    final int binWidth = (int) m_binRectangle.getWidth();
    final int noOfBars = aggrColumns.size();
    m_presentable = elementsFitInBin(noOfBars, binWidth);
    if (!m_presentable) {
        return;
    }
    // calculate the height
    final int binHeight = (int) m_binRectangle.getHeight();
    final double maxAggrVal = Math.max(getMaxAggregationValue(aggrMethod, layout), 0);
    final double minAggrVal = Math.min(getMinAggregationValue(aggrMethod, layout), 0);
    final double valRange = maxAggrVal + Math.abs(minAggrVal);
    if (valRange <= 0) {
        m_presentable = false;
        return;
    }
    final int barWidth = calculateBarWidth(binWidth, noOfBars);
    final double heightPerVal = binHeight / valRange;
    final int binX = (int) m_binRectangle.getX();
    int xCoord = binX;
    for (final ColorColumn aggrColumn : aggrColumns) {
        final BarDataModel bar = m_bars.get(aggrColumn.getColor());
        if (bar != null) {
            // set the rectangle only for the bars which are available
            // in this bin
            final double barMaxAggrVal = Math.max(bar.getMaxAggregationValue(aggrMethod, layout), 0);
            final double barMinAggrVal = Math.min(bar.getMinAggregationValue(aggrMethod, layout), 0);
            final double aggrVal = barMaxAggrVal + Math.abs(barMinAggrVal);
            final int yCoord = (int) (baseLine - (barMaxAggrVal * heightPerVal));
            final int barHeight = (int) (aggrVal * heightPerVal);
            final Rectangle barRect = new Rectangle(xCoord, yCoord, barWidth, barHeight);
            bar.setBarRectangle(barRect, baseLine, barElementColors, calculator);
        }
        // add the bar width and the space between bars to the current
        // x coordinate
        xCoord += barWidth + AbstractHistogramVizModel.SPACE_BETWEEN_BARS;
    }
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) Rectangle(java.awt.Rectangle) Point(java.awt.Point) HistogramLayout(org.knime.base.node.viz.histogram.HistogramLayout)

Aggregations

AggregationMethod (org.knime.base.node.viz.aggregation.AggregationMethod)17 HistogramLayout (org.knime.base.node.viz.histogram.HistogramLayout)5 Rectangle2D (java.awt.geom.Rectangle2D)4 ColorColumn (org.knime.base.node.viz.histogram.util.ColorColumn)4 Point (java.awt.Point)3 Rectangle (java.awt.Rectangle)3 AbstractHistogramVizModel (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)3 Color (java.awt.Color)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 Arc2D (java.awt.geom.Arc2D)2 ChangeEvent (javax.swing.event.ChangeEvent)2 ChangeListener (javax.swing.event.ChangeListener)2 BinDataModel (org.knime.base.node.viz.histogram.datamodel.BinDataModel)2 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1