greuler v1.0.0-alpha2
greuler
greuler is graph theory visualization tool powered by d3 and on top of WebCola which allows the creation and manipulation of graphs with a simple api
Installation
npm install greuleror
<script src="TODO"></script>Usage
var greuler = require('greuler')
greuler({
// options below
})Examples
Check out the examples at the homepage
Usage Notes
- The
dataproperty of the configuration option sent to greuler maps all the properties to calls to methods of WebCola
// e.g.
greuler({
// ...
data: {
linkDistance: 100,
avoidOverlaps: true,
nodes: [...],
links: [...],
groups: [...],
}
})
// is mapped to
cola.d3Adaptor()
.linkDistance(data.linkDistance)
.avoidOverlaps(data.avoidOverlaps)
.nodes(data.nodes)
.links(data.links)
// ...- layout methods that receive multiple arguments are sent in data in an array form
e.g. layout.flowLayout('y', 50)
data: {
// ...
symmetricDiffLinkLengths: ['y', 50]
}On runtime, you can add/remove/update the properties through instance.options.data, make sure you don't modify
instance.options.data.nodes or instance.options.data.links to avoid layout errors, after all this is the job of
instance.graph.* methods :)
- The layout adaptor instance can be accessed through
instance.layout - To make the nodes have a fixed position listen for the
firstLayoutEndevent and add thefixedproperty to each one of the nodes you want to be fixed e.g.
instance.events.on('firstLayoutEnd', function () {
instance.graph.nodes.forEach(function (d) {
d.fixed = true
})
});- Custom animations can easily be created, for any of the values returned from
instance.graph.*callinstance.selector.selectand you obtain the group that represents the node/edge e.g.
var nodes = instance.graph.getNodesByFn(function (node) {
return node.id > 5;
});
// a selection of <g> tags
var selection = instance.selection.select(nodes);API
import greuler from 'greuler'instance = greuler(options)
params
The smallest program consists of call to greuler with an object with two properties
options.target: The container to hold the graphoptions.data: The data that contains the description of the graph, all the properties are mapped to calls to methods of the layout program, check WebCola's documentation for a full overview of the layout options
The required properties of data are:
nodes=[]An array of objects, each object describes the properties of a nodenode.id(required) Theidof the node, the mapping of the endpoints of an edge is done by idnode.x=undefinedThexposition in the graph of this nodenode.y=undefinedTheyposition in the graph of this nodenode.fixed=falseTrue to keep this node in a fixed position after it was dragged, (style properties)node.fillThe fill of the circle representing a nodenode.rThe radius of the circle representing a nodenode.label=''Label to be shown inside the node, theidis shown by defaultnode.topRightLabel=''Label to be shown on the top right of the node, useful for additional annotations
links=[]An array of objects, each object describes the properties of an edgelink.sourceThe id of the source nodelink.targetThe id of the target node (style properties)link.directed=falseTrue to make the edge directed
Additional options
options.width=700Width of the graphoptions.height=300Height of the graphoptions.directed=falseTrue to make the graph directedoptions.animationTime=1000Time in ms used for the transitions done withinstance.selector.*options.labels=trueFalse to hide the labels on the nodes
returns
A greuler instance used to interact with the graph
instance.events
All the events are exposed through this object
events
firstLayoutEndfired when the initial layout has finished, it's fired only once
instance.update([options])
params
options={}options.skipLayout=falseTrue to skip layout and only bind the data to the svg elements (a layout operations needs to be done only when nodes/edges are added/removed to the graph, any other operation that modifies existing properties of the nodes/edges don't need a layout)options.iterations=[]The number of iterations run by WebCola see layout.start
instance.graph
Check out the Graph class
instance.selector
Check out the Selector class
greuler.colors
An object containing the predefined palette used in greuler which is built with d3.scale.category20()
e.g.
greuler.colors.RED
greuler.colors.BLUE
greuler.colors.LIGHT_GREENLicense
2021 MIT © Mauricio Poppe
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago