Search in sources :

Example 1 with LabelDisplayPolicy

use of org.knime.base.node.viz.aggregation.util.LabelDisplayPolicy 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;
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) LabelDisplayPolicy(org.knime.base.node.viz.aggregation.util.LabelDisplayPolicy) AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) Rectangle2D(java.awt.geom.Rectangle2D) BinDataModel(org.knime.base.node.viz.histogram.datamodel.BinDataModel) InteractiveBinDataModel(org.knime.base.node.viz.histogram.datamodel.InteractiveBinDataModel) InteractiveBinDataModel(org.knime.base.node.viz.histogram.datamodel.InteractiveBinDataModel) TexturePaint(java.awt.TexturePaint) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D) InteractiveBarDataModel(org.knime.base.node.viz.histogram.datamodel.InteractiveBarDataModel) BarDataModel(org.knime.base.node.viz.histogram.datamodel.BarDataModel) InteractiveBarDataModel(org.knime.base.node.viz.histogram.datamodel.InteractiveBarDataModel) HistogramLayout(org.knime.base.node.viz.histogram.HistogramLayout)

Example 2 with LabelDisplayPolicy

use of org.knime.base.node.viz.aggregation.util.LabelDisplayPolicy in project knime-core by knime.

the class PieDrawingPane method paintContent.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void paintContent(final Graphics g) {
    final Graphics2D g2 = (Graphics2D) g;
    String msg = m_infoMsg;
    if (m_vizModel == null) {
        // if we have no bins and no info message display a no bars info
        if (msg == null) {
            msg = "No pie data available";
        }
    }
    // check if we have to display an information message
    if (msg != null) {
        DrawingUtils.drawMessage(g2, INFO_MSG_FONT, msg, getBounds());
        return;
    }
    final RenderingHints origHints = g2.getRenderingHints();
    if (m_vizModel.drawAntialias()) {
        // Enable antialiasing for shapes
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    } else {
        // Disable antialiasing for shapes
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    final Rectangle2D explodeArea = m_vizModel.getExplodedArea();
    final Rectangle2D pieArea = m_vizModel.getPieArea();
    final double labelLinkSize = m_vizModel.getLabelLinkSize();
    final boolean explode = m_vizModel.explodeSelectedSections();
    final boolean drawOutline = m_vizModel.drawSectionOutline();
    // final AggregationMethod aggrMethod = m_vizModel.getAggregationMethod();
    // final double totalValue = m_vizModel.getAbsAggregationValue();
    final LabelDisplayPolicy labelPolicy = m_vizModel.getLabelDisplayPolicy();
    final boolean showDetails = m_vizModel.showDetails();
    for (final PieSectionDataModel section : m_vizModel.getSections2Draw()) {
        if (!section.isPresentable()) {
            // skip not presentable sections
            continue;
        }
        // check if we should draw ...
        if (showDetails && section.isSelected()) {
            // ... all subsections of this section or...
            final Collection<PieSubSectionDataModel> elements = section.getElements();
            for (final PieSubSectionDataModel subSection : elements) {
                drawSection(g2, subSection, false);
                if (LabelDisplayPolicy.ALL.equals(labelPolicy) || (LabelDisplayPolicy.SELECTED.equals(labelPolicy) && subSection.isSelected())) {
                    final Rectangle2D labelArea;
                    if (explode && section.isSelected()) {
                        labelArea = explodeArea;
                    } else {
                        labelArea = pieArea;
                    }
                    final String label = m_vizModel.createLabel(section, subSection);
                    drawLabel(g2, label, labelArea, labelLinkSize, subSection);
                }
            }
        } else {
            // ...only the main section itself
            drawSection(g2, section, drawOutline);
            if (LabelDisplayPolicy.ALL.equals(labelPolicy) || (LabelDisplayPolicy.SELECTED.equals(labelPolicy) && section.isSelected())) {
                final Rectangle2D labelArea;
                if (explode && section.isSelected()) {
                    labelArea = explodeArea;
                } else {
                    labelArea = pieArea;
                }
                final String label = m_vizModel.createLabel(section);
                drawLabel(g2, label, labelArea, labelLinkSize, section);
            }
        }
    }
    // set the old rendering hints
    g2.setRenderingHints(origHints);
// draw the rectangles for debugging
// g2.setStroke(SECTION_OUTLINE_STROKE);
// g2.setColor(Color.CYAN);
// g2.draw(m_vizModel.getLabelArea());
// g2.draw(m_vizModel.getExplodedArea());
// g2.draw(m_vizModel.getPieArea());
}
Also used : PieSectionDataModel(org.knime.base.node.viz.pie.datamodel.PieSectionDataModel) PieSubSectionDataModel(org.knime.base.node.viz.pie.datamodel.PieSubSectionDataModel) LabelDisplayPolicy(org.knime.base.node.viz.aggregation.util.LabelDisplayPolicy) Rectangle2D(java.awt.geom.Rectangle2D) RenderingHints(java.awt.RenderingHints) Graphics2D(java.awt.Graphics2D)

Aggregations

Graphics2D (java.awt.Graphics2D)2 Rectangle2D (java.awt.geom.Rectangle2D)2 LabelDisplayPolicy (org.knime.base.node.viz.aggregation.util.LabelDisplayPolicy)2 Paint (java.awt.Paint)1 RenderingHints (java.awt.RenderingHints)1 TexturePaint (java.awt.TexturePaint)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 BarDataModel (org.knime.base.node.viz.histogram.datamodel.BarDataModel)1 BinDataModel (org.knime.base.node.viz.histogram.datamodel.BinDataModel)1 InteractiveBarDataModel (org.knime.base.node.viz.histogram.datamodel.InteractiveBarDataModel)1 InteractiveBinDataModel (org.knime.base.node.viz.histogram.datamodel.InteractiveBinDataModel)1 PieSectionDataModel (org.knime.base.node.viz.pie.datamodel.PieSectionDataModel)1 PieSubSectionDataModel (org.knime.base.node.viz.pie.datamodel.PieSubSectionDataModel)1