Search in sources :

Example 1 with SotaTreeCellLocations

use of org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations in project knime-core by knime.

the class SotaDrawingPane method getCellAtCursor.

/**
 * Returns the cell related to the given mouse position, if no cell is
 * related to that position <code>null</code> is returned.
 *
 * @param x mouse position on x coordinate
 * @param y mouse position on y coordinate
 * @return the cell related to the given mouse position or <code>null</code>
 *         if no cell is available at that position
 */
private SotaTreeCell getCellAtCursor(final int x, final int y) {
    if (m_data != null && m_root != null) {
        int maxX = m_data.size() * m_pixelWidth;
        int yCoord = y;
        int xCoord;
        // for a cell.
        for (int j = 0; j <= m_impreciseness; j++) {
            for (int dir = -1; dir <= 1; dir += 2) {
                xCoord = x + (j * dir);
                if (xCoord <= maxX && xCoord >= 0 && yCoord <= m_jpHeight - PIXEL_HEIGHT) {
                    ArrayList<SotaTreeCell> list = m_nodesCoordIndex.get(xCoord);
                    if (list != null) {
                        for (int i = 0; i < list.size(); i++) {
                            SotaTreeCellLocations cellLocation = m_cellLocations.get(list.get(i));
                            if (yCoord <= cellLocation.getStartY() && yCoord >= cellLocation.getEndY()) {
                                return list.get(i);
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) SotaTreeCellLocations(org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations)

Example 2 with SotaTreeCellLocations

use of org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations in project knime-core by knime.

the class SotaDrawingPane method computeParentTreeNodeCoordinates.

/**
 * Computes the coordinates of the parents of the given children nodes.
 *
 * @param children the children of the parents to compute the coordinates
 *            for
 * @param level current tree level
 * @return the parents in a list for which the coordinates were computed
 */
private ArrayList<?> computeParentTreeNodeCoordinates(final ArrayList<SotaTreeCell> children, final int level) {
    ArrayList<SotaTreeCell> parents = new ArrayList<SotaTreeCell>();
    for (int i = 0; i < children.size(); i++) {
        // only if cell has given level, if not put cell in parents array
        if (children.get(i).getLevel() == level) {
            // if parent is not in parents list and has no coordinates
            if (!parents.contains(children.get(i).getAncestor())) {
                parents.add(children.get(i).getAncestor());
                // SotaTreeCell c = children.get(i);
                // SotaTreeCell cS = children.get(i).getSister();
                SotaTreeCellLocations childrenCellLocation = m_cellLocations.get(children.get(i));
                SotaTreeCellLocations childrenSisterCellLocation = m_cellLocations.get(children.get(i).getSister());
                int x = (childrenCellLocation.getStartX() + childrenSisterCellLocation.getStartX()) / 2;
                int startY = childrenCellLocation.getEndY();
                int heightFactor = 0;
                if (m_isHierarchicalFuzzyData && m_drawHierarchicalFuzzyData) {
                    // if hierarchical data is used:
                    heightFactor = level - children.get(i).getAncestor().getLevel();
                    int currentHLevel = children.get(i).getAncestor().getHierarchyLevel();
                    int childrenHLevel = children.get(i).getHierarchyLevel();
                    if (currentHLevel != childrenHLevel) {
                        heightFactor += m_hierarchicalMaxLevels.get(currentHLevel) - children.get(i).getAncestor().getLevelInHierarchy();
                        for (int l = childrenHLevel - 1; l > currentHLevel; l--) {
                            heightFactor += m_hierarchicalMaxLevels.get(l);
                        }
                    }
                } else {
                    heightFactor = level - children.get(i).getAncestor().getLevel();
                }
                int endY = startY - (heightFactor * m_clusterLineHeight);
                SotaTreeCellLocations childrenAncestorCellLocation = m_cellLocations.get(children.get(i).getAncestor());
                if (childrenAncestorCellLocation != null) {
                    childrenAncestorCellLocation.setStartX(x);
                    childrenAncestorCellLocation.setEndX(x);
                    childrenAncestorCellLocation.setStartY(startY);
                    childrenAncestorCellLocation.setEndY(endY);
                }
                // Save the X coordinates and the related cell
                addCellToCoordHash(x, children.get(i).getAncestor());
            }
        } else if (children.get(i).getLevel() < level) {
            parents.add(children.get(i));
        }
    }
    if (level > 1) {
        return computeParentTreeNodeCoordinates(parents, level - 1);
    }
    return null;
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) SotaTreeCellLocations(org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations) ArrayList(java.util.ArrayList)

Example 3 with SotaTreeCellLocations

use of org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations in project knime-core by knime.

the class SotaDrawingPane method drawTreeNode.

/**
 * Draws the given {@link SotaTreeCell} and its children recursive, by using
 * their coordinates.
 *
 * @param g graphics instance to draw with
 * @param cell the cell to draw
 */
private void drawTreeNode(final Graphics g, final SotaTreeCell cell) {
    if (!cell.isCell()) {
        drawTreeNode(g, cell.getLeft());
        drawTreeNode(g, cell.getRight());
    }
    g.setColor(getCellColor(cell, false));
    SotaTreeCellLocations cellLocation = m_cellLocations.get(cell);
    // Draw cluster line
    g.drawLine(cellLocation.getStartX(), cellLocation.getStartY(), cellLocation.getEndX(), cellLocation.getEndY());
    // Draw cluster rectangle
    g.drawRect(cellLocation.getEndX() - (m_clusterRectWidth / 2), cellLocation.getEndY() - (m_clusterRectWidth / 2), m_clusterRectWidth, m_clusterRectWidth);
    SotaTreeCell sister = cell.getSister();
    if (sister == null) {
        sister = cell;
    }
    if (cell.isHilited() && sister.isHilited() && !cell.isSelected()) {
        g.setColor(m_hilit);
    } else if (cell.isHilited() && sister.isHilited() && cell.isSelected()) {
        g.setColor(m_selectedHilited);
    } else {
        g.setColor(getCellColor(cell, true));
    }
    // Draw line between sisters
    if (cell.getSister() != null) {
        SotaTreeCellLocations sisterCellLocation = m_cellLocations.get(cell.getSister());
        g.drawLine(cellLocation.getStartX(), cellLocation.getEndY(), sisterCellLocation.getStartX(), sisterCellLocation.getEndY());
    }
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) SotaTreeCellLocations(org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations)

Example 4 with SotaTreeCellLocations

use of org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations in project knime-core by knime.

the class SotaDrawingPane method modelChanged.

/**
 * Creates the Tree structure for the JTree and paints it.
 *
 * @param first if <code>true</code> size of JPanel will be recomputed
 */
public void modelChanged(final boolean first) {
    if (m_root != null && m_data != null) {
        // computes size for the first time the oanel is shown
        if (first) {
            // when there is only a small amount of data increase the
            // default pixel width by the magic factor.
            int factor = 1;
            if (m_data.size() <= 150) {
                factor = 2;
                if (m_data.size() <= 50) {
                    factor = 5;
                }
            }
            m_jpWidth = m_data.size() * DEF_PIXEL_WIDTH * factor;
            // resize to optimal size
            setSize(m_jpWidth, m_jpHeight);
            setPreferredSize(new Dimension(m_jpWidth, m_jpHeight));
        }
        // compute pixel width of data pixels
        if (m_data.size() == 0) {
            m_pixelWidth = 0;
        } else {
            m_pixelWidth = m_jpWidth / m_data.size();
        }
        // get all cells
        m_cells = new ArrayList<SotaTreeCell>();
        SotaManager.getCells(m_cells, m_root);
        // set default locations
        m_cellLocations = new HashMap<SotaTreeCell, SotaTreeCellLocations>();
        SotaManager.initDefaultLocations(m_cellLocations, m_root);
        // compute maxmimum tree level
        m_maxLevel = getMaxLevel(m_maxLevel, m_root);
        m_clusterLineHeight = (m_jpHeight - PIXEL_HEIGHT) / m_maxLevel;
        // store max Level in each hierarchy if data is hierarchical
        if (m_isHierarchicalFuzzyData && m_drawHierarchicalFuzzyData) {
            getHierarchicalMaxLevels();
        }
        // reset X coordinates and related cells
        m_nodesCoordIndex.clear();
        // copmute the coordinates for the tree nodes and cluster lines
        computeTreeNodeCoordinates();
        // and redurce them if they are.
        if (m_isHierarchicalFuzzyData && m_drawHierarchicalFuzzyData) {
            // if clusterlines too high
            if (m_rootLocation.getEndY() < 0) {
                int lineCount = (Math.abs(m_rootLocation.getEndY()) + m_jpHeight - PIXEL_HEIGHT) / m_clusterLineHeight;
                m_clusterLineHeight = (m_jpHeight - PIXEL_HEIGHT) / lineCount;
                // after new computation of optimal cluster line height
                // recompute the cluster line positions.
                m_nodesCoordIndex.clear();
                computeTreeNodeCoordinates();
            }
        }
        repaint();
    }
}
Also used : SotaTreeCell(org.knime.base.node.mine.sota.logic.SotaTreeCell) SotaTreeCellLocations(org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations) Dimension(java.awt.Dimension)

Example 5 with SotaTreeCellLocations

use of org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations in project knime-core by knime.

the class SotaManager method initDefaultLocations.

public static void initDefaultLocations(final HashMap<SotaTreeCell, SotaTreeCellLocations> cellLocations, final SotaTreeCell currentCell) {
    cellLocations.put(currentCell, new SotaTreeCellLocations());
    if (!currentCell.isCell()) {
        SotaManager.initDefaultLocations(cellLocations, currentCell.getLeft());
        SotaManager.initDefaultLocations(cellLocations, currentCell.getRight());
    }
}
Also used : SotaTreeCellLocations(org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations)

Aggregations

SotaTreeCellLocations (org.knime.base.node.mine.sota.view.interaction.SotaTreeCellLocations)6 SotaTreeCell (org.knime.base.node.mine.sota.logic.SotaTreeCell)4 Dimension (java.awt.Dimension)1 ArrayList (java.util.ArrayList)1