Class: GraphEditor

ge.GraphEditor(svg, data, options)

Graph editor class.

Constructor

new GraphEditor(svg, data, options)

Graph editor constructor.
Parameters:
Name Type Description
svg SVGElement | Selector | D3Selection SVG element.
data ImportGraphData Graph data.
options GraphOptions Graph options.
Source:

Members

(readonly) bbox :BBox

Graph bounding box.
Type:
  • BBox
Source:

(readonly) container :D3Selection

Graph container element.
Type:
Source:

(readonly) data :GraphData

Graph data.
Type:
Source:

defaults :GraphOptions

Default options for all graph types.
Type:
Source:

(readonly) defs :D3Selection

Link text path elements.
Type:
Source:

(readonly) dispatch :D3Dispatch

Type:
Source:

(readonly) drag :D3Drag

Node drag behavior.
Type:
Source:

(readonly) dragLine :D3Selection

'Drag to link nodes' line.
Type:
Source:

(readonly) linkById :Object.<ID, Link>

Links by ID.
Type:
  • Object.<ID, Link>
Source:
Link elements.
Type:
Source:

(readonly) nodeById :Object.<ID, Node>

Nodes by ID.
Type:
  • Object.<ID, Node>
Source:

(readonly) nodes :D3Selection

Node elements.
Type:
Source:

(readonly) onresize :function

Window resize event handler.
Type:
  • function
Source:

(readonly) state :Object

Graph editor state.
Type:
  • Object
Properties:
Name Type Attributes Description
zoomed boolean False if the graph is clicked.
dragged boolean False if a node is clicked.
simulation D3Simulation <nullable>
Current simulation object.
simulationStarted boolean True if a simulation is started.
dragToLink boolean True in 'drag to link nodes' mode.
newLinkTarget Node <nullable>
New link target in 'drag to link nodes' mode.
selectedNode Node <nullable>
Selected node.
selectedLink Link <nullable>
Selected link.
dragPos Point <nullable>
Last drag end position.
zoom number Zoom level.
Source:

(readonly) svg :D3Selection

Graph SVG element.
Type:
Source:

(readonly) textSize :ge.TextSize

Text size calculator.
Type:
Source:

typeDefaults :Array.<GraphOptions>

Default options by graph type.
Type:
Source:

(readonly) zoom :D3Zoom

Graph zoom behavior.
Type:
Source:

Methods

(private) _remove(data, skipUpdateopt) → {boolean}

Remove a node or a link.
Parameters:
Name Type Attributes Default Description
data Reference Reference.
skipUpdate boolean <optional>
false Skip DOM update.
Source:
Returns:
False if object does not exist.
Type
boolean
Remove a link by index.
Parameters:
Name Type Description
idx number Link index.
Source:

add(data, skipUpdateopt)

Add one or multiple nodes/links.
Parameters:
Name Type Attributes Default Description
data ImportNodeData | ImportLinkData | Array.<(ImportNodeData|ImportLinkData)> Data.
skipUpdate boolean <optional>
false Skip DOM update.
Source:
Add a link if it does not exist.
Parameters:
Name Type Attributes Default Description
link ImportLinkData Link data.
skipUpdate boolean <optional>
false Skip DOM update.
Source:
Returns:
Added link.
Type
ge.Link
Add multiple links.
Parameters:
Name Type Attributes Default Description
links Array.<ImportLinkData> Link data.
skipUpdate boolean <optional>
false Skip DOM update.
Source:
Returns:
Added links.
Type
Array.<Link>

addNode(node, skipUpdateopt) → (nullable) {ge.Node}

Add a node if it does not exist.
Parameters:
Name Type Attributes Default Description
node ImportNodeData Node data.
skipUpdate boolean <optional>
false Skip DOM update.
Source:
Returns:
Added node.
Type
ge.Node

addNodes(nodes, skipUpdateopt)

Add multiple nodes.
Parameters:
Name Type Attributes Default Description
nodes Array.<ImportNodeData> Node data.
skipUpdate boolean <optional>
false Skip DOM update.
Source:

