Search in sources :

Example 1 with AbstractHistogramVizModel

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

the class InteractiveHistogramPlotter method setAggregationMethod.

/**
 * {@inheritDoc}
 */
@Override
public boolean setAggregationMethod(final AggregationMethod aggrMethod) {
    if (aggrMethod == null) {
        throw new IllegalArgumentException("Aggregation method must not" + " be null");
    }
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    final Collection<? extends ColorColumn> oldAggrCols = vizModel.getAggrColumns();
    if (oldAggrCols == null || oldAggrCols.size() < 1) {
        // aggregation column
        if (vizModel instanceof InteractiveHistogramVizModel) {
            final InteractiveHistogramVizModel interactiveVizModel = (InteractiveHistogramVizModel) vizModel;
            final AbstractHistogramProperties abstHistoProps = getHistogramPropertiesPanel();
            if (abstHistoProps instanceof InteractiveHistogramProperties) {
                final InteractiveHistogramProperties props = (InteractiveHistogramProperties) abstHistoProps;
                final DataTableSpec spec = interactiveVizModel.getTableSpec();
                final int numColumns = spec.getNumColumns();
                boolean found = false;
                for (int i = 0; i < numColumns; i++) {
                    final DataColumnSpec colSpec = spec.getColumnSpec(i);
                    if (AbstractHistogramPlotter.AGGREGATION_COLUMN_FILTER.includeColumn(colSpec)) {
                        final ColorColumn aggrColumn = new ColorColumn(Color.LIGHT_GRAY, colSpec.getName());
                        final ArrayList<ColorColumn> aggrCols = new ArrayList<ColorColumn>(1);
                        aggrCols.add(aggrColumn);
                        props.updateColumnSelection(spec, getXColName(), aggrCols, aggrMethod);
                        final List<ColorColumn> selectedAggrCols = props.getSelectedAggrColumns();
                        interactiveVizModel.setAggregationColumns(selectedAggrCols);
                        // set the current hilited keys in the new bins
                        vizModel.updateHiliteInfo(delegateGetHiLitKeys(), true);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    props.updateHistogramSettings(interactiveVizModel);
                    return false;
                }
            } else {
                throw new IllegalStateException("ProeprtiesPanel should  be of interactive type.");
            }
        } else {
            throw new IllegalStateException("Visualization model should " + " be of interactive type.");
        }
    }
    return super.setAggregationMethod(aggrMethod);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) ArrayList(java.util.ArrayList) AbstractHistogramProperties(org.knime.base.node.viz.histogram.impl.AbstractHistogramProperties) InteractiveHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.InteractiveHistogramVizModel) DataColumnSpec(org.knime.core.data.DataColumnSpec)

Example 2 with AbstractHistogramVizModel

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

the class AbstractHistogramPlotter method updateSize.

/**
 * {@inheritDoc}
 */
@Override
public void updateSize() {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null) {
        LOGGER.debug("VizModel was null");
        return;
    }
    final Dimension newDrawingSpace = getDrawingPaneDimension();
    if (!vizModel.setDrawingSpace(newDrawingSpace)) {
        return;
    }
    if (HistogramLayout.SIDE_BY_SIDE.equals(vizModel.getHistogramLayout()) && vizModel.containsNotPresentableBin()) {
        // set the bin with to the maximum bin if the layout
        // is side-by-side or the bin is not presentable with
        // the current width
        vizModel.setBinWidth(vizModel.getMaxBinWidth());
    }
    updatePaintModel();
}
Also used : AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) Dimension(java.awt.Dimension)

Example 3 with AbstractHistogramVizModel

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

the class AbstractHistogramPlotter method updateBinWidth.

/**
 * Updates ONLY the width of the bins.
 * @param binWidth the new bin width
 */
protected void updateBinWidth(final int binWidth) {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null) {
        LOGGER.debug("VizModel was null");
        return;
    }
    if (!vizModel.setBinWidth(binWidth)) {
        return;
    }
    final Dimension drawingSpace = vizModel.getDrawingSpace();
    if (drawingSpace == null) {
        throw new IllegalStateException("Drawing space must not be null");
    }
    final double drawingWidth = drawingSpace.getWidth();
    final double drawingHeight = drawingSpace.getHeight();
    final Coordinate xCoordinates = getXCoordinate();
    final Coordinate aggrCoordinate = getAggregationCoordinate();
    final int baseLine = (int) (drawingHeight - aggrCoordinate.calculateMappedValue(new DoubleCell(0), drawingHeight));
    final HistogramDrawingPane drawingPane = getHistogramDrawingPane();
    final int newBinWidth = vizModel.getBinWidth();
    final List<Color> barElementColors = vizModel.getRowColors();
    final HistogramHiliteCalculator calculator = vizModel.getHiliteCalculator();
    final Collection<ColorColumn> aggrColumns = vizModel.getAggrColumns();
    for (final BinDataModel bin : vizModel.getBins()) {
        final DataCell captionCell = bin.getXAxisCaptionCell();
        final double labelCoord = xCoordinates.calculateMappedValue(captionCell, drawingWidth);
        // subtract half of the bar width from the start position to place
        // the middle point of the bar on the mapped coordinate position
        final int xCoord = (int) (labelCoord - (newBinWidth / 2.0));
        bin.updateBinWidth(xCoord, newBinWidth, barElementColors, aggrColumns, baseLine, calculator);
    }
    // if only the bar width changes we don't need to update the properties
    // since the bar width change is triggered by the property component
    // itself
    drawingPane.setHistogramVizModel(vizModel, false);
}
Also used : AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) DoubleCell(org.knime.core.data.def.DoubleCell) Color(java.awt.Color) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) BinDataModel(org.knime.base.node.viz.histogram.datamodel.BinDataModel) Dimension(java.awt.Dimension) Point(java.awt.Point) HistogramHiliteCalculator(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel.HistogramHiliteCalculator) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataCell(org.knime.core.data.DataCell)

Example 4 with AbstractHistogramVizModel

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

the class AbstractHistogramPlotter method setShowEmptyBins.

/**
 * @param showEmptyBins set to <code>true</code> if the empty bins should
 * be displayed
 * @return <code>true</code> if the value has changed
 */
public boolean setShowEmptyBins(final boolean showEmptyBins) {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null) {
        LOGGER.debug("VizModel was null");
        throw new IllegalStateException("Exception in setShowEmptyBins: " + "Viz model must not be null");
    }
    if (vizModel.setShowEmptyBins(showEmptyBins)) {
        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)

Example 5 with AbstractHistogramVizModel

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

the class AbstractHistogramPlotter method selectElementsIn.

/**
 * {@inheritDoc}
 */
@Override
public void selectElementsIn(final Rectangle selectionRectangle) {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null) {
        LOGGER.debug("VizModel was null");
        return;
    }
    vizModel.selectElement(selectionRectangle);
    m_histoProps.updateHTMLDetailsPanel(vizModel.getHTMLDetailData());
    repaint();
}
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