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