Search in sources :

Example 1 with MultiColumnPlotterProperties

use of org.knime.base.node.viz.plotter.columns.MultiColumnPlotterProperties in project knime-core by knime.

the class BinModelPlotter method updatePaintModel.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void updatePaintModel() {
    if (m_discretizationModel == null) {
        return;
    }
    // clear the drawing pane
    ((BinModelDrawingPane) getDrawingPane()).setBinningSchemes(null);
    // get the first columns
    if (m_selectedColumns == null) {
        m_selectedColumns = new LinkedHashSet<String>();
        String[] binnedColumnNames = m_discretizationModel.getIncludedColumnNames();
        for (int i = 0; i < binnedColumnNames.length; i++) {
            // add them to the selected columns
            m_selectedColumns.add(binnedColumnNames[i]);
        }
        ((MultiColumnPlotterProperties) getProperties()).updateColumnSelection(m_binnedColumnsSpec, m_selectedColumns);
    }
    if (m_selectedColumns.size() == 0) {
        getDrawingPane().repaint();
        return;
    }
    Set<DataCell> selectedColumnCells = new LinkedHashSet<DataCell>();
    m_coordinates = new ArrayList<Coordinate>();
    List<Integer> columnIndices = new ArrayList<Integer>();
    for (String name : m_selectedColumns) {
        int idx = m_binnedColumnsSpec.findColumnIndex(name);
        if (idx >= 0) {
            selectedColumnCells.add(new StringCell(name));
            DataColumnSpec colSpec = m_binnedColumnsSpec.getColumnSpec(idx);
            columnIndices.add(idx);
            Coordinate coordinate = Coordinate.createCoordinate(colSpec);
            m_coordinates.add(coordinate);
        }
    }
    // get the binning schemes for the selected columns
    DiscretizationScheme[] selectedSchemes = getSelectedSchemes();
    String[] selectedColumnNames = getSelectedColumnNames();
    // calculate the display coordinates for the drawing pane
    BinRuler[] binRulers = new BinRuler[selectedSchemes.length];
    // determine the width available for a bin ruler
    int rulerWidth = getDrawingPaneDimension().width - 2 * m_hMargin;
    for (int i = 0; i < selectedSchemes.length; i++) {
        double[] bounds = selectedSchemes[i].getBounds();
        double min = bounds[0];
        double max = bounds[bounds.length - 1];
        // first create a colum spec from the schemes
        DataColumnSpecCreator columnSpecCreator = new DataColumnSpecCreator("", DoubleCell.TYPE);
        columnSpecCreator.setDomain(new DataColumnDomainCreator(new DoubleCell(min), new DoubleCell(max)).createDomain());
        DoubleCoordinate coordinate = (DoubleCoordinate) Coordinate.createCoordinate(columnSpecCreator.createSpec());
        Point leftStart = new Point(m_hMargin, m_vMargin + (i + 1) * m_columnDisplayHeight);
        int[] binPositions = new int[bounds.length];
        String[] binLabels = new String[bounds.length];
        int count = 0;
        for (double bound : bounds) {
            binPositions[count] = (int) coordinate.calculateMappedValue(new DoubleCell(bound), rulerWidth, true);
            binLabels[count] = coordinate.formatNumber(bounds[count]);
            count++;
        }
        binRulers[i] = new BinRuler(leftStart, rulerWidth, binPositions, binLabels, selectedColumnNames[i]);
    }
    ((BinModelDrawingPane) getDrawingPane()).setBinningSchemes(binRulers);
    m_hMargin = 10;
    m_vMargin = 10;
    ((BinModelDrawingPane) getDrawingPane()).setHorizontalMargin(m_hMargin);
    setHeight(binRulers[binRulers.length - 1].getLeftStartPoint().y + 40);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DiscretizationScheme(org.knime.base.node.preproc.discretization.caim2.DiscretizationScheme) ArrayList(java.util.ArrayList) DoubleCoordinate(org.knime.base.util.coordinate.DoubleCoordinate) DataColumnSpec(org.knime.core.data.DataColumnSpec) MultiColumnPlotterProperties(org.knime.base.node.viz.plotter.columns.MultiColumnPlotterProperties) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) Point(java.awt.Point) Point(java.awt.Point) DoubleCoordinate(org.knime.base.util.coordinate.DoubleCoordinate) Coordinate(org.knime.base.util.coordinate.Coordinate) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell)

Example 2 with MultiColumnPlotterProperties

use of org.knime.base.node.viz.plotter.columns.MultiColumnPlotterProperties in project knime-core by knime.

the class ParallelCoordinatesPlotter method updatePaintModel.

// ----------- painting ----------------
/**
 * Creates a nominal x axis with the names of the selected columns,
 * the referring
 * {@link org.knime.base.node.viz.plotter.parcoord.ParallelAxis} for each
 * column and calculates the lines with the mapped values which are passed
 * together with the axes to the
 * {@link org.knime.base.node.viz.plotter.parcoord
 * .ParallelCoordinateDrawingPane}.
 *
 * @see org.knime.base.node.viz.plotter.AbstractPlotter#updatePaintModel()
 */
@Override
public synchronized void updatePaintModel() {
    if (getDataProvider() != null && getDataProvider().getDataArray(getDataArrayIdx()) != null) {
        DataArray array = getDataProvider().getDataArray(getDataArrayIdx());
        Set<DataCell> columns = new LinkedHashSet<DataCell>();
        m_axes = new LinkedList<ParallelAxis>();
        if (m_columnNames == null) {
            initColumnNames(array);
        }
        // create the x axis
        for (String columnName : m_columnNames) {
            DataColumnSpec colSpec = array.getDataTableSpec().getColumnSpec(columnName);
            if (colSpec == null) {
                initColumnNames(array);
                updatePaintModel();
                break;
            }
            columns.add(new StringCell(colSpec.getName()));
            m_axes.add(ParallelAxis.createParallelAxis(colSpec));
        }
        createNominalXCoordinate(columns);
        if (getDrawingPane() instanceof ParallelCoordinateDrawingPane) {
            ((ParallelCoordinateDrawingPane) getDrawingPane()).setAxes(m_axes);
            updateAxesPosition();
            m_lines = calculateLines();
            ((ParallelCoordinateDrawingPane) getDrawingPane()).setLines(m_lines);
        }
        if (getProperties() instanceof MultiColumnPlotterProperties) {
            Set<String> selectedColumns = new LinkedHashSet<String>();
            selectedColumns.addAll(m_columnNames);
            ((MultiColumnPlotterProperties) getProperties()).updateColumnSelection(array.getDataTableSpec(), selectedColumns);
        }
    }
    getDrawingPane().repaint();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataColumnSpec(org.knime.core.data.DataColumnSpec) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) MultiColumnPlotterProperties(org.knime.base.node.viz.plotter.columns.MultiColumnPlotterProperties) DataArray(org.knime.base.node.util.DataArray)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)2 MultiColumnPlotterProperties (org.knime.base.node.viz.plotter.columns.MultiColumnPlotterProperties)2 DataCell (org.knime.core.data.DataCell)2 DataColumnSpec (org.knime.core.data.DataColumnSpec)2 StringCell (org.knime.core.data.def.StringCell)2 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 DiscretizationScheme (org.knime.base.node.preproc.discretization.caim2.DiscretizationScheme)1 DataArray (org.knime.base.node.util.DataArray)1 Coordinate (org.knime.base.util.coordinate.Coordinate)1 DoubleCoordinate (org.knime.base.util.coordinate.DoubleCoordinate)1 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)1 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)1 DoubleCell (org.knime.core.data.def.DoubleCell)1