Search in sources :

Example 1 with DotInfo

use of org.knime.base.node.viz.plotter.scatter.DotInfo in project knime-core by knime.

the class ScatterMatrixPlotter method updatePaintModel.

/**
 * Creates the nominal coordinates with the selected column names,
 * calculates the surrounding rectangle for the scatter matrix elements,
 * then maps the points to the screen coordinates, associates the
 * {@link org.knime.base.node.viz.plotter.scatter.DotInfo}s with the
 * referring
 * {@link
 * org.knime.base.node.viz.plotter.scattermatrix.ScatterMatrixElement}
 * and passes them to the
 * {@link
 * org.knime.base.node.viz.plotter.scattermatrix.ScatterMatrixDrawingPane}.
 * The {@link
 * org.knime.base.node.viz.plotter.scattermatrix.ScatterMatrixDrawingPane}
 * then extracts the dots from the
 *{@link org.knime.base.node.viz.plotter.scattermatrix.ScatterMatrixElement}
 * and stores them in a
 * {@link org.knime.base.node.viz.plotter.scatter.DotInfoArray}.
 *
 * @see org.knime.base.node.viz.plotter.AbstractPlotter#updatePaintModel()
 */
@Override
public synchronized void updatePaintModel() {
    // clear the drawing pane
    ((ScatterMatrixDrawingPane) getDrawingPane()).setDotInfoArray(null);
    ((ScatterMatrixDrawingPane) getDrawingPane()).setScatterMatrixElements(null);
    // get the number of columns c
    if (getDataProvider() == null || getDataProvider().getDataArray(getDataArrayIdx()) == null) {
        return;
    }
    DataArray data = getDataProvider().getDataArray(getDataArrayIdx());
    // get the first columns
    if (m_selectedColumns == null) {
        m_selectedColumns = new LinkedHashSet<String>();
        for (int i = 0; i < DEFAULT_NR_COLS && i < data.getDataTableSpec().getNumColumns(); i++) {
            // add them to selected columns
            String colName = data.getDataTableSpec().getColumnSpec(i).getName();
            m_selectedColumns.add(colName);
        }
        if (data.getDataTableSpec().getNumColumns() > DEFAULT_NR_COLS) {
            getProperties().setSelectedIndex(MultiColumnPlotterProperties.COLUMN_FILTER_IDX);
        }
        ((ScatterMatrixProperties) getProperties()).updateColumnSelection(data.getDataTableSpec(), 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 = data.getDataTableSpec().findColumnIndex(name);
        if (idx >= 0) {
            selectedColumnCells.add(new StringCell(name));
            DataColumnSpec colSpec = data.getDataTableSpec().getColumnSpec(idx);
            columnIndices.add(idx);
            Coordinate coordinate = Coordinate.createCoordinate(colSpec);
            m_coordinates.add(coordinate);
        }
    }
    // create coordinates with the column names
    createNominalXCoordinate(selectedColumnCells);
    // reverse list for y axis...
    List<DataCell> reverseList = new ArrayList<DataCell>(selectedColumnCells);
    Collections.reverse(reverseList);
    createNominalYCoordinate(new LinkedHashSet<DataCell>(reverseList));
    m_hMargin = (int) (getDrawingPaneDimension().height * H_MARGIN_FACTOR);
    m_vMargin = (int) (getDrawingPaneDimension().width * V_MARGIN_FACTOR);
    ((ScatterMatrixDrawingPane) getDrawingPane()).setHorizontalMargin(m_hMargin);
    ((ScatterMatrixDrawingPane) getDrawingPane()).setVerticalMargin(m_vMargin);
    // set the offset for the column axes
    getXAxis().setStartTickOffset(m_vMargin);
    getYAxis().setStartTickOffset(m_hMargin);
    int nrOfColumns = selectedColumnCells.size();
    // and update the properties
    int width = (getDrawingPaneDimension().width - (nrOfColumns * GAP) - (2 * m_vMargin)) / nrOfColumns;
    m_matrixElementWidth = width;
    int height = (getDrawingPaneDimension().height - (nrOfColumns * GAP) - (2 * m_hMargin)) / nrOfColumns;
    int rowNr = 0;
    ScatterMatrixElement[][] matrixElements = new ScatterMatrixElement[nrOfColumns][nrOfColumns];
    for (DataRow row : data) {
        for (int i = 0; i < nrOfColumns; i++) {
            for (int j = 0; j < nrOfColumns; j++) {
                Coordinate xCoordinate = m_coordinates.get(i);
                Coordinate yCoordinate = m_coordinates.get(j);
                DataCell xValue = row.getCell(columnIndices.get(i));
                DataCell yValue = row.getCell(columnIndices.get(j));
                int x = -1;
                int y = -1;
                int xOffset = (i * (width + GAP)) + m_vMargin;
                int yOffset = (j * (height + GAP)) + m_hMargin;
                ScatterMatrixElement matrixElement = matrixElements[i][j];
                if (matrixElement == null) {
                    matrixElement = new ScatterMatrixElement(new Point(xOffset, yOffset), width, height, xCoordinate, yCoordinate);
                    matrixElements[i][j] = matrixElement;
                }
                if (!xValue.isMissing()) {
                    x = (int) xCoordinate.calculateMappedValue(xValue, width - (2 * getDotSize()), true);
                    // offset
                    x += xOffset + getDotSize();
                }
                if (!yValue.isMissing()) {
                    y = (int) (height - yCoordinate.calculateMappedValue(yValue, height - (2 * getDotSize()), true));
                    // v offset
                    y += yOffset - getDotSize();
                }
                boolean hilite = delegateIsHiLit(row.getKey());
                if (!hilite && isHideMode()) {
                    continue;
                }
                if (isHideMode() && hilite) {
                    hilite = false;
                }
                DotInfo dot = new DotInfo(x, y, row.getKey(), hilite, data.getDataTableSpec().getRowColor(row), data.getDataTableSpec().getRowSizeFactor(row), rowNr);
                dot.setShape(data.getDataTableSpec().getRowShape(row));
                dot.setXDomainValue(xValue);
                dot.setYDomainValue(yValue);
                matrixElement.addDot(dot);
            // dotList.add(dot);
            }
        // j
        }
        // i
        rowNr++;
    }
    // rows
    // jitter
    jitter(matrixElements);
    ((ScatterMatrixDrawingPane) getDrawingPane()).setScatterMatrixElements(matrixElements);
    getDrawingPane().repaint();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) ArrayList(java.util.ArrayList) Point(java.awt.Point) DataRow(org.knime.core.data.DataRow) DataArray(org.knime.base.node.util.DataArray) Point(java.awt.Point) DataColumnSpec(org.knime.core.data.DataColumnSpec) Coordinate(org.knime.base.util.coordinate.Coordinate) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell)

