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);
}
Aggregations