Package: thinkmap.graph.expand

This module exposes the Thinkmap ExpandManager. The ExpandManager is used to manage the expansion and collapse of entities in a predictable manner. It works by incrementally calling expand with a given node that has been expanded and the results of the expansion.

Generally these are the steps. There is a general center function in the application. When this function is called, the expand manager is first cleared. When the query completes, the expand manager calls expand using the center entity and results. Now when expanding entities, there is an expand query that is meant for expanding parts of the query. Once this completes, the ExpandManager's expand method is called with the given expand entity and the results of the query. Collapse works by rebuilding the graphs and truncating any expansions which are no longer visible.

The ExpandManager also takes an optional HistoryManager for managing history. It listens to calls for saving and restoring history, and rebuilds its internal datastructures appropriately.

Examples:

Incrementally expand a simple tree layout display while also using a history manager // build three graphs var graph = new thinkmap.graph.Graph(); var display = new thinkmap.display.Display(document.getElementById('map')); var tree = new thinkmap.graph.Tree(); // attach a datasource to the main graph graph.datasource('/moviedb.tas'); // construct a history manager var historyManager = new thinkmap.graph.history.HistoryManager(graph) .add(display).add(tree); // make two expands - one for each direction var expander = new thinkmap.graph.expand.ExpandManager(graph,historyManager) .add(display).add(tree); function center(entity) { // return if entity is undefined or equal to the current root or not // a movie if (!entity || root === entity || !entity.isType('movie')) return; // set the root to the new entity root = entity; tree.root(root); // add the root to the display display.add(root); // clear the expand manager so we start from scratch expander.clear(); query(entity).then(function(results) { display.retainOnly(results); expander.expand(entity,results); historyManager.pushState(); return display.transition().scrollTo(treeLayout.targetPosition(entity)); }); } // handles expansion of ent - assumes expanded entity is in the display/tree function expand(ent) { graph.query(....).execute(ent) .onresult(tree.add) .onresult(display.add) .oncomplete(function(results) { expander.expand(ent,results); historyManager.pushState(); }); } function query(entity) { return graph.query({$choice:[ ['movie','edge', 'person'], ['person','edge', 'movie'] ]}) .execute(entity) .onresult(display.add) .onresult(tree.add) .oncomplete(function(results){ display.layout(); return results; }); } // handles when to center/expand/collapse display.on('click',function(evt) { var entity = evt.entity; if (evt.shiftKey) { center(entity); } else if(expander.isExpanded(entity)) { expand(entity); } else { expander.collapse(entity); historyManager.pushState(): } });

Classes: