-
Notifications
You must be signed in to change notification settings - Fork 54
API Reference
# graph.setConfig(config)
Set Cosmos configuration. The changes will be applied in real time.
# graph.setData(nodes, links, [runSimulation])
Pass data to Cosmos: an array of nodes and an array of links. When runSimulation is set to false
, the simulation won't be started automatically (true
by default).
# graph.zoomToNodeById(id, [duration], [scale], [canZoomOut])
Center the view on the specified node (by its id) and zoom in with given animation duration and scale value. The default duration is 700 and the default scale is 3. To zoom in closer set a greater scale value. If the scale value is less than the current scale value, the view will be zoomed out. To prevent zooming out from the node, set canZoomOut value to false
.
# graph.zoomToNodeByIndex(index, [duration], [scale], [canZoomOut])
Center the view on the specified node (by its index) and zoom in with given animation duration and scale value. The default duration is 700 and the default scale is 3. To zoom in closer set a greater scale value. If the scale value is less than the current scale value, the view will be zoomed out. To prevent zooming out from the node, set canZoomOut value to false
.
# graph.setZoomLevel(value, [duration])
Zoom the view in or out to the specified zoom level value with given animation duration. The default duration is 0.
# graph.fitView(duration)
Center and zoom in/out the view to fit all nodes in the scene with given animation duration. The default duration is 250 ms.
# graph.fitViewByNodeIds(ids, [duration])
Center and zoom in/out the view to fit nodes by their ids in the scene with given animation duration. The default duration is 250 ms.
# graph.selectNodesInRange(selection)
Select nodes inside a rectangular area defined by two corner points [[left, top], [right, bottom]]
.
The left
and right
values should be from 0 to the width of the canvas in pixels.
The top
and bottom
values should be from 0 to the height of the canvas in pixels.
# graph.selectNodeById(id, [selectAdjacentNodes])
Select a node by id. If you want the adjacent nodes to get selected too, provide true
as the second argument.
# graph.selectNodeByIndex(index, [selectAdjacentNodes])
Select a node by index. If you want the adjacent nodes to get selected too, provide true
as the second argument.
# graph.selectNodesByIds(ids)
Select multiple nodes by an array of their ids.
# graph.selectNodesByIndices(indices)
Select multiple nodes by an array of their indices.
# graph.unselectNodes()
Unselect all nodes.
# graph.getSelectedNodes()
Get an array of currently selected nodes.
# graph.getAdjacentNodes(id)
Get nodes that are adjacent to a specific node by its id.
# graph.getNodeRadiusByIndex(index)
Get node radius by its index.
# graph.getNodeRadiusById(id)
Get node radius by its id.
# graph.trackNodePositionsByIds(ids)
Track multiple node positions by their ids on each Cosmos tick. Use the getTrackedNodePositionsMap method to get a Map
object with node coordinates.
# graph.trackNodePositionsByIndices(indices)
Track multiple node positions by their indices on each Cosmos tick. Use the getTrackedNodePositionsMap method to get a Map
object with node coordinates.
# graph.getTrackedNodePositionsMap()
If node positions are tracked, get a Map
object with node coordinates. The keys of the Map
are the ids of the nodes being tracked and the values are their X and Y coordinates in the [number, number]
format. Works in pairs with the trackNodePositionsByIds or trackNodePositionsByIndices method.
# graph.getSampledNodePositionsMap()
For the nodes that are currently visible on the screen, get a sample of node ids with their coordinates. The keys of the Map
are the ids of the nodes being tracked and the values are their X and Y coordinates in the [number, number]
format. The resulting number of nodes will depend on the nodeSamplingDistance
configuration property, and the sampled nodes will be evenly distributed.
# graph.setFocusedNodeById(id)
Focus on a node using its id. A ring will be highlighted around the node that is in focus. The default color of the ring is white, but it can be changed using the focusedNodeRingColor configuration.
# graph.setFocusedNodeByIndex(index)
Focus on a node using its index. A ring will be highlighted around the node that is in focus. The default color of the ring is white, but it can be changed using the focusedNodeRingColor configuration.
# graph.start([alpha])
Start the simulation. The alpha value can be from 0 to 1 (1 by default). The higher the value, the more initial energy the simulation will get.
# graph.pause()
Pause the simulation.
# graph.restart()
Restart the simulation.
# graph.step()
Render only one frame of the simulation. The simulation will be paused if it was active.
# graph.destroy()
Destroy this Cosmos instance.
# graph.getZoomLevel()
Get current zoom level of the view.
# graph.getNodePositions()
Get an object with node coordinates, where keys are the ids of the nodes and values are their X and Y coordinates in the { x: number; y: number }
format.
# graph.getNodePositionsMap()
Get a Map
object with node coordinates, where keys are the ids of the nodes and the values are their X and Y coordinates in the [number, number]
format.
# graph.getNodePositionsArray()
Get an array of [number, number]
arrays corresponding to the X and Y coordinates of the nodes.
# graph.spaceToScreenPosition(coordinates)
Converts the X and Y node coordinates in the [number, number]
format from the space coordinate system to the screen coordinate system.
# graph.spaceToScreenRadius(radius)
Converts the node radius value from the space coordinate system to the screen coordinate system.
# graph.isSimulationRunning
A boolean value showing whether the simulation is active or not.
# graph.maxPointSize
The maximum point size the user's hardware can render. This value is a limitation of the gl.POINTS
primitive of WebGL and differs from GPU to GPU.