Search in sources :

Example 6 with HistogramLayout

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

the class InteractiveBinDataModel method calculateHiliteRectangle.

/**
 * This calculates the proportional hilite rectangle of this bar which
 * could be displayed if the elements of this bar can't be draw.
 * Set the hilite rectangle in the middle of the bar since we
 * @param calculator the {@link HistogramHiliteCalculator} to use
 */
private void calculateHiliteRectangle(final HistogramHiliteCalculator calculator) {
    final Rectangle2D binRectangle = getBinRectangle();
    if (isPresentable() || binRectangle == null) {
        m_hiliteRectangle = null;
        return;
    }
    final int noOfHilitedRows = getNoOfHilitedRows();
    if (noOfHilitedRows <= 0) {
        m_hiliteRectangle = null;
        return;
    }
    if (calculator == null) {
        return;
    }
    final AggregationMethod aggrMethod = calculator.getAggrMethod();
    final HistogramLayout layout = calculator.getLayout();
    final int binY = (int) binRectangle.getY();
    final int binHeight = (int) binRectangle.getHeight();
    final int binWidth = (int) binRectangle.getWidth();
    final int rowCount = getBinRowCount();
    final double fraction = noOfHilitedRows / (double) rowCount;
    int hiliteHeight = (int) (binHeight * fraction);
    final int hiliteWidth = Math.max((int) (binWidth * AbstractHistogramVizModel.HILITE_RECT_WIDTH_FACTOR), 1);
    final int hiliteX = (int) (binRectangle.getX() + (binWidth - hiliteWidth) / 2.0);
    int hiliteY = binY;
    if (getMinAggregationValue(aggrMethod, layout) < 0 && getMaxAggregationValue(aggrMethod, layout) > 0) {
        // set the hilite rectangle in the side by side mode in the middle
        // if the minimum aggregation value is negative and the maximum
        // aggregation value is positive
        final int middleY = (int) (binY + (binHeight / 2.0));
        hiliteY = middleY - (hiliteHeight / 2);
    } else if (getMaxAggregationValue(aggrMethod, layout) > 0) {
        hiliteY = hiliteY + binHeight - hiliteHeight;
    }
    // check for possible rounding errors
    if (hiliteHeight > binHeight) {
        hiliteHeight = binHeight;
        LOGGER.warn("Hilite rectangle higher than surrounding bar");
    }
    if (hiliteY < binY) {
        hiliteY = binY;
        LOGGER.warn("Hilite rectangle y coordinate above " + "surrounding bar y coordinate");
    }
    m_hiliteRectangle = new Rectangle(hiliteX, hiliteY, hiliteWidth, hiliteHeight);
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) Rectangle2D(java.awt.geom.Rectangle2D) Rectangle(java.awt.Rectangle) HistogramLayout(org.knime.base.node.viz.histogram.HistogramLayout)

Aggregations

HistogramLayout (org.knime.base.node.viz.histogram.HistogramLayout)6 AggregationMethod (org.knime.base.node.viz.aggregation.AggregationMethod)5 Rectangle (java.awt.Rectangle)4 Rectangle2D (java.awt.geom.Rectangle2D)4 Color (java.awt.Color)2 Point (java.awt.Point)2 BinDataModel (org.knime.base.node.viz.histogram.datamodel.BinDataModel)2 ColorColumn (org.knime.base.node.viz.histogram.util.ColorColumn)2 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 Paint (java.awt.Paint)1 TexturePaint (java.awt.TexturePaint)1 LabelDisplayPolicy (org.knime.base.node.viz.aggregation.util.LabelDisplayPolicy)1 AbstractHistogramVizModel (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel)1 HistogramHiliteCalculator (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel.HistogramHiliteCalculator)1 BarDataModel (org.knime.base.node.viz.histogram.datamodel.BarDataModel)1 InteractiveBarDataModel (org.knime.base.node.viz.histogram.datamodel.InteractiveBarDataModel)1 InteractiveBinDataModel (org.knime.base.node.viz.histogram.datamodel.InteractiveBinDataModel)1 DataCell (org.knime.core.data.DataCell)1 DoubleCell (org.knime.core.data.def.DoubleCell)1