use of org.knime.core.data.property.ColorAttr 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.core.data.property.ColorAttr in project knime-core by knime.
the class ColorManager2DialogNominal method loadSettings.
/**
* Reads the color settings for the given column.
*
* @param settings to read from
* @param column the selected column
*/
void loadSettings(final NodeSettingsRO settings, final String column) {
if (column == null) {
return;
}
DataCell[] vals = settings.getDataCellArray(ColorManager2NodeModel.VALUES, (DataCell[]) null);
if (vals == null) {
return;
}
Map<DataCell, ColorAttr> map = m_map.get(column);
if (map == null) {
return;
}
for (int i = 0; i < vals.length; i++) {
if (map.containsKey(vals[i])) {
Color dftColor = map.get(vals[i]).getColor();
int c = settings.getInt(vals[i].toString(), dftColor.getRGB());
Color color = new Color(c, true);
m_alpha = color.getAlpha();
color = new Color(color.getRGB(), false);
map.put(vals[i], ColorAttr.getInstance(color));
}
}
}
use of org.knime.core.data.property.ColorAttr in project knime-core by knime.
the class LinePlotter method calculateDots.
/**
* Calculates the screen coordinates (dots) for the lines and puts them in a
* large {@link org.knime.base.node.viz.plotter.scatter.DotInfoArray}, which
* is passed to the
* {@link org.knime.base.node.viz.plotter.line.LinePlotterDrawingPane}.
*/
protected void calculateDots() {
if (!(getDrawingPane() instanceof ScatterPlotterDrawingPane)) {
return;
}
if (m_columnNames == null) {
return;
}
if (getDataProvider() != null && getDataProvider().getDataArray(getDataArrayIdx()) != null) {
DataArray array = getDataProvider().getDataArray(getDataArrayIdx());
int nrOfRows = array.size();
// set the empty dots to delete the old ones
// if we have no columns to display
((ScatterPlotterDrawingPane) getDrawingPane()).setDotInfoArray(new DotInfoArray(new DotInfo[0]));
// first store them in a list to avoid keep tracking of indices
List<DotInfo> dotList = new ArrayList<DotInfo>();
for (String col : m_columnNames) {
int colIdx = array.getDataTableSpec().findColumnIndex(col);
Color c = m_colorMapping.get(col);
if (c == null) {
c = Color.black;
}
ColorAttr color = ColorAttr.getInstance(c);
// store the last point with valid value for interpolation
Point p1 = new Point(-1, -1);
Point p2;
List<DotInfo> missingValues = new ArrayList<DotInfo>();
// create the dots
for (int row = 0; row < nrOfRows; row++) {
DataCell cell = array.getRow(row).getCell(colIdx);
int y = -1;
DotInfo dot;
int x = getMappedXValue(new StringCell(array.getRow(row).getKey().getString()));
if (!cell.isMissing()) {
y = getMappedYValue(cell);
if (missingValues.size() > 0) {
// we have some missing values in between,
// thus we have to interpolate
p2 = new Point(x, y);
DotInfo[] interpolated = interpolate(p1, p2, missingValues);
// and add them
for (DotInfo p : interpolated) {
dotList.add(p);
}
// and clear the list again
missingValues.clear();
}
p1 = new Point(x, y);
dot = new DotInfo(x, y, array.getRow(row).getKey(), delegateIsHiLit(array.getRow(row).getKey()), color, 1, row);
dot.setXDomainValue(new StringCell(array.getRow(row).getKey().getString()));
dot.setYDomainValue(cell);
dotList.add(dot);
} else if (!m_interpolate) {
// LOGGER.debug("missing value");
dot = new DotInfo(x, -1, array.getRow(row).getKey(), delegateIsHiLit(array.getRow(row).getKey()), color, 1, row);
dotList.add(dot);
} else {
// interpolate
dot = new DotInfo(x, -1, array.getRow(row).getKey(), delegateIsHiLit(array.getRow(row).getKey()), color, 1, row);
missingValues.add(dot);
}
}
// un-interpolated at the end, we add them anyway
if (!missingValues.isEmpty()) {
DotInfo[] interpolated = interpolate(p1, null, missingValues);
// and add them
for (DotInfo p : interpolated) {
dotList.add(p);
}
// and clear the list again
missingValues.clear();
}
}
DotInfo[] dots = new DotInfo[dotList.size()];
dotList.toArray(dots);
((LinePlotterDrawingPane) getDrawingPane()).setNumberOfLines(nrOfRows);
((ScatterPlotterDrawingPane) getDrawingPane()).setDotInfoArray(new DotInfoArray(dots));
}
}
use of org.knime.core.data.property.ColorAttr in project knime-core by knime.
the class ColorManager2DialogNominal method select.
/**
* Called is a new column is selected. If the column is null every
*
* @param column the new selected column
* @return <code>true</code>, if the call caused any changes
*/
boolean select(final String column) {
m_columnModel.removeAllElements();
Map<DataCell, ColorAttr> map = m_map.get(column);
boolean flag;
if (map == null) {
m_columnModel.removeAllElements();
m_columnValues.setEnabled(false);
flag = false;
} else {
m_columnValues.setEnabled(true);
for (DataCell cell : map.keySet()) {
assert cell != null;
ColorAttr color = map.get(cell);
assert color != null;
m_columnModel.addElement(new ColorManager2Icon(cell, color.getColor()));
}
flag = true;
}
super.validate();
super.repaint();
return flag;
}
use of org.knime.core.data.property.ColorAttr in project knime-core by knime.
the class ColorManager2DialogNominal method createColorMapping.
/**
* Create default color mapping for the given set of possible <code>DataCell</code> values.
*
* @param set possible values
* @return a map of possible value to color
*/
static final Map<DataCell, ColorAttr> createColorMapping(final Set<DataCell> set) {
if (set == null) {
return Collections.EMPTY_MAP;
}
Map<DataCell, ColorAttr> map = new LinkedHashMap<DataCell, ColorAttr>();
int idx = 0;
for (DataCell cell : set) {
if (idx >= ColorManager2NodeDialogPane.PALETTE_SET1.length) {
idx = 0;
}
Color color = Color.decode(ColorManager2NodeDialogPane.PALETTE_SET1[idx]);
map.put(cell, ColorAttr.getInstance(color));
idx++;
}
return map;
}
Aggregations