use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.
the class HistogramDrawingPane method paintContent.
// **********************************************
/*--------- the drawing methods ----------------*/
// **********************************************
/**
* {@inheritDoc}
*/
@Override
public void paintContent(final Graphics g) {
final Graphics2D g2 = (Graphics2D) g;
final Rectangle2D bounds = getBounds();
String msg = m_infoMsg;
final AbstractHistogramVizModel vizModel = m_vizModel;
if (vizModel == null || vizModel.getBins() == null) {
// if we have no bins and no info message display a no bars info
if (msg == null) {
msg = "No bins to display";
}
}
// check if we have to display an information message
if (msg != null) {
DrawingUtils.drawMessage(g2, INFO_MSG_FONT, msg, bounds);
return;
}
if (m_updatePropertiesPanel && m_properties != null) {
m_properties.updateHistogramSettings(vizModel);
m_updatePropertiesPanel = false;
}
// check if we have to draw the grid lines
if (vizModel.isShowGridLines() && m_gridLines != null) {
for (final int gridLine : m_gridLines) {
DrawingUtils.paintHorizontalLine(g2, 0, gridLine, (int) bounds.getWidth(), GRID_LINE_COLOR, GRID_LINE_STROKE);
}
}
// get all variables which are needed multiple times
final AggregationMethod aggrMethod = vizModel.getAggregationMethod();
// final Collection<ColorColumn> aggrColumns =
// vizModel.getAggrColumns();
final HistogramLayout layout = vizModel.getHistogramLayout();
// if the user has selected more then one aggregation column we have to
// draw the bar outline to how him which bar belongs to which aggregation
// column
final boolean drawBinOutline = vizModel.isShowBinOutline();
final boolean drawBarOutline = vizModel.isShowBarOutline();
// (aggrColumns != null
// && aggrColumns.size() > 1)
// || HistogramLayout.SIDE_BY_SIDE.equals(
// m_vizModel.getHistogramLayout());
final boolean showElementOutline = vizModel.isShowElementOutline();
final LabelDisplayPolicy labelDisplayPolicy = vizModel.getLabelDisplayPolicy();
final boolean showLabelVertical = vizModel.isShowLabelVertical();
final float barOutlineAlpha;
if (HistogramLayout.SIDE_BY_SIDE.equals(vizModel.getHistogramLayout())) {
barOutlineAlpha = BAR_SIDE_BY_SIDE_SURROUNDING_ALPHA;
} else {
barOutlineAlpha = BAR_STACKED_SURROUNDING_ALPHA;
}
// loop over all bins and paint them
for (final BinDataModel bin : vizModel.getBins()) {
if (drawBinOutline) {
DrawingUtils.drawRectangle(g2, bin.getSurroundingRectangle(), BIN_SURROUNDING_COLOR, BIN_SURROUNDING_STROKE);
}
if (!bin.isPresentable()) {
// the bars doen't fit in this bin so we have to
// fill the complete bin in black to show it to the user
DrawingUtils.drawBlock(g2, bin.getBinRectangle(), OVERLOADED_ELEMENT_FILLING, OVERLOADED_ELEMENT_ALPHA);
if (bin.isSelected()) {
DrawingUtils.drawRectangle(g2, bin.getBinRectangle(), ELEMENT_SELECTED_OUTLINE_COLOR, ELEMENT_SELECTED_OUTLINE_STROKE);
}
if (bin instanceof InteractiveBinDataModel) {
final InteractiveBinDataModel interactiveBin = (InteractiveBinDataModel) bin;
drawHiliteRect(g2, interactiveBin.getHiliteRectangle());
}
continue;
}
final Collection<BarDataModel> bars = bin.getBars();
for (final BarDataModel bar : bars) {
if (drawBarOutline) {
// draw the outline of the bar if we have multiple
// aggregation columns
DrawingUtils.drawBlock(g2, bar.getSurroundingRectangle(), bar.getColor(), barOutlineAlpha);
}
if (bar.isPresentable()) {
drawElements(g2, bar.getElements(), showElementOutline);
} else {
// the elements doen't fit in this bar so we have to
// fill the complete bar to show it to the user
final Rectangle2D barRectangle = bar.getShape();
DrawingUtils.drawBlock(g2, barRectangle, OVERLOADED_ELEMENT_FILLING, OVERLOADED_ELEMENT_ALPHA);
if (bar.isSelected()) {
DrawingUtils.drawRectangle(g2, barRectangle, ELEMENT_SELECTED_OUTLINE_COLOR, ELEMENT_SELECTED_OUTLINE_STROKE);
}
if (bar instanceof InteractiveBarDataModel) {
final InteractiveBarDataModel interactiveBar = (InteractiveBarDataModel) bar;
drawHiliteRect(g2, interactiveBar.getHiliteShape());
}
}
// draw the bar label at last to have them on top
drawLabels(g2, bar, aggrMethod, layout, bounds, labelDisplayPolicy, showLabelVertical);
}
// end of bar loop
}
// check if we have to draw the base line
if (m_baseLine != null) {
DrawingUtils.paintHorizontalLine(g2, 0, m_baseLine.intValue(), (int) bounds.getWidth(), BASE_LINE_COLOR, BASE_LINE_STROKE);
}
return;
}
use of org.knime.base.node.viz.aggregation.AggregationMethod 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);
}
use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.
the class PieSectionDataModel method setSubSection.
/**
* Calculates the size of all subsections of this section based on the
* size of the given arc.
* @param arc the arc of this section
* @param calculator the hilite calculator which provides implementation
* specific information
*/
private void setSubSection(final Arc2D arc, final PieHiliteCalculator calculator) {
final Collection<PieSubSectionDataModel> subSections = getElements();
if (subSections == null || subSections.size() < 1) {
return;
}
if (arc == null) {
// reset all subsections
for (final PieSubSectionDataModel subSection : subSections) {
subSection.setSubSection(null, calculator);
}
return;
}
final AggregationMethod method = calculator.getAggrMethod();
double startAngle = arc.getAngleStart();
final double totalValue;
if ((AggregationMethod.AVERAGE.equals(method) || AggregationMethod.SUM.equals(method))) {
double value = 0;
for (final PieSubSectionDataModel element : subSections) {
value += Math.abs(element.getAggregationValue(method));
}
totalValue = value;
} else {
totalValue = getAggregationValue(method);
}
for (final PieSubSectionDataModel subSection : subSections) {
final double value = Math.abs(subSection.getAggregationValue(method));
double fraction;
if (totalValue == 0) {
fraction = 0;
} else {
fraction = value / totalValue;
}
final double partialExtend = GeometryUtil.calculatePartialExtent(arc, fraction);
final Arc2D subArc = new Arc2D.Double(arc.getBounds(), startAngle, partialExtend, Arc2D.PIE);
subSection.setSubSection(subArc, calculator);
startAngle += partialExtend;
}
}
use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.
the class PieVizModel method getAbsAggregationValue.
/**
* @return the total absolute aggregation value of the sections to draw
*/
public double getAbsAggregationValue() {
final AggregationMethod aggrMethod = getAggregationMethod();
final List<PieSectionDataModel> sections = getSections2Draw();
double sum = 0;
for (final PieSectionDataModel section : sections) {
sum += Math.abs(section.getAggregationValue(aggrMethod));
}
return sum;
}
use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.
the class PieVizModel method createLabel.
/**
* @param section the section to create the label for
* @return the label of this section depending on the visualization flags
*/
public String createLabel(final PieSectionDataModel section) {
if (section == null) {
throw new NullPointerException("Section must not be null");
}
final String name = section.getName();
final AggregationMethod aggrMethod = getAggregationMethod();
final double totalValue = getAbsAggregationValue();
final double value = section.getAggregationValue(aggrMethod);
final double scaledValue = m_valueScale.scale(value, totalValue);
final String valuePart = GUIUtils.createLabel(scaledValue, NO_OF_LABEL_DIGITS, aggrMethod, m_valueScale);
final StringBuilder buf = new StringBuilder();
if (name != null) {
buf.append(name);
buf.append(": ");
buf.append(aggrMethod.getText());
buf.append(' ');
}
buf.append(valuePart);
return buf.toString();
}
Aggregations