// data
var network = 'dinetwork { ';
// This attribute applies to the graph itself
network += 'size="1,1";';
// The label attribute can be used to change the label of a node
network += 'a [label="should i stop \n working on this project \n or not?"];';
network += 'a [shape="text"];';
// Here, the node shape is changed.
network += 'b [shape=diamond];';
network += 'b [label=decision];';
// These edges both have different line properties
network += 'a -- b -- c [color=blue];';
network += 'b -> d [style=dotted]; }';
// provide data in the DOT language
var DOTstring = 'dinetwork {1 -> 1 -> 2; 2 -> 3; 2 -- 4; 2 -> 1 }';
var parsedData = vis.network.convertDot(network);
var data = {
nodes: parsedData.nodes,
edges: parsedData.edges
}
console.log(data);
var options = parsedData.options;
// you can extend the options like a normal JSON variable:
options.nodes = {
}
// create a network
var network = new vis.Network(document.getElementById('container'), data, options);
network.on("beforeDrawing", function (ctx) {
var nodeId = 'a';
console.log(network.getPositions([nodeId]));
var nodePosition = network.getPositions([nodeId]);
ctx.beginPath();
console.log(this.width);
var x = nodePosition[nodeId].x;
var y = nodePosition[nodeId].y;
var b = network.getBoundingBox(nodeId);
ctx.moveTo(b.left - 20, y);
ctx.lineTo(x , b.bottom + 30);
ctx.lineTo(b.right + 20, y);
ctx.lineTo(x, b.top - 30);
//Define the style of the shape
ctx.lineWidth = 1;
ctx.fillStyle = "rgb(102, 204, 0)";
ctx.strokeStyle = "rgb(0, 50, 200)";
//Close the path
ctx.closePath();
//Fill the path with ourline and color
ctx.fill();
ctx.stroke();
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.