Search in sources :

Example 1 with ColorColumn

use of org.knime.base.node.viz.histogram.util.ColorColumn in project knime-core by knime.

the class InteractiveHistogramPlotter method setAggregationMethod.

/**
 * {@inheritDoc}
 */
@Override
public boolean setAggregationMethod(final AggregationMethod aggrMethod) {
    if (aggrMethod == null) {
        throw new IllegalArgumentException("Aggregation method must not" + " be null");
    }
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    final Collection<? extends ColorColumn> oldAggrCols = vizModel.getAggrColumns();
    if (oldAggrCols == null || oldAggrCols.size() < 1) {
        // aggregation column
        if (vizModel instanceof InteractiveHistogramVizModel) {
            final InteractiveHistogramVizModel interactiveVizModel = (InteractiveHistogramVizModel) vizModel;
            final AbstractHistogramProperties abstHistoProps = getHistogramPropertiesPanel();
            if (abstHistoProps instanceof InteractiveHistogramProperties) {
                final InteractiveHistogramProperties props = (InteractiveHistogramProperties) abstHistoProps;
                final DataTableSpec spec = interactiveVizModel.getTableSpec();
                final int numColumns = spec.getNumColumns();
                boolean found = false;
                for (int i = 0; i < numColumns; i++) {
                    final DataColumnSpec colSpec = spec.getColumnSpec(i);
                    if (AbstractHistogramPlotter.AGGREGATION_COLUMN_FILTER.includeColumn(colSpec)) {
                        final ColorColumn aggrColumn = new ColorColumn(Color.LIGHT_GRAY, colSpec.getName());
                        final ArrayList<ColorColumn> aggrCols = new ArrayList<ColorColumn>(1);
                        aggrCols.add(aggrColumn);
                        props.updateColumnSelection(spec, getXColName(), aggrCols, aggrMethod);
                        final List<ColorColumn> selectedAggrCols = props.getSelectedAggrColumns();
                        interactiveVizModel.setAggregationColumns(selectedAggrCols);
                        // set the current hilited keys in the new bins
                        vizModel.updateHiliteInfo(delegateGetHiLitKeys(), true);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    props.updateHistogramSettings(interactiveVizModel);
                    return false;
                }
            } else {
                throw new IllegalStateException("ProeprtiesPanel should  be of interactive type.");
            }
        } else {
            throw new IllegalStateException("Visualization model should " + " be of interactive type.");
        }
    }
    return super.setAggregationMethod(aggrMethod);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) ArrayList(java.util.ArrayList) AbstractHistogramProperties(org.knime.base.node.viz.histogram.impl.AbstractHistogramProperties) InteractiveHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.InteractiveHistogramVizModel) DataColumnSpec(org.knime.core.data.DataColumnSpec)

Example 2 with ColorColumn

use of org.knime.base.node.viz.histogram.util.ColorColumn in project knime-core by knime.

the class BinDataModel method setBarRectangle.

/**
 * Sets the rectangle for all bars in this bin.
 * @param baseLine the x coordinate of the base line (0) on the screen
 * @param barElementColors all element colors which define the order
 * the elements should be drawn
 * @param aggrColumns the aggregation column array which indicates
 * the order of the bars
 */
private void setBarRectangle(final int baseLine, final List<Color> barElementColors, final Collection<? extends ColorColumn> aggrColumns, final HistogramHiliteCalculator calculator) {
    if (m_binRectangle == null) {
        final Collection<BarDataModel> bars = m_bars.values();
        // also reset the bar rectangle
        for (final BarDataModel bar : bars) {
            bar.setBarRectangle(null, baseLine, barElementColors, calculator);
        }
        return;
    }
    final AggregationMethod aggrMethod = calculator.getAggrMethod();
    final HistogramLayout layout = calculator.getLayout();
    final int binWidth = (int) m_binRectangle.getWidth();
    final int noOfBars = aggrColumns.size();
    m_presentable = elementsFitInBin(noOfBars, binWidth);
    if (!m_presentable) {
        return;
    }
    // calculate the height
    final int binHeight = (int) m_binRectangle.getHeight();
    final double maxAggrVal = Math.max(getMaxAggregationValue(aggrMethod, layout), 0);
    final double minAggrVal = Math.min(getMinAggregationValue(aggrMethod, layout), 0);
    final double valRange = maxAggrVal + Math.abs(minAggrVal);
    if (valRange <= 0) {
        m_presentable = false;
        return;
    }
    final int barWidth = calculateBarWidth(binWidth, noOfBars);
    final double heightPerVal = binHeight / valRange;
    final int binX = (int) m_binRectangle.getX();
    int xCoord = binX;
    for (final ColorColumn aggrColumn : aggrColumns) {
        final BarDataModel bar = m_bars.get(aggrColumn.getColor());
        if (bar != null) {
            // set the rectangle only for the bars which are available
            // in this bin
            final double barMaxAggrVal = Math.max(bar.getMaxAggregationValue(aggrMethod, layout), 0);
            final double barMinAggrVal = Math.min(bar.getMinAggregationValue(aggrMethod, layout), 0);
            final double aggrVal = barMaxAggrVal + Math.abs(barMinAggrVal);
            final int yCoord = (int) (baseLine - (barMaxAggrVal * heightPerVal));
            final int barHeight = (int) (aggrVal * heightPerVal);
            final Rectangle barRect = new Rectangle(xCoord, yCoord, barWidth, barHeight);
            bar.setBarRectangle(barRect, baseLine, barElementColors, calculator);
        }
        // add the bar width and the space between bars to the current
        // x coordinate
        xCoord += barWidth + AbstractHistogramVizModel.SPACE_BETWEEN_BARS;
    }
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) Rectangle(java.awt.Rectangle) Point(java.awt.Point) HistogramLayout(org.knime.base.node.viz.histogram.HistogramLayout)

