Search in sources :

Example 16 with Coordinate

use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.

the class ScatterPlotter method calculateCoordinates.

/*
     * given the actual size of the drawing pane, the actual zoom factor, and
     * min/max values it calculates the screen coordinates for each dot info in
     * the array passed in. It accesses the model to retrieve the actual values
     * of the rows. It changes the contents of the DotInfos passed in. It also
     * triggers resorting of the sorted lists in the dot container.
     */
private void calculateCoordinates(final DotInfoArray dotsArray) {
    if (dotsArray == null) {
        return;
    }
    DotInfo[] dots = dotsArray.getDots();
    if ((dots == null) || (dots.length == 0)) {
        return;
    }
    // check whether there is a row container
    if (m_rowContainer == null) {
        return;
    }
    // if there is a invalid column return
    checkColumns();
    if (m_invalidColumn) {
        return;
    }
    // the actual size we can draw in
    // the max dot size is subtracted as a dot can vary in size
    Rectangle drawingRectangle = calculateDrawingRectangle();
    int width = drawingRectangle.width;
    int height = drawingRectangle.height;
    int xOffset = drawingRectangle.x;
    int yOffset = drawingRectangle.y;
    assert dots.length <= m_rowContainer.size();
    // get the coordinates from the headers
    Coordinate xCoordinate = getColHeader().getCoordinate();
    Coordinate yCoordinate = getRowHeader().getCoordinate();
    // if one of the coordinates is missing returns
    if (xCoordinate == null || yCoordinate == null) {
        return;
    }
    // calculate the mapping for each domain value
    for (int i = 0; i < dots.length; i++) {
        // as the dots may have been sorted the loop index does not
        // neccessarily corresponds with the row ids any more
        // therefore the row id is retrieved from the dot info
        int rowId = dots[i].getRowIndex();
        DataRow row = m_rowContainer.getRow(rowId);
        DataCell xCell = row.getCell(m_xIndex);
        DataCell yCell = row.getCell(m_yIndex);
        if (!xCell.isMissing() && !yCell.isMissing()) {
            // temp variables for the coordinates
            int x = (int) (xCoordinate.calculateMappedValue(xCell, width, true));
            // need to be transformed to lower left origin later on
            // (see below)
            int y = (int) (yCoordinate.calculateMappedValue(yCell, height, true));
            // if one of the values is not a valid one set -1 for both
            if (x < 0 || y < 0) {
                dots[i].setXCoord(-1);
                dots[i].setYCoord(-1);
            } else {
                // for coordinate origin down there in the left lower
                // corner:
                dots[i].setXCoord(xOffset + x);
                dots[i].setYCoord(yOffset + height - y);
            }
        } else {
            // at least one coordinate is missing, set invalid screen coord
            dots[i].setXCoord(-1);
            dots[i].setYCoord(-1);
        }
    }
    if ((xCoordinate.isNominal() || yCoordinate.isNominal())) {
        // for jittering only 90% of the available space are used
        // to avoid that the dots of different nominal values touces each
        // other
        int xAxisJitterRange = (int) (Math.round(xCoordinate.getUnusedDistBetweenTicks(width)) * 0.9);
        int yAxisJitterRange = (int) (Math.round(yCoordinate.getUnusedDistBetweenTicks(height)) * 0.9);
        jitterDots(dots, xAxisJitterRange, yAxisJitterRange);
    }
}
Also used : Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) Rectangle(java.awt.Rectangle) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow)

Example 17 with Coordinate

use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.

the class AbstractHistogramPlotter method getXCoordinate.

/**
 * @return the {@link Coordinate} of the x axis.
 */
private Coordinate getXCoordinate() {
    final Axis xAxis = getXAxis();
    if (xAxis == null) {
        throw new IllegalStateException("X axis must not be null");
    }
    final Coordinate xCoordinate = xAxis.getCoordinate();
    if (xCoordinate == null) {
        throw new IllegalStateException("X coordinate must not be null");
    }
    return xCoordinate;
}
Also used : Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) Axis(org.knime.base.node.viz.plotter.Axis)

Example 18 with Coordinate

use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.

the class AbstractHistogramPlotter method updatePaintModel.

/**
 * {@inheritDoc}
 */
