Search in sources :

Example 11 with AbstractHistogramVizModel

use of org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel in project knime-core by knime.

the class AbstractHistogramPlotter method hiLite.

// *************************************************************************
// Selection and hiliting section
// *************************************************************************
/**
 * {@inheritDoc}
 */
@Override
public void hiLite(final KeyEvent event) {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null || !vizModel.supportsHiliting()) {
        LOGGER.debug("VizModel doesn't support hiliting or was null");
        return;
    }
    final Set<RowKey> hilited = event.keys();
    vizModel.updateHiliteInfo(hilited, true);
    repaint();
}
Also used : AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) RowKey(org.knime.core.data.RowKey)

Example 12 with AbstractHistogramVizModel

use of org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel in project knime-core by knime.

the class AbstractHistogramPlotter method getAggregationColSpec.

/**
 * @return the <code>DataColumnSpec</code> of the aggregation column
 */
public DataColumnSpec getAggregationColSpec() {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null) {
        LOGGER.debug("VizModel was null");
        throw new IllegalStateException("Exception in getAggregationColSpec: " + "Viz model must not be null");
    }
    double lowerBound = vizModel.getMinAggregationValue();
    double upperBound = vizModel.getMaxAggregationValue();
    // coordinate
    if (lowerBound > 0) {
        lowerBound = 0;
    } else if (upperBound < 0) {
        upperBound = 0;
    }
    final AggregationMethod aggrMethod = vizModel.getAggregationMethod();
    // set the column type depending on the aggregation method and type of
    // the aggregation column. If the method is count set it to integer. If
    // the aggregation method is summary and the data type of the
    // aggregation column is integer the result must be an integer itself
    DataType type = DoubleCell.TYPE;
    final Collection<? extends ColorColumn> columnNames = vizModel.getAggrColumns();
    if (AggregationMethod.COUNT.equals(aggrMethod) || AggregationMethod.VALUE_COUNT.equals(aggrMethod)) {
        type = IntCell.TYPE;
    }
    if (AggregationMethod.SUM.equals(aggrMethod) && columnNames != null) {
        // if the aggregation method is summary and ...
        boolean allInteger = true;
        for (final ColorColumn column : columnNames) {
            final DataColumnSpec colSpec = m_tableSpec.getColumnSpec(column.getColumnName());
            if (colSpec == null || !colSpec.getType().isCompatible(IntValue.class)) {
                allInteger = false;
                break;
            }
        }
        // ... all columns of the int type we can set the column type to int
        if (allInteger) {
            type = IntCell.TYPE;
        }
    }
    final String displayColumnName = createAggregationColumnName(columnNames, aggrMethod);
    final DataColumnSpec spec = createColumnSpec(displayColumnName, type, lowerBound, upperBound, null);
    return spec;
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) DataColumnSpec(org.knime.core.data.DataColumnSpec) AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) DataType(org.knime.core.data.DataType)

Example 13 with AbstractHistogramVizModel

use of org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel in project knime-core by knime.

the class AbstractHistogramPlotter method setHistogramLayout.

/**
 * @param layout the {@link HistogramLayout} to use
 */
public void setHistogramLayout(final HistogramLayout layout) {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null) {
        return;
    }
    if (vizModel.setHistogramLayout(layout)) {
        // if the layout has changed we have to update the y coordinates
        setYCoordinates();
        // save the current bin width
        final int currentWidth = vizModel.getBinWidth();
        if (m_lastBinWidth > 0) {
            // set the bin width to the last used width for this layout
            vizModel.setBinWidth(m_lastBinWidth);
        } else if (HistogramLayout.SIDE_BY_SIDE.equals(layout)) {
            // one element
            if (vizModel.getNoOfElements() > 1) {
                vizModel.setBinWidth(vizModel.getMaxBinWidth());
            }
        }
        // and save the bin width for the next change
        m_lastBinWidth = currentWidth;
        updatePaintModel();
    }
}
Also used : AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) Point(java.awt.Point)

Example 14 with AbstractHistogramVizModel

use of org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel in project knime-core by knime.

the class AbstractHistogramPlotter method registerPropertiesChangeListener.

/**
 * Registers all histogram properties listener to the histogram
 * properties panel.
 */