Example 3 with ColorColumn

use of org.knime.base.node.viz.histogram.util.ColorColumn in project knime-core by knime.

the class FixedHistogramDataModel 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 is 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);
    final ConfigWO xConf = config.addConfig(CFG_X_COL_SPEC);
    m_xColSpec.save(xConf);
    if (exec != null) {
        exec.setProgress(0.1, "Binning column specification saved");
        exec.setMessage("Start saving aggregation columns...");
    }
    config.addBoolean(CFG_NOMINAL, m_binNominal);
    config.addString(CFG_AGGR_METHOD, m_aggrMethod.getActionCommand());
    final Config aggrConf = config.addConfig(CFG_AGGR_COLS);
    aggrConf.addInt(CFG_AGGR_COL_COUNTER, m_aggrColumns.size());
    int idx = 0;
    for (final ColorColumn col : m_aggrColumns) {
        final ConfigWO aggrColConf = aggrConf.addConfig(CFG_COLOR_COL + idx++);
        col.save2File(aggrColConf, exec);
    }
    if (exec != null) {
        exec.setProgress(0.3, "Start saving bins...");
    }
    final ConfigWO binsConf = config.addConfig(CFG_BINS);
    binsConf.addInt(CFG_BIN_COUNTER, m_bins.size());
    idx = 0;
    for (final BinDataModel bin : m_bins) {
        final ConfigWO binConf = binsConf.addConfig(CFG_BIN + idx++);
        bin.save2File(binConf, exec);
    }
    final ConfigWO missingBin = binsConf.addConfig(CFG_MISSING_BIN);
    m_missingValueBin.save2File(missingBin, exec);
    if (m_invalidValueBin != null) {
        final ConfigWO invalidBin = binsConf.addConfig(CFG_INVALID_BIN);
        m_invalidValueBin.save2File(invalidBin, exec);
    }
    if (exec != null) {
        exec.setProgress(0.8, "Start saving element colors...");
    }
    final List<Color> rowColors = getRowColors();
    final ConfigWO colorColsConf = config.addConfig(CFG_COLOR_COLS);
    colorColsConf.addInt(CFG_ROW_COLOR_COUNTER, rowColors.size());
    idx = 0;
    for (final Color color : rowColors) {
        colorColsConf.addInt(CFG_ROW_COLOR + idx++, color.getRGB());
    }
    config.saveToXML(dataOS);
    dataOS.flush();
    dataOS.close();
    os.flush();
    os.close();
    if (exec != null) {
        exec.setProgress(1.0, "Histogram data model saved");
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) GZIPOutputStream(java.util.zip.GZIPOutputStream) Config(org.knime.core.node.config.Config) FileOutputStream(java.io.FileOutputStream) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) Color(java.awt.Color) ConfigWO(org.knime.core.node.config.ConfigWO) File(java.io.File)

Example 4 with ColorColumn

use of org.knime.base.node.viz.histogram.util.ColorColumn 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);
}
Also used : AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) DoubleCell(org.knime.core.data.def.DoubleCell) Color(java.awt.Color) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) BinDataModel(org.knime.base.node.viz.histogram.datamodel.BinDataModel) Dimension(java.awt.Dimension) Point(java.awt.Point) HistogramHiliteCalculator(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel.HistogramHiliteCalculator) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataCell(org.knime.core.data.DataCell)

Example 5 with ColorColumn

use of org.knime.base.node.viz.histogram.util.ColorColumn in project knime-core by knime.

the class AbstractHistogramNodeModel method loadAggrColumns.

/**
 */
private void loadAggrColumns() {
    final ColorColumn[] aggrCols = m_aggrColName.getColorNameColumns();
    if (aggrCols == null) {
        // the user hasn't selected an aggregation column
        // thats fine since it is optional
        m_aggrCols = null;
    } else {
        m_aggrCols = new ArrayList<ColorColumn>(aggrCols.length);
        for (final ColorColumn column : aggrCols) {
            final String columnName = column.getColumnName();
            final int aggrColIdx = m_tableSpec.findColumnIndex(columnName);
            if (aggrColIdx < 0) {
                throw new IllegalArgumentException("Selected aggregation column not found.");
            }
            final ColorColumn aggrColumn = new ColorColumn(column.getColor(), columnName);
            m_aggrCols.add(aggrColumn);
        }
    }
}
Also used : ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

ColorColumn (org.knime.base.node.viz.histogram.util.ColorColumn)17 Color (java.awt.Color)7 Point (java.awt.Point)5 DataCell (org.knime.core.data.DataCell)5 DataColumnSpec (org.knime.core.data.DataColumnSpec)5 DataTableSpec (org.knime.core.data.DataTableSpec)5 AggregationMethod (org.knime.base.node.viz.aggregation.AggregationMethod)4 AbstractHistogramVizModel (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel)4 ArrayList (java.util.ArrayList)3 DoubleCell (org.knime.core.data.def.DoubleCell)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)3 Dimension (java.awt.Dimension)2 Rectangle (java.awt.Rectangle)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 HistogramLayout (org.knime.base.node.viz.histogram.HistogramLayout)2 HistogramHiliteCalculator (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel.HistogramHiliteCalculator)2 BinDataModel (org.knime.base.node.viz.histogram.datamodel.BinDataModel)2 InteractiveHistogramVizModel (org.knime.base.node.viz.histogram.datamodel.InteractiveHistogramVizModel)2 AbstractHistogramProperties (org.knime.base.node.viz.histogram.impl.AbstractHistogramProperties)2