use of org.knime.base.node.util.DataArray in project knime-core by knime.
the class HistogramNodeModel method createHistogramModel.
/**
* {@inheritDoc}
*/
@Override
protected void createHistogramModel(final ExecutionContext exec, final int noOfRows, final BufferedDataTable data) throws CanceledExecutionException {
LOGGER.debug("Entering createHistogramModel(exec, dataTable) " + "of class HistogramNodeModel.");
if (noOfRows == 0) {
m_model = null;
return;
}
if (exec == null) {
throw new NullPointerException("exec must not be null");
}
if (data == null) {
throw new IllegalArgumentException("Table shouldn't be null");
}
ExecutionMonitor subExec = exec.createSubProgress(0.5);
exec.setMessage("Adding rows to histogram model...");
final DataArray dataArray = new DefaultDataArray(data, 1, noOfRows, subExec);
exec.setMessage("Adding row color to histogram...");
final SortedSet<Color> colorSet = new TreeSet<Color>(HSBColorComparator.getInstance());
subExec = exec.createSubProgress(0.5);
final double progressPerRow = 1.0 / noOfRows;
double progress = 0.0;
final CloseableRowIterator rowIterator = data.iterator();
try {
for (int i = 0; i < noOfRows && rowIterator.hasNext(); i++) {
final DataRow row = rowIterator.next();
final Color color = data.getDataTableSpec().getRowColor(row).getColor(false, false);
if (!colorSet.contains(color)) {
colorSet.add(color);
}
progress += progressPerRow;
subExec.setProgress(progress, "Adding data rows to histogram...");
subExec.checkCanceled();
}
} finally {
if (rowIterator != null) {
rowIterator.close();
}
}
exec.setProgress(1.0, "Histogram finished.");
m_model = new InteractiveHistogramDataModel(dataArray, new ArrayList<Color>(colorSet));
LOGGER.debug("Exiting createHistogramModel(exec, dataTable) " + "of class HistogramNodeModel.");
}
use of org.knime.base.node.util.DataArray in project knime-core by knime.
the class ParallelCoordinatesPlotter method calculateLines.
/**
* Calculates the lines, containing the mapped data points.
*/
private synchronized List<LineInfo> calculateLines() {
if (getDataProvider() == null || getDataProvider().getDataArray(getDataArrayIdx()) == null || m_axes == null) {
return new ArrayList<LineInfo>();
}
DataArray array = getDataProvider().getDataArray(getDataArrayIdx());
// LOGGER.debug("calculate points: " + m_axes);
List<LineInfo> lines = new ArrayList<LineInfo>(array.size());
row: for (DataRow row : array) {
List<Point> points = new ArrayList<Point>();
List<DataCell> domainValues = new ArrayList<DataCell>();
for (ParallelAxis axis : m_axes) {
int colIdx = array.getDataTableSpec().findColumnIndex(axis.getName());
DataCell value = row.getCell(colIdx);
if (value.isMissing() && m_skipMissingValues) {
continue row;
}
domainValues.add(value);
int x = (int) getXAxis().getCoordinate().calculateMappedValue(new StringCell(axis.getName()), getDrawingPaneDimension().width);
int y = MISSING;
if (!value.isMissing()) {
y = getDrawingPaneDimension().height - ParallelCoordinateDrawingPane.BOTTOM_SPACE - (int) axis.getMappedValue(value);
}
Point p = new Point(x, y);
points.add(p);
}
boolean isHilite = delegateIsHiLit(row.getKey());
if (!m_hide || (m_hide && isHilite)) {
LineInfo line = new LineInfo(points, domainValues, m_selected.contains(row.getKey()), isHilite, array.getDataTableSpec().getRowColor(row), array.getDataTableSpec().getRowSizeFactor(row), row.getKey());
line.setShape(array.getDataTableSpec().getRowShape(row));
lines.add(line);
}
}
return lines;
}
use of org.knime.base.node.util.DataArray in project knime-core by knime.
the class ScatterPlotter method updatePaintModel.
/**
* The data points of the data to visulaize are mapped to screen
* coordinates, represented by
* {@link org.knime.base.node.viz.plotter.scatter.DotInfo} and are passed in
* a {@link org.knime.base.node.viz.plotter.scatter.DotInfoArray} to the
* {@link org.knime.base.node.viz.plotter.scatter
* .ScatterPlotterDrawingPane}. Repaint of the drawing pane is triggered.
* Jittering is also triggered from here.
*
* @see org.knime.base.node.viz.plotter.columns.TwoColumnPlotter
* #updatePaintModel()
*/
@Override
public void updatePaintModel() {
if (getDataProvider() == null || getDataProvider().getDataArray(getDataArrayIdx()) == null) {
return;
}
if (getSelectedXColumnIndex() == -1 || getSelectedYColumnIndex() == -1) {
return;
}
// check if the selected column indices are available
int xIdx = getSelectedXColumnIndex();
int yIdx = getSelectedYColumnIndex();
int numCols = getDataProvider().getDataArray(getDataArrayIdx()).getDataTableSpec().getNumColumns();
if (xIdx >= numCols || yIdx >= numCols) {
return;
}
// getScatterPlotterDrawingPane().clearSelection();
// get the rowInfo from the model
DataArray rowsCont = getDataProvider().getDataArray(getDataArrayIdx());
if (rowsCont != null) {
// LOGGER.debug("row container != null");
// and create a new DotInfo array with the rowKeys in the DotInfos.
List<DotInfo> dotList = new ArrayList<DotInfo>();
int rowNr = 0;
for (DataRow row : rowsCont) {
double size = rowsCont.getDataTableSpec().getRowSizeFactor(row);
ColorAttr colorAttr = rowsCont.getDataTableSpec().getRowColor(row);
boolean isHilite = delegateIsHiLit(row.getKey());
if ((isHilite && m_hide) || !m_hide) {
if (m_hide) {
isHilite = false;
}
DotInfo dot = new DotInfo(0, 0, row.getKey(), isHilite, colorAttr, size, rowNr);
dot.setShape(rowsCont.getDataTableSpec().getRowShape(row));
DataCell xDomain = row.getCell(getSelectedXColumnIndex());
dot.setXDomainValue(xDomain);
DataCell yDomain = row.getCell(getSelectedYColumnIndex());
dot.setYDomainValue(yDomain);
dotList.add(dot);
}
rowNr++;
}
DotInfo[] dotArray = new DotInfo[dotList.size()];
dotList.toArray(dotArray);
// now create a new DotInfoArray
DotInfoArray newDotArray = new DotInfoArray(dotArray);
// store it in the drawing pane
if (isScatterPlotterDrawingPane()) {
getScatterPlotterDrawingPane().setDotInfoArray(newDotArray);
}
// and get the coordinates calculated.
calculateCoordinates(newDotArray);
}
getDrawingPane().repaint();
}
use of org.knime.base.node.util.DataArray 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.node.util.DataArray in project knime-core by knime.
the class SotaNodeModel method loadInternals.
/**
* {@inheritDoc}
*/
@Override
protected void loadInternals(final File internDir, final ExecutionMonitor exec) throws IOException {
File file = new File(internDir, TREE_FILE);
FileInputStream fis = new FileInputStream(file);
ModelContentRO modelContent = ModelContent.loadFromXML(fis);
// Load settings
int inDataSize = 0;
int origDataSize = 0;
try {
m_sota.setUseHierarchicalFuzzyData(modelContent.getBoolean(SotaPortObject.CFG_KEY_USE_FUZZY_HIERARCHY));
m_sota.setMaxHierarchicalLevel(modelContent.getInt(SotaPortObject.CFG_KEY_MAX_FUZZY_LEVEL));
inDataSize = modelContent.getInt(SotaPortObject.CFG_KEY_INDATA_SIZE);
origDataSize = modelContent.getInt(SotaPortObject.CFG_KEY_ORIGDATA_SIZE);
} catch (InvalidSettingsException e1) {
IOException ioe = new IOException("Could not load settings," + "due to invalid settings in model content !");
ioe.initCause(e1);
fis.close();
throw ioe;
}
// Load in data
DataTable table = DataContainer.readFromZip(new File(internDir, IN_DATA_FILE));
final DataArray inData = new DefaultDataArray(table, 1, inDataSize);
m_sota.setInData(inData);
// Load orig data
table = DataContainer.readFromZip(new File(internDir, ORIG_DATA_FILE));
final DataArray origData = new DefaultDataArray(table, 1, origDataSize);
m_sota.setOriginalData(origData);
// Load tree
SotaTreeCell root = new SotaTreeCell(0, false);
try {
root.loadFrom(modelContent, 0, null, false);
} catch (InvalidSettingsException e) {
IOException ioe = new IOException("Could not load tree cells," + "due to invalid settings in model content !");
ioe.initCause(e);
fis.close();
throw ioe;
}
m_sota.setRoot(root);
fis.close();
}
Aggregations