Simple tool to quickly build an SVG grid/graph using method chaining.
const graph = Graph.newGraph('root');
graph.width(250).height(250);
graph.gridSize(10,10);
graph.drawAxes()
graph.build();
Alternatively, you could have built the whole thing using one string of methods:
graph.width(250).height(250).gridSize(10,10).buildGrid().drawAxes();
You can also use the following functions:
graph.appendSingleLine(attrs);
graph.appendPath(attrs);
The attrs
parameter is an object that contains key-value pairs of all the attributes you want to pass in. For example,
const attrs = {
d: 'M0 50 H 250',
stroke:'red',
'stroke-width': 2
};
graph.appendPath(attrs);
will result in,
Notice that you need to wrap quotes around attribute properties that have hyphens in their name.
It's very minimal right now, but it's a nice way to see how easy it is to use method chaining to add SVG elements to the DOM.