use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.
the class ScatterMatrixPlotter method updatePaintModel.
/**
* Creates the nominal coordinates with the selected column names,
* calculates the surrounding rectangle for the scatter matrix elements,
* then maps the points to the screen coordinates, associates the
* {@link org.knime.base.node.viz.plotter.scatter.DotInfo}s with the
* referring
* {@link
* org.knime.base.node.viz.plotter.scattermatrix.ScatterMatrixElement}
* and passes them to the
* {@link
* org.knime.base.node.viz.plotter.scattermatrix.ScatterMatrixDrawingPane}.
* The {@link
* org.knime.base.node.viz.plotter.scattermatrix.ScatterMatrixDrawingPane}
* then extracts the dots from the
*{@link org.knime.base.node.viz.plotter.scattermatrix.ScatterMatrixElement}
* and stores them in a
* {@link org.knime.base.node.viz.plotter.scatter.DotInfoArray}.
*
* @see org.knime.base.node.viz.plotter.AbstractPlotter#updatePaintModel()
*/
@Override
public synchronized void updatePaintModel() {
// clear the drawing pane
((ScatterMatrixDrawingPane) getDrawingPane()).setDotInfoArray(null);
((ScatterMatrixDrawingPane) getDrawingPane()).setScatterMatrixElements(null);
// get the number of columns c
if (getDataProvider() == null || getDataProvider().getDataArray(getDataArrayIdx()) == null) {
return;
}
DataArray data = getDataProvider().getDataArray(getDataArrayIdx());
// get the first columns
if (m_selectedColumns == null) {
m_selectedColumns = new LinkedHashSet<String>();
for (int i = 0; i < DEFAULT_NR_COLS && i < data.getDataTableSpec().getNumColumns(); i++) {
// add them to selected columns
String colName = data.getDataTableSpec().getColumnSpec(i).getName();
m_selectedColumns.add(colName);
}
if (data.getDataTableSpec().getNumColumns() > DEFAULT_NR_COLS) {
getProperties().setSelectedIndex(MultiColumnPlotterProperties.COLUMN_FILTER_IDX);
}
((ScatterMatrixProperties) getProperties()).updateColumnSelection(data.getDataTableSpec(), 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 = data.getDataTableSpec().findColumnIndex(name);
if (idx >= 0) {
selectedColumnCells.add(new StringCell(name));
DataColumnSpec colSpec = data.getDataTableSpec().getColumnSpec(idx);
columnIndices.add(idx);
Coordinate coordinate = Coordinate.createCoordinate(colSpec);
m_coordinates.add(coordinate);
}
}
// create coordinates with the column names
createNominalXCoordinate(selectedColumnCells);
// reverse list for y axis...
List<DataCell> reverseList = new ArrayList<DataCell>(selectedColumnCells);
Collections.reverse(reverseList);
createNominalYCoordinate(new LinkedHashSet<DataCell>(reverseList));
m_hMargin = (int) (getDrawingPaneDimension().height * H_MARGIN_FACTOR);
m_vMargin = (int) (getDrawingPaneDimension().width * V_MARGIN_FACTOR);
((ScatterMatrixDrawingPane) getDrawingPane()).setHorizontalMargin(m_hMargin);
((ScatterMatrixDrawingPane) getDrawingPane()).setVerticalMargin(m_vMargin);
// set the offset for the column axes
getXAxis().setStartTickOffset(m_vMargin);
getYAxis().setStartTickOffset(m_hMargin);
int nrOfColumns = selectedColumnCells.size();
// and update the properties
int width = (getDrawingPaneDimension().width - (nrOfColumns * GAP) - (2 * m_vMargin)) / nrOfColumns;
m_matrixElementWidth = width;
int height = (getDrawingPaneDimension().height - (nrOfColumns * GAP) - (2 * m_hMargin)) / nrOfColumns;
int rowNr = 0;
ScatterMatrixElement[][] matrixElements = new ScatterMatrixElement[nrOfColumns][nrOfColumns];
for (DataRow row : data) {
for (int i = 0; i < nrOfColumns; i++) {
for (int j = 0; j < nrOfColumns; j++) {
Coordinate xCoordinate = m_coordinates.get(i);
Coordinate yCoordinate = m_coordinates.get(j);
DataCell xValue = row.getCell(columnIndices.get(i));
DataCell yValue = row.getCell(columnIndices.get(j));
int x = -1;
int y = -1;
int xOffset = (i * (width + GAP)) + m_vMargin;
int yOffset = (j * (height + GAP)) + m_hMargin;
ScatterMatrixElement matrixElement = matrixElements[i][j];
if (matrixElement == null) {
matrixElement = new ScatterMatrixElement(new Point(xOffset, yOffset), width, height, xCoordinate, yCoordinate);
matrixElements[i][j] = matrixElement;
}
if (!xValue.isMissing()) {
x = (int) xCoordinate.calculateMappedValue(xValue, width - (2 * getDotSize()), true);
// offset
x += xOffset + getDotSize();
}
if (!yValue.isMissing()) {
y = (int) (height - yCoordinate.calculateMappedValue(yValue, height - (2 * getDotSize()), true));
// v offset
y += yOffset - getDotSize();
}
boolean hilite = delegateIsHiLit(row.getKey());
if (!hilite && isHideMode()) {
continue;
}
if (isHideMode() && hilite) {
hilite = false;
}
DotInfo dot = new DotInfo(x, y, row.getKey(), hilite, data.getDataTableSpec().getRowColor(row), data.getDataTableSpec().getRowSizeFactor(row), rowNr);
dot.setShape(data.getDataTableSpec().getRowShape(row));
dot.setXDomainValue(xValue);
dot.setYDomainValue(yValue);
matrixElement.addDot(dot);
// dotList.add(dot);
}
// j
}
// i
rowNr++;
}
// rows
// jitter
jitter(matrixElements);
((ScatterMatrixDrawingPane) getDrawingPane()).setScatterMatrixElements(matrixElements);
getDrawingPane().repaint();
}
use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.
the class ScatterMatrixPlotter method jitter.
private void jitter(final ScatterMatrixElement[][] matrixElements) {
for (int i = 0; i < matrixElements.length; i++) {
for (int j = 0; j < matrixElements[i].length; j++) {
ScatterMatrixElement element = matrixElements[i][j];
// the array is initialized with column length
if (element == null) {
continue;
}
Coordinate xCoordinate = element.getXCoordinate();
Coordinate yCoordinate = element.getYCoordinate();
if ((xCoordinate.isNominal() || yCoordinate.isNominal())) {
// for jittering only 90% of the available space are used
// to avoid that the dots of different nominal values
// touches each other
int width = element.getWidth();
int height = element.getHeight();
List<DotInfo> dotList = element.getDots();
DotInfo[] dots = new DotInfo[dotList.size()];
dotList.toArray(dots);
int xAxisJitterRange = (int) (Math.round(xCoordinate.getUnusedDistBetweenTicks(width)) * 0.9);
int yAxisJitterRange = (int) (Math.round(yCoordinate.getUnusedDistBetweenTicks(height)) * 0.9);
jitterDots(dots, xAxisJitterRange, yAxisJitterRange);
matrixElements[i][j].setDots(Arrays.asList(dots));
}
}
}
}
use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.
the class AbstractPlotter method createNominalYCoordinate.
/**
* Creates a nominal y axis.
*
* @param values the possible values.
*/
public void createNominalYCoordinate(final Set<DataCell> values) {
DataColumnDomainCreator domainCreator = new DataColumnDomainCreator();
domainCreator.setValues(values);
DataColumnSpecCreator specCreator = new DataColumnSpecCreator("X", StringCell.TYPE);
specCreator.setDomain(domainCreator.createDomain());
Coordinate nominalCoordinate = Coordinate.createCoordinate(specCreator.createSpec());
if (getYAxis() == null) {
Axis yAxis = new Axis(Axis.VERTICAL, getDrawingPaneDimension().width);
setYAxis(yAxis);
}
getYAxis().setCoordinate(nominalCoordinate);
}
use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.
the class AbstractPlotter method createNominalXCoordinate.
/**
* Creates a nominal x axis.
*
* @param values the possible values.
*/
public void createNominalXCoordinate(final Set<DataCell> values) {
DataColumnDomainCreator domainCreator = new DataColumnDomainCreator();
domainCreator.setValues(values);
DataColumnSpecCreator specCreator = new DataColumnSpecCreator("X", StringCell.TYPE);
specCreator.setDomain(domainCreator.createDomain());
Coordinate nominalCoordinate = Coordinate.createCoordinate(specCreator.createSpec());
if (getXAxis() == null) {
Axis xAxis = new Axis(Axis.HORIZONTAL, getDrawingPaneDimension().width);
setXAxis(xAxis);
}
getXAxis().setCoordinate(nominalCoordinate);
}
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 double min, final double max) {
DataColumnDomainCreator xDomainCreator = new DataColumnDomainCreator();
double actualMin = min;
double actualMax = max;
if (getXAxis() != null && getXAxis().getCoordinate() != null && m_preserve) {
if (!(getXAxis().getCoordinate() instanceof NumericCoordinate)) {
return;
}
actualMin = Math.min(min, ((NumericCoordinate) getXAxis().getCoordinate()).getMinDomainValue());
actualMax = Math.max(max, ((NumericCoordinate) getXAxis().getCoordinate()).getMaxDomainValue());
}
xDomainCreator.setLowerBound(new DoubleCell(actualMin));
xDomainCreator.setUpperBound(new DoubleCell(actualMax));
DataColumnSpecCreator xSpecCreator = new DataColumnSpecCreator("X", DoubleCell.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);
}
Aggregations