use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class NumericCoordinate method getMaxDomainValue.
/**
* @return Returns the maxDomainValue.
*/
public final double getMaxDomainValue() {
DataCell cell = new DoubleCell(m_maxDomainValue);
cell = applyMappingMethod(cell);
return ((DoubleValue) cell).getDoubleValue();
}
use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class NumericCoordinate method getMinDomainValue.
/**
* @return Returns the minDomainValue.
*/
public final double getMinDomainValue() {
DataCell cell = new DoubleCell(m_minDomainValue);
cell = applyMappingMethod(cell);
return ((DoubleValue) cell).getDoubleValue();
}
use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class NumericCoordinate method getTickPositionsWithLabels.
/**
* Returns an array with the positions of all ticks and their corresponding
* domain values given an absolute length. The pre-specified tick policy
* also influences the tick positions, e.g. ascending or descending.
*
* @param absolutLength the absolute length the domain is mapped on
*
* @return the mapping of tick positions and corresponding domain values
*/
@Override
protected CoordinateMapping[] getTickPositionsWithLabels(final double absolutLength) {
CoordinateMapping[] coordMap = getTickPositionsInternal(absolutLength);
if (coordMap == null || coordMap.length < 1 || getActiveMappingMethod() == null || getCurrentPolicy() == null || !getCurrentPolicy().isMappingAllowed()) {
return coordMap;
}
CoordinateMapping[] result = new CoordinateMapping[coordMap.length];
int index = 0;
for (CoordinateMapping cm : coordMap) {
// each numeric coordinate must have exactly one value per tick
// and each tick a numeric value ( = DoubleValue ) set.
DoubleValue value = (DoubleValue) cm.getValues()[0];
double val = getActiveMappingMethod().getLabel(new DoubleCell(value.getDoubleValue()));
result[index++] = new DoubleCoordinateMapping("" + val, val, cm.getMappingValue());
}
return result;
}
use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class BasicPlotter method addLine.
/**
* Plots the column in the table specified by the column index as a
* line plot.
*
* @param table the table containing the data to be plotted.
* @param xIdx - the x column index specifying the data to be plotted.
* @param yIdx - the x column index specifying the data to be plotted.
* @param color the color of the line (may be null)
* @param stroke the stroke of the line (may be null)
*/
public void addLine(final DataArray table, final int xIdx, final int yIdx, final Color color, final Stroke stroke) {
if (!(getDrawingPane() instanceof BasicDrawingPane)) {
return;
}
if (!table.getDataTableSpec().getColumnSpec(yIdx).getType().isCompatible(DoubleValue.class)) {
return;
}
// if (!checkCompatibleAxis()) {
// return;
// }
// x axis
DataColumnSpec xColSpec = table.getDataTableSpec().getColumnSpec(xIdx);
if (xColSpec.getType().isCompatible(NominalValue.class)) {
Set<DataCell> rowKeys = new LinkedHashSet<DataCell>();
for (int i = 0; i < table.size(); i++) {
rowKeys.add(new StringCell(table.getRow(i).getKey().getString()));
}
createNominalXCoordinate(rowKeys);
} else if (xColSpec.getType().isCompatible(DoubleValue.class)) {
double newXMin = ((DoubleValue) xColSpec.getDomain().getLowerBound()).getDoubleValue();
double newXMax = ((DoubleValue) xColSpec.getDomain().getUpperBound()).getDoubleValue();
createXCoordinate(newXMin, newXMax);
} else {
return;
}
double newYMin = ((DoubleValue) table.getDataTableSpec().getColumnSpec(yIdx).getDomain().getLowerBound()).getDoubleValue();
double newYMax = ((DoubleValue) table.getDataTableSpec().getColumnSpec(yIdx).getDomain().getUpperBound()).getDoubleValue();
createYCoordinate(newYMin, newYMax);
BasicLine line = new BasicLine();
if (color != null) {
line.setColor(color);
}
if (stroke != null) {
line.setStroke(stroke);
}
// int x = 0;
for (DataRow row : table) {
DataCell value = row.getCell(yIdx);
if (!value.isMissing()) {
int mappedX = getMappedXValue(row.getCell(xIdx));
int mappedY = getMappedYValue(value);
DataCellPoint domainPoint = new DataCellPoint(row.getCell(xIdx), value);
line.addDomainValue(domainPoint);
Point p = new Point(mappedX, mappedY);
line.addPoint(p);
} else {
// if value.isMissing() -> create newLine
((BasicDrawingPane) getDrawingPane()).addDrawingElement(line);
line = new BasicLine();
line.setColor(color);
line.setStroke(stroke);
}
// x++;
}
((BasicDrawingPane) getDrawingPane()).addDrawingElement(line);
fitToScreen();
}
use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class BasicPlotter method addBasicDrawingElement.
/**
* Adds a drawing element to the drawing pane. The mapping of the domain
* values to the screen coordinates is done here
* Only numeric values are supported. All the rest like color
* and stroke setting has to be done outside.
* @param element a drawing element.
*/
public void addBasicDrawingElement(final BasicDrawingElement element) {
if (!(getDrawingPane() instanceof BasicDrawingPane)) {
return;
}
double minX = Integer.MAX_VALUE;
double maxX = Integer.MIN_VALUE;
double minY = Integer.MAX_VALUE;
double maxY = Integer.MIN_VALUE;
for (DataCellPoint p : element.getDomainValues()) {
// determine the min and max values for the coordinates
if (!p.getX().getType().isCompatible(DoubleValue.class) || !p.getY().getType().isCompatible(DoubleValue.class)) {
LOGGER.warn("a basic drawing element can onyl be defined for " + "numeric values!");
return;
}
double x = ((DoubleValue) p.getX()).getDoubleValue();
double y = ((DoubleValue) p.getY()).getDoubleValue();
minX = Math.min(x, minX);
maxX = Math.max(x, maxX);
minY = Math.min(y, minY);
maxY = Math.max(y, maxY);
}
createXCoordinate(minX, maxX);
createYCoordinate(minY, maxY);
// calculate the mapped values
List<Point> newPoints = new LinkedList<Point>();
for (DataCellPoint p : element.getDomainValues()) {
double mappedX = getXAxis().getCoordinate().calculateMappedValue(p.getX(), getDrawingPaneDimension().width);
double mappedY = getYAxis().getCoordinate().calculateMappedValue(p.getY(), getDrawingPaneDimension().height);
newPoints.add(new Point((int) mappedX, (int) getScreenYCoordinate(mappedY)));
}
element.setPoints(newPoints);
((BasicDrawingPane) getDrawingPane()).addDrawingElement(element);
}
Aggregations