Search in sources :

Example 1 with DotInfoArray

use of org.knime.base.node.viz.plotter.scatter.DotInfoArray 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 2 with DotInfoArray

use of org.knime.base.node.viz.plotter.scatter.DotInfoArray 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)

Example 3 with DotInfoArray

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

the class ScatterMatrixDrawingPane method setScatterMatrixElements.

/**
 * @param elements the rectangles with the coordinates.
 */
public void setScatterMatrixElements(final ScatterMatrixElement[][] elements) {
    m_matrixElements = elements;
    if (elements != null) {
        List<DotInfo> dotList = new ArrayList<DotInfo>();
        for (int i = 0; i < m_matrixElements.length; i++) {
            for (int j = 0; j < m_matrixElements[i].length; j++) {
                // the array is initialized with column length
                if (m_matrixElements[i][j] == null) {
                    continue;
                }
                dotList.addAll(m_matrixElements[i][j].getDots());
            }
        }
        DotInfo[] dots = new DotInfo[dotList.size()];
        dotList.toArray(dots);
        setDotInfoArray(new DotInfoArray(dots));
    // repaint();
    }
}
Also used : DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) DotInfoArray(org.knime.base.node.viz.plotter.scatter.DotInfoArray) ArrayList(java.util.ArrayList)

Example 4 with DotInfoArray

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

the class BoxPlotter method updateSize.

/**
 * {@inheritDoc}
 */
@Override
public void updateSize() {
    if (getDataProvider() == null || ((BoxPlotDataProvider) getDataProvider()).getStatistics() == null) {
        return;
    }
    if (m_selectedColumns == null) {
        return;
    }
    Map<DataColumnSpec, double[]> statistics = ((BoxPlotDataProvider) getDataProvider()).getStatistics();
    List<Box> boxes = new ArrayList<Box>();
    List<DotInfo> outliers = new ArrayList<DotInfo>();
    for (Map.Entry<DataColumnSpec, double[]> entry : statistics.entrySet()) {
        Coordinate yCoordinate;
        if (!m_selectedColumns.contains(entry.getKey().getName())) {
            continue;
        }
        if (m_normalize) {
            yCoordinate = m_coordinates.get(entry.getKey());
        } else {
            if (getYAxis() == null) {
                updatePaintModel();
            }
            yCoordinate = getYAxis().getCoordinate();
            getYAxis().setStartTickOffset(OFFSET / 2);
        }
        String colName = entry.getKey().getName();
        double[] stats = entry.getValue();
        int x = (int) getXAxis().getCoordinate().calculateMappedValue(new StringCell(colName), getDrawingPaneDimension().width);
        int height = getDrawingPaneDimension().height - OFFSET;
        int yMin = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(stats[BoxPlotNodeModel.MIN]), height));
        int yLowQuart = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(stats[BoxPlotNodeModel.LOWER_QUARTILE]), height));
        int yMed = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(stats[BoxPlotNodeModel.MEDIAN]), height));
        int yUppQuart = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(stats[BoxPlotNodeModel.UPPER_QUARTILE]), height));
        int yMax = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(stats[BoxPlotNodeModel.MAX]), height));
        Box box = new Box(x, yMin - (OFFSET / 2), yLowQuart - (OFFSET / 2), yMed - (OFFSET / 2), yUppQuart - (OFFSET / 2), yMax - (OFFSET / 2), stats);
        box.setColumnName(entry.getKey().getName());
        // whiskers
        int lowerWhisker = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(stats[BoxPlotNodeModel.LOWER_WHISKER]), height));
        int upperWhisker = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(stats[BoxPlotNodeModel.UPPER_WHISKER]), height));
        box.setLowerWhiskers(lowerWhisker - (OFFSET / 2));
        box.setUpperWhiskers(upperWhisker - (OFFSET / 2));
        boxes.add(box);
        outliers.addAll(updateOutliers(yCoordinate, box));
    }
    ((BoxPlotDrawingPane) getDrawingPane()).setBoxes(boxes);
    DotInfo[] dots = new DotInfo[outliers.size()];
    outliers.toArray(dots);
    ((BoxPlotDrawingPane) getDrawingPane()).setDotInfoArray(new DotInfoArray(dots));
    if (getXAxis() != null && getXAxis().getCoordinate() != null) {
        int boxWidth = (int) getXAxis().getCoordinate().getUnusedDistBetweenTicks(getDrawingPaneDimension().width);
        boxWidth = boxWidth / 4;
        ((BoxPlotDrawingPane) getDrawingPane()).setBoxWidth(boxWidth);
    }
    getDrawingPane().repaint();
}
Also used : DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) JCheckBox(javax.swing.JCheckBox) Point(java.awt.Point) DataColumnSpec(org.knime.core.data.DataColumnSpec) Coordinate(org.knime.base.util.coordinate.Coordinate) StringCell(org.knime.core.data.def.StringCell) DotInfoArray(org.knime.base.node.viz.plotter.scatter.DotInfoArray) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

DotInfo (org.knime.base.node.viz.plotter.scatter.DotInfo)4 DotInfoArray (org.knime.base.node.viz.plotter.scatter.DotInfoArray)4 ArrayList (java.util.ArrayList)3 Point (java.awt.Point)2 StringCell (org.knime.core.data.def.StringCell)2 Color (java.awt.Color)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 JCheckBox (javax.swing.JCheckBox)1 DataArray (org.knime.base.node.util.DataArray)1 ScatterPlotterDrawingPane (org.knime.base.node.viz.plotter.scatter.ScatterPlotterDrawingPane)1 Coordinate (org.knime.base.util.coordinate.Coordinate)1 DataCell (org.knime.core.data.DataCell)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DoubleValue (org.knime.core.data.DoubleValue)1 DoubleCell (org.knime.core.data.def.DoubleCell)1 ColorAttr (org.knime.core.data.property.ColorAttr)1