Example 2 with DotInfo

use of org.knime.base.node.viz.plotter.scatter.DotInfo in project knime-core by knime.

the class ScatterMatrixPlotter method jitter.

private void jitter(final ScatterMatrixElement[][] matrixElements) {
    for (int i = 0; i < matrixElements.length; i++) {
        for (int j = 0; j < matrixElements[i].length; j++) {
            ScatterMatrixElement element = matrixElements[i][j];
            // the array is initialized with column length
            if (element == null) {
                continue;
            }
            Coordinate xCoordinate = element.getXCoordinate();
            Coordinate yCoordinate = element.getYCoordinate();
            if ((xCoordinate.isNominal() || yCoordinate.isNominal())) {
                // for jittering only 90% of the available space are used
                // to avoid that the dots of different nominal values
                // touches each other
                int width = element.getWidth();
                int height = element.getHeight();
                List<DotInfo> dotList = element.getDots();
                DotInfo[] dots = new DotInfo[dotList.size()];
                dotList.toArray(dots);
                int xAxisJitterRange = (int) (Math.round(xCoordinate.getUnusedDistBetweenTicks(width)) * 0.9);
                int yAxisJitterRange = (int) (Math.round(yCoordinate.getUnusedDistBetweenTicks(height)) * 0.9);
                jitterDots(dots, xAxisJitterRange, yAxisJitterRange);
                matrixElements[i][j].setDots(Arrays.asList(dots));
            }
        }
    }
}
Also used : DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) Coordinate(org.knime.base.util.coordinate.Coordinate) Point(java.awt.Point)

Example 3 with DotInfo

use of org.knime.base.node.viz.plotter.scatter.DotInfo in project knime-core by knime.

the class BoxPlotDrawingPane method paintOutlierLabels.

/**
 * Paints the label(value) of each outlier dot.
 * @param g graphics.
 */
