Search in sources :

Example 11 with ColorColumn

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

the class AbstractHistogramPlotter method setHistogramBinRectangle.

/**
 * Calculates and sets the drawing rectangle of each bin.
 * @param xCoordinates The <code>Coordinate</code> object which contains
 * the start position of an bar on the x axis
 * @param yCoordinates The <code>Coordinate</code> object which contains
 * the start position of an bar on the y axis
 */
private static void setHistogramBinRectangle(final AbstractHistogramVizModel vizModel, final Coordinate xCoordinates, final Coordinate yCoordinates) {
    final Dimension drawingSpace = vizModel.getDrawingSpace();
    final int binWidth = vizModel.getBinWidth();
    final AggregationMethod aggrMethod = vizModel.getAggregationMethod();
    final List<Color> barElementColors = vizModel.getRowColors();
    final Collection<ColorColumn> aggrColumns = vizModel.getAggrColumns();
    final HistogramLayout layout = vizModel.getHistogramLayout();
    final HistogramHiliteCalculator calculator = vizModel.getHiliteCalculator();
    final double drawingWidth = drawingSpace.getWidth();
    final double drawingHeight = drawingSpace.getHeight();
    final int baseLine = (int) (drawingHeight - yCoordinates.calculateMappedValue(new DoubleCell(0), drawingHeight));
    // this is the minimum size of a bar with an aggregation value > 0
    final int minHeight = Math.max((int) HistogramDrawingPane.getBarStrokeWidth(), AbstractHistogramVizModel.MINIMUM_BAR_HEIGHT);
    // final int binWidth = getBinWidth();
    for (final BinDataModel bin : vizModel.getBins()) {
        final DataCell captionCell = bin.getXAxisCaptionCell();
        final double labelCoord = xCoordinates.calculateMappedValue(captionCell, drawingWidth);
        if (labelCoord < 0) {
            // this bin is not on the x axis (because it is empty and the
            // empty bins shouldn't be displayed) so we simply set the
            // rectangle to null and continue
            bin.setBinRectangle(null, baseLine, barElementColors, aggrColumns, calculator);
            continue;
        }
        // if the maximum value is negative use 0 to end at the base line
        final double maxAggrVal = Math.max(bin.getMaxAggregationValue(aggrMethod, layout), 0);
        // if the minimum value is positive use 0 to start at the base line
        final double minAggrVal = Math.min(bin.getMinAggregationValue(aggrMethod, layout), 0);
        // 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 - (binWidth / 2.0));
        final int upperY = (int) (drawingHeight - yCoordinates.calculateMappedValue(new DoubleCell(maxAggrVal), drawingHeight));
        final int lowerY = (int) (drawingHeight - yCoordinates.calculateMappedValue(new DoubleCell(minAggrVal), drawingHeight));
        final Rectangle binRect = calculateBorderRectangle(xCoord, lowerY, upperY, minHeight, binWidth, maxAggrVal, baseLine);
        bin.setBinRectangle(binRect, baseLine, barElementColors, aggrColumns, calculator);
    }
// end of for loop over the x axis coordinates
}
Also used : AggregationMethod(org.knime.base.node.viz.aggregation.AggregationMethod) DoubleCell(org.knime.core.data.def.DoubleCell) Color(java.awt.Color) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) Rectangle(java.awt.Rectangle) 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) DataCell(org.knime.core.data.DataCell) HistogramLayout(org.knime.base.node.viz.histogram.HistogramLayout)

Example 12 with ColorColumn

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

the class AbstractHistogramPlotter method createAggregationColumnName.

/**
 * Returns the column name including the aggregation method.
 *
 * @param columnNames the origin column name
 * @param aggrMethod the aggregation method
 * @return column name with a hint about the aggregation method
 */
private String createAggregationColumnName(final Collection<? extends ColorColumn> columnNames, final AggregationMethod aggrMethod) {
    if (aggrMethod.equals(AggregationMethod.COUNT)) {
        return AbstractHistogramPlotter.COL_NAME_COUNT;
    }
    final StringBuilder name = new StringBuilder();
    if (columnNames == null || columnNames.size() < 0) {
        // select a aggregation column
        throw new IllegalArgumentException("Column name not defined.");
    } else if (aggrMethod.equals(AggregationMethod.SUM)) {
        name.append("Sum of ");
    } else if (aggrMethod.equals(AggregationMethod.AVERAGE)) {
        name.append("Avg of ");
    } else if (aggrMethod.equals(AggregationMethod.VALUE_COUNT)) {
        name.append("No of values for ");
    } else {
        throw new IllegalArgumentException("Aggregation method not supported.");
    }
    boolean first = true;
    for (final ColorColumn column : columnNames) {
        if (first) {
            first = false;
        } else {
            name.append(", ");
        }
        name.append(column.getColumnName());
    }
    return name.toString();
}
Also used : ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn)

Example 13 with ColorColumn

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

the class FixedHistogramProperties method createAggrColTable.

private static String createAggrColTable(final Collection<ColorColumn> cols) {
    if (cols == null || cols.size() < 1) {
        return "no columns selected";
    }
    final StringBuilder buf = new StringBuilder();
    buf.append("<br>");
    buf.append("<table cellspacing='5'>");
    int i = 0;
    for (final ColorColumn col : cols) {
        if (i % NO_OF_AGGR_COLS_PER_ROW == 0) {
            buf.append("<tr>");
        }
        buf.append("<td bgcolor='#");
        buf.append(Integer.toHexString(col.getColor().getRGB() & 0x00ffffff));
        buf.append("'>");
        buf.append(col.getColumnName());
        buf.append("</td>");
        if (i % NO_OF_AGGR_COLS_PER_ROW == NO_OF_AGGR_COLS_PER_ROW - 1) {
            buf.append("</tr>");
        }
        i++;
    }
    if (i % NO_OF_AGGR_COLS_PER_ROW != 0) {
        while (i % NO_OF_AGGR_COLS_PER_ROW != 0) {
            // close the table line if the number of columns wasn't even
            buf.append("<td>&nbsp;</td>");
            i++;
        }
        buf.append("</tr>");
    }
    buf.append("</table>");
    return buf.toString();
}
Also used : ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn)