@Override
public void updatePaintModel() {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null) {
        LOGGER.debug("VizModel was null");
        return;
    }
    final Coordinate xCoordinates = getXCoordinate();
    final Coordinate yCoordinates = getAggregationCoordinate();
    final HistogramDrawingPane drawingPane = getHistogramDrawingPane();
    final Dimension drawingSpace = vizModel.getDrawingSpace();
    setHistogramBinRectangle(vizModel, xCoordinates, yCoordinates);
    final double drawingHeight = drawingSpace.getHeight();
    if (!yCoordinates.isNominal() && ((NumericCoordinate) yCoordinates).getMinDomainValue() < 0) {
        final int baseLine = (int) (drawingHeight - yCoordinates.calculateMappedValue(new DoubleCell(0), drawingHeight));
        drawingPane.setBaseLine(Integer.valueOf(baseLine));
    } else {
        drawingPane.setBaseLine(null);
    }
    if (vizModel.isShowGridLines()) {
        final int[] gridLines = getGridLineCoordinates(yCoordinates, drawingHeight);
        drawingPane.setGridLines(gridLines);
    } else {
        drawingPane.setGridLines(null);
    }
    // update the properties panel as well since something could have changed
    drawingPane.setHistogramVizModel(vizModel, true);
}
Also used : AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DoubleCell(org.knime.core.data.def.DoubleCell) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 19 with Coordinate

use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.

the class AbstractHistogramPlotter method setShowGridLines.

/**
 * @param showGridLines set to <code>true</code> if the grid lines of the
 * y axis should be shown
 */
public void setShowGridLines(final boolean showGridLines) {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null) {
        throw new IllegalStateException("Exception in setShowGridLines: " + "Viz model must not be null");
    }
    if (vizModel.setShowGridLines(showGridLines)) {
        final HistogramDrawingPane drawingPane = getHistogramDrawingPane();
        if (showGridLines) {
            final Coordinate yCoordinates = getYAxis().getCoordinate();
            if (yCoordinates == null) {
                return;
            }
            final double drawingHeight = vizModel.getDrawingSpace().getHeight();
            final int[] gridLines = getGridLineCoordinates(yCoordinates, drawingHeight);
            drawingPane.setGridLines(gridLines);
        } else {
            drawingPane.setGridLines(null);
        }
        repaint();
    }
}
Also used : AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate)

Example 20 with Coordinate

use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.

the class AbstractHistogramPlotter method setYCoordinates.

/**
 * Sets the y coordinates for the current
 * {@link AbstractHistogramVizModel}.
 */
protected void setYCoordinates() {
    final DataColumnSpec aggrColSpec = getAggregationColSpec();
    // setYColName(aggrColSpec.getName());
    // tell the headers to display the new column names
    final Coordinate yCoordinate = Coordinate.createCoordinate(aggrColSpec);
    if (getYAxis() == null) {
        final Axis yAxis = new Axis(Axis.VERTICAL, getDrawingPaneDimension().height);
        setYAxis(yAxis);
    }
    getYAxis().setCoordinate(yCoordinate);
    getYAxis().setToolTipText(aggrColSpec.getName());
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) Axis(org.knime.base.node.viz.plotter.Axis)

Aggregations

Coordinate (org.knime.base.util.coordinate.Coordinate)26 NumericCoordinate (org.knime.base.util.coordinate.NumericCoordinate)17 Point (java.awt.Point)8 DataCell (org.knime.core.data.DataCell)8 DataColumnSpec (org.knime.core.data.DataColumnSpec)8 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)7 DoubleCell (org.knime.core.data.def.DoubleCell)7 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)6 Axis (org.knime.base.node.viz.plotter.Axis)4 DataRow (org.knime.core.data.DataRow)4 ArrayList (java.util.ArrayList)3 AbstractHistogramVizModel (org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel)3 DotInfo (org.knime.base.node.viz.plotter.scatter.DotInfo)3 DataTableSpec (org.knime.core.data.DataTableSpec)3 StringCell (org.knime.core.data.def.StringCell)3 Dimension (java.awt.Dimension)2 Rectangle (java.awt.Rectangle)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 DataArray (org.knime.base.node.util.DataArray)2