Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
470
xamTreeMap - getting nodes within a bounding box
posted

I would like to be able to let the user select the nodes by drawing a lasso box around the nodes they are interested in. Is there a good way to do this?

To be more specific -- is there a way to get the nodes that are within a bounding box (say upper left and lower right corners of a rectangle).

  • 895
    Suggested Answer
    posted

    Hello,

    Attached is a WPF project, which performs the selection of Treemap nodes using a bounding box.

    Note that the selection will work in the yellow area and only leaf nodes are selected.

    You can alter the seleciton logic in the TreemapDragSelectionViewModel.cs file - TreemapNodeHitTestFilter method:

            /// <summary>
            /// Filters only the <see cref="TreemapNode"/> objects from the HitTest.
            /// </summary>
            /// <remarks>
            /// Note that this method will keep only the leaf nodes, but it can be modified
            /// to keep all nodes, which are under the selection region.
            /// </remarks>
            private HitTestFilterBehavior TreemapNodeHitTestFilter(DependencyObject potentialHitTestTarget)
            {
                HitTestFilterBehavior behavior = HitTestFilterBehavior.ContinueSkipSelf;
    
                if (potentialHitTestTarget is TreemapNode)
                {
                    TreemapNode node = (TreemapNode) potentialHitTestTarget;
                    if (node.Children.Count == 0)
                    {
                        _hitItems.Add(node);
                        behavior = HitTestFilterBehavior.ContinueSkipChildren;
                    }
                }
    
                return behavior;
            }
    

     

    Will this work for you?

  • 605
    Suggested Answer
    posted

    Hi, jnyikos,

    The current logic of the treemap is to show the child nodes of a certain parent, it is not possible to show just a subset of them. One could do so by setting the ItemsSourceRoot of the treemap to the data of a particular subitem.

    So a possible solution is to use the NodeMouseLeftButtonDown, NodeMouseLeftButtonUp, NodeMouseMove events in order to get the items on which the dragging begins and ends. Then you could search the children of the treemap RootNode in order to find a node that is common parent of the "begin" and "end" nodes and to set it as ItemsSourceRoot.I know this is not exactly what you want to do but i think this is the best that could be done now.

    Thanks,

    Miroslav