graph-visualizer
v0.10.12
Published
discover nodes and edges in a flexible way
Downloads
29
Readme
Graph visualizer
Displays the nodes and edges from a dataset that the user can specify. Meant to be integrated in other applications.
Live demo
https://afasresearch.github.io/graph-visualizer/
Embedding
When loaded, this library exposes a <graph-visualizer>
(GraphVisualizerElement
) custom element. it has the following attributes:
data-url
: url which can be fetched that will retrieve json in theGraphData
format describing all nodes and edgesdata-variable
: global variable stored on window that containsGraphData
, alternative ofdata-url
local-storage-key
: when specified, the library stores its state in localstorage under this keyedges-to-highlight
: a space separated string consisting of keys from edges that should be highlightednodes-to-highlight
: a space separated string consisting of keys from nodes that should be highlighted
It also has the following properties:
data
: can be used to programmatically set theGraphData
for the graph to render. Two things are important:- All arrays, maps and objects in
GraphData
are considered immutable once they have been set on the component. Making changes to these objects will cause problems. - Reuse as many arrays, maps and objects from previous
GraphData
as possible for optimal performance.
Changing a location programmatically can therefore be best achieved using the following code:
- All arrays, maps and objects in
let data = { ...graphVisualizerElement.data, positions: [...graphVisualizerElement.data.positions] };
data.positions[2] = { nodeKey: 'a', x: 0, y: 0 }; // modifications are still allowed, because data.positions is a new array
graphVisualizerElement.data = data;
It fires the following events:
navigate
: will be called when the user clicks on the arrow of a node to navigate to its detailsselectionchange
: will be used to notify that the user changed the selected nodepositionschange
: used to inform that the user modified/deleted/cleared the positions of one of the nodes. Detail is aPositionsChange
type
Custom styling
Attributes can be placed on nodes, like typename=Event. These can be picked up in css using the following construct
graph-visualizer::part(typename\=Event) {
--color-primary:blue;
}
Which causes the primary color to change. variables used are --color-background
, --color-primary
and --color-secondary
.
Internals
Algorithm: pure function executed on every render:
input (API): NodeData + VisualizationEntry
- config = NodeModel
nodeRenderers provide Dimensions to NodeModels
EdgeData is queried to determine visible edges, create EdgeLayouts
Render:
- EdgeLayouts line
- NodeLayouts
- EdgeLayouts decoration
'Session' state:
- zoom, transform
- selected node
Future plans / niceties
- Gray out existing nodes, center on click
- hover for long names in sidebar
- Dark mode
- Touch support