Search in sources :

Example 1 with PieSectionDataModel

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

the class InteractivePieVizModel method addRows2Sections.

/**
 * Adds all rows to the available sections.
 * @throws TooManySectionsException if more sections are created than
 * supported
 */
private void addRows2Sections() throws TooManySectionsException {
    final int pieColIdx = m_model.getColIndex(m_pieColSpec.getName());
    final int aggrColIdx;
    if (m_aggrColSpec == null) {
        aggrColIdx = -1;
    } else {
        aggrColIdx = m_model.getColIndex(m_aggrColSpec.getName());
    }
    for (final DataRow row : m_model) {
        final DataCell pieCell = row.getCell(pieColIdx);
        final DataCell aggrCell;
        if (aggrColIdx < 0) {
            aggrCell = null;
        } else {
            aggrCell = row.getCell(aggrColIdx);
        }
        final Color rowColor = m_model.getRowColor(row);
        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, m_model.supportsHiliting());
                m_sections.add(section);
            }
        }
        section.addDataRow(rowColor, row.getKey(), aggrCell);
    }
}
Also used : PieSectionDataModel(org.knime.base.node.viz.pie.datamodel.PieSectionDataModel) Color(java.awt.Color) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow) TooManySectionsException(org.knime.base.node.viz.pie.util.TooManySectionsException)

Example 2 with PieSectionDataModel

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

the class PiePlotter method setPieSections.

/**
 * Calculates the size of all pie sections.
 * @param vizModel the {@link PieVizModel} that provides visualisation
 * information and the sections
 */
private void setPieSections(final PieVizModel vizModel) {
    final Rectangle2D pieArea = vizModel.getPieArea();
    final Rectangle2D explodedArea = vizModel.getExplodedArea();
    final boolean explode = vizModel.explodeSelectedSections();
    // final double explodePercentage = vizModel.getExplodeMargin();
    final double totalVal = vizModel.getAbsAggregationValue();
    final double arcPerVal = 360 / totalVal;
    final AggregationMethod method = vizModel.getAggregationMethod();
    final PieHiliteCalculator calculator = vizModel.getCalculator();
    final List<PieSectionDataModel> pieSections = vizModel.getSections2Draw();
    final int noOfSections = pieSections.size();
    double startAngle = 0;
    for (int i = 0; i < noOfSections; i++) {
        final PieSectionDataModel section = pieSections.get(i);
        final double value = Math.abs(section.getAggregationValue(method));
        double arcAngle = value * arcPerVal;
        // avoid a rounding gap
        if (i == noOfSections - 1) {
            arcAngle = 360 - startAngle;
        }
        if (arcAngle < PieVizModel.MINIMUM_ARC_ANGLE) {
            LOGGER.debug("Pie section: " + vizModel.createLabel(section) + " angle " + arcAngle + " to small to display." + " Angle updated to set to minimum angle " + PieVizModel.MINIMUM_ARC_ANGLE);
            arcAngle = PieVizModel.MINIMUM_ARC_ANGLE;
        // skip this section
        // section.setPieSection(null, calculator);
        // continue;
        }
        final Rectangle2D bounds;
        // explode selected sections
        if (explode && section.isSelected()) {
            bounds = GeometryUtil.getArcBounds(pieArea, explodedArea, startAngle, arcAngle, 1.0);
        } else {
            bounds = pieArea;
        }
        final Arc2D arc = new Arc2D.Double(bounds, startAngle, arcAngle, Arc2D.PIE);
        section.setPieSection(arc, calculator);
        startAngle += arcAngle;
    }
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) PieSectionDataModel(org.knime.base.node.viz.pie.datamodel.PieSectionDataModel) PieHiliteCalculator(org.knime.base.node.viz.pie.datamodel.PieHiliteCalculator) Rectangle2D(java.awt.geom.Rectangle2D) Arc2D(java.awt.geom.Arc2D) Point(java.awt.Point)

Example 3 with PieSectionDataModel

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

the class FixedPieDataModel method getClonedSections.

/**
 * @return a real copy of all sections
 */