private void registerPropertiesChangeListener() {
    if (m_histoProps == null) {
        throw new IllegalStateException("Properties panel must not be null");
    }
    m_histoProps.addShowGridChangedListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            setShowGridLines(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    m_histoProps.addShowBinOutlineChangedListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            final AbstractHistogramVizModel vizModel = getHistogramVizModel();
            if (vizModel != null) {
                vizModel.setShowBinOutline(e.getStateChange() == ItemEvent.SELECTED);
                final HistogramDrawingPane histoDrawingPane = getHistogramDrawingPane();
                histoDrawingPane.repaint();
            }
        }
    });
    m_histoProps.addShowBarOutlineChangedListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            final AbstractHistogramVizModel vizModel = getHistogramVizModel();
            if (vizModel != null) {
                vizModel.setShowBarOutline(e.getStateChange() == ItemEvent.SELECTED);
                final HistogramDrawingPane histoDrawingPane = getHistogramDrawingPane();
                histoDrawingPane.repaint();
            }
        }
    });
    m_histoProps.addShowElementOutlineChangedListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            final AbstractHistogramVizModel vizModel = getHistogramVizModel();
            if (vizModel != null) {
                vizModel.setShowElementOutline(e.getStateChange() == ItemEvent.SELECTED);
                final HistogramDrawingPane histoDrawingPane = getHistogramDrawingPane();
                histoDrawingPane.repaint();
            }
        }
    });
    m_histoProps.addLabelOrientationListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            final AbstractHistogramVizModel vizModel = getHistogramVizModel();
            if (vizModel != null) {
                final AbstractHistogramProperties histoProps = getHistogramPropertiesPanel();
                if (histoProps != null) {
                    vizModel.setShowLabelVertical(histoProps.isShowLabelVertical());
                    final HistogramDrawingPane histoDrawingPane = getHistogramDrawingPane();
                    histoDrawingPane.repaint();
                }
            }
        }
    });
    m_histoProps.addLabelDisplayListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            final AbstractHistogramVizModel vizModel = getHistogramVizModel();
            if (vizModel != null) {
                final AbstractHistogramProperties histoProps = getHistogramPropertiesPanel();
                if (histoProps != null) {
                    vizModel.setLabelDisplayPolicy(histoProps.getLabelDisplayPolicy());
                    final HistogramDrawingPane histoDrawingPane = getHistogramDrawingPane();
                    histoDrawingPane.repaint();
                }
            }
        }
    });
    m_histoProps.addLayoutListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            final AbstractHistogramProperties histoProps = getHistogramPropertiesPanel();
            if (histoProps != null) {
                setHistogramLayout(histoProps.getHistogramLayout());
            }
        }
    });
    m_histoProps.addBinWidthChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent e) {
            final int binWidth = m_histoProps.getBinWidth();
            updateBinWidth(binWidth);
        }
    });
    m_histoProps.addNoOfBinsChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent e) {
            final int noOfBins = m_histoProps.getNoOfBins();
            if (setNumberOfBins(noOfBins)) {
                updatePaintModel();
            }
        }
    });
    m_histoProps.addAggrMethodListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            final String methodName = e.getActionCommand();
            if (!AggregationMethod.valid(methodName)) {
                throw new IllegalArgumentException("No valid aggregation method");
            }
            final AggregationMethod aggrMethod = AggregationMethod.getMethod4Command(methodName);
            if (setAggregationMethod(aggrMethod)) {
                updatePaintModel();
            }
        }
    });
    m_histoProps.addShowEmptyBinListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (setShowEmptyBins(e.getStateChange() == ItemEvent.SELECTED)) {
                updatePaintModel();
            }
        }
    });
    m_histoProps.addShowMissingValBinListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (setShowMissingValBin(e.getStateChange() == ItemEvent.SELECTED)) {
                updatePaintModel();
            }
        }
    });
    m_histoProps.addShowInvalidValBinListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (setShowInvalidValBin(e.getStateChange() == ItemEvent.SELECTED)) {
                updatePaintModel();
            }
        }
    });
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) ItemEvent(java.awt.event.ItemEvent) AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) ActionEvent(java.awt.event.ActionEvent) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ItemListener(java.awt.event.ItemListener) ChangeListener(javax.swing.event.ChangeListener)

Example 15 with AbstractHistogramVizModel

use of org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel in project knime-core by knime.

the class AbstractHistogramPlotter method setShowInvalidValBin.

/**
 * @param showInvalidValBin the showMissingvalBar to set
 * @return <code>true</code> if the value has changed
 * @since 2.9
 */
public boolean setShowInvalidValBin(final boolean showInvalidValBin) {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null) {
        LOGGER.debug("VizModel was null");
        throw new IllegalStateException("Exception in setShowInvalidValBin: " + "Viz model must not be null");
    }
    if (vizModel.setShowInvalidValBin(showInvalidValBin)) {
        // set the coordinates to the new boundaries
        setXCoordinates();
        setYCoordinates();
        if (HistogramLayout.SIDE_BY_SIDE.equals(vizModel.getHistogramLayout()) && vizModel.containsNotPresentableBin() && (vizModel.getAggrColumns() != null && vizModel.getAggrColumns().size() > 1)) {
            vizModel.setBinWidth(vizModel.getMaxBinWidth());
        }
        return true;
    }
    return false;
}
Also used : AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel)

Aggregations

AbstractHistogramVizModel (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel)27 ColorColumn (org.knime.base.node.viz.histogram.util.ColorColumn)4 DataColumnSpec (org.knime.core.data.DataColumnSpec)4 RowKey (org.knime.core.data.RowKey)4 Dimension (java.awt.Dimension)3 Point (java.awt.Point)3 AggregationMethod (org.knime.base.node.viz.aggregation.AggregationMethod)3 InteractiveHistogramVizModel (org.knime.base.node.viz.histogram.datamodel.InteractiveHistogramVizModel)3 Coordinate (org.knime.base.util.coordinate.Coordinate)3 NumericCoordinate (org.knime.base.util.coordinate.NumericCoordinate)3 DataTableSpec (org.knime.core.data.DataTableSpec)3 BinDataModel (org.knime.base.node.viz.histogram.datamodel.BinDataModel)2 AbstractHistogramProperties (org.knime.base.node.viz.histogram.impl.AbstractHistogramProperties)2 DataCell (org.knime.core.data.DataCell)2 DoubleCell (org.knime.core.data.def.DoubleCell)2 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 Paint (java.awt.Paint)1 TexturePaint (java.awt.TexturePaint)1 ActionEvent (java.awt.event.ActionEvent)1