use of org.knime.base.node.viz.plotter.scatter.DotInfo in project knime-core by knime.
the class ScatterMatrixDrawingPane method setScatterMatrixElements.
/**
* @param elements the rectangles with the coordinates.
*/
public void setScatterMatrixElements(final ScatterMatrixElement[][] elements) {
m_matrixElements = elements;
if (elements != null) {
List<DotInfo> dotList = new ArrayList<DotInfo>();
for (int i = 0; i < m_matrixElements.length; i++) {
for (int j = 0; j < m_matrixElements[i].length; j++) {
// the array is initialized with column length
if (m_matrixElements[i][j] == null) {
continue;
}
dotList.addAll(m_matrixElements[i][j].getDots());
}
}
DotInfo[] dots = new DotInfo[dotList.size()];
dotList.toArray(dots);
setDotInfoArray(new DotInfoArray(dots));
// repaint();
}
}
use of org.knime.base.node.viz.plotter.scatter.DotInfo 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.node.viz.plotter.scatter.DotInfo in project knime-core by knime.
the class LinePlotter method interpolate.
/**
* The nr of intermediate points and the last row index is used to determine
* the x value (only the y value is interpolated).
*
* @param p1
* the domain value 1
* @param p2
* the domain value 2
* @param xValues
* an array containing opoints with the right x value but missing
* y value.
* @return the interpolated domain values.
*/
public DotInfo[] interpolate(final Point p1, final Point p2, final List<DotInfo> xValues) {
DotInfo[] interpolated = new DotInfo[xValues.size()];
if (p1 == null || p2 == null || p1.getY() < 0 || p2.getY() < 0) {
// -> don't interpolate but replace with not visible points
for (int i = 0; i < xValues.size(); i++) {
// don't interpolate if one of the points is invalid
DotInfo newDot = xValues.get(i);
newDot.setYCoord(-1);
interpolated[i] = newDot;
}
return interpolated;
}
// both points are valid -> interpolate
for (int i = 0; i < xValues.size(); i++) {
int x = xValues.get(i).getXCoord();
double m = 0;
if (!p1.equals(p2)) {
m = ((p2.getY() - p1.getY()) / (p2.getX() - p1.getX()));
}
double y = (m * x) - (m * p1.getX()) + p1.getY();
DotInfo newDot = xValues.get(i);
newDot.setYCoord((int) getScreenYCoordinate(y));
interpolated[i] = newDot;
x++;
}
return interpolated;
}
use of org.knime.base.node.viz.plotter.scatter.DotInfo in project knime-core by knime.
the class LinePlotterDrawingPane method paintContent.
/**
* Connects the points of one column by a line, which is done by modulo
* calculation, the color information is stored in the
* {@link org.knime.base.node.viz.plotter.scatter.DotInfo}s.
*
* @see org.knime.base.node.viz.plotter.scatter.ScatterPlotterDrawingPane
* #paintContent(java.awt.Graphics)
*/
@Override
public void paintContent(final Graphics g) {
if (getDotInfoArray() == null || getDotInfoArray().getDots().length == 0) {
return;
}
ShapeFactory.Shape shape = ShapeFactory.getShape(ShapeFactory.RECTANGLE);
int dotSize = getDotSize();
DotInfo[] dotInfo = getDotInfoArray().getDots();
GeneralPath path = new GeneralPath();
for (int i = 0; i < dotInfo.length; i++) {
DotInfo dot1 = dotInfo[i];
if (m_showDots && dot1.paintDot()) {
boolean isSelected = getSelectedDots().contains(dotInfo[i].getRowID());
boolean isHilite = dotInfo[i].isHiLit();
Color c = dotInfo[i].getColor().getColor();
int x = dotInfo[i].getXCoord();
int y = dotInfo[i].getYCoord();
shape.paint(g, x, y, dotSize, c, isHilite, isSelected, false);
}
if (i % m_nrOfLines == 0 && path != null) {
// start of one line
path.reset();
// move to start point
path.moveTo(dot1.getXCoord(), dot1.getYCoord());
}
if (dot1.paintDot()) {
// if we had a missing value and !interpolate
if (path == null) {
path = new GeneralPath();
path.moveTo(dot1.getXCoord(), dot1.getYCoord());
} else {
// add line segment to path
path.lineTo(dot1.getXCoord(), dot1.getYCoord());
}
} else if (path != null) {
// if not paint dot (y = -1) => missing value && !interpolate
// we have to close the path and continue a new one
g.setColor(dot1.getColor().getColor());
((Graphics2D) g).setStroke(new BasicStroke(m_thickness));
((Graphics2D) g).draw(path);
path = null;
}
if (i % m_nrOfLines == (m_nrOfLines - 1) && path != null) {
// end of one line -> paint it
g.setColor(dot1.getColor().getColor());
((Graphics2D) g).setStroke(new BasicStroke(m_thickness));
((Graphics2D) g).draw(path);
}
}
}
Aggregations