Search in sources :

Example 6 with Coordinate

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

the class AbstractPlotter method createYCoordinate.

/**
 * Recalculates the domain of the y axis. If preserve is set to false the
 * passed values are taken as min and max no matter was was set before. If
 * preserve is set to true (default) the possibly already available min and
 * max values are preserved.
 *
 * @param min the min value
 * @param max the max value {@link AbstractPlotter#setPreserve(boolean)}
 */
public void createYCoordinate(final double min, final double max) {
    DataColumnDomainCreator yDomainCreator = new DataColumnDomainCreator();
    double actualMin = min;
    double actualMax = max;
    if (getYAxis() != null && getYAxis().getCoordinate() != null && m_preserve) {
        if (!(getYAxis().getCoordinate() instanceof NumericCoordinate)) {
            return;
        }
        actualMin = Math.min(min, ((NumericCoordinate) getYAxis().getCoordinate()).getMinDomainValue());
        actualMax = Math.max(max, ((NumericCoordinate) getYAxis().getCoordinate()).getMaxDomainValue());
    }
    yDomainCreator.setLowerBound(new DoubleCell(actualMin));
    yDomainCreator.setUpperBound(new DoubleCell(actualMax));
    DataColumnSpecCreator ySpecCreator = new DataColumnSpecCreator("Y", DoubleCell.TYPE);
    ySpecCreator.setDomain(yDomainCreator.createDomain());
    Coordinate yCoordinate = Coordinate.createCoordinate(ySpecCreator.createSpec());
    if (getYAxis() == null) {
        Axis yAxis = new Axis(Axis.VERTICAL, getDrawingPaneDimension().height);
        setYAxis(yAxis);
    }
    getYAxis().setCoordinate(yCoordinate);
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) 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) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator)

Example 7 with Coordinate

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

the class BinModelPlotter method updatePaintModel.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void updatePaintModel() {
    if (m_discretizationModel == null) {
        return;
    }
    // clear the drawing pane
    ((BinModelDrawingPane) getDrawingPane()).setBinningSchemes(null);
    // get the first columns
    if (m_selectedColumns == null) {
        m_selectedColumns = new LinkedHashSet<String>();
        String[] binnedColumnNames = m_discretizationModel.getIncludedColumnNames();
        for (int i = 0; i < binnedColumnNames.length; i++) {
            // add them to the selected columns
            m_selectedColumns.add(binnedColumnNames[i]);
        }
        ((MultiColumnPlotterProperties) getProperties()).updateColumnSelection(m_binnedColumnsSpec, 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 = m_binnedColumnsSpec.findColumnIndex(name);
        if (idx >= 0) {
            selectedColumnCells.add(new StringCell(name));
            DataColumnSpec colSpec = m_binnedColumnsSpec.getColumnSpec(idx);
            columnIndices.add(idx);
            Coordinate coordinate = Coordinate.createCoordinate(colSpec);
            m_coordinates.add(coordinate);
        }
    }
    // get the binning schemes for the selected columns
    DiscretizationScheme[] selectedSchemes = getSelectedSchemes();
    String[] selectedColumnNames = getSelectedColumnNames();
    // calculate the display coordinates for the drawing pane
    BinRuler[] binRulers = new BinRuler[selectedSchemes.length];
    // determine the width available for a bin ruler
    int rulerWidth = getDrawingPaneDimension().width - 2 * m_hMargin;
    for (int i = 0; i < selectedSchemes.length; i++) {
        double[] bounds = selectedSchemes[i].getBounds();
        double min = bounds[0];
        double max = bounds[bounds.length - 1];
        // first create a colum spec from the schemes
        DataColumnSpecCreator columnSpecCreator = new DataColumnSpecCreator("", DoubleCell.TYPE);
        columnSpecCreator.setDomain(new DataColumnDomainCreator(new DoubleCell(min), new DoubleCell(max)).createDomain());
        DoubleCoordinate coordinate = (DoubleCoordinate) Coordinate.createCoordinate(columnSpecCreator.createSpec());
        Point leftStart = new Point(m_hMargin, m_vMargin + (i + 1) * m_columnDisplayHeight);
        int[] binPositions = new int[bounds.length];
        String[] binLabels = new String[bounds.length];
        int count = 0;
        for (double bound : bounds) {
            binPositions[count] = (int) coordinate.calculateMappedValue(new DoubleCell(bound), rulerWidth, true);
            binLabels[count] = coordinate.formatNumber(bounds[count]);
            count++;
        }
        binRulers[i] = new BinRuler(leftStart, rulerWidth, binPositions, binLabels, selectedColumnNames[i]);
    }
    ((BinModelDrawingPane) getDrawingPane()).setBinningSchemes(binRulers);
    m_hMargin = 10;
    m_vMargin = 10;
    ((BinModelDrawingPane) getDrawingPane()).setHorizontalMargin(m_hMargin);
    setHeight(binRulers[binRulers.length - 1].getLeftStartPoint().y + 40);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DoubleCell(org.knime.core.data.def.DoubleCell) DiscretizationScheme(org.knime.base.node.preproc.discretization.caim2.DiscretizationScheme) ArrayList(java.util.ArrayList) DoubleCoordinate(org.knime.base.util.coordinate.DoubleCoordinate) DataColumnSpec(org.knime.core.data.DataColumnSpec) MultiColumnPlotterProperties(org.knime.base.node.viz.plotter.columns.MultiColumnPlotterProperties) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) Point(java.awt.Point) Point(java.awt.Point) DoubleCoordinate(org.knime.base.util.coordinate.DoubleCoordinate) Coordinate(org.knime.base.util.coordinate.Coordinate) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell)

