Search in sources :

Example 6 with DotInfo

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

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

Example 8 with DotInfo

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

the class LinePlotter method interpolate.

/**
 * The nr of intermediate points and the last row index is used to determine
 * the x value (only the y value is interpolated).
 *
 * @param p1
 *            the domain value 1
 * @param p2
 *            the domain value 2
 * @param xValues
 *            an array containing opoints with the right x value but missing
 *            y value.
 * @return the interpolated domain values.
 */
public DotInfo[] interpolate(final Point p1, final Point p2, final List<DotInfo> xValues) {
    DotInfo[] interpolated = new DotInfo[xValues.size()];
    if (p1 == null || p2 == null || p1.getY() < 0 || p2.getY() < 0) {
        // -> don't interpolate but replace with not visible points
        for (int i = 0; i < xValues.size(); i++) {
            // don't interpolate if one of the points is invalid
            DotInfo newDot = xValues.get(i);
            newDot.setYCoord(-1);
            interpolated[i] = newDot;
        }
        return interpolated;
    }
    // both points are valid -> interpolate
    for (int i = 0; i < xValues.size(); i++) {
        int x = xValues.get(i).getXCoord();
        double m = 0;
        if (!p1.equals(p2)) {
            m = ((p2.getY() - p1.getY()) / (p2.getX() - p1.getX()));
        }
        double y = (m * x) - (m * p1.getX()) + p1.getY();
        DotInfo newDot = xValues.get(i);
        newDot.setYCoord((int) getScreenYCoordinate(y));
        interpolated[i] = newDot;
        x++;
    }
    return interpolated;
}
Also used : DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) Point(java.awt.Point)

Example 9 with DotInfo

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

the class LinePlotterDrawingPane method paintContent.

/**
 * Connects the points of one column by a line, which is done by modulo
 * calculation, the color information is stored in the
 * {@link org.knime.base.node.viz.plotter.scatter.DotInfo}s.
 *
 * @see org.knime.base.node.viz.plotter.scatter.ScatterPlotterDrawingPane
 * #paintContent(java.awt.Graphics)
 */
@Override
public void paintContent(final Graphics g) {
    if (getDotInfoArray() == null || getDotInfoArray().getDots().length == 0) {
        return;
    }
    ShapeFactory.Shape shape = ShapeFactory.getShape(ShapeFactory.RECTANGLE);
    int dotSize = getDotSize();
    DotInfo[] dotInfo = getDotInfoArray().getDots();
    GeneralPath path = new GeneralPath();
    for (int i = 0; i < dotInfo.length; i++) {
        DotInfo dot1 = dotInfo[i];
        if (m_showDots && dot1.paintDot()) {
            boolean isSelected = getSelectedDots().contains(dotInfo[i].getRowID());
            boolean isHilite = dotInfo[i].isHiLit();
            Color c = dotInfo[i].getColor().getColor();
            int x = dotInfo[i].getXCoord();
            int y = dotInfo[i].getYCoord();
            shape.paint(g, x, y, dotSize, c, isHilite, isSelected, false);
        }
        if (i % m_nrOfLines == 0 && path != null) {
            // start of one line
            path.reset();
            // move to start point
            path.moveTo(dot1.getXCoord(), dot1.getYCoord());
        }
        if (dot1.paintDot()) {
            // if we had a missing value and !interpolate
            if (path == null) {
                path = new GeneralPath();
                path.moveTo(dot1.getXCoord(), dot1.getYCoord());
            } else {
                // add line segment to path
                path.lineTo(dot1.getXCoord(), dot1.getYCoord());
            }
        } else if (path != null) {
            // if not paint dot (y = -1) => missing value && !interpolate
            // we have to close the path and continue a new one
            g.setColor(dot1.getColor().getColor());
            ((Graphics2D) g).setStroke(new BasicStroke(m_thickness));
            ((Graphics2D) g).draw(path);
            path = null;
        }
        if (i % m_nrOfLines == (m_nrOfLines - 1) && path != null) {
            // end of one line -> paint it
            g.setColor(dot1.getColor().getColor());
            ((Graphics2D) g).setStroke(new BasicStroke(m_thickness));
            ((Graphics2D) g).draw(path);
        }
    }
}
Also used : DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) Color(java.awt.Color) ShapeFactory(org.knime.core.data.property.ShapeFactory) Graphics2D(java.awt.Graphics2D)

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