A display is a graph that renders its node's and edges on screen using SVG.
Constructs a new Thinkmap display, hosted by the given DOM Element.
the DOM element to attach this display to
Returns the current active entity in the display. This is typically the last or current entity interacted with via the mouse.
Returns the current active entity in the display. Returns undefined or null if this entity is not defined.
Gets the bounding box that contains an entity, or if no arguments are passed, all entities in this display.
the entity to get the bounds for, or undefined to get the bounds of all entities.
the SVG bounding box for the given entity, or all entities
Sets (or gets) the Context Menu for this display. The ContextMenu will be shown on mouse clicks. The event passed to the show and action methods will include an entity and selection properties which represent the active entity and its display elements (if an active entity was indeed clicked else those properties will be undefined).
Also, any entity clicked is frozen and will be unfrozen once the menu hides.
Using a context menu with a display will disable the default right click menu of the browser for the element containing the display.
the optional menu. If no arguments are passed than the current ContextMenu for this display is returned.
this context menu if no arguments were passed else the context menu is set and the Display is returned
var contextMenu = new thinkmap.contextmenu.ContextMenu();
contextMenu.item('center',"Make Center").onshow(function(evt) {
// only make the item visible if an entity exists
this.visible(!!evt.entity);
}).onaction(function(evt){
// call this function when the user selects this menu option
makeCenter(evt.entity);
});
display.contextMenu(contextMenu);
Sets (or gets) whether entities can be dragged with the mouse in this display.
If called with no arguments, this method returns the current value of "draggable".
true to make all entities draggable, or a function which gets passed an entity and returns a boolean.
this display, or boolean if called with no arguments.
display.draggable(true);
display.draggable(function(entity){
return entity.isType('movie');
});
display.draggable(false);
Get the SVG element that represents this entity on screen (or null).
Returns the Entity associated with the given SVG element (or null).
the Entity associated with the given SVG element (or null).
Transform a point from an entity's coordinate system to the display's "world" space.
an entity contained by this display
Get's (or sets) the global offset (scroll) to the given coordinate.
this display, or the current global offset, if called with no arguments
Select all the nodes inside the given bounding box.
the nodes inside the given selection box
Mark the given entity (or entities) as being invalid and schedule the display to be redrawn if necessary.
the entity or entities to be invalidated
Returns true if the given entity is frozen in this Display.
The entity to check if frozen
Check if the given entity is frozen for dragging.
true if the entity is frozen in this Display.
Returns true if the given entity has just been added to this display and has not yet been drawn.
Returns true if the given entity has been positioned or transformed by the user or a layout. This will return false for any entity that has not yet been drawn (is new) and has not yet been assigned a position by the user or a layout.
Mark this display as having an invalid layout and schedule a layout recompute and redraw for the near future.
this display
Sets or gets the max scale to be used on the display. If the max scale is less than or equal to 0, then there is no limit on the scale to be set. The default is -1.
The max scale to be set.
returns the maxScale if no arguments are passed in, or returns the this Display if the maxScale was set.
Sets or gets the min scale to be used on the display. If the min scale is less than or equal to 0, then there is no limit on the scale to be set. The default is -1.
The min scale to be set.
returns the minScale if no arguments are passed in, or returns the this Display if the minScale was set.
Select all the nodes outside the given bounding box.
the nodes outside the given selection box
Transform a point from screen space (pixels relative to screen) into "world" space of the Display.
Get (or set) the position of a node in this display.
If called with one argument, this method returns the current position of the given node. The point that is returned is not a copy, and if manipulated will manipulate the location of the entity.
If called with two arguments, this method sets the position of the given node, invalidates it and returns this Display.
the node to get or set the position of
the position of the given node, or this display, if two arguments were provided.
Schedule this display to be redrawn in the near future.
this display
Sets (or gets) the scale of this display. If no arguments are provided the current scale is returned.
Scroll the display by the given x and y amount in pixels. This is achievied by translating the global offset.
the amount to scroll in the x dimension, in pixels
the amount to scroll in the y dimension, in pixels
this display
Scroll the display so that the point given in world space is placed at the given screen point. If the screen point is undefined, then the center of the display is used.
the point in world space that will be scrolled to the given screen point
the optional point on the screen at which the world point will be scrolled to. If not defined, then the center of the screen is used.
Sets (or gets) whether this display can be scrolled with the mouse. This function accepts either a boolean, or an object that has two boolean properties, "x" and "y". This way, you can enable/disable scrolling entirely, or along a given axis.
Enables/Disables whether scrollbars should be used on this display when entities in this display go off the screen.
If no arguments are passed in, this function returns true/false depending on whether this feature is enabled or disabled.
Set to true if scrollbars should be enabled. False disables scrollbars.
If no arguments are passed in, true or false is returned depending on whether the scrollbars are enabled. If arguments are passed in, scrollbars are enabled/disabled and this display is returned.
display.scrollbars(true);
Create a selection on this Display from a BitSet that contains the ids of the entities to select.
This feature shows the amount of frames per second being drawn on the bottom right of this display.
This feature should only be used for debugging performance.
Set to true to enable, false to disable
If no arguments are passed in, true or false is returned depending on whether the frame rate is enabled. If arguments are passed in, the frame rate is enabled/disabled and this display is returned.
display.showFPS(true)
Returns a new display template builder for the given entity type. Calling this method will clear any previously configured renderer for this type. Builders returned from this method must be configured immediately, and cannot be stored for use/reuse later.
the entity type to create a template for
a new builder to customize.
Transform a point from world space into the coordinate system of a given entity.
an entity contained by this display
Sets or gets the Tooltip to show on an entity in this display. Tooltips allow a user to show additional information about an entity when moused over.
There can be only one tooltip function per display. Calling this function will result in the previous tooltip function being disabled and removed.
The function parameter for this tooltip, if it returns a non-null value for the current moused over entity, will result in the tooltip being active. If the function returns null, then the tooltip will not be used for the current moused over entity.
the tooltip function to be evaluated on the currently moused over entity in this display.
this displays Tooltip
display.tooltips(function(e) {
if (e.isType('movie')) {
return ''+e.data.title+'
'+e.data.year+' ('+e.data.rating+')';
}
});
Returns the transform for the given entity. This Transform is not a copy, and if manipulated will manipulate the location of the entity.
the entity to get the transform for.
the transform of the entity, or null if the entity is not in this display.
Creates and returns a DisplayTransition which can be used to animate certain elements of the Display such as the scale, globalOffset, and scrollTo
Mark the given entity (or entities) as being invalid and call the update method on the template(s) associated with the entity(ies).
Also, schedule the display to be redrawn if necessary.
the entity or entities to be updated
Transform a point from screen space (pixels relative to screen) into "world" space of the Display.
a point in "world" space
Enables and disables the mousewheel being used for scaling this display.
Set to true if zooming on the mousewheel should be enabled
If no arguments are passed in, then true or false is returned depending on whether zooming is enabled or disabled. If there are arguments, zooming is enabled/disabled and this display is returned.
display.zoomOnWheel(true);
Adds an entity (or set of entities) to this graph.
this graph
Add a graph loader to this graph
the loader to add
the loader that was added
Create an annotation that allows you to associate arbitrary data with entities in this graph. The special thing about annotations is that they allow you to weakly associate data. When the annotation is garbage-collected, all data associated with the annotation is garbage collected, even though the graph may still contain the entities that have been annotated.
However, data in the annotation is not garbage collected when entities are
removed from the Graph. You MUST remove the annotated data manually when
entities are removed from the Graph. This is typically done by adding a
listener to the Graph's 'removenode' and 'removeedge' events.
the annotation.
Returns this graph as a tree.
The tree is built by performing a visit on this graph. This graph can be visited in either depth first or breadth first order.
the node that will be the root of the tree
set to true if the tree should be built by visiting this graph in depth first order. If not true, this graph will be visited in breadth-first order.
the optional filter function that should return true if the edge should be visited
Find an entity by internal entity id.
the id of the entity to retrieve
the entity with that id, or null no entity with that id exists in this graph.
Test whether an entity (or selection of entities) can be removed. This will return false if a retention policy is in place for an entity, and that policy prevents the entity from being removed from this graph.
true if this entity (or selection) can be removed
Returns true if this graph contains the given entity.
Create an edge that may be added to this graph at a later time.
the from node (required)
the to node (required)
true if this is a directed edge. The default is false
optional data to be associated with this edge
optional type of this edge, the default is "edge"
var actor = graph.createNode({name:'Harrison Ford'});
var movie = graph.createNode({title:'Star Wars'});
// add a new non-directed edge
var edge = graph.add(graph.createEdge(actor,movie,false,{role:'Han Solo'}));
Create a full-text index on this graph. Full-text indexes allow search queries to run faster.
full-text index specification in JSON format
the name of the entity type to index - the default is all entities
the resulting index, or an existing index if one with this specification existed.
// create an employee type
graph.createType('employee','node');
// create the index
graph.createFullTextIndex({'lastname':true,'firstname':true},'employee');
Create an index on this graph. Indexes allow queries to run faster.
index specification in JSON format
true if this index should enforce uniqueness
the name of the entity type to index - the default is all entities
the resulting index, or an existing index if one with this specification existed.
// create an employee type
graph.createType('employee','node');
// create the index
graph.createIndex({'lastname':true,'firstname':true},true,'employee');
Create a node that may be added to this graph at a later time.
the newly added node.
var newnode = graph.add(graph.createNode({name:'John Smith'}));
var newnode = graph.add(graph.createNode({title:'Star Wars'},'movie'));
var newnode = graph1.createNode({name:'John Smith'});
graph2.add(newnode);
Create an entity type.
the name of the new type
required parent type - usually 'node' or 'edge'
this graph
// create a node entity type called "movie"
var movies = graph.createType('movie','node');
Tell this graph that a given entity (or entities) have had their data updated.
the entity or entities to be updated
Connect this graph to a remote Thinkmap 2.9.2+ datasource at the given URL
the graph loader associated with the datasource
Find an edge by internal entity id.
the id of the node to retrieve
the edge with that id, or null if no entity with that id exists.
Select edges from this graph.
If this function is called with no arguments, it selects all the edges in the graph.
a reference node to start from
the direction to traverse from the reference node. The default is Edge.Direction.BOTH.
an optional filter function used to filter the selection
Asynchronously fetch the entities related to the given entity, using any associated graph loaders to retrieve the related entities.
This method is typically not called by users, but is called by the query API when fecthing remote data.
the entity to fetch data for
the current query (part) being executed
a future entity that will be fulfilled when all data related to the given entity has been loaded.
Return a filtered view of this Graph.
a function used to filter this graph into a new graph
set to true if you want the resulting Graph to be kept up to date with the original graph by listening to it for changes. If set to false, the returned graph will be a point-in-time snapshot of this graph.
a new graph, filtered by the given function.
Call the given function once for every entity in this graph.
the value to use as "this" when calling the callback
Returns an array of indexes that have been created on this graph.
Returns true if the given entity type descends from the given parent type.
true if the given type name descends from the given parent
// create a node entity type called "movie"
var movies = graph.createType('movie','node');
// prints true to the console
console.log( graph.isType('movie','node' ) );
Get the graph loaders associated with this graph.
Find a node by internal entity id.
the id of the node to retrieve
the node with that id, or null if no node with that id exists.
Select nodes from this graph.
If this function is called with no arguments, it selects all the nodes in the graph.
a reference entity to start from (either a node or edge)
the direction to traverse from the reference entity. The default is Edge.Direction.BOTH.
an optional filter function used to filter the selection
Link this graph to another, so that any entities that are added to the other graph are added/removed from this graph.
the graph to observe
a filter function that must return true for entities to be reflected in this graph
this graph
Returns this graph as a precedence tree.
A precedence tree is a tree ordered by dependencies such as a schedule. More specifically, the tree is the result of a topological sort on a directed graph. A directed graph is a graph where all edges are directed and has no cycles (i.e. a node doesn't have a directed edge pointing to any ancestors). If this method is called on a graph with cycles, an error is thrown.
For example, if this graph has Node A which has an edge to nodes
B and C and C is also connected to B, the result of calling this method is a tree with:
A -> C -> B
The starting point of the precedence tree.
an optional error callback useful when trying to debug any cycles when building the precedence tree. The parameters are the tree built, the visited nodes, and the removed edges so far, both stored as bitsets.
Compile a Query object for executing queries on this Graph. Queries are specified as a JSON object in Thinkmap Graph Query Language. See the Thinkmap Graph Query Language documentation for details.
a Thinkmap query in JSON query format
the parsed query object
graph.query({$search:'breakfast',$t:'node'}).execute().oncomplete(function() {
console.log('found', this.count(), 'results' );
});
Remove an entity (or selection of entities) from this Graph.
this graph
Set a retention policy for an entity (or selection) of entities. A policy function takes one argument (an entity) and returns true if that entity MAY NOT be removed from the graph. Returning false or undefined means that the entity MAY be removed. Retention policies are cumulative. That means that if more than one policy is in place, if any one of the policies return true for an entity, that entity cannot be removed.
If the same exact policy function is added more than once for any entity, only one copy is retained.
a function that determines if an entity is retained.
Remove all entities, except the ones contained in the given selection.
the selection to retain
this graph
Select entities from this graph
selection parameter
Unlinks this graph from a graph it was previously observing via the Graph.observe() method.
the graph to stop observing
this graph
Add a listener to this EventSource
the name of the event to listen for
the callback to add
this eventsource
Dispatch an event from this EventSource, supplying arguments to the listeners via an Array, rather than var-args.
the name of the event to dispatch
this EventSource
Dispatch an event from this EventSource
the name of the event to dispatch
optional arguments sent to the event listeners
this EventSource
Fire an event from this EventSource
the name of the event to dispatch
optional arguments sent to the event listeners
this EventSource
Remove a listener from this EventSource
the name of the event to remove the listener for
the callback to remove
this eventsource
Add a listener to this EventSource
the name of the event to listen for
the callback
this eventsource
Add a listener to this EventSource, which will be called at most once and will be removed the first time the given event fires.
the name of the event to listen for
the callback to add
this eventsource
Remove a listener from this EventSource
the name of the event to remove the listener for
the callback to remove
this eventsource
this event is fired when the display is drawing and requires a layout to be performed (New entities added to the display or elements changing in size ). Most layouts listen for this event and perform the layout calculation when it is fired. However, it can also be useful to know when the display needs to do a new layout for scrolling and animations.
this event is fired on each frame. All work during this event should be completed quickly as it can effect performance
this event is fired when the scale for the display has changed.
this event is fired when the globalOffset for the display has changed.
This event is fired each time a node is added to the graph. The parameter is the node added.
This event is fired each time an edge is added to the graph. The parameter is the edge added.
This event is fired each time a node is removed from the graph. The parameter is the node removed.
This event is fired each time an edge is removed from the graph. The parameter is the edge removed.
This event is fired each time each time dataUpdate on graph is called. This typically signifies that some change occured to the entity's data object. The single parameter is the entity passed to the graphs dataUpdate method.