use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.
the class ParallelAxis method createParallelAxis.
/**
* Factory method to get an instance of a <code>ParallelAxis</code>.
* Determines whether a
* {@link org.knime.base.node.viz.plotter.parcoord.NumericParallelAxis} or
* a {@link org.knime.base.node.viz.plotter.parcoord.NominalParallelAxis}
* should be returned, based on the passed
* {@link org.knime.core.data.DataColumnSpec}.
*
* @param colSpec the column spec for this parallel axis.
* @return either a nominal or a numeric parallel axis based on the column
* spec.
* @see Coordinate
*/
public static ParallelAxis createParallelAxis(final DataColumnSpec colSpec) {
Coordinate coordinate = Coordinate.createCoordinate(colSpec);
ParallelAxis axis;
if (coordinate instanceof NumericCoordinate) {
axis = new NumericParallelAxis();
} else {
axis = new NominalParallelAxis();
}
axis.setName(colSpec.getName());
axis.setCoordinate(coordinate);
return axis;
}
use of org.knime.base.util.coordinate.Coordinate 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();
}
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.
*
* @param dotsArray the array containing the dots.
*/
protected synchronized void calculateCoordinates(final DotInfoArray dotsArray) {
final DataProvider provider = getDataProvider();
if ((provider == null) || !isScatterPlotterDrawingPane()) {
// TODO: maybe return the calculated dot info array???
return;
}
if (dotsArray == null) {
return;
}
DotInfo[] dots = dotsArray.getDots();
if ((dots == null) || (dots.length == 0)) {
return;
}
DataArray data = getDataProvider().getDataArray(getDataArrayIdx());
// check whether there is a row container
if (data == null) {
return;
}
// get the coordinates from the headers
Coordinate xCoordinate = getXAxis().getCoordinate();
Coordinate yCoordinate = getYAxis().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 = data.getRow(rowId);
DataCell xCell = row.getCell(getSelectedXColumnIndex());
DataCell yCell = row.getCell(getSelectedYColumnIndex());
if (!xCell.isMissing() && !yCell.isMissing()) {
// temp variables for the coordinates
int x = getMappedXValue(xCell);
// need to be transformed to lower left origin later on
// (see below)
int y = getMappedYValue(yCell);
// 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 {
// here was the offset used
dots[i].setXCoord(x);
dots[i].setYCoord(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())) {
if (getProperties() instanceof ScatterPlotterProperties) {
getScatterPlotterProperties().getJitterSlider().setEnabled(true);
}
// the max dot size is subtracted as a dot can vary in size
int width = getDrawingPaneDimension().width - (2 * m_dotSize);
int height = getDrawingPaneDimension().height - (2 * m_dotSize);
// 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);
} else {
// bugfix 1253
if (getProperties() instanceof ScatterPlotterProperties) {
getScatterPlotterProperties().getJitterSlider().setEnabled(false);
}
}
getScatterPlotterDrawingPane().setDotInfoArray(new DotInfoArray(dots));
}
use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.
the class AbstractPlotter method createXCoordinate.
/**
* Recalculates the domain of the x 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 createXCoordinate(final int min, final int max) {
DataColumnDomainCreator xDomainCreator = new DataColumnDomainCreator();
int actualMin = min;
int actualMax = max;
if (getXAxis() != null && getXAxis().getCoordinate() != null && m_preserve) {
if (!(getXAxis().getCoordinate() instanceof NumericCoordinate)) {
return;
}
actualMin = (int) Math.min(min, ((NumericCoordinate) getXAxis().getCoordinate()).getMinDomainValue());
actualMax = (int) Math.max(max, ((NumericCoordinate) getXAxis().getCoordinate()).getMaxDomainValue());
}
xDomainCreator.setLowerBound(new IntCell(actualMin));
xDomainCreator.setUpperBound(new IntCell(actualMax));
DataColumnSpecCreator xSpecCreator = new DataColumnSpecCreator("X", IntCell.TYPE);
xSpecCreator.setDomain(xDomainCreator.createDomain());
Coordinate xCoordinate = Coordinate.createCoordinate(xSpecCreator.createSpec());
if (getXAxis() == null) {
Axis xAxis = new Axis(Axis.HORIZONTAL, getDrawingPaneDimension().width);
setXAxis(xAxis);
}
getXAxis().setCoordinate(xCoordinate);
}
use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.
the class BasicPlotter method isLogarithmic.
private boolean isLogarithmic(final Axis axis) {
Coordinate coordinate = axis.getCoordinate();
MappingMethod mapMethod = coordinate.getActiveMappingMethod();
if (mapMethod != null && mapMethod instanceof LogarithmicMappingMethod) {
return true;
}
return false;
}
Aggregations