JointJS - How can i expand and shrink from a parent node?

1,059 views
Skip to first unread message

Prashanth krishnan

unread,
Nov 4, 2015, 8:00:10 AM11/4/15
to JointJS
Hello,

I am evaluating JointJS Rapid framework.

How can I expand and shrink from a parent node?

Example: My requirement is on a node click I should hide all sub nodes and expand it on clicking it again(Just like a toggle button)

Regards
Prasanth

dave

unread,
Nov 4, 2015, 2:58:48 PM11/4/15
to JointJS
Hi Prasanth,

You can react on the element:pointerdown event on paper and show/hide any other elements. Here's an example of showing/hiding embedded elements on click:

// Toggle our custom 'hidden' property on all embedded cells:
paper.on('element:pointerdown', function(cellView, evt, x, y) {
    var cell = cellView.model;
    var embeddedCells = cell.getEmbeddedCells();
    _.each(embeddedCells, function(child) {
        child.set('hidden', !child.get('hidden'))
    })
})

// React on changes in the 'hidden' property and show/hide the cell for which the property has changed.
// Note that all changes bubble up to the graph so we don't have to listen on all the cells separately.
// Instead, we can have just one handler for the change:hidden event on the graph.
graph.on('change:hidden', function(cell, changed, opt) {
    cell.attr('./opacity', cell.get('hidden') ? 0 : 1);
})

Govinda Totla

unread,
Oct 8, 2020, 9:34:43 AM10/8/20
to JointJS
Hi Dave,
Thanks for the answer, even after 4 years I was able find to it useful. Just one thing here - 

I am using DirectedGraphLayout. After the elements have collapsed, how can I trigger the layout to re-render. It is possible in TreeLayout from Rappid using layout.layout(). Is it possible to do the same in DirectedLayout as well? Also, is there a filter property similar to that in TreeLayout which I can use for ignoring the hidden nodes?

Thanks 

Roman Bruckner

unread,
Oct 8, 2020, 9:47:20 AM10/8/20
to joi...@googlegroups.com
Hi,

1. It's better to use the `viewport` paper option to hide/show elements. (https://resources.jointjs.com/docs/jointjs/v3.2/joint.html#dia.Paper.prototype.options.viewport).

2.  DirectedGraph layout() function accepts an array of cells as the first parameter. So you can filter the cells  yourself before calling the layout.

joint.layout.DirectedGraph.layout(cells.filter(c => !c.isHidden()), { /* ...options... */ })

Best,
Roman

--

---
You received this message because you are subscribed to the Google Groups "JointJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jointjs+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jointjs/dff908e1-6803-4b37-9e83-bd23da4a78e7n%40googlegroups.com.


--

Govinda Totla

unread,
Oct 10, 2020, 12:25:46 PM10/10/20
to JointJS
Thanks a lot Roman, that works. 
Reply all
Reply to author
Forward
0 new messages