clear(clearDataopt) → {ge.GraphEditor}

Clear graph DOM.
Parameters:
Name Type Attributes Default Description
clearData boolean <optional>
true Clear graph data.
Source:
Fires:
Returns:
Type
ge.GraphEditor

(private) clickPosition(containeropt) → {Point}

Get mouse or touch coordinates relative to container.
Parameters:
Name Type Attributes Default Description
container HTMLElement | SVGElement <optional>
this.container.node()
Source:
See:
Returns:
Type
Point

destroy() → {ge.GraphEditor}

Destroy the graph.
Source:
Fires:
Returns:
Type
ge.GraphEditor

(private) dragEvents(drag) → {D3Drag}

Set node drag event handlers.
Parameters:
Name Type Description
drag D3Drag Node drag behavior.
Source:
Fires:
Returns:
Type
D3Drag
Return true if 'drag to link nodes' is enabled.
Source:
Returns:
Type
boolean
Set 'drag to link nodes' state.
Parameters:
Name Type Attributes Description
on boolean | string <optional>
state | 'toggle'
Source:
Returns:
Type
ge.GraphEditor

getData(elnullable) → (nullable) {Node|Link}

Get node/link data.
Parameters:
Name Type Attributes Description
el Reference <nullable>
Source:
Returns:
Type
Node | Link

getElement(elnullable) → (nullable) {D3Selection}

Get node/link SVG element.
Parameters:
Name Type Attributes Description
el Reference <nullable>
Source:
Returns:
Type
D3Selection

(private) initData(data) → {ge.GraphEditor}

Initialize graph data.
This:
Parameters:
Name Type Description
data ImportGraphData
Source:
Returns:
Type
ge.GraphEditor

(private) initMarkers(svg) → {ge.GraphEditor}

Create SVG markers.
Parameters:
Name Type Description
svg D3Selection
Source:
Returns:
Type
ge.GraphEditor

(private) initOptions(options, svg) → {ge.GraphEditor}

Initialize graph options.
Parameters:
Name Type Description
options GraphOptions
svg D3Selection
Source:
Returns:
Type
ge.GraphEditor

(private) initState() → {ge.GraphEditor}

Initialize graph state.
This:
Source:
Returns:
Type
ge.GraphEditor

(private) initSvg(svg) → {ge.GraphEditor}

Initialize SVG element.
This:
Parameters:
Name Type Description
svg D3Selection
Source:
Returns:
Type
ge.GraphEditor

(private) isLinkData(data) → {boolean}

Return true if object is a link.
Parameters:
Name Type Description
data Object
Source:
Returns:
Type
boolean

(private) linkEvents(links) → {D3Selection}

Set link event handlers.
Parameters:
Name Type Description
links D3Selection
Source:
Fires:
Returns:
Type
D3Selection

(private) linkId(source, target) → {ID}

Get link ID.
Parameters:
Name Type Description
source ge.Node Link source.
target ge.Node Link target.
Source:
Returns:
Type
ID

(private) nodeEvents(nodes) → {D3Selection}

Set node event handlers.
Parameters:
Name Type Description
nodes D3Selection
Source:
Returns:
Type
D3Selection

(private) nodeId() → {ID}

Get unused node ID.
Source:
Returns:
Type
ID

on(event, handlernullable) → {ge.GraphEditor}

Add an event handler.
Parameters:
Name Type Attributes Description
event string
handler function <nullable>
Source:
See:
Returns:
Type
ge.GraphEditor

redraw() → {ge.GraphEditor}

Regenerate graph DOM.
Source:
Fires:
Returns:
Type
ge.GraphEditor

remove(data, skipUpdateopt)

Remove one or multiple nodes/links.
Parameters:
Name Type Attributes Default Description
data Reference | Array.<Reference> References.
skipUpdate boolean <optional>
false Skip DOM update.
Source:
Remove a link.
Parameters:
Name Type Attributes Default Description
data Reference Link.
skipUpdate boolean <optional>
false Skip DOM update.
Source:
Returns:
False if link does not exist.
Type
boolean

