Search in sources :

Example 1 with ScatterPlotterDrawingPane

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

Color (java.awt.Color)1 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 DataArray (org.knime.base.node.util.DataArray)1 DotInfo (org.knime.base.node.viz.plotter.scatter.DotInfo)1 DotInfoArray (org.knime.base.node.viz.plotter.scatter.DotInfoArray)1 ScatterPlotterDrawingPane (org.knime.base.node.viz.plotter.scatter.ScatterPlotterDrawingPane)1 DataCell (org.knime.core.data.DataCell)1 StringCell (org.knime.core.data.def.StringCell)1 ColorAttr (org.knime.core.data.property.ColorAttr)1