Search in sources :

Example 1 with HistogramHiliteCalculator

use of org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel.HistogramHiliteCalculator 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 2 with HistogramHiliteCalculator

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

the class AbstractHistogramPlotter method setHistogramBinRectangle.

/**
 * Calculates and sets the drawing rectangle of each bin.
 * @param xCoordinates The <code>Coordinate</code> object which contains
 * the start position of an bar on the x axis
 * @param yCoordinates The <code>Coordinate</code> object which contains
 * the start position of an bar on the y axis
 */
private static void setHistogramBinRectangle(final AbstractHistogramVizModel vizModel, final Coordinate xCoordinates, final Coordinate yCoordinates) {
    final Dimension drawingSpace = vizModel.getDrawingSpace();
    final int binWidth = vizModel.getBinWidth();
    final AggregationMethod aggrMethod = vizModel.getAggregationMethod();
    final List<Color> barElementColors = vizModel.getRowColors();
    final Collection<ColorColumn> aggrColumns = vizModel.getAggrColumns();
    final HistogramLayout layout = vizModel.getHistogramLayout();
    final HistogramHiliteCalculator calculator = vizModel.getHiliteCalculator();
    final double drawingWidth = drawingSpace.getWidth();
    final double drawingHeight = drawingSpace.getHeight();
    final int baseLine = (int) (drawingHeight - yCoordinates.calculateMappedValue(new DoubleCell(0), drawingHeight));
    // this is the minimum size of a bar with an aggregation value > 0
    final int minHeight = Math.max((int) HistogramDrawingPane.getBarStrokeWidth(), AbstractHistogramVizModel.MINIMUM_BAR_HEIGHT);
    // final int binWidth = getBinWidth();
    for (final BinDataModel bin : vizModel.getBins()) {
        final DataCell captionCell = bin.getXAxisCaptionCell();
        final double labelCoord = xCoordinates.calculateMappedValue(captionCell, drawingWidth);
        if (labelCoord < 0) {
            // this bin is not on the x axis (because it is empty and the
            // empty bins shouldn't be displayed) so we simply set the
            // rectangle to null and continue
            bin.setBinRectangle(null, baseLine, barElementColors, aggrColumns, calculator);
            continue;
        }
        // if the maximum value is negative use 0 to end at the base line
        final double maxAggrVal = Math.max(bin.getMaxAggregationValue(aggrMethod, layout), 0);
        // if the minimum value is positive use 0 to start at the base line
        final double minAggrVal = Math.min(bin.getMinAggregationValue(aggrMethod, layout), 0);
        // 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 - (binWidth / 2.0));
        final int upperY = (int) (drawingHeight - yCoordinates.calculateMappedValue(new DoubleCell(maxAggrVal), drawingHeight));
        final int lowerY = (int) (drawingHeight - yCoordinates.calculateMappedValue(new DoubleCell(minAggrVal), drawingHeight));
        final Rectangle binRect = calculateBorderRectangle(xCoord, lowerY, upperY, minHeight, binWidth, maxAggrVal, baseLine);
        bin.setBinRectangle(binRect, baseLine, barElementColors, aggrColumns, calculator);
    }
// end of for loop over the x axis coordinates
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) DoubleCell(org.knime.core.data.def.DoubleCell) Color(java.awt.Color) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) Rectangle(java.awt.Rectangle) 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) DataCell(org.knime.core.data.DataCell) HistogramLayout(org.knime.base.node.viz.histogram.HistogramLayout)

Aggregations

Color (java.awt.Color)2 Dimension (java.awt.Dimension)2 Point (java.awt.Point)2 HistogramHiliteCalculator (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel.HistogramHiliteCalculator)2 BinDataModel (org.knime.base.node.viz.histogram.datamodel.BinDataModel)2 ColorColumn (org.knime.base.node.viz.histogram.util.ColorColumn)2 DataCell (org.knime.core.data.DataCell)2 DoubleCell (org.knime.core.data.def.DoubleCell)2 Rectangle (java.awt.Rectangle)1 AggregationMethod (org.knime.base.node.viz.aggregation.AggregationMethod)1 HistogramLayout (org.knime.base.node.viz.histogram.HistogramLayout)1 AbstractHistogramVizModel (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel)1 Coordinate (org.knime.base.util.coordinate.Coordinate)1 NumericCoordinate (org.knime.base.util.coordinate.NumericCoordinate)1