Search in sources :

Example 6 with PieSectionDataModel

use of org.knime.base.node.viz.pie.datamodel.PieSectionDataModel in project knime-core by knime.

the class FixedPieDataModel method addDataRow.

/**
 * @param row the row to add
 * @param rowColor the color of the roe
 * @param pieCell the cell with the pie value
 * @param aggrCell the cell with the aggregation value
 * @throws TooManySectionsException if more sections are created than
 * supported
 */
public void addDataRow(final DataRow row, final Color rowColor, final DataCell pieCell, final DataCell aggrCell) throws TooManySectionsException {
    if (pieCell == null) {
        throw new NullPointerException("Pie section value must not be null.");
    }
    PieSectionDataModel section;
    if (pieCell.isMissing()) {
        section = getMissingSection();
    } else {
        section = getSection(pieCell);
        if (section == null) {
            if (m_sections.size() >= PieColumnFilter.MAX_NO_OF_SECTIONS) {
                throw new TooManySectionsException("Selected pie column contains more than " + PieColumnFilter.MAX_NO_OF_SECTIONS + " unique values.");
            }
            // throw new IllegalArgumentException("No section found for: "
            // + pieCell.toString());
            section = new PieSectionDataModel(pieCell.toString(), Color.BLACK, supportsHiliting());
            m_sections.add(section);
        }
        m_sectionsInitialized = false;
    }
    section.addDataRow(rowColor, row.getKey(), aggrCell);
}
Also used : PieSectionDataModel(org.knime.base.node.viz.pie.datamodel.PieSectionDataModel) TooManySectionsException(org.knime.base.node.viz.pie.util.TooManySectionsException)

Example 7 with PieSectionDataModel

use of org.knime.base.node.viz.pie.datamodel.PieSectionDataModel in project knime-core by knime.

the class FixedPieDataModel method save2File.

/**
 * @param directory the directory to write to
 * @param exec the {@link ExecutionMonitor} to provide progress messages
 * @throws IOException if a file exception occurs
 * @throws CanceledExecutionException if the operation was canceled
 */
public void save2File(final File directory, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    if (exec != null) {
        exec.setProgress(0.0, "Start saving histogram data model to file");
    }
    final File dataFile = new File(directory, CFG_DATA_FILE);
    final FileOutputStream os = new FileOutputStream(dataFile);
    final GZIPOutputStream dataOS = new GZIPOutputStream(os);
    final Config config = new NodeSettings(CFG_DATA);
    config.addString(CFG_PIE_COL, m_pieCol);
    config.addBoolean(CFG_NUMERIC_PIE_COL, m_numericPieCol);
    config.addString(CFG_AGGR_COL, m_aggrCol);
    config.addBoolean(CFG_HILITING, supportsHiliting());
    config.addBoolean(CFG_DETAILS, detailsAvailable());
    config.addBoolean(CFG_IS_COLOR_COLUMN, m_isColorColumn);
    if (exec != null) {
        exec.setProgress(0.3, "Start saving sections...");
        exec.checkCanceled();
    }
    final Config sectionsConf = config.addConfig(CFG_SECTIONS);
    sectionsConf.addInt(CFG_SECTION_COUNT, m_sections.size());
    int idx = 0;
    for (final PieSectionDataModel section : m_sections) {
        final ConfigWO sectionConf = sectionsConf.addConfig(CFG_SECTION + idx++);
        section.save2File(sectionConf, exec);
    }
    if (exec != null) {
        exec.setProgress(0.8, "Start saving missing section...");
        exec.checkCanceled();
    }
    final ConfigWO missingSection = sectionsConf.addConfig(CFG_MISSING_SECTION);
    m_missingSection.save2File(missingSection, exec);
    config.saveToXML(dataOS);
    dataOS.flush();
    dataOS.close();
    os.flush();
    os.close();
    if (exec != null) {
        exec.setProgress(1.0, "Pie data model saved");
    }
}
Also used : PieSectionDataModel(org.knime.base.node.viz.pie.datamodel.PieSectionDataModel) NodeSettings(org.knime.core.node.NodeSettings) GZIPOutputStream(java.util.zip.GZIPOutputStream) Config(org.knime.core.node.config.Config) FileOutputStream(java.io.FileOutputStream) ConfigWO(org.knime.core.node.config.ConfigWO) File(java.io.File)

Example 8 with PieSectionDataModel

use of org.knime.base.node.viz.pie.datamodel.PieSectionDataModel 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

PieSectionDataModel (org.knime.base.node.viz.pie.datamodel.PieSectionDataModel)8 TooManySectionsException (org.knime.base.node.viz.pie.util.TooManySectionsException)4 Rectangle2D (java.awt.geom.Rectangle2D)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 IOException (java.io.IOException)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 Config (org.knime.core.node.config.Config)2 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 RenderingHints (java.awt.RenderingHints)1 Arc2D (java.awt.geom.Arc2D)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1