protected void paintOutlierLabels(final Graphics g) {
    int fontHeight = g.getFontMetrics().getHeight();
    DotInfoArray dotArray = getDotInfoArray();
    DotInfo lastDot = null;
    for (DotInfo dot : dotArray.getDots()) {
        if (lastDot != null && dot.getXCoord() == lastDot.getXCoord()) {
            // check the y coordinates for enough space
            if (Math.abs(lastDot.getYCoord() - dot.getYCoord()) < fontHeight) {
                // lastDot = dot;
                continue;
            }
        }
        int y = dot.getYCoord() + fontHeight / 4;
        int x = dot.getXCoord() + DOT_SIZE;
        if (dot.getYDomainValue() != null) {
            double d = ((DoubleValue) dot.getYDomainValue()).getDoubleValue();
            g.drawString(LabelPaintUtil.getDoubleAsString(d, Box.ROUNDING_FACTOR), x, y);
        }
        lastDot = dot;
    }
}
Also used : DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) DoubleValue(org.knime.core.data.DoubleValue) DotInfoArray(org.knime.base.node.viz.plotter.scatter.DotInfoArray)

Example 4 with DotInfo

use of org.knime.base.node.viz.plotter.scatter.DotInfo in project knime-core by knime.

the class BoxPlotter method updateOutliers.

/**
 * Sets the outliers as dotinfo to the scatterplotter drawing pane to
 * make them selectable and hilite-able.
 * @param yCoordinate the corresponding y coordinate.
 * @param box the box (column).
 * @return the mapped outliers for this column.
 */
protected List<DotInfo> updateOutliers(final Coordinate yCoordinate, final Box box) {
    int height = getDrawingPaneDimension().height - OFFSET;
    List<DotInfo> dotList = new ArrayList<DotInfo>();
    int x = box.getX();
    String colName = box.getColumnName();
    // the mild outliers
    Map<Double, Set<RowKey>> mildOutliers = ((BoxPlotDataProvider) getDataProvider()).getMildOutliers().get(colName);
    for (Map.Entry<Double, Set<RowKey>> entry : mildOutliers.entrySet()) {
        double value = entry.getKey();
        for (RowKey key : entry.getValue()) {
            int y = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(value), height)) - (OFFSET / 2);
            DotInfo dot = new DotInfo(x, y, key, delegateIsHiLit(key), ColorAttr.DEFAULT, 1, 0);
            dot.setXDomainValue(new StringCell(colName));
            dot.setYDomainValue(new DoubleCell(value));
            dot.setShape(ShapeFactory.getShape(ShapeFactory.CIRCLE));
            dotList.add(dot);
        }
    }
    // the extreme outliers
    Map<Double, Set<RowKey>> extremeOutliers = ((BoxPlotDataProvider) getDataProvider()).getExtremeOutliers().get(colName);
    for (Map.Entry<Double, Set<RowKey>> entry : extremeOutliers.entrySet()) {
        double value = entry.getKey();
        for (RowKey key : entry.getValue()) {
            int y = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(value), height)) - (OFFSET / 2);
            DotInfo dot = new DotInfo(x, y, key, delegateIsHiLit(key), ColorAttr.DEFAULT, 1, 0);
            dot.setShape(ShapeFactory.getShape(ShapeFactory.CROSS));
            dot.setXDomainValue(new StringCell(colName));
            dot.setYDomainValue(new DoubleCell(value));
            dotList.add(dot);
        }
    }
    return dotList;
}
Also used : DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) Point(java.awt.Point) StringCell(org.knime.core.data.def.StringCell) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with DotInfo

use of org.knime.base.node.viz.plotter.scatter.DotInfo in project knime-core by knime.

the class LinePlotter method calculateDots.

/**
 * Calculates the screen coordinates (dots) for the lines and puts them in a
 * large {@link org.knime.base.node.viz.plotter.scatter.DotInfoArray}, which
 * is passed to the
 * {@link org.knime.base.node.viz.plotter.line.LinePlotterDrawingPane}.
 */
