use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.
the class BoxPlotter method createNormalizedCoordinates.
/**
* @param statistics
*/
protected void createNormalizedCoordinates(final Map<DataColumnSpec, double[]> statistics) {
m_coordinates = new LinkedHashMap<DataColumnSpec, Coordinate>();
for (DataColumnSpec colSpec : statistics.keySet()) {
m_coordinates.put(colSpec, Coordinate.createCoordinate(colSpec));
}
// hack to achieve an empty y axis
createNominalYCoordinate(new LinkedHashSet<DataCell>());
}
use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.
the class ConditionalBoxPlotter method createNormalizedCoordinates.
/**
* {@inheritDoc}
*/
@Override
protected void createNormalizedCoordinates(final Map<DataColumnSpec, double[]> statistics) {
// create y-axis that consider the input domain
Map<DataColumnSpec, Coordinate> coordinates = new LinkedHashMap<DataColumnSpec, Coordinate>();
for (DataColumnSpec colSpec : statistics.keySet()) {
/*
* Pass the input domain's min and max values of the numerical
* column to all box plots by providing the column spec of the
* numerical column to all box plots. In this way they all use the
* same scale and the whole domain range is displayed.
*/
coordinates.put(colSpec, Coordinate.createCoordinate(colSpec));
}
setCoordinates(coordinates);
/*DataColumnDomain domain = numColSpec.getDomain();
double min = ((DoubleValue)domain.getLowerBound()).getDoubleValue();
double max = ((DoubleValue)domain.getUpperBound()).getDoubleValue();
createYCoordinate(min, max);*/
// hack to achieve an empty y axis
createNominalYCoordinate(new LinkedHashSet<DataCell>());
}
use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.
the class TwoColumnProperties method updateRangeSpinner.
/**
* Updates the values of the range spinner acording to the current
* columns.
*
* @param xColumn selected x column
* @param yColumn selected y column
*/
protected void updateRangeSpinner(final DataColumnSpec xColumn, final DataColumnSpec yColumn) {
Coordinate xCoordinate = Coordinate.createCoordinate(xColumn);
Coordinate yCoordinate = Coordinate.createCoordinate(yColumn);
if (xCoordinate == null || xCoordinate.isNominal()) {
// disable: no ranges
m_xMinSpinner.setEnabled(false);
m_xMaxSpinner.setEnabled(false);
} else {
// enable
m_xMinSpinner.setEnabled(true);
m_xMaxSpinner.setEnabled(true);
// get min and max values
double xMin = ((NumericCoordinate) xCoordinate).getMinDomainValue();
double xMax = ((NumericCoordinate) xCoordinate).getMaxDomainValue();
// set them
m_xMinSpinner.setValue(xMin);
m_xMaxSpinner.setValue(xMax);
}
if (yCoordinate == null || yCoordinate.isNominal()) {
// disable: no ranges
m_yMinSpinner.setEnabled(false);
m_yMaxSpinner.setEnabled(false);
} else {
// enable
m_yMinSpinner.setEnabled(true);
m_yMaxSpinner.setEnabled(true);
// get min and max values
double yMin = ((NumericCoordinate) yCoordinate).getMinDomainValue();
double yMax = ((NumericCoordinate) yCoordinate).getMaxDomainValue();
// set them
m_yMinSpinner.setValue(yMin);
m_yMaxSpinner.setValue(yMax);
}
}
use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.
the class Rule2DPlotter method updatePaintModel.
/**
* {@inheritDoc}
*/
@Override
protected void updatePaintModel() {
super.updatePaintModel();
if (m_rules != null) {
Rule2DDrawingPane drawingPane = getDrawingPane();
drawingPane.setOriginalRuleTable(m_rules);
String xName = getXColName();
String yName = getYColName();
int xIdx = -1;
int yIdx = -1;
if (xName != null && yName != null) {
xIdx = m_rules.getDataTableSpec().findColumnIndex(xName);
yIdx = m_rules.getDataTableSpec().findColumnIndex(yName);
}
if (xIdx >= 0 && yIdx >= 0) {
Coordinate x = getColHeader().getCoordinate();
Coordinate y = getRowHeader().getCoordinate();
// check if the coordinates are valid
if (x == null || y == null) {
return;
}
// calculate the coordinates of the rules here
// List<DataRow> rows = new ArrayList<DataRow>();
DataColumnSpecCreator creator = new DataColumnSpecCreator("xValues", FuzzyIntervalCell.TYPE);
DataColumnSpec col1 = creator.createSpec();
creator = new DataColumnSpecCreator("yValues", FuzzyIntervalCell.TYPE);
DataColumnSpec col2 = creator.createSpec();
DataTableSpec spec = new DataTableSpec(new DataColumnSpec[] { col1, col2 });
DataContainer rows = new DataContainer(spec);
for (RowIterator itr = m_rules.iterator(); itr.hasNext(); ) {
DataRow currRow = itr.next();
DataCell[] newCells = new DataCell[2];
for (int cell = 0; cell < currRow.getNumCells(); cell++) {
// if (!m_rules.getDataTableSpec().getColumnSpec(cell)
// .getType().isCompatible(
// FuzzyIntervalValue.class)) {
// continue;
// }
Rectangle rect = calculateDrawingRectangle();
double a;
double b;
double c;
double d;
if (cell == xIdx) {
if (currRow.getCell(cell).isMissing()) {
// normalize xValues
a = getXmin();
b = getXmin();
c = getXmax();
d = getXmax();
} else {
// normalize xValues
a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
}
double newA = x.calculateMappedValue(new DoubleCell(a), rect.width, true);
double newB = x.calculateMappedValue(new DoubleCell(b), rect.width, true);
double newC = x.calculateMappedValue(new DoubleCell(c), rect.width, true);
double newD = x.calculateMappedValue(new DoubleCell(d), rect.width, true);
DataCell newInterval = new FuzzyIntervalCell(rect.x + newA, rect.x + newB, rect.x + newC, rect.x + newD);
newCells[0] = newInterval;
}
if (cell == yIdx) {
if (currRow.getCell(cell).isMissing()) {
a = getYmin();
b = getYmin();
c = getYmax();
d = getYmax();
} else {
// normalize yValues
a = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinSupport();
b = ((FuzzyIntervalValue) currRow.getCell(cell)).getMinCore();
c = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxCore();
d = ((FuzzyIntervalValue) currRow.getCell(cell)).getMaxSupport();
}
double newA = y.calculateMappedValue(new DoubleCell(a), rect.height, true);
double newB = y.calculateMappedValue(new DoubleCell(b), rect.height, true);
double newC = y.calculateMappedValue(new DoubleCell(c), rect.height, true);
double newD = y.calculateMappedValue(new DoubleCell(d), rect.height, true);
DataCell newInterval = new FuzzyIntervalCell(rect.y + rect.height - newD, rect.y + rect.height - newC, rect.y + rect.height - newB, rect.y + rect.height - newA);
newCells[1] = newInterval;
}
}
// create new row out of the normalized cells
rows.addRowToTable(new DefaultRow(currRow.getKey(), newCells));
}
rows.close();
drawingPane.setNormalizedRules(new DefaultDataArray(rows.getTable(), 1, m_rules.size()));
}
super.updatePaintModel();
}
}
use of org.knime.base.util.coordinate.Coordinate in project knime-core by knime.
the class ScatterPlotter method setYColumn.
/**
* Sets new y columns and recalculates/repaints.
*
* @param yColName name of the new y column to plot
*/
public void setYColumn(final String yColName) {
setYColName(yColName);
// tell the headers to display the new column names
getRowHeader().setToolTipText(getYColName());
// check if the column names set so far are valid
// this check also checks the y axis
// if invalid a boolean flag is set in the method for later use
checkColumns();
if (m_rowContainer == null) {
return;
}
DataTableSpec tSpec = m_rowContainer.getDataTableSpec();
// set the chosen column specs via a coordinate into the
// axis headers
int idx = tSpec.findColumnIndex(getYColName());
if (idx >= 0) {
Coordinate yCoordinate = Coordinate.createCoordinate(tSpec.getColumnSpec(idx));
if (yCoordinate == null) {
m_yIndex = -1;
} else {
// check whether the bounds are set properly
if (!yCoordinate.isNominal()) {
if (!((NumericCoordinate) yCoordinate).isMinDomainValueSet()) {
((NumericCoordinate) yCoordinate).setMinDomainValue(getYmin());
}
if (!((NumericCoordinate) yCoordinate).isMaxDomainValueSet()) {
((NumericCoordinate) yCoordinate).setMaxDomainValue(getYmax());
}
}
getRowHeader().setCoordinate(yCoordinate);
m_yIndex = idx;
}
} else {
// set -1 to indicate an invalid column index
m_yIndex = -1;
}
// redo everything
if (!m_invalidColumn) {
updateDotsAndPaint();
}
}
Aggregations