use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.
the class PieVizModel method createLabel.
/**
* @param section the main section
* @param subSection the sub section of interest
* @return the label for the sub section including some section information
*/
public String createLabel(final PieSectionDataModel section, final PieSubSectionDataModel subSection) {
if (section == null) {
throw new NullPointerException("Section must not be null");
}
if (section.getElements().size() == 1) {
// if the section contains only one label just draw the section label
return createLabel(section);
}
if (subSection == null) {
throw new NullPointerException("subSection must not be null");
}
final String name = section.getName();
final AggregationMethod aggrMethod = getAggregationMethod();
final double value = section.getAggregationValue(aggrMethod);
final double totalValue = getAbsAggregationValue();
final double scaledValue = m_valueScale.scale(value, totalValue);
final String valuePart = GUIUtils.createLabel(scaledValue, NO_OF_LABEL_DIGITS, aggrMethod, m_valueScale);
final double subValue = subSection.getAggregationValue(aggrMethod);
final double scaledSubValue = m_valueScale.scale(subValue, totalValue);
final String subValuePart = GUIUtils.createLabel(scaledSubValue, NO_OF_LABEL_DIGITS, aggrMethod, m_valueScale);
final StringBuilder buf = new StringBuilder();
if (name != null) {
buf.append(name);
buf.append(": ");
buf.append(aggrMethod.getText());
buf.append(' ');
}
buf.append(subValuePart);
buf.append(" (");
buf.append(valuePart);
buf.append(')');
return buf.toString();
}
use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.
the class PiePlotter method setPieSections.
/**
* Calculates the size of all pie sections.
* @param vizModel the {@link PieVizModel} that provides visualisation
* information and the sections
*/
private void setPieSections(final PieVizModel vizModel) {
final Rectangle2D pieArea = vizModel.getPieArea();
final Rectangle2D explodedArea = vizModel.getExplodedArea();
final boolean explode = vizModel.explodeSelectedSections();
// final double explodePercentage = vizModel.getExplodeMargin();
final double totalVal = vizModel.getAbsAggregationValue();
final double arcPerVal = 360 / totalVal;
final AggregationMethod method = vizModel.getAggregationMethod();
final PieHiliteCalculator calculator = vizModel.getCalculator();
final List<PieSectionDataModel> pieSections = vizModel.getSections2Draw();
final int noOfSections = pieSections.size();
double startAngle = 0;
for (int i = 0; i < noOfSections; i++) {
final PieSectionDataModel section = pieSections.get(i);
final double value = Math.abs(section.getAggregationValue(method));
double arcAngle = value * arcPerVal;
// avoid a rounding gap
if (i == noOfSections - 1) {
arcAngle = 360 - startAngle;
}
if (arcAngle < PieVizModel.MINIMUM_ARC_ANGLE) {
LOGGER.debug("Pie section: " + vizModel.createLabel(section) + " angle " + arcAngle + " to small to display." + " Angle updated to set to minimum angle " + PieVizModel.MINIMUM_ARC_ANGLE);
arcAngle = PieVizModel.MINIMUM_ARC_ANGLE;
// skip this section
// section.setPieSection(null, calculator);
// continue;
}
final Rectangle2D bounds;
// explode selected sections
if (explode && section.isSelected()) {
bounds = GeometryUtil.getArcBounds(pieArea, explodedArea, startAngle, arcAngle, 1.0);
} else {
bounds = pieArea;
}
final Arc2D arc = new Arc2D.Double(bounds, startAngle, arcAngle, Arc2D.PIE);
section.setPieSection(arc, calculator);
startAngle += arcAngle;
}
}
use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.
the class PiePlotter method registerPropertiesChangeListener.
/**
* Registers all histogram properties listener to the histogram
* properties panel.
*/
private void registerPropertiesChangeListener() {
m_props.addShowSectionOutlineChangedListener(new ItemListener() {
public void itemStateChanged(final ItemEvent e) {
final PieVizModel vizModel = getVizModel();
if (vizModel != null) {
vizModel.setDrawSectionOutline(e.getStateChange() == ItemEvent.SELECTED);
final AbstractDrawingPane drawingPane = getPieDrawingPane();
drawingPane.repaint();
}
}
});
m_props.addLabelDisplayListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
final PieVizModel vizModel = getVizModel();
if (vizModel != null) {
final P props = getPropertiesPanel();
if (props != null) {
vizModel.setLabelDisplayPolicy(props.getLabelDisplayPolicy());
final AbstractDrawingPane drawingPane = getPieDrawingPane();
drawingPane.repaint();
}
}
}
});
m_props.addValueScaleListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
final PieVizModel vizModel = getVizModel();
if (vizModel != null) {
final P props = getPropertiesPanel();
if (props != null) {
vizModel.setValueScale(props.getValueScale());
final AbstractDrawingPane drawingPane = getPieDrawingPane();
drawingPane.repaint();
}
}
}
});
m_props.addShowDetailsListener(new ItemListener() {
public void itemStateChanged(final ItemEvent e) {
final PieVizModel vizModel = getVizModel();
if (vizModel != null) {
if (vizModel.setShowDetails(e.getStateChange() == ItemEvent.SELECTED)) {
final AbstractDrawingPane drawingPane = getPieDrawingPane();
drawingPane.repaint();
}
}
}
});
m_props.addPieSizeChangeListener(new ChangeListener() {
public void stateChanged(final ChangeEvent e) {
final JSlider source = (JSlider) e.getSource();
final int pieSize = source.getValue();
final PieVizModel vizModel = getVizModel();
if (vizModel == null) {
return;
}
if (vizModel.setPieSize((pieSize / 100.0))) {
updatePaintModel();
}
}
});
m_props.addExplodeSizeChangeListener(new ChangeListener() {
public void stateChanged(final ChangeEvent e) {
final JSlider source = (JSlider) e.getSource();
final int explodeSize = source.getValue();
final PieVizModel vizModel = getVizModel();
if (vizModel == null) {
return;
}
if (vizModel.setExplodeSize((explodeSize / 100.0))) {
updatePaintModel();
}
}
});
m_props.addAggrMethodListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
final PieVizModel vizModel = getVizModel();
if (vizModel == null) {
return;
}
final String methodName = e.getActionCommand();
if (!AggregationMethod.valid(methodName)) {
throw new IllegalArgumentException("No valid aggregation method");
}
final AggregationMethod aggrMethod = AggregationMethod.getMethod4Command(methodName);
if (vizModel.setAggregationMethod(aggrMethod)) {
updatePaintModel();
}
}
});
m_props.addShowMissingValSectionListener(new ItemListener() {
public void itemStateChanged(final ItemEvent e) {
final PieVizModel vizModel = getVizModel();
if (vizModel == null) {
return;
}
if (vizModel.setShowMissingValSection(e.getStateChange() == ItemEvent.SELECTED)) {
// reset the details view if the missing section was selected
final P properties = getPropertiesPanel();
if (properties != null) {
properties.updateHTMLDetailsPanel(vizModel.getHTMLDetailData());
}
updatePaintModel();
}
}
});
m_props.addExplodeSelectedSectionListener(new ItemListener() {
public void itemStateChanged(final ItemEvent e) {
final PieVizModel vizModel = getVizModel();
if (vizModel == null) {
return;
}
if (vizModel.setExplodeSelectedSections(e.getStateChange() == ItemEvent.SELECTED)) {
updatePaintModel();
}
}
});
}
use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.
the class PieNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final DataTableSpec spec = (DataTableSpec) inSpecs[0];
if (spec == null) {
throw new IllegalArgumentException("Table specification must not be null");
}
final String colName = m_pieColumn.getStringValue();
if (colName == null || colName.length() < 1) {
throw new InvalidSettingsException("Please select the pie column");
}
final DataColumnSpec pieCol = spec.getColumnSpec(colName);
if (pieCol == null) {
throw new InvalidSettingsException("Specified column name '" + colName + "' not found in input table");
}
if (!PieColumnFilter.validDomain(pieCol)) {
throw new InvalidSettingsException("No valid pie column selected.");
}
final AggregationMethod method = AggregationMethod.getMethod4Command(m_aggrMethod.getStringValue());
if (method == null) {
throw new InvalidSettingsException("No valid aggregation method");
}
return new DataTableSpec[0];
}
use of org.knime.base.node.viz.aggregation.AggregationMethod in project knime-core by knime.
the class BinDataModel method setBarRectangle.
/**
* Sets the rectangle for all bars in this bin.
* @param baseLine the x coordinate of the base line (0) on the screen
* @param barElementColors all element colors which define the order
* the elements should be drawn
* @param aggrColumns the aggregation column array which indicates
* the order of the bars
*/
private void setBarRectangle(final int baseLine, final List<Color> barElementColors, final Collection<? extends ColorColumn> aggrColumns, final HistogramHiliteCalculator calculator) {
if (m_binRectangle == null) {
final Collection<BarDataModel> bars = m_bars.values();
// also reset the bar rectangle
for (final BarDataModel bar : bars) {
bar.setBarRectangle(null, baseLine, barElementColors, calculator);
}
return;
}
final AggregationMethod aggrMethod = calculator.getAggrMethod();
final HistogramLayout layout = calculator.getLayout();
final int binWidth = (int) m_binRectangle.getWidth();
final int noOfBars = aggrColumns.size();
m_presentable = elementsFitInBin(noOfBars, binWidth);
if (!m_presentable) {
return;
}
// calculate the height
final int binHeight = (int) m_binRectangle.getHeight();
final double maxAggrVal = Math.max(getMaxAggregationValue(aggrMethod, layout), 0);
final double minAggrVal = Math.min(getMinAggregationValue(aggrMethod, layout), 0);
final double valRange = maxAggrVal + Math.abs(minAggrVal);
if (valRange <= 0) {
m_presentable = false;
return;
}
final int barWidth = calculateBarWidth(binWidth, noOfBars);
final double heightPerVal = binHeight / valRange;
final int binX = (int) m_binRectangle.getX();
int xCoord = binX;
for (final ColorColumn aggrColumn : aggrColumns) {
final BarDataModel bar = m_bars.get(aggrColumn.getColor());
if (bar != null) {
// set the rectangle only for the bars which are available
// in this bin
final double barMaxAggrVal = Math.max(bar.getMaxAggregationValue(aggrMethod, layout), 0);
final double barMinAggrVal = Math.min(bar.getMinAggregationValue(aggrMethod, layout), 0);
final double aggrVal = barMaxAggrVal + Math.abs(barMinAggrVal);
final int yCoord = (int) (baseLine - (barMaxAggrVal * heightPerVal));
final int barHeight = (int) (aggrVal * heightPerVal);
final Rectangle barRect = new Rectangle(xCoord, yCoord, barWidth, barHeight);
bar.setBarRectangle(barRect, baseLine, barElementColors, calculator);
}
// add the bar width and the space between bars to the current
// x coordinate
xCoord += barWidth + AbstractHistogramVizModel.SPACE_BETWEEN_BARS;
}
}
Aggregations