protected void calculateDots() {
    if (!(getDrawingPane() instanceof ScatterPlotterDrawingPane)) {
        return;
    }
    if (m_columnNames == null) {
        return;
    }
    if (getDataProvider() != null && getDataProvider().getDataArray(getDataArrayIdx()) != null) {
        DataArray array = getDataProvider().getDataArray(getDataArrayIdx());
        int nrOfRows = array.size();
        // set the empty dots to delete the old ones
        // if we have no columns to display
        ((ScatterPlotterDrawingPane) getDrawingPane()).setDotInfoArray(new DotInfoArray(new DotInfo[0]));
        // first store them in a list to avoid keep tracking of indices
        List<DotInfo> dotList = new ArrayList<DotInfo>();
        for (String col : m_columnNames) {
            int colIdx = array.getDataTableSpec().findColumnIndex(col);
            Color c = m_colorMapping.get(col);
            if (c == null) {
                c = Color.black;
            }
            ColorAttr color = ColorAttr.getInstance(c);
            // store the last point with valid value for interpolation
            Point p1 = new Point(-1, -1);
            Point p2;
            List<DotInfo> missingValues = new ArrayList<DotInfo>();
            // create the dots
            for (int row = 0; row < nrOfRows; row++) {
                DataCell cell = array.getRow(row).getCell(colIdx);
                int y = -1;
                DotInfo dot;
                int x = getMappedXValue(new StringCell(array.getRow(row).getKey().getString()));
                if (!cell.isMissing()) {
                    y = getMappedYValue(cell);
                    if (missingValues.size() > 0) {
                        // we have some missing values in between,
                        // thus we have to interpolate
                        p2 = new Point(x, y);
                        DotInfo[] interpolated = interpolate(p1, p2, missingValues);
                        // and add them
                        for (DotInfo p : interpolated) {
                            dotList.add(p);
                        }
                        // and clear the list again
                        missingValues.clear();
                    }
                    p1 = new Point(x, y);
                    dot = new DotInfo(x, y, array.getRow(row).getKey(), delegateIsHiLit(array.getRow(row).getKey()), color, 1, row);
                    dot.setXDomainValue(new StringCell(array.getRow(row).getKey().getString()));
                    dot.setYDomainValue(cell);
                    dotList.add(dot);
                } else if (!m_interpolate) {
                    // LOGGER.debug("missing value");
                    dot = new DotInfo(x, -1, array.getRow(row).getKey(), delegateIsHiLit(array.getRow(row).getKey()), color, 1, row);
                    dotList.add(dot);
                } else {
                    // interpolate
                    dot = new DotInfo(x, -1, array.getRow(row).getKey(), delegateIsHiLit(array.getRow(row).getKey()), color, 1, row);
                    missingValues.add(dot);
                }
            }
            // un-interpolated at the end, we add them anyway
            if (!missingValues.isEmpty()) {
                DotInfo[] interpolated = interpolate(p1, null, missingValues);
                // and add them
                for (DotInfo p : interpolated) {
                    dotList.add(p);
                }
                // and clear the list again
                missingValues.clear();
            }
        }
        DotInfo[] dots = new DotInfo[dotList.size()];
        dotList.toArray(dots);
        ((LinePlotterDrawingPane) getDrawingPane()).setNumberOfLines(nrOfRows);
        ((ScatterPlotterDrawingPane) getDrawingPane()).setDotInfoArray(new DotInfoArray(dots));
    }
}
Also used : DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) Color(java.awt.Color) ArrayList(java.util.ArrayList) ColorAttr(org.knime.core.data.property.ColorAttr) Point(java.awt.Point) ScatterPlotterDrawingPane(org.knime.base.node.viz.plotter.scatter.ScatterPlotterDrawingPane) DataArray(org.knime.base.node.util.DataArray) Point(java.awt.Point) StringCell(org.knime.core.data.def.StringCell) DotInfoArray(org.knime.base.node.viz.plotter.scatter.DotInfoArray) DataCell(org.knime.core.data.DataCell)

Aggregations

DotInfo (org.knime.base.node.viz.plotter.scatter.DotInfo)9 Point (java.awt.Point)6 ArrayList (java.util.ArrayList)5 DotInfoArray (org.knime.base.node.viz.plotter.scatter.DotInfoArray)4 StringCell (org.knime.core.data.def.StringCell)4 Coordinate (org.knime.base.util.coordinate.Coordinate)3 Color (java.awt.Color)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 DataArray (org.knime.base.node.util.DataArray)2 DataCell (org.knime.core.data.DataCell)2 DataColumnSpec (org.knime.core.data.DataColumnSpec)2 DoubleCell (org.knime.core.data.def.DoubleCell)2 BasicStroke (java.awt.BasicStroke)1 Graphics2D (java.awt.Graphics2D)1 GeneralPath (java.awt.geom.GeneralPath)1 Set (java.util.Set)1 JCheckBox (javax.swing.JCheckBox)1 ScatterPlotterDrawingPane (org.knime.base.node.viz.plotter.scatter.ScatterPlotterDrawingPane)1