Example 14 with ColorColumn

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

the class InteractiveHistogramVizModel method addRows2Bins.

/**
 *This method should loop through all data rows and should add each row
 *to the corresponding bin by calling the
 *{@link #addDataRow2Bin(int, DataCell, Color, DataCell,
 *Collection, DataCell[])} method.
 * @param missingValBin the bin for missing values
 * @param bins the different bins
 * @param invalidValBin the bin for invalid values such as NaN and infinite. Might be <code>null</code>
 */
private void addRows2Bins(final List<? extends BinDataModel> bins, final BinDataModel missingValBin, final BinDataModel invalidValBin) {
    // add the data rows to the new bins
    int startBin = 0;
    if (m_aggrColumns == null || m_aggrColumns.size() < 1) {
        // if the user hasn't selected a aggregation column
        for (final DataRow row : getSortedRows()) {
            final DataCell xCell = row.getCell(m_xColIdx);
            final Color color = m_tableSpec.getRowColor(row).getColor(false, false);
            final RowKey id = row.getKey();
            try {
                startBin = BinningUtil.addDataRow2Bin(isBinNominal(), bins, missingValBin, invalidValBin, startBin, xCell, color, id, m_aggrColumns, DataType.getMissingCell());
            } catch (final IllegalArgumentException e) {
                if (!BinningUtil.checkDomainRange(xCell, getXColumnSpec())) {
                    throw new IllegalStateException("Invalid column domain for column " + m_xColSpec.getName() + ". " + e.getMessage());
                }
                throw e;
            }
        }
    } else {
        final DataTableSpec tableSpec = getTableSpec();
        final int aggrSize = m_aggrColumns.size();
        final int[] aggrIdx = new int[aggrSize];
        int i = 0;
        for (final ColorColumn aggrColumn : m_aggrColumns) {
            aggrIdx[i++] = tableSpec.findColumnIndex(aggrColumn.getColumnName());
        }
        for (final DataRow row : getSortedRows()) {
            final DataCell xCell = row.getCell(m_xColIdx);
            final Color color = m_tableSpec.getRowColor(row).getColor(false, false);
            final RowKey id = row.getKey();
            final DataCell[] aggrVals = new DataCell[aggrSize];
            for (int j = 0, length = aggrIdx.length; j < length; j++) {
                aggrVals[j] = row.getCell(aggrIdx[j]);
            }
            try {
                startBin = BinningUtil.addDataRow2Bin(isBinNominal(), bins, missingValBin, invalidValBin, startBin, xCell, color, id, m_aggrColumns, aggrVals);
            } catch (final IllegalArgumentException e) {
                if (!BinningUtil.checkDomainRange(xCell, getXColumnSpec())) {
                    throw new IllegalStateException("Invalid column domain for column " + m_xColSpec.getName() + ". " + e.getMessage());
                }
                throw e;
            }
        }
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RowKey(org.knime.core.data.RowKey) Color(java.awt.Color) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow)

Example 15 with ColorColumn

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

the class InteractiveHistogramPlotter method onAggrColChanged.

/**
 * Called whenever the user changes the aggregation column.
 */
protected void onAggrColChanged() {
    final AbstractHistogramVizModel abstractVizModel = getHistogramVizModel();
    if (abstractVizModel == null) {
        LOGGER.debug("VizModel was null");
        return;
    }
    final AbstractHistogramProperties abstractHistogramProperties = getHistogramPropertiesPanel();
    if (abstractHistogramProperties == null) {
        LOGGER.debug("ProeprtiesPanel was null");
        return;
    }
    if (abstractVizModel instanceof InteractiveHistogramVizModel) {
        final InteractiveHistogramVizModel vizModel = (InteractiveHistogramVizModel) abstractVizModel;
        if (abstractHistogramProperties instanceof InteractiveHistogramProperties) {
            final InteractiveHistogramProperties props = (InteractiveHistogramProperties) abstractHistogramProperties;
            final List<ColorColumn> aggrCols = props.getSelectedAggrColumns();
            if (vizModel.setAggregationColumns(aggrCols)) {
                // show the bar outline automatically depending on the
                // number of selected aggregation columns
                vizModel.setShowBarOutline(aggrCols != null && aggrCols.size() > 1);
                setYCoordinates();
                // set the current hilited keys in the new bins
                vizModel.updateHiliteInfo(delegateGetHiLitKeys(), true);
                if (vizModel.containsNotPresentableBin()) {
                    vizModel.setBinWidth(vizModel.getMaxBinWidth());
                }
                // update the details tab
                getHistogramPropertiesPanel().updateHTMLDetailsPanel(vizModel.getHTMLDetailData());
                updatePaintModel();
            }
        } else {
            throw new IllegalStateException(" PropertiesPanel should be of type interactive");
        }
    } else {
        throw new IllegalStateException("VizModel should be of type interactive");
    }
}
Also used : AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) AbstractHistogramProperties(org.knime.base.node.viz.histogram.impl.AbstractHistogramProperties) InteractiveHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.InteractiveHistogramVizModel)

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