Example 8 with Coordinate

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

the class AbstractHistogramPlotter method setXCoordinates.

/**
 * Sets the x coordinates for the current
 * {@link AbstractHistogramVizModel}.
 */
protected void setXCoordinates() {
    final DataColumnSpec colSpec = getXColumnSpec();
    // tell the headers to display the new column names
    final Coordinate xCoordinate = Coordinate.createCoordinate(colSpec);
    if (xCoordinate == null) {
        throw new IllegalStateException("Internal exception: " + " Unable to create x coordinates");
    }
    if (getXAxis() == null) {
        final Axis xAxis = new Axis(Axis.HORIZONTAL, getDrawingPaneDimension().width);
        setXAxis(xAxis);
    }
    getXAxis().setCoordinate(xCoordinate);
    getXAxis().setToolTipText(colSpec.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)

Example 9 with Coordinate

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

the class AbstractHistogramPlotter method updateBinWidth.

/**
 * Updates ONLY the width of the bins.
 * @param binWidth the new bin width
 */
protected void updateBinWidth(final int binWidth) {
    final AbstractHistogramVizModel vizModel = getHistogramVizModel();
    if (vizModel == null) {
        LOGGER.debug("VizModel was null");
        return;
    }
    if (!vizModel.setBinWidth(binWidth)) {
        return;
    }
    final Dimension drawingSpace = vizModel.getDrawingSpace();
    if (drawingSpace == null) {
        throw new IllegalStateException("Drawing space must not be null");
    }
    final double drawingWidth = drawingSpace.getWidth();
    final double drawingHeight = drawingSpace.getHeight();
    final Coordinate xCoordinates = getXCoordinate();
    final Coordinate aggrCoordinate = getAggregationCoordinate();
    final int baseLine = (int) (drawingHeight - aggrCoordinate.calculateMappedValue(new DoubleCell(0), drawingHeight));
    final HistogramDrawingPane drawingPane = getHistogramDrawingPane();
    final int newBinWidth = vizModel.getBinWidth();
    final List<Color> barElementColors = vizModel.getRowColors();
    final HistogramHiliteCalculator calculator = vizModel.getHiliteCalculator();
    final Collection<ColorColumn> aggrColumns = vizModel.getAggrColumns();
    for (final BinDataModel bin : vizModel.getBins()) {
        final DataCell captionCell = bin.getXAxisCaptionCell();
        final double labelCoord = xCoordinates.calculateMappedValue(captionCell, drawingWidth);
        // subtract half of the bar width from the start position to place
        // the middle point of the bar on the mapped coordinate position
        final int xCoord = (int) (labelCoord - (newBinWidth / 2.0));
        bin.updateBinWidth(xCoord, newBinWidth, barElementColors, aggrColumns, baseLine, calculator);
    }
    // if only the bar width changes we don't need to update the properties
    // since the bar width change is triggered by the property component
    // itself
    drawingPane.setHistogramVizModel(vizModel, false);
}
Also used : AbstractHistogramVizModel(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel) DoubleCell(org.knime.core.data.def.DoubleCell) Color(java.awt.Color) ColorColumn(org.knime.base.node.viz.histogram.util.ColorColumn) BinDataModel(org.knime.base.node.viz.histogram.datamodel.BinDataModel) Dimension(java.awt.Dimension) Point(java.awt.Point) HistogramHiliteCalculator(org.knime.base.node.viz.histogram.datamodel.AbstractHistogramVizModel.HistogramHiliteCalculator) Coordinate(org.knime.base.util.coordinate.Coordinate) NumericCoordinate(org.knime.base.util.coordinate.NumericCoordinate) DataCell(org.knime.core.data.DataCell)

Example 10 with Coordinate

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

the class AbstractHistogramPlotter method getAggregationCoordinate.

/**
 * @return the {@link Coordinate} of the aggregation axis.
 */
private Coordinate getAggregationCoordinate() {
    final Axis aggrAxis = getYAxis();
    if (aggrAxis == null) {
        throw new IllegalStateException("Aggregation axis must not be null");
    }
    final Coordinate aggrCoordinate = aggrAxis.getCoordinate();
    if (aggrCoordinate == null) {
        throw new IllegalStateException("Aggregation coordinate must not be null");
    }
    return aggrCoordinate;
}
Also used : 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