removeNode(data, skipUpdateopt) → {boolean}

Remove a node.
Parameters:
Name Type Attributes Default Description
data Reference Node.
skipUpdate boolean <optional>
false Skip DOM update.
Source:
Returns:
False if node does not exist.
Type
boolean

resized() → {ge.GraphEditor}

Handle graph SVG element resize.
Source:
Returns:
Type
ge.GraphEditor

select(dataopt, nullable, updateopt) → {ge.GraphEditor}

Select a node or a link.
Parameters:
Name Type Attributes Default Description
data Reference <optional>
<nullable>
Node or link to select.
update boolean <optional>
false Update DOM if the node/link is already selected.
Source:
Returns:
Type
ge.GraphEditor

select() → {Selection}

Return selected node/link.
Source:
Returns:
Type
Selection
Selected a link.
Parameters:
Name Type Attributes Default Description
link Reference <optional>
<nullable>
Link to select.
update boolean <optional>
false Update DOM if the link is already selected.
Source:
Returns:
Type
ge.GraphEditor
Return selected link.
Source:
Returns:
Type
Link

selectNode(nodeopt, nullable, updateopt) → {ge.GraphEditor}

Select a node.
Parameters:
Name Type Attributes Default Description
node Reference <optional>
<nullable>
Node to select.
update boolean <optional>
false Update DOM if the node is already selected.
Source:
Returns:
Type
ge.GraphEditor

selectNode() → (nullable) {Node}

Return selected node.
Source:
Returns:
Type
Node

simulation(onopt) → {boolean|ge.GraphEditor}

Set or return force simulation state.
Parameters:
Name Type Attributes Description
on boolean | string <optional>
state | 'start' | 'stop' | 'restart' | 'toggle'
Source:
Fires:
Returns:
Type
boolean | ge.GraphEditor

startSimulation(stopOnEndopt) → {ge.GraphEditor}

Start force simulation.
Parameters:
Name Type Attributes Default Description
stopOnEnd boolean <optional>
this.options.simulation.stop Stop the simulation when it converges.
Source:
Fires:
Returns:
Type
ge.GraphEditor

stopSimulation() → {ge.GraphEditor}

Stop force simulation.
Source:
Fires:
Returns:
Type
ge.GraphEditor

toJson() → {ExportGraphData}

Convert to JSON.
Source:
Returns:
Type
ExportGraphData

(private) touchedNode() → (nullable) {Node}

Get touched node.
Source:
See:
Returns:
Type
Node

(private) transition(selection, type, name) → {ge.GraphEditor}

Create a transition if necessary.
Parameters:
Name Type Description
selection D3Selection
type string duration = options.transition[type]
name string
Source:
See:
Returns:
Type
ge.GraphEditor

update(simulationopt) → {ge.GraphEditor}

Update everything.
Parameters:
Name Type Attributes Default Description
simulation boolean <optional>
false True if called from the simulation tick handler.
Source:
Returns:
Type
ge.GraphEditor

(private) updateBBox(nodeopt) → {ge.GraphEditor}

Update bounding box.
Parameters:
Name Type Attributes Description
node Node <optional>
Moved node.
Source:
Returns:
Type
ge.GraphEditor

(private) updateExtent() → {ge.GraphEditor}

Update zoom behavior extent.
Source:
Returns:
Type
ge.GraphEditor
Update a link.
Parameters:
Name Type Description
link Reference Changed link.
Source:
Returns:
Type
ge.GraphEditor

updateNode(node) → {ge.GraphEditor}

Update a node. If it was moved or resized, update its links.
Parameters:
Name Type Description
node Reference Changed node.
Source:
Returns:
Type
ge.GraphEditor

(private) updateSimulation() → {ge.GraphEditor}

Update force simulation.
Source:
Returns:
Type
ge.GraphEditor

(private) zoomEvents(zoom) → {D3Zoom}

Set zoom event handlers.
Parameters:
Name Type Description
zoom D3Zoom Graph zoom behavior.
Source:
Fires:
Returns:
Type
D3Zoom