@SuppressWarnings("unchecked")
public List<PieSectionDataModel> getClonedSections() {
    LOGGER.debug("Entering getClonedSections() of class " + "FixedPieDataModel.");
    final long startTime = System.currentTimeMillis();
    List<PieSectionDataModel> binClones = null;
    try {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        new ObjectOutputStream(baos).writeObject(getSections());
        final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        binClones = (List<PieSectionDataModel>) new ObjectInputStream(bais).readObject();
    } catch (final Exception e) {
        final String msg = "Exception while cloning pie sections: " + e.getMessage();
        LOGGER.debug(msg);
        throw new IllegalStateException(msg);
    }
    final long endTime = System.currentTimeMillis();
    final long durationTime = endTime - startTime;
    LOGGER.debug("Time for cloning. " + durationTime + " ms");
    LOGGER.debug("Exiting getClonedSections() of class " + "FixedPieDataModel.");
    return binClones;
}
Also used : PieSectionDataModel(org.knime.base.node.viz.pie.datamodel.PieSectionDataModel) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) TooManySectionsException(org.knime.base.node.viz.pie.util.TooManySectionsException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with PieSectionDataModel

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

the class FixedPieDataModel method loadFromFile.

/**
 * @param directory the directory to write to
 * @param exec the {@link ExecutionMonitor} to provide progress messages
 * @return the data model
 * wasn't valid
 * @throws IOException if a file exception occurs
 * @throws CanceledExecutionException if the operation was canceled
 * @throws InvalidSettingsException if the file is invalid
 */
@SuppressWarnings("unchecked")
public static FixedPieDataModel loadFromFile(final File directory, final ExecutionMonitor exec) throws IOException, CanceledExecutionException, InvalidSettingsException {
    if (exec != null) {
        exec.setProgress(0.0, "Start reading data from file");
    }
    final File settingsFile = new File(directory, CFG_DATA_FILE);
    final FileInputStream is = new FileInputStream(settingsFile);
    final GZIPInputStream inData = new GZIPInputStream(is);
    final ConfigRO config = NodeSettings.loadFromXML(inData);
    final String pieCol = config.getString(CFG_PIE_COL);
    final boolean numericPieCol = config.getBoolean(CFG_NUMERIC_PIE_COL);
    final String aggrCol = config.getString(CFG_AGGR_COL);
    final boolean supportHiliting = config.getBoolean(CFG_HILITING);
    final boolean detailsAvailable = config.getBoolean(CFG_DETAILS);
    if (exec != null) {
        exec.setProgress(0.3, "Loading sections...");
        exec.checkCanceled();
    }
    final Config sectionsConf = config.getConfig(CFG_SECTIONS);
    final int counter = sectionsConf.getInt(CFG_SECTION_COUNT);
    final List<PieSectionDataModel> sections = new ArrayList<PieSectionDataModel>(counter);
    for (int i = 0; i < counter; i++) {
        final Config sectionConf = sectionsConf.getConfig(CFG_SECTION + i);
        sections.add(PieSectionDataModel.loadFromFile(sectionConf, exec));
    }
    if (exec != null) {
        exec.setProgress(0.9, "Loading missing section...");
        exec.checkCanceled();
    }
    final Config missingConf = sectionsConf.getConfig(CFG_MISSING_SECTION);
    final PieSectionDataModel missingSection = PieSectionDataModel.loadFromFile(missingConf, exec);
    final boolean isColorColumn;
    if (config.containsKey(CFG_IS_COLOR_COLUMN)) {
        isColorColumn = config.getBoolean(CFG_IS_COLOR_COLUMN);
    } else {
        isColorColumn = false;
        // reset the color of all elements
        for (final PieSectionDataModel section : sections) {
            section.setColor(Color.BLACK);
        }
    }
    if (exec != null) {
        exec.setProgress(1.0, "Pie data model loaded ");
    }
    // close the stream
    inData.close();
    is.close();
    return new FixedPieDataModel(pieCol, numericPieCol, aggrCol, sections, missingSection, supportHiliting, detailsAvailable, isColorColumn);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) PieSectionDataModel(org.knime.base.node.viz.pie.datamodel.PieSectionDataModel) Config(org.knime.core.node.config.Config) ArrayList(java.util.ArrayList) ConfigRO(org.knime.core.node.config.ConfigRO) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 5 with PieSectionDataModel

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

the class FixedPieDataModel method getClonedMissingSection.

/**
 * @return a real copy of the missing section
 */
public PieSectionDataModel getClonedMissingSection() {
    LOGGER.debug("Entering getClonedMissingSection() of class " + "FixedPieDataModel.");
    final long startTime = System.currentTimeMillis();
    PieSectionDataModel missingClone = null;
    try {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        new ObjectOutputStream(baos).writeObject(m_missingSection);
        final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        missingClone = (PieSectionDataModel) new ObjectInputStream(bais).readObject();
    } catch (final Exception e) {
        final String msg = "Exception while cloning pie sections: " + e.getMessage();
        LOGGER.debug(msg);
        throw new IllegalStateException(msg);
    }
    final long endTime = System.currentTimeMillis();
    final long durationTime = endTime - startTime;
    LOGGER.debug("Time for cloning. " + durationTime + " ms");
    LOGGER.debug("Exiting getClonedMissingSection() of class " + "FixedPieDataModel.");
    return missingClone;
}
Also used : PieSectionDataModel(org.knime.base.node.viz.pie.datamodel.PieSectionDataModel) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) TooManySectionsException(org.knime.base.node.viz.pie.util.TooManySectionsException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

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