提交 fe4e2d03 authored 作者: Christof Angermueller's avatar Christof Angermueller

Add context menu and javascript libs

上级 aa62fad6
.d3-context-menu {
position: absolute;
display: none;
background-color: #f2f2f2;
border-radius: 4px;
font-family: Arial, sans-serif;
font-size: 14px;
min-width: 50px;
border: 1px solid #d4d4d4;
z-index:1200;
}
.d3-context-menu ul {
list-style-type: none;
margin: 4px 0px;
padding: 0px;
cursor: default;
}
.d3-context-menu ul li {
padding: 4px 16px;
}
.d3-context-menu ul li:hover {
background-color: #4677f8;
color: #fefefe;
}
d3.contextMenu = function (menu, openCallback) {
// create the div element that will hold the context menu
d3.selectAll('.d3-context-menu').data([1])
.enter()
.append('div')
.attr('class', 'd3-context-menu');
// close menu
d3.select('body').on('click.d3-context-menu', function() {
d3.select('.d3-context-menu').style('display', 'none');
});
// this gets executed when a contextmenu event occurs
return function(data, index) {
var elm = this;
d3.selectAll('.d3-context-menu').html('');
var list = d3.selectAll('.d3-context-menu').append('ul');
list.selectAll('li').data(menu).enter()
.append('li')
.html(function(d) {
return d.title;
})
.on('click', function(d, i) {
d.action(elm, data, index);
d3.select('.d3-context-menu').style('display', 'none');
});
// the openCallback allows an action to fire before the menu is displayed
// an example usage would be closing a tooltip
if (openCallback) openCallback(data, index);
// display context menu
d3.select('.d3-context-menu')
.style('left', (d3.event.pageX - 2) + 'px')
.style('top', (d3.event.pageY - 2) + 'px')
.style('display', 'block');
d3.event.preventDefault();
};
};
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<script type='text/javascript' src="http://cpettitt.github.io/project/dagre-d3/v0.1.5/dagre-d3.min.js"></script>
<script type='text/javascript' src="http://cpettitt.github.io/project/graphlib-dot/v0.4.10/graphlib-dot.min.js"></script>
<link rel="stylesheet" href="d3-context-menu.css" />
<script src="d3-context-menu.js"></script>
</head>
<body>
<style>
svg {
margin-left:auto;
margin-right:auto;
display:block;
position: fixed;
border: 0px solid black;
top:5%; left:0%; right:0% bottom=10%
}
.nodeRect {
stroke: black;
border: 3px solid black;
}
.nodeEllipse {
stroke: black;
border: 3px solid black;
}
.nodeText {
color: black;
}
.edge {
stroke-width: 3px;
cursor: pointer;
opacity: 0.4;
}
.edgeLabelRect {
stroke: black;
border: 1px solid black;
fill: skyblue;
opacity: 0.9;
}
.edgeLabelText {
fill: black;
text-anchor: start;
}
.arrowHead {
stroke: green;
stroke-width: 1px;
}
.arrowHead_n {
stroke: green;
}
.arrowHead_r {
stroke-width: 3px;
fill: red;
stroke: red;
}
.arrowHead_b {
stroke: dodgerblue;
}
.edgeTooltip {
position: absolute;
text-align: center;
vertical-align: middle;
min-width: 10px;
min-height: 10px;
padding: 5px;
background: lightsteelblue;
border: 1px solid black;
border-radius: 8px;
pointer-events: none;
}
.nodeTooltip {
position: absolute;
text-align: left;
vertical-align: middle;
min-width: 10px;
min-height: 10px;
padding: 5px;
background: lightsteelblue;
border: 1px solid black;
border-radius: 8px;
pointer-events: none;
}
</style>
<div id='menu'>
<input name="resetNodes"
type="button"
value="Reset nodes"
onclick="resetNodes()"/>
<input name="releaseNodes"
type="button"
value="Release nodes"
onclick="releaseNodes()"/>
</div>
<script type="text/javascript">
var path='predict_unprofiled.dot'; // '%% DOT_FILE %%'
var isProfiled = false;
var colorProfile = false;
var maxProfilePer = 0;
var profileColors = ["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15"];
// Global attributes
var pad = 10;
d3.select('body').select('svg').remove();
var svg = d3.select('body').append('svg')
.attr('width', '100%')
.attr('height', '95%');
var pane = svg.append('g');
var edgeDiv = d3.select('body').append('div')
.attr('class', 'edgeTooltip')
.style('opacity', 0.0);
var nodeDiv = d3.select('body').append('div')
.attr('class', 'nodeTooltip')
.style('opacity', 0.0);
// Definition head of edges
var markerData = [
{'id': 'n', 'color': 'black'},
{'id': 'r', 'color': 'red'},
{'id': 'b', 'color': 'dodgerblue'}];
svg.append("defs").selectAll('marker').data(markerData).enter().append("marker")
.attr("id", function(d) { return 'edgeArrow_' + d.id;})
.attr("markerWidth", 4)
.attr("markerHeight", 4)
.attr("refX", 2)
.attr("refY", 2)
.attr("orient", "auto")
.append("path")
.attr("d", "M0,0 L4,2 L0,4 Z")
.attr('fill', function(d) { return d.color;});
function toggleColors() {
colorProfile = !colorProfile;
updateNodes();
updateGraph();
}
function textSize(text, attr) {
var t = svg.append('text').text(text);
if (typeof(attr) != 'undefined') {
for (a in attr) {
t.attr(a, attr[a]);
}
}
var bbox = t.node().getBBox();
t.remove();
return bbox;
}
function exists(x) {
return typeof(x) != 'undefined';
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}
function parseProfile(profile) {
if (typeof(profile) == 'undefined') {
return [];
}
profile = profile.replace('[', '');
profile = profile.replace(']', '');
profile = replaceAll(profile, ' ', '');
profile = profile.split(',');
if (profile.length < 2) {
return [];
}
profile = profile.map(function(x) { return parseFloat(x); });
return profile;
}
function linspace(start, end, len) {
var d = (end - start) / (len - 1);
var rv = [start];
for (i = 1; i < len; ++i) {
rv.push(rv[i - 1] + d);
}
return rv;
}
function profileColor(per) {
var s = d3.scale.linear()
.domain(linspace(0, maxProfilePer, profileColors.length))
.range(profileColors)
.interpolate(d3.interpolateRgb);
return s(per);
}
function fillColor(d) {
if (colorProfile && d.value.profile.length) {
if (d.value.shape == 'ellipse') {
return profileColor(d.value.profile[0] / d.value.profile[1]);
} else {
return 'white';
}
} else {
return typeof(d.value.fillcolor) == 'undefined' ? 'white' : d.value.fillcolor;
}
}
function formatTime(sec) {
var s;
if (sec < 0.1) {
s = (sec * 1000).toFixed(1) + 'ms';
} else {
s = sec.toFixed(1) + 's';
}
return s;
}
function nodeDetails(node) {
var s = '<b>' + node.value.label + '</b>';
var p = node.value.profile;
if (p.length) {
s += '<br>Time: ' + formatTime(p[0]);
s += '<br>Time: ' + (p[0] / p[1] * 100).toFixed(1) + '%';
}
return s;
}
function updateNode(d, node) {
var shape;
if (d.value.shape == 'ellipse') {
node.selectAll('ellipse').remove();
shape = node.append('ellipse')
.attr('class', 'nodeEllipse')
.attr('cx', d.value.cx)
.attr('cy', d.value.cy)
.attr('rx', d.value.width * 0.6)
.attr('ry', d.value.height * 0.6);
} else {
node.selectAll('rect').remove();
shape = node.append('rect')
.attr('class', 'nodeRect')
.attr('width', d.value.width)
.attr('height', d.value.height);
}
shape.attr('fill', fillColor(d));
node.selectAll('text').remove();
var text = node.append('text')
.attr('class', 'nodeText')
.attr('x', pad)
.attr('dy', function(d) {return d.value.height - pad - 5;})
.text(function(d) {return d.value.label;});
}
function updateNodes() {
nodes.each(function(d) {var node = d3.select(this); updateNode(d, node);});
}
function hideNodeDiv() {
nodeDiv.transition()
.duration(200)
.style('opacity', 0);
}
function setNodeSize(node) {
var size = textSize(node.value.label, {'class': 'nodeText'});
node.value.width = size.width + 2 * pad;
node.value.height = size.height + 2 * pad;
node.value.cx = node.value.width / 2;
node.value.cy = node.value.height / 2;
}
var isEditNode = false;
function editNode(elm, d) {
var node = d3.select(elm);
var pos = elm.getBBox();
if (d3.event.defaultPrevented) return;
isEditNode = true;
hideNodeDiv();
var form = node.append('foreignObject')
.attr('x', pos.x)
.attr('y', pos.y)
.attr('width', d.value.width)
.attr('height', 25);
var input = form.append('xhtml:form').append('input')
.attr('style', 'width: ' + d.value.width + 'px')
.attr('value', function() {
this.focus();
return d.value.label;
})
.on('blur', function() {
d.value.label = input.node().value;
setNodeSize(d);
updateNode(d, node);
form.remove(); // TODO: check this
isEditNode = false;
})
.on('keypress', function() {
if (!d3.event) {
d3.event = window.event;
}
var event = d3.event;
if (event.keyCode == 13) {
if (typeof(event.cancelBubble)) {
event.cancelBubble = true;
}
if (event.stopPropagation) {
event.stopPropagation();
}
event.preventDefault();
d.value.label = input.node().value;
setNodeSize(d);
updateNode(d, node);
form.remove(); // TODO: check this
isEditNode = false;
}
});
}
function releaseNode(d) {
d.fixed = false;
layout.start();
}
function releaseNodes() {
graph['nodes'].forEach (function (d) {
d.fixed = false;
});
layout.start();
}
function resetNodes() {
layout.stop();
var nodes = graph['nodes'];
nodes.forEach(function (node, i){
nodes[i].x = scaleDotX(node.value.pos[0]);
nodes[i].y = scaleDotY(dotHeight - (node.value.pos[1] + node.value.height));
nodes[i].px = nodes[i].x;
nodes[i].py = nodes[i].y;
nodes[i].fixed = true;
});
updateGraph();
layout.start();
}
var menuItems = [
{
title: 'Edit',
action: function(elm, d, i) {
editNode(elm, d);
}
},
{
title: 'Release',
action: function(elm, d, i) {
releaseNode(d);
}
}
];
var dotGraph;
var graph = {};
var nodes = [];
var edges = [];
var layout;
var scaleDotX;
var scaleDotY;
d3.text(path, function(data) {
dotGraph = graphlibDot.parse(data);
// Calculate width and height
var posMax = [0, 0];
for (var nodeId in dotGraph._nodes) {
var node = dotGraph._nodes[nodeId];
node.value.label = node.id;
node.value.pos = node.value.pos.split(',').map(function(d) {return parseInt(d);});
node.value.width = parseInt(node.value.width);
node.value.height = parseInt(node.value.height);
posMax[0] = Math.max(posMax[0], node.value.pos[0] + node.value.width);
posMax[1] = Math.max(posMax[1], node.value.pos[1] + node.value.height);
}
dotWidth = posMax[0];
dotHeight = posMax[1];
//svg.attr('viewBox', '0,0,' + dotWidth + ',' + dotHeight);
scaleDotX = d3.scale.linear().domain([0, dotWidth]).range([20, dotWidth * 1.2]);
scaleDotY = d3.scale.linear().domain([0, dotHeight]).range([20, dotHeight * 1.2]);
// Parse nodes
var i = 0;
for (nodeId in dotGraph._nodes) {
var node = dotGraph._nodes[nodeId];
node.index = i++;
// x, y is center of node (not corner)
node.x = scaleDotX(node.value.pos[0]);
node.y = scaleDotY(dotHeight - (node.value.pos[1] + node.value.height));
var size = textSize(node.value.label, {'class': 'nodeText'});
node.value.width = size.width + 2 * pad;
node.value.height = size.height + 2 * pad;
node.value.cx = node.value.width / 2;
node.value.cy = node.value.height / 2;
node.value.profile = parseProfile(node.value.profile);
if (node.value.profile.length) {
isProfiled = true;
}
node.fixed = true;
nodes.push(node);
dotGraph._nodes[nodeId] = node;
}
if (isProfiled) {
d3.select('body').select('#menu').append('input')
.attr('name', 'tColors')
.attr('type', 'button')
.attr('value', 'Toggle profile colors')
.attr('onclick', "toggleColors()");
maxProfilePer = 0;
for (i in nodes) {
var p = nodes[i].value.profile;
if (p.length) {
maxProfilePer = Math.max(maxProfilePer, p[0] / p[1]);
}
}
}
// Parse edges
for (edgeId in dotGraph._edges) {
var edge = dotGraph._edges[edgeId];
edge.source = dotGraph._nodes[edge.u].index;
edge.target = dotGraph._nodes[edge.v].index;
var size = textSize(edge.value.label, {'class': 'edgeLabelText'});
edge.value.width = size.width + 2 * pad;
edge.value.height = size.height + 2 * pad;
if (!exists(edge.value.color)) {
edge.value.color = 'black';
}
switch (edge.value.color) {
case 'dodgerblue':
edge.value.type = 'b';
break;
case 'red':
edge.value.type = 'r';
break;
default:
edge.value.type = 'n';
}
edges.push(edge);
dotGraph._edges[edgeId] = edge;
}
// Setup graph
graph['nodes'] = nodes;
graph['edges'] = edges;
var isEdgeOver = false;
var isEdgeLabelOver = false;
// Add edges
edges = pane.append('g').attr('id', 'edges').selectAll('path').data(graph['edges']).enter().append('path')
.attr('class', 'edge')
.attr('stroke', function(d) {return d.value.color;})
.attr('marker-mid', function(d) { return 'url(#edgeArrow_' + d.value.type + ')';})
.on('mouseover', function(d) {
var edge = d3.select(this);
edge.transition()
.duration(200)
.style('opacity', 1.0);
edgeDiv.transition()
.duration(200)
.style('opacity', .9);
edgeDiv
.html(d.value.label)
.style('left', (d3.event.pageX) + 'px')
.style('top', (d3.event.pageY - 28) + 'px');
})
.on('mouseout', function(d) {
var edge = d3.select(this);
edge.transition()
.duration(200)
.style('opacity', 0.4);
edgeDiv.transition()
.duration(200)
.style('opacity', 0);
});
// Add nodes
nodes = pane.append('g').attr('id', 'nodes').selectAll('g').data(graph['nodes']).enter().append('g');
updateNodes();
nodes.on('dblclick', function(d) {editNode(this, d);});
nodes.on('mouseover', function(node) {
if (isEditNode || typeof(node.value.profile) == 'undefined') {
return;
}
edges.each(function (d, i) {
var edge = d3.select(this);
if (d.source == node || d.target == node) {
edge.transition()
.duration(200)
.style('opacity', 1.0);
}
});
nodeDiv.transition()
.duration(200)
.style('opacity', .9);
nodeDiv
.html(nodeDetails(node))
.style('left', (d3.event.pageX) + 30 + 'px')
.style('top', (d3.event.pageY - 28) + 'px');
});
nodes.on('mouseout', function(node) {
edges.each(function (d, i) {
var edge = d3.select(this);
if (d.source.index == node.index || d.target.index == node.index) {
edge.transition()
.duration(200)
.style('opacity', 0.4);
}
});
hideNodeDiv();
});
nodes.on('contextmenu', d3.contextMenu(menuItems));
// Zoom and translate event handler
function zoom(d) {
pane.attr('transform', 'translate(' + d3.event.translate + ') scale(' + d3.event.scale + ')');
}
// Force layout
layout = d3.layout.force()
.nodes(graph['nodes'])
.links(graph['edges'])
.size([dotWidth, dotHeight])
.charge(-3000)
.linkDistance(50)
.linkStrength(0.1)
.on('tick', updateGraph);
// Drag behavour
var drag = layout.drag()
.on('dragstart', function(d) {
d3.event.sourceEvent.stopPropagation();
d3.event.sourceEvent.preventDefault();
d.fixed = true;
});
nodes.call(drag);
// Zoom behaviour
var bZoom = d3.behavior.zoom()
.scaleExtent([0.2, 8])
//.on("dblclick.zoom", null)
.on('zoom', zoom);
svg.call(bZoom);
svg.on("dblclick.zoom", null);
// Start force layout
layout.start();
});
function length(x1, y1, x2, y2) {
return Math.sqrt(Math.pow(x1-x2, 2) + Math.pow(y1-y2, 2));
}
function pathPos(x1, y1, x2, y2, c) {
x = (1 - c) * x1 + c * x2;
y = (1 - c) * y1 + c * y2;
p = x + ',' + y;
return p;
}
// Update graph
function updateGraph() {
// Update nodes
nodes.attr('transform', function(d) { return 'translate(' + (d.x - d.value.cx) + ' ' + (d.y - d.value.cy) + ')'; });
// Update edges
edges.attr('d', function(d) {
var dist = 100;
var l = length(d.source.x, d.source.y, d.target.x, d.target.y);
var n = Math.max(2, Math.floor(l / dist));
var marker = [];
for (var i = 1; i < n; ++i) {
marker.push(i / n);
}
var markerPos = marker.map(function(c) {return pathPos(d.source.x, d.source.y, d.target.x, d.target.y, c);});
var markerPos = ' L' + markerPos.join(' L');
return 'M' + d.source.x + ',' + d.source.y + markerPos + ' L' + d.target.x + ',' + d.target.y;
});
}
</script>
</body>
</html>
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Couldn't import dot_parser, loading of dot files will not be possible.\n"
]
}
],
"source": [
"import numpy\n",
"import numpy.random as rng\n",
"import theano\n",
"import theano.tensor as T\n",
"import theano.printing as pr\n",
"import theano.d3printing as d3p\n",
"from theano.d3printing.formatting import GraphFormatter\n",
"from theano import ProfileMode\n",
"\n",
"from IPython.display import SVG"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Model "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"nsamples = 10000\n",
"ninput = 100\n",
"nhidden = 50\n",
"noutput = 1\n",
"\n",
"def init_params(m, n):\n",
" W = np.random.normal(0, 1, (m, n)).astype(theano.config.floatX)\n",
" return theano.shared(W, borrow=True)\n",
"\n",
"W1 = init_params(ninput, nhidden)\n",
"W2 = init_params(nhidden, noutput)\n",
"X = T.dmatrix('X')\n",
"\n",
"H = T.nnet.sigmoid(T.dot(X, W1))\n",
"Z = T.nnet.sigmoid(T.dot(H, W2))\n",
"zm = T.mean(Z)\n",
"\n",
"predict_profiled = theano.function([X], [Z, zm], profile=True)\n",
"data = rng.rand(nsamples, ninput)\n",
"dZ, dzm = predict_profiled(data)\n",
"\n",
"predict_unprofiled = theano.function([X], [Z, zm], profile=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Timining information via debugpring "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Timing Info\n",
"-----------\n",
"--> <time> <% time> - <total time> <% total time>'\n",
"\n",
"<time> computation time for this node\n",
"<% time> fraction of total computation time for this node\n",
"<total time> time for this node + total times for this node's ancestors\n",
"<% total time> total time for this node over total computation time\n",
"\n",
"N.B.:\n",
"* Times include the node time and the function overhead.\n",
"* <total time> and <% total time> may over-count computation times\n",
" if inputs to a node share a common ancestor and should be viewed as a\n",
" loose upper bound. Their intended use is to help rule out potential nodes\n",
" to remove when optimizing a graph because their <total time> is very low.\n",
"\n",
"Elemwise{ScalarSigmoid}[(0, 0)] [@A] '' 9 --> 1.16e-04s 0.9% 1.21e-02s 95.4%\n",
" |Dot22 [@B] '' 6 --> 9.38e-04s 7.4% 1.20e-02s 94.5%\n",
" |Elemwise{ScalarSigmoid}[(0, 0)] [@C] '' 4 --> 4.59e-03s 36.1% 1.11e-02s 87.1%\n",
" | |Dot22 [@D] '' 2 --> 6.48e-03s 51.0% 6.48e-03s 51.0%\n",
" | |X [@E]\n",
" | |<TensorType(float64, matrix)> [@F]\n",
" |<TensorType(float64, matrix)> [@G]\n",
"\n",
"Timing Info\n",
"-----------\n",
"--> <time> <% time> - <total time> <% total time>'\n",
"\n",
"<time> computation time for this node\n",
"<% time> fraction of total computation time for this node\n",
"<total time> time for this node + total times for this node's ancestors\n",
"<% total time> total time for this node over total computation time\n",
"\n",
"N.B.:\n",
"* Times include the node time and the function overhead.\n",
"* <total time> and <% total time> may over-count computation times\n",
" if inputs to a node share a common ancestor and should be viewed as a\n",
" loose upper bound. Their intended use is to help rule out potential nodes\n",
" to remove when optimizing a graph because their <total time> is very low.\n",
"\n",
"Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] [@H] '' 11 --> 9.54e-07s 0.0% 1.22e-02s 95.8%\n",
" |Sum{acc_dtype=float64} [@I] '' 10 --> 1.50e-05s 0.1% 1.21e-02s 95.5%\n",
" | |Elemwise{ScalarSigmoid}[(0, 0)] [@A] '' 9 --> 1.16e-04s 0.9% 1.21e-02s 95.4%\n",
" |Subtensor{int64} [@J] '' 8 --> 3.10e-06s 0.0% 1.48e-05s 0.1%\n",
" | |Elemwise{Cast{float64}} [@K] '' 5 --> 3.81e-06s 0.0% 1.17e-05s 0.1%\n",
" | | |MakeVector [@L] '' 3 --> 5.96e-06s 0.0% 7.87e-06s 0.1%\n",
" | | |Shape_i{0} [@M] '' 1 --> 9.54e-07s 0.0% 9.54e-07s 0.0%\n",
" | | | |X [@E]\n",
" | | |Shape_i{1} [@N] '' 0 --> 9.54e-07s 0.0% 9.54e-07s 0.0%\n",
" | | |<TensorType(float64, matrix)> [@G]\n",
" | |Constant{0} [@O]\n",
" |Subtensor{int64} [@P] '' 7 --> 9.54e-07s 0.0% 1.26e-05s 0.1%\n",
" |Elemwise{Cast{float64}} [@K] '' 5 --> 3.81e-06s 0.0% 1.17e-05s 0.1%\n",
" |Constant{1} [@Q]\n"
]
}
],
"source": [
"pr.debugprint(predict_profiled)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Profiled graphed "
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The output file is available at predict_profiled.html\n"
]
}
],
"source": [
"d3p.d3print(predict_profiled, 'predict_profiled.html')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[open](./predict_profiled.html) "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"pr.pydot"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The output file is available at predict_profiled.svg\n"
]
}
],
"source": [
"pr.pydotprint(predict_profiled, 'predict_profiled', format='svg')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![predict_profiled.svg](predict_profiled.svg)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Unprofiled graph"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The output file is available at predict_unprofiled.html\n"
]
}
],
"source": [
"d3p.d3print(predict_unprofiled, 'predict_unprofiled.html')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[open](./predict_unprofiled.html) "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
digraph G {
graph [bb="0,0,1055,672"];
node [label="\N"];
"Shape_i{1}" [fillcolor=cyan,
height=0.5,
pos="427,458",
profile="[9.5367431640625e-07, 0.012705802917480469]",
shape=ellipse,
style=filled,
type=colored,
width=1.4763];
MakeVector [height=0.5,
pos="250,370",
profile="[5.9604644775390625e-06, 0.012705802917480469]",
shape=ellipse,
width=1.5402];
"Shape_i{1}" -> MakeVector [label="1 TensorType(int64, scalar)",
lp="433,414",
pos="e,279.57,385.37 397.77,442.8 368.01,428.34 321.7,405.84 288.87,389.89"];
"TensorType(float64, matrix)" [fillcolor=limegreen,
height=0.5,
pos="464,566",
profile="[0.0009379386901855469, 0.012705802917480469]",
shape=box,
style=filled,
width=2.4444];
"TensorType(float64, matrix)" -> "Shape_i{1}" [label="TensorType(float64, matrix)",
lp="504,512",
pos="e,422.08,476.18 437.6,547.65 432.1,542.66 427.05,536.72 424,530 417.83,516.39 418.16,499.77 420.24,486.03"];
"Dot22 id=6" [height=0.5,
pos="716,370",
profile="[0.0009379386901855469, 0.012705802917480469]",
shape=ellipse,
width=1.4534];
"TensorType(float64, matrix)" -> "Dot22 id=6" [label="1 TensorType(float64, matrix)",
lp="692,458",
pos="e,682.81,383.97 552,551.07 563.93,546.03 575.1,539.2 584,530 612.7,500.32 582.73,473.4 607,440 623.72,416.99 650.68,399.83 673.6,\
388.37"];
"Shape_i{0}" [fillcolor=cyan,
height=0.5,
pos="229,512",
profile="[9.5367431640625e-07, 0.012705802917480469]",
shape=ellipse,
style=filled,
type=colored,
width=1.4763];
"Shape_i{0}" -> MakeVector [label="0 TensorType(int64, scalar)",
lp="287,458",
pos="e,236.58,387.68 217.14,494.33 213.83,488.77 210.69,482.36 209,476 204.89,460.54 204.76,455.43 209,440 213.31,424.32 222.2,408.6 \
230.61,396.13"];
"name=X TensorType(float64, matrix)" [fillcolor=limegreen,
height=0.5,
pos="334,654",
profile="[0.0064849853515625, 0.012705802917480469]",
shape=box,
style=filled,
width=3.1667];
"name=X TensorType(float64, matrix)" -> "Shape_i{0}" [label="TensorType(float64, matrix)",
lp="344,610",
pos="e,230.68,530.25 286.71,635.8 278.29,631.06 270.23,625.19 264,618 244.98,596.07 236.22,563.46 232.23,540.41"];
Dot22 [height=0.5,
pos="645,566",
profile="[0.0064849853515625, 0.012705802917480469]",
shape=ellipse,
width=0.92774];
"name=X TensorType(float64, matrix)" -> Dot22 [label="0 TensorType(float64, matrix)",
lp="556,610",
pos="e,614.28,573.23 377.6,635.91 410.55,623.16 453.06,607.1 471,602 510.24,590.85 521.01,592.05 561,584 575.06,581.17 590.45,578.06 \
604.17,575.28"];
"Elemwise{ScalarSigmoid}[(0, 0)]" [fillcolor="#FFAABB",
height=0.5,
pos="921,458",
profile="[0.004585981369018555, 0.012705802917480469]",
shape=ellipse,
style=filled,
type=colored,
width=3.7297];
Dot22 -> "Elemwise{ScalarSigmoid}[(0, 0)]" [color=red,
label="TensorType(float64, matrix)",
lp="903,512",
pos="e,879,475.13 671.46,554.84 716.96,537.36 810.78,501.33 869.53,478.77"];
"TensorType(float64, matrix) id=4" [fillcolor=limegreen,
height=0.5,
pos="645,654",
profile="[0.0064849853515625, 0.012705802917480469]",
shape=box,
style=filled,
width=2.8403];
"TensorType(float64, matrix) id=4" -> Dot22 [label="1 TensorType(float64, matrix)",
lp="730,610",
pos="e,645,584.08 645,635.6 645,623.75 645,607.82 645,594.29"];
"Elemwise{Cast{float64}}" [fillcolor="#FFAABB",
height=0.5,
pos="250,282",
profile="[3.814697265625e-06, 0.012705802917480469]",
shape=ellipse,
style=filled,
type=colored,
width=2.9207];
MakeVector -> "Elemwise{Cast{float64}}" [label="TensorType(int64, vector)",
lp="324,326",
pos="e,250,300.08 250,351.6 250,339.75 250,323.82 250,310.29"];
"Elemwise{ScalarSigmoid}[(0, 0)]" -> "Dot22 id=6" [label="0 TensorType(float64, matrix)",
lp="921,414",
pos="e,747.84,384.36 881.96,440.62 846.23,425.63 793.55,403.53 757.17,388.27"];
"Subtensor{int64}" [fillcolor="#FFAAFF",
height=0.5,
pos="317,194",
profile="[9.5367431640625e-07, 0.012705802917480469]",
shape=ellipse,
style=filled,
type=colored,
width=2.0659];
"Elemwise{Cast{float64}}" -> "Subtensor{int64}" [color=dodgerblue,
label="0 TensorType(float64, vector)",
lp="374.5,238",
pos="e,303.79,211.96 263.24,264.01 273.06,251.41 286.6,234.03 297.63,219.86"];
"Subtensor{int64} id=8" [fillcolor="#FFAAFF",
height=0.5,
pos="103,194",
profile="[3.0994415283203125e-06, 0.012705802917480469]",
shape=ellipse,
style=filled,
type=colored,
width=2.5916];
"Elemwise{Cast{float64}}" -> "Subtensor{int64} id=8" [color=dodgerblue,
label="0 TensorType(float64, vector)",
lp="189.5,238",
pos="e,98.802,212.45 169.53,270.28 141.06,264.73 113.86,256.82 105,246 99.708,239.54 98.04,230.93 98.046,222.62"];
"Elemwise{ScalarSigmoid}[(0, 0)] id=9" [fillcolor="#FFAABB",
height=0.5,
pos="716,282",
profile="[0.00011587142944335938, 0.012705802917480469]",
shape=ellipse,
style=filled,
type=colored,
width=4.2783];
"Dot22 id=6" -> "Elemwise{ScalarSigmoid}[(0, 0)] id=9" [color=red,
label="TensorType(float64, matrix)",
lp="796,326",
pos="e,716,300.08 716,351.6 716,339.75 716,323.82 716,310.29"];
"Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]" [fillcolor="#FFAABB",
height=0.5,
pos="317,106",
profile="[9.5367431640625e-07, 0.012705802917480469]",
shape=ellipse,
style=filled,
type=colored,
width=4.8998];
"Subtensor{int64}" -> "Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]" [label="2 TensorType(float64, scalar)",
lp="400.5,150",
pos="e,317,124.08 317,175.6 317,163.75 317,147.82 317,134.29"];
"val=1 int64" [fillcolor=limegreen,
height=0.5,
pos="487,282",
profile="[9.5367431640625e-07, 0.012705802917480469]",
shape=box,
style=filled,
width=1.1181];
"val=1 int64" -> "Subtensor{int64}" [label="1 int64",
lp="496,238",
pos="e,378.35,204.25 483.08,263.92 479.63,252.68 473.47,238.52 463,230 451.1,220.31 419.25,212.13 388.33,206.12"];
"Subtensor{int64} id=8" -> "Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]" [label="1 TensorType(float64, scalar)",
lp="229.5,150",
pos="e,201.3,119.69 113.23,175.69 120.84,164.35 132.26,150.16 146,142 159.92,133.73 175.47,127.39 191.37,122.53"];
"val=0 int64" [fillcolor=limegreen,
height=0.5,
pos="40,282",
profile="[3.0994415283203125e-06, 0.012705802917480469]",
shape=box,
style=filled,
width=1.1181];
"val=0 int64" -> "Subtensor{int64} id=8" [label="1 int64",
lp="61,238",
pos="e,61.928,210.23 36.259,263.76 34.929,253.28 35.008,240.04 41,230 44.243,224.57 48.669,219.91 53.673,215.93"];
"TensorType(float64, matrix) id=14" [fillcolor=dodgerblue,
height=0.5,
pos="539,194",
profile="[0.00011587142944335938, 0.012705802917480469]",
shape=box,
style=filled,
width=2.9444];
"Elemwise{ScalarSigmoid}[(0, 0)] id=9" -> "TensorType(float64, matrix) id=14" [label="TensorType(float64, matrix)",
lp="653,238",
pos="e,546.35,212.14 619.81,267.9 603.25,262.81 586.92,255.76 573,246 563.98,239.68 556.7,230.13 551.22,221"];
"Sum{acc_dtype=float64}" [height=0.5,
pos="766,194",
profile="[1.5020370483398438e-05, 0.012705802917480469]",
shape=ellipse,
width=2.8658];
"Elemwise{ScalarSigmoid}[(0, 0)] id=9" -> "Sum{acc_dtype=float64}" [label="TensorType(float64, matrix)",
lp="826,238",
pos="e,756.14,211.96 725.88,264.01 733.07,251.64 742.93,234.68 751.08,220.66"];
"Sum{acc_dtype=float64}" -> "Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]" [color=red,
label="0 TensorType(float64, scalar)",
lp="665.5,150",
pos="e,396.23,122.17 699.26,180.22 621.48,165.32 492.61,140.64 406.28,124.1"];
"TensorType(float64, scalar) id=16" [fillcolor=dodgerblue,
height=0.5,
pos="317,18",
profile="[9.5367431640625e-07, 0.012705802917480469]",
shape=box,
style=filled,
width=2.8889];
"Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]" -> "TensorType(float64, scalar) id=16" [label="TensorType(float64, scalar)",
lp="395,62",
pos="e,317,36.084 317,87.597 317,75.746 317,59.817 317,46.292"];
}
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<script type='text/javascript' src="http://cpettitt.github.io/project/dagre-d3/v0.1.5/dagre-d3.min.js"></script>
<script type='text/javascript' src="http://cpettitt.github.io/project/graphlib-dot/v0.4.10/graphlib-dot.min.js"></script>
<link rel="stylesheet" href="d3-context-menu.css" />
<script src="d3-context-menu.js"></script>
</head>
<body>
<style>
svg {
margin-left:auto;
margin-right:auto;
display:block;
position: fixed;
border: 0px solid black;
top:5%; left:0%; right:0% bottom=10%
}
.nodeRect {
stroke: black;
border: 3px solid black;
}
.nodeEllipse {
stroke: black;
border: 3px solid black;
}
.nodeText {
color: black;
}
.edge {
stroke-width: 3px;
cursor: pointer;
opacity: 0.4;
}
.edgeLabelRect {
stroke: black;
border: 1px solid black;
fill: skyblue;
opacity: 0.9;
}
.edgeLabelText {
fill: black;
text-anchor: start;
}
.arrowHead {
stroke: green;
stroke-width: 1px;
}
.arrowHead_n {
stroke: green;
}
.arrowHead_r {
stroke-width: 3px;
fill: red;
stroke: red;
}
.arrowHead_b {
stroke: dodgerblue;
}
.edgeTooltip {
position: absolute;
text-align: center;
vertical-align: middle;
min-width: 10px;
min-height: 10px;
padding: 5px;
background: lightsteelblue;
border: 1px solid black;
border-radius: 8px;
pointer-events: none;
}
.nodeTooltip {
position: absolute;
text-align: left;
vertical-align: middle;
min-width: 10px;
min-height: 10px;
padding: 5px;
background: lightsteelblue;
border: 1px solid black;
border-radius: 8px;
pointer-events: none;
}
</style>
<div id='menu'>
<input name="resetNodes"
type="button"
value="Reset nodes"
onclick="resetNodes()"/>
<input name="releaseNodes"
type="button"
value="Release nodes"
onclick="releaseNodes()"/>
</div>
<script type="text/javascript">
var path = 'predict_profiled.dot';
var isProfiled = false;
var colorProfile = false;
var maxProfilePer = 0;
var profileColors = ["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15"];
// Global attributes
var pad = 10;
d3.select('body').select('svg').remove();
var svg = d3.select('body').append('svg')
.attr('width', '100%')
.attr('height', '95%');
var pane = svg.append('g');
var edgeDiv = d3.select('body').append('div')
.attr('class', 'edgeTooltip')
.style('opacity', 0.0);
var nodeDiv = d3.select('body').append('div')
.attr('class', 'nodeTooltip')
.style('opacity', 0.0);
// Definition head of edges
var markerData = [
{'id': 'n', 'color': 'black'},
{'id': 'r', 'color': 'red'},
{'id': 'b', 'color': 'dodgerblue'}];
svg.append("defs").selectAll('marker').data(markerData).enter().append("marker")
.attr("id", function(d) { return 'edgeArrow_' + d.id;})
.attr("markerWidth", 4)
.attr("markerHeight", 4)
.attr("refX", 2)
.attr("refY", 2)
.attr("orient", "auto")
.append("path")
.attr("d", "M0,0 L4,2 L0,4 Z")
.attr('fill', function(d) { return d.color;});
function toggleColors() {
colorProfile = !colorProfile;
updateNodes();
updateGraph();
}
function textSize(text, attr) {
var t = svg.append('text').text(text);
if (typeof(attr) != 'undefined') {
for (a in attr) {
t.attr(a, attr[a]);
}
}
var bbox = t.node().getBBox();
t.remove();
return bbox;
}
function exists(x) {
return typeof(x) != 'undefined';
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}
function parseProfile(profile) {
if (typeof(profile) == 'undefined') {
return [];
}
profile = profile.replace('[', '');
profile = profile.replace(']', '');
profile = replaceAll(profile, ' ', '');
profile = profile.split(',');
if (profile.length < 2) {
return [];
}
profile = profile.map(function(x) { return parseFloat(x); });
return profile;
}
function linspace(start, end, len) {
var d = (end - start) / (len - 1);
var rv = [start];
for (i = 1; i < len; ++i) {
rv.push(rv[i - 1] + d);
}
return rv;
}
function profileColor(per) {
var s = d3.scale.linear()
.domain(linspace(0, maxProfilePer, profileColors.length))
.range(profileColors)
.interpolate(d3.interpolateRgb);
return s(per);
}
function fillColor(d) {
if (colorProfile && d.value.profile.length) {
if (d.value.shape == 'ellipse') {
return profileColor(d.value.profile[0] / d.value.profile[1]);
} else {
return 'white';
}
} else {
return typeof(d.value.fillcolor) == 'undefined' ? 'white' : d.value.fillcolor;
}
}
function formatTime(sec) {
var s;
if (sec < 0.1) {
s = (sec * 1000).toFixed(1) + 'ms';
} else {
s = sec.toFixed(1) + 's';
}
return s;
}
function nodeDetails(node) {
var s = '<b>' + node.value.label + '</b>';
var p = node.value.profile;
if (p.length) {
s += '<br>Time: ' + formatTime(p[0]);
s += '<br>Time: ' + (p[0] / p[1] * 100).toFixed(1) + '%';
}
return s;
}
function updateNode(d, node) {
var shape;
if (d.value.shape == 'ellipse') {
node.selectAll('ellipse').remove();
shape = node.append('ellipse')
.attr('class', 'nodeEllipse')
.attr('cx', d.value.cx)
.attr('cy', d.value.cy)
.attr('rx', d.value.width * 0.6)
.attr('ry', d.value.height * 0.6);
} else {
node.selectAll('rect').remove();
shape = node.append('rect')
.attr('class', 'nodeRect')
.attr('width', d.value.width)
.attr('height', d.value.height);
}
shape.attr('fill', fillColor(d));
node.selectAll('text').remove();
var text = node.append('text')
.attr('class', 'nodeText')
.attr('x', pad)
.attr('dy', function(d) {return d.value.height - pad - 5;})
.text(function(d) {return d.value.label;});
}
function updateNodes() {
nodes.each(function(d) {var node = d3.select(this); updateNode(d, node);});
}
function hideNodeDiv() {
nodeDiv.transition()
.duration(200)
.style('opacity', 0);
}
function setNodeSize(node) {
var size = textSize(node.value.label, {'class': 'nodeText'});
node.value.width = size.width + 2 * pad;
node.value.height = size.height + 2 * pad;
node.value.cx = node.value.width / 2;
node.value.cy = node.value.height / 2;
}
var isEditNode = false;
function editNode(elm, d) {
var node = d3.select(elm);
var pos = elm.getBBox();
if (d3.event.defaultPrevented) return;
isEditNode = true;
hideNodeDiv();
var form = node.append('foreignObject')
.attr('x', pos.x)
.attr('y', pos.y)
.attr('width', d.value.width)
.attr('height', 25);
var input = form.append('xhtml:form').append('input')
.attr('style', 'width: ' + d.value.width + 'px')
.attr('value', function() {
this.focus();
return d.value.label;
})
.on('blur', function() {
d.value.label = input.node().value;
setNodeSize(d);
updateNode(d, node);
form.remove(); // TODO: check this
isEditNode = false;
})
.on('keypress', function() {
if (!d3.event) {
d3.event = window.event;
}
var event = d3.event;
if (event.keyCode == 13) {
if (typeof(event.cancelBubble)) {
event.cancelBubble = true;
}
if (event.stopPropagation) {
event.stopPropagation();
}
event.preventDefault();
d.value.label = input.node().value;
setNodeSize(d);
updateNode(d, node);
form.remove(); // TODO: check this
isEditNode = false;
}
});
}
function releaseNode(d) {
d.fixed = false;
layout.start();
}
function releaseNodes() {
graph['nodes'].forEach (function (d) {
d.fixed = false;
});
layout.start();
}
function resetNodes() {
layout.stop();
var nodes = graph['nodes'];
nodes.forEach(function (node, i){
nodes[i].x = scaleDotX(node.value.pos[0]);
nodes[i].y = scaleDotY(dotHeight - (node.value.pos[1] + node.value.height));
nodes[i].px = nodes[i].x;
nodes[i].py = nodes[i].y;
nodes[i].fixed = true;
});
updateGraph();
layout.start();
}
var menuItems = [
{
title: 'Edit',
action: function(elm, d, i) {
editNode(elm, d);
}
},
{
title: 'Release',
action: function(elm, d, i) {
releaseNode(d);
}
}
];
var dotGraph;
var graph = {};
var nodes = [];
var edges = [];
var layout;
var scaleDotX;
var scaleDotY;
d3.text(path, function(data) {
dotGraph = graphlibDot.parse(data);
// Calculate width and height
var posMax = [0, 0];
for (var nodeId in dotGraph._nodes) {
var node = dotGraph._nodes[nodeId];
node.value.label = node.id;
node.value.pos = node.value.pos.split(',').map(function(d) {return parseInt(d);});
node.value.width = parseInt(node.value.width);
node.value.height = parseInt(node.value.height);
posMax[0] = Math.max(posMax[0], node.value.pos[0] + node.value.width);
posMax[1] = Math.max(posMax[1], node.value.pos[1] + node.value.height);
}
dotWidth = posMax[0];
dotHeight = posMax[1];
//svg.attr('viewBox', '0,0,' + dotWidth + ',' + dotHeight);
scaleDotX = d3.scale.linear().domain([0, dotWidth]).range([20, dotWidth * 1.2]);
scaleDotY = d3.scale.linear().domain([0, dotHeight]).range([20, dotHeight * 1.2]);
// Parse nodes
var i = 0;
for (nodeId in dotGraph._nodes) {
var node = dotGraph._nodes[nodeId];
node.index = i++;
// x, y is center of node (not corner)
node.x = scaleDotX(node.value.pos[0]);
node.y = scaleDotY(dotHeight - (node.value.pos[1] + node.value.height));
var size = textSize(node.value.label, {'class': 'nodeText'});
node.value.width = size.width + 2 * pad;
node.value.height = size.height + 2 * pad;
node.value.cx = node.value.width / 2;
node.value.cy = node.value.height / 2;
node.value.profile = parseProfile(node.value.profile);
if (node.value.profile.length) {
isProfiled = true;
}
node.fixed = true;
nodes.push(node);
dotGraph._nodes[nodeId] = node;
}
if (isProfiled) {
d3.select('body').select('#menu').append('input')
.attr('name', 'tColors')
.attr('type', 'button')
.attr('value', 'Toggle profile colors')
.attr('onclick', "toggleColors()");
maxProfilePer = 0;
for (i in nodes) {
var p = nodes[i].value.profile;
if (p.length) {
maxProfilePer = Math.max(maxProfilePer, p[0] / p[1]);
}
}
}
// Parse edges
for (edgeId in dotGraph._edges) {
var edge = dotGraph._edges[edgeId];
edge.source = dotGraph._nodes[edge.u].index;
edge.target = dotGraph._nodes[edge.v].index;
var size = textSize(edge.value.label, {'class': 'edgeLabelText'});
edge.value.width = size.width + 2 * pad;
edge.value.height = size.height + 2 * pad;
if (!exists(edge.value.color)) {
edge.value.color = 'black';
}
switch (edge.value.color) {
case 'dodgerblue':
edge.value.type = 'b';
break;
case 'red':
edge.value.type = 'r';
break;
default:
edge.value.type = 'n';
}
edges.push(edge);
dotGraph._edges[edgeId] = edge;
}
// Setup graph
graph['nodes'] = nodes;
graph['edges'] = edges;
var isEdgeOver = false;
var isEdgeLabelOver = false;
// Add edges
edges = pane.append('g').attr('id', 'edges').selectAll('path').data(graph['edges']).enter().append('path')
.attr('class', 'edge')
.attr('stroke', function(d) {return d.value.color;})
.attr('marker-mid', function(d) { return 'url(#edgeArrow_' + d.value.type + ')';})
.on('mouseover', function(d) {
var edge = d3.select(this);
edge.transition()
.duration(200)
.style('opacity', 1.0);
edgeDiv.transition()
.duration(200)
.style('opacity', .9);
edgeDiv
.html(d.value.label)
.style('left', (d3.event.pageX) + 'px')
.style('top', (d3.event.pageY - 28) + 'px');
})
.on('mouseout', function(d) {
var edge = d3.select(this);
edge.transition()
.duration(200)
.style('opacity', 0.4);
edgeDiv.transition()
.duration(200)
.style('opacity', 0);
});
// Add nodes
nodes = pane.append('g').attr('id', 'nodes').selectAll('g').data(graph['nodes']).enter().append('g');
updateNodes();
nodes.on('dblclick', function(d) {editNode(this, d);});
nodes.on('mouseover', function(node) {
if (isEditNode || typeof(node.value.profile) == 'undefined') {
return;
}
edges.each(function (d, i) {
var edge = d3.select(this);
if (d.source == node || d.target == node) {
edge.transition()
.duration(200)
.style('opacity', 1.0);
}
});
nodeDiv.transition()
.duration(200)
.style('opacity', .9);
nodeDiv
.html(nodeDetails(node))
.style('left', (d3.event.pageX) + 30 + 'px')
.style('top', (d3.event.pageY - 28) + 'px');
});
nodes.on('mouseout', function(node) {
edges.each(function (d, i) {
var edge = d3.select(this);
if (d.source.index == node.index || d.target.index == node.index) {
edge.transition()
.duration(200)
.style('opacity', 0.4);
}
});
hideNodeDiv();
});
nodes.on('contextmenu', d3.contextMenu(menuItems));
// Zoom and translate event handler
function zoom(d) {
pane.attr('transform', 'translate(' + d3.event.translate + ') scale(' + d3.event.scale + ')');
}
// Force layout
layout = d3.layout.force()
.nodes(graph['nodes'])
.links(graph['edges'])
.size([dotWidth, dotHeight])
.charge(-3000)
.linkDistance(50)
.linkStrength(0.1)
.on('tick', updateGraph);
// Drag behavour
var drag = layout.drag()
.on('dragstart', function(d) {
d3.event.sourceEvent.stopPropagation();
d3.event.sourceEvent.preventDefault();
d.fixed = true;
});
nodes.call(drag);
// Zoom behaviour
var bZoom = d3.behavior.zoom()
.scaleExtent([0.2, 8])
//.on("dblclick.zoom", null)
.on('zoom', zoom);
svg.call(bZoom);
svg.on("dblclick.zoom", null);
// Start force layout
layout.start();
});
function length(x1, y1, x2, y2) {
return Math.sqrt(Math.pow(x1-x2, 2) + Math.pow(y1-y2, 2));
}
function pathPos(x1, y1, x2, y2, c) {
x = (1 - c) * x1 + c * x2;
y = (1 - c) * y1 + c * y2;
p = x + ',' + y;
return p;
}
// Update graph
function updateGraph() {
// Update nodes
nodes.attr('transform', function(d) { return 'translate(' + (d.x - d.value.cx) + ' ' + (d.y - d.value.cy) + ')'; });
// Update edges
edges.attr('d', function(d) {
var dist = 100;
var l = length(d.source.x, d.source.y, d.target.x, d.target.y);
var n = Math.max(2, Math.floor(l / dist));
var marker = [];
for (var i = 1; i < n; ++i) {
marker.push(i / n);
}
var markerPos = marker.map(function(c) {return pathPos(d.source.x, d.source.y, d.target.x, d.target.y, c);});
var markerPos = ' L' + markerPos.join(' L');
return 'M' + d.source.x + ',' + d.source.y + markerPos + ' L' + d.target.x + ',' + d.target.y;
});
}
</script>
</body>
</html>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.36.0 (20140111.2315)
-->
<!-- Title: G Pages: 1 -->
<svg width="1268pt" height="680pt"
viewBox="0.00 0.00 1268.00 680.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 676)">
<title>G</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-676 1264,-676 1264,4 -4,4"/>
<!-- Shape_i{1} &#160;&#160;(0.000s,0.008%) -->
<g id="node1" class="node"><title>Shape_i{1} &#160;&#160;(0.000s,0.008%)</title>
<ellipse fill="cyan" stroke="black" cx="494" cy="-458" rx="120.359" ry="18"/>
<text text-anchor="middle" x="494" y="-454.3" font-family="Times,serif" font-size="14.00">Shape_i{1} &#160;&#160;(0.000s,0.008%)</text>
</g>
<!-- MakeVector &#160;&#160;(0.000s,0.047%) -->
<g id="node7" class="node"><title>MakeVector &#160;&#160;(0.000s,0.047%)</title>
<ellipse fill="none" stroke="black" cx="339" cy="-370" rx="123.234" ry="18"/>
<text text-anchor="middle" x="339" y="-366.3" font-family="Times,serif" font-size="14.00">MakeVector &#160;&#160;(0.000s,0.047%)</text>
</g>
<!-- Shape_i{1} &#160;&#160;(0.000s,0.008%)&#45;&gt;MakeVector &#160;&#160;(0.000s,0.047%) -->
<g id="edge6" class="edge"><title>Shape_i{1} &#160;&#160;(0.000s,0.008%)&#45;&gt;MakeVector &#160;&#160;(0.000s,0.047%)</title>
<path fill="none" stroke="black" d="M464.114,-440.418C439.562,-426.796 404.601,-407.398 377.874,-392.569"/>
<polygon fill="black" stroke="black" points="379.236,-389.322 368.794,-387.531 375.84,-395.443 379.236,-389.322"/>
<text text-anchor="middle" x="509" y="-410.3" font-family="Times,serif" font-size="14.00">1 TensorType(int64, scalar)</text>
</g>
<!-- TensorType(float64, matrix) -->
<g id="node2" class="node"><title>TensorType(float64, matrix)</title>
<polygon fill="green" stroke="black" points="600,-584 424,-584 424,-548 600,-548 600,-584"/>
<text text-anchor="middle" x="512" y="-562.3" font-family="Times,serif" font-size="14.00">TensorType(float64, matrix)</text>
</g>
<!-- TensorType(float64, matrix)&#45;&gt;Shape_i{1} &#160;&#160;(0.000s,0.008%) -->
<g id="edge1" class="edge"><title>TensorType(float64, matrix)&#45;&gt;Shape_i{1} &#160;&#160;(0.000s,0.008%)</title>
<path fill="none" stroke="black" d="M495.193,-547.823C491.05,-542.525 487.179,-536.392 485,-530 480.176,-515.849 481.875,-499.315 485.031,-485.764"/>
<polygon fill="black" stroke="black" points="488.42,-486.639 487.645,-476.072 481.662,-484.816 488.42,-486.639"/>
<text text-anchor="middle" x="565" y="-508.3" font-family="Times,serif" font-size="14.00">TensorType(float64, matrix)</text>
</g>
<!-- Dot22 &#160;&#160;(0.001s,7.382%) -->
<g id="node10" class="node"><title>Dot22 &#160;&#160;(0.001s,7.382%)</title>
<ellipse fill="none" stroke="black" cx="889" cy="-370" rx="100.611" ry="18"/>
<text text-anchor="middle" x="889" y="-366.3" font-family="Times,serif" font-size="14.00">Dot22 &#160;&#160;(0.001s,7.382%)</text>
</g>
<!-- TensorType(float64, matrix)&#45;&gt;Dot22 &#160;&#160;(0.001s,7.382%) -->
<g id="edge10" class="edge"><title>TensorType(float64, matrix)&#45;&gt;Dot22 &#160;&#160;(0.001s,7.382%)</title>
<path fill="none" stroke="black" d="M600.241,-555.766C616.848,-550.417 632.803,-542.284 645,-530 674.089,-500.703 639.582,-469.948 668,-440 699.7,-406.593 747.293,-389.268 790.203,-380.321"/>
<polygon fill="black" stroke="black" points="790.993,-383.733 800.136,-378.38 789.65,-376.863 790.993,-383.733"/>
<text text-anchor="middle" x="753" y="-454.3" font-family="Times,serif" font-size="14.00">1 TensorType(float64, matrix)</text>
</g>
<!-- Shape_i{0} &#160;&#160;(0.000s,0.008%) -->
<g id="node3" class="node"><title>Shape_i{0} &#160;&#160;(0.000s,0.008%)</title>
<ellipse fill="cyan" stroke="black" cx="235" cy="-512" rx="120.359" ry="18"/>
<text text-anchor="middle" x="235" y="-508.3" font-family="Times,serif" font-size="14.00">Shape_i{0} &#160;&#160;(0.000s,0.008%)</text>
</g>
<!-- Shape_i{0} &#160;&#160;(0.000s,0.008%)&#45;&gt;MakeVector &#160;&#160;(0.000s,0.047%) -->
<g id="edge5" class="edge"><title>Shape_i{0} &#160;&#160;(0.000s,0.008%)&#45;&gt;MakeVector &#160;&#160;(0.000s,0.047%)</title>
<path fill="none" stroke="black" d="M219.08,-494.095C214.988,-488.714 211.139,-482.468 209,-476 203.975,-460.81 200.754,-453.712 209,-440 223.187,-416.409 248.457,-400.454 272.969,-389.885"/>
<polygon fill="black" stroke="black" points="274.355,-393.1 282.302,-386.094 271.72,-386.615 274.355,-393.1"/>
<text text-anchor="middle" x="287" y="-454.3" font-family="Times,serif" font-size="14.00">0 TensorType(int64, scalar)</text>
</g>
<!-- name=X TensorType(float64, matrix) -->
<g id="node4" class="node"><title>name=X TensorType(float64, matrix)</title>
<polygon fill="green" stroke="black" points="517,-672 289,-672 289,-636 517,-636 517,-672"/>
<text text-anchor="middle" x="403" y="-650.3" font-family="Times,serif" font-size="14.00">name=X TensorType(float64, matrix)</text>
</g>
<!-- name=X TensorType(float64, matrix)&#45;&gt;Shape_i{0} &#160;&#160;(0.000s,0.008%) -->
<g id="edge2" class="edge"><title>name=X TensorType(float64, matrix)&#45;&gt;Shape_i{0} &#160;&#160;(0.000s,0.008%)</title>
<path fill="none" stroke="black" d="M377.404,-635.934C369.443,-630.401 360.73,-624.111 353,-618 319.757,-591.72 283.651,-558.908 260.251,-537.025"/>
<polygon fill="black" stroke="black" points="262.51,-534.344 252.825,-530.048 257.717,-539.446 262.51,-534.344"/>
<text text-anchor="middle" x="433" y="-606.3" font-family="Times,serif" font-size="14.00">TensorType(float64, matrix)</text>
</g>
<!-- Dot22 &#160;&#160;(0.006s,51.040%) -->
<g id="node5" class="node"><title>Dot22 &#160;&#160;(0.006s,51.040%)</title>
<ellipse fill="none" stroke="black" cx="747" cy="-566" rx="104.937" ry="18"/>
<text text-anchor="middle" x="747" y="-562.3" font-family="Times,serif" font-size="14.00">Dot22 &#160;&#160;(0.006s,51.040%)</text>
</g>
<!-- name=X TensorType(float64, matrix)&#45;&gt;Dot22 &#160;&#160;(0.006s,51.040%) -->
<g id="edge3" class="edge"><title>name=X TensorType(float64, matrix)&#45;&gt;Dot22 &#160;&#160;(0.006s,51.040%)</title>
<path fill="none" stroke="black" d="M455.111,-635.996C488.576,-625.417 533.092,-611.977 573,-602 603.617,-594.346 637.588,-587.214 667.327,-581.411"/>
<polygon fill="black" stroke="black" points="668.085,-584.83 677.239,-579.496 666.757,-577.957 668.085,-584.83"/>
<text text-anchor="middle" x="658" y="-606.3" font-family="Times,serif" font-size="14.00">0 TensorType(float64, matrix)</text>
</g>
<!-- Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.005s,36.094%) -->
<g id="node8" class="node"><title>Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.005s,36.094%)</title>
<ellipse fill="#ffaabb" stroke="black" cx="1054" cy="-458" rx="206.522" ry="18"/>
<text text-anchor="middle" x="1054" y="-454.3" font-family="Times,serif" font-size="14.00">Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.005s,36.094%)</text>
</g>
<!-- Dot22 &#160;&#160;(0.006s,51.040%)&#45;&gt;Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.005s,36.094%) -->
<g id="edge7" class="edge"><title>Dot22 &#160;&#160;(0.006s,51.040%)&#45;&gt;Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.005s,36.094%)</title>
<path fill="none" stroke="red" d="M791.64,-549.587C845.752,-530.903 937.049,-499.381 996.412,-478.884"/>
<polygon fill="red" stroke="red" points="997.707,-482.139 1006.02,-475.567 995.423,-475.523 997.707,-482.139"/>
<text text-anchor="middle" x="1025" y="-508.3" font-family="Times,serif" font-size="14.00">TensorType(float64, matrix)</text>
</g>
<!-- TensorType(float64, matrix) id=4 -->
<g id="node6" class="node"><title>TensorType(float64, matrix) id=4</title>
<polygon fill="green" stroke="black" points="849.25,-672 644.75,-672 644.75,-636 849.25,-636 849.25,-672"/>
<text text-anchor="middle" x="747" y="-650.3" font-family="Times,serif" font-size="14.00">TensorType(float64, matrix) id=4</text>
</g>
<!-- TensorType(float64, matrix) id=4&#45;&gt;Dot22 &#160;&#160;(0.006s,51.040%) -->
<g id="edge4" class="edge"><title>TensorType(float64, matrix) id=4&#45;&gt;Dot22 &#160;&#160;(0.006s,51.040%)</title>
<path fill="none" stroke="black" d="M747,-635.597C747,-623.746 747,-607.817 747,-594.292"/>
<polygon fill="black" stroke="black" points="750.5,-594.084 747,-584.084 743.5,-594.084 750.5,-594.084"/>
<text text-anchor="middle" x="832" y="-606.3" font-family="Times,serif" font-size="14.00">1 TensorType(float64, matrix)</text>
</g>
<!-- Elemwise{Cast{float64}} &#160;&#160;(0.000s,0.030%) -->
<g id="node9" class="node"><title>Elemwise{Cast{float64}} &#160;&#160;(0.000s,0.030%)</title>
<ellipse fill="#ffaabb" stroke="black" cx="339" cy="-282" rx="172.327" ry="18"/>
<text text-anchor="middle" x="339" y="-278.3" font-family="Times,serif" font-size="14.00">Elemwise{Cast{float64}} &#160;&#160;(0.000s,0.030%)</text>
</g>
<!-- MakeVector &#160;&#160;(0.000s,0.047%)&#45;&gt;Elemwise{Cast{float64}} &#160;&#160;(0.000s,0.030%) -->
<g id="edge8" class="edge"><title>MakeVector &#160;&#160;(0.000s,0.047%)&#45;&gt;Elemwise{Cast{float64}} &#160;&#160;(0.000s,0.030%)</title>
<path fill="none" stroke="black" d="M339,-351.597C339,-339.746 339,-323.817 339,-310.292"/>
<polygon fill="black" stroke="black" points="342.5,-310.084 339,-300.084 335.5,-310.084 342.5,-310.084"/>
<text text-anchor="middle" x="413" y="-322.3" font-family="Times,serif" font-size="14.00">TensorType(int64, vector)</text>
</g>
<!-- Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.005s,36.094%)&#45;&gt;Dot22 &#160;&#160;(0.001s,7.382%) -->
<g id="edge9" class="edge"><title>Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.005s,36.094%)&#45;&gt;Dot22 &#160;&#160;(0.001s,7.382%)</title>
<path fill="none" stroke="black" d="M1021.79,-440.214C995.222,-426.364 957.392,-406.647 928.902,-391.798"/>
<polygon fill="black" stroke="black" points="930.492,-388.679 920.006,-387.161 927.257,-394.887 930.492,-388.679"/>
<text text-anchor="middle" x="1071" y="-410.3" font-family="Times,serif" font-size="14.00">0 TensorType(float64, matrix)</text>
</g>
<!-- Subtensor{int64} &#160;&#160;(0.000s,0.008%) -->
<g id="node11" class="node"><title>Subtensor{int64} &#160;&#160;(0.000s,0.008%)</title>
<ellipse fill="#ffaaff" stroke="black" cx="442" cy="-194" rx="141.531" ry="18"/>
<text text-anchor="middle" x="442" y="-190.3" font-family="Times,serif" font-size="14.00">Subtensor{int64} &#160;&#160;(0.000s,0.008%)</text>
</g>
<!-- Elemwise{Cast{float64}} &#160;&#160;(0.000s,0.030%)&#45;&gt;Subtensor{int64} &#160;&#160;(0.000s,0.008%) -->
<g id="edge11" class="edge"><title>Elemwise{Cast{float64}} &#160;&#160;(0.000s,0.030%)&#45;&gt;Subtensor{int64} &#160;&#160;(0.000s,0.008%)</title>
<path fill="none" stroke="blue" d="M349.78,-263.96C357.108,-253.302 367.53,-239.787 379,-230 384.628,-225.198 391.016,-220.747 397.514,-216.742"/>
<polygon fill="blue" stroke="blue" points="399.511,-219.629 406.381,-211.564 395.981,-213.584 399.511,-219.629"/>
<text text-anchor="middle" x="463.5" y="-234.3" font-family="Times,serif" font-size="14.00">0 TensorType(float64, vector)</text>
</g>
<!-- Subtensor{int64} &#160;&#160;(0.000s,0.024%) -->
<g id="node13" class="node"><title>Subtensor{int64} &#160;&#160;(0.000s,0.024%)</title>
<ellipse fill="#ffaaff" stroke="black" cx="141" cy="-194" rx="141.531" ry="18"/>
<text text-anchor="middle" x="141" y="-190.3" font-family="Times,serif" font-size="14.00">Subtensor{int64} &#160;&#160;(0.000s,0.024%)</text>
</g>
<!-- Elemwise{Cast{float64}} &#160;&#160;(0.000s,0.030%)&#45;&gt;Subtensor{int64} &#160;&#160;(0.000s,0.024%) -->
<g id="edge13" class="edge"><title>Elemwise{Cast{float64}} &#160;&#160;(0.000s,0.030%)&#45;&gt;Subtensor{int64} &#160;&#160;(0.000s,0.024%)</title>
<path fill="none" stroke="blue" d="M245.124,-266.818C226.808,-261.824 208.26,-255.086 192,-246 180.215,-239.415 169.311,-229.331 160.636,-219.863"/>
<polygon fill="blue" stroke="blue" points="163.114,-217.38 153.903,-212.145 157.84,-221.981 163.114,-217.38"/>
<text text-anchor="middle" x="276.5" y="-234.3" font-family="Times,serif" font-size="14.00">0 TensorType(float64, vector)</text>
</g>
<!-- Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.000s,0.912%) -->
<g id="node15" class="node"><title>Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.000s,0.912%)</title>
<ellipse fill="#ffaabb" stroke="black" cx="889" cy="-282" rx="202.198" ry="18"/>
<text text-anchor="middle" x="889" y="-278.3" font-family="Times,serif" font-size="14.00">Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.000s,0.912%)</text>
</g>
<!-- Dot22 &#160;&#160;(0.001s,7.382%)&#45;&gt;Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.000s,0.912%) -->
<g id="edge15" class="edge"><title>Dot22 &#160;&#160;(0.001s,7.382%)&#45;&gt;Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.000s,0.912%)</title>
<path fill="none" stroke="red" d="M889,-351.597C889,-339.746 889,-323.817 889,-310.292"/>
<polygon fill="red" stroke="red" points="892.5,-310.084 889,-300.084 885.5,-310.084 892.5,-310.084"/>
<text text-anchor="middle" x="969" y="-322.3" font-family="Times,serif" font-size="14.00">TensorType(float64, matrix)</text>
</g>
<!-- Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] &#160;&#160;(0.000s,0.008%) -->
<g id="node18" class="node"><title>Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] &#160;&#160;(0.000s,0.008%)</title>
<ellipse fill="#ffaabb" stroke="black" cx="442" cy="-106" rx="243.592" ry="18"/>
<text text-anchor="middle" x="442" y="-102.3" font-family="Times,serif" font-size="14.00">Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] &#160;&#160;(0.000s,0.008%)</text>
</g>
<!-- Subtensor{int64} &#160;&#160;(0.000s,0.008%)&#45;&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] &#160;&#160;(0.000s,0.008%) -->
<g id="edge20" class="edge"><title>Subtensor{int64} &#160;&#160;(0.000s,0.008%)&#45;&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] &#160;&#160;(0.000s,0.008%)</title>
<path fill="none" stroke="black" d="M442,-175.597C442,-163.746 442,-147.817 442,-134.292"/>
<polygon fill="black" stroke="black" points="445.5,-134.084 442,-124.084 438.5,-134.084 445.5,-134.084"/>
<text text-anchor="middle" x="525.5" y="-146.3" font-family="Times,serif" font-size="14.00">2 TensorType(float64, scalar)</text>
</g>
<!-- val=1 int64 -->
<g id="node12" class="node"><title>val=1 int64</title>
<polygon fill="green" stroke="black" points="610.25,-300 529.75,-300 529.75,-264 610.25,-264 610.25,-300"/>
<text text-anchor="middle" x="570" y="-278.3" font-family="Times,serif" font-size="14.00">val=1 int64</text>
</g>
<!-- val=1 int64&#45;&gt;Subtensor{int64} &#160;&#160;(0.000s,0.008%) -->
<g id="edge12" class="edge"><title>val=1 int64&#45;&gt;Subtensor{int64} &#160;&#160;(0.000s,0.008%)</title>
<path fill="none" stroke="black" d="M566.407,-263.724C563.278,-252.695 557.674,-238.855 548,-230 540.709,-223.327 532.117,-217.923 523.03,-213.548"/>
<polygon fill="black" stroke="black" points="524.373,-210.315 513.809,-209.507 521.563,-216.727 524.373,-210.315"/>
<text text-anchor="middle" x="580" y="-234.3" font-family="Times,serif" font-size="14.00">1 int64</text>
</g>
<!-- Subtensor{int64} &#160;&#160;(0.000s,0.024%)&#45;&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] &#160;&#160;(0.000s,0.008%) -->
<g id="edge19" class="edge"><title>Subtensor{int64} &#160;&#160;(0.000s,0.024%)&#45;&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] &#160;&#160;(0.000s,0.008%)</title>
<path fill="none" stroke="black" d="M177.951,-176.537C203.65,-165.577 238.92,-151.499 271,-142 293.246,-135.413 317.481,-129.635 340.525,-124.772"/>
<polygon fill="black" stroke="black" points="341.236,-128.199 350.318,-122.744 339.817,-121.345 341.236,-128.199"/>
<text text-anchor="middle" x="354.5" y="-146.3" font-family="Times,serif" font-size="14.00">1 TensorType(float64, scalar)</text>
</g>
<!-- val=0 int64 -->
<g id="node14" class="node"><title>val=0 int64</title>
<polygon fill="green" stroke="black" points="148.25,-300 67.75,-300 67.75,-264 148.25,-264 148.25,-300"/>
<text text-anchor="middle" x="108" y="-278.3" font-family="Times,serif" font-size="14.00">val=0 int64</text>
</g>
<!-- val=0 int64&#45;&gt;Subtensor{int64} &#160;&#160;(0.000s,0.024%) -->
<g id="edge14" class="edge"><title>val=0 int64&#45;&gt;Subtensor{int64} &#160;&#160;(0.000s,0.024%)</title>
<path fill="none" stroke="black" d="M107.275,-263.884C107.422,-253.698 108.643,-240.714 113,-230 114.402,-226.554 116.256,-223.174 118.346,-219.955"/>
<polygon fill="black" stroke="black" points="121.178,-222.012 124.277,-211.881 115.536,-217.868 121.178,-222.012"/>
<text text-anchor="middle" x="133" y="-234.3" font-family="Times,serif" font-size="14.00">1 int64</text>
</g>
<!-- TensorType(float64, matrix) id=14 -->
<g id="node16" class="node"><title>TensorType(float64, matrix) id=14</title>
<polygon fill="blue" stroke="black" points="814,-212 602,-212 602,-176 814,-176 814,-212"/>
<text text-anchor="middle" x="708" y="-190.3" font-family="Times,serif" font-size="14.00">TensorType(float64, matrix) id=14</text>
</g>
<!-- Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.000s,0.912%)&#45;&gt;TensorType(float64, matrix) id=14 -->
<g id="edge16" class="edge"><title>Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.000s,0.912%)&#45;&gt;TensorType(float64, matrix) id=14</title>
<path fill="none" stroke="black" d="M818.58,-265.026C802.466,-260.043 785.75,-253.762 771,-246 757.372,-238.828 743.882,-228.468 732.903,-218.956"/>
<polygon fill="black" stroke="black" points="735.175,-216.292 725.387,-212.237 730.51,-221.511 735.175,-216.292"/>
<text text-anchor="middle" x="851" y="-234.3" font-family="Times,serif" font-size="14.00">TensorType(float64, matrix)</text>
</g>
<!-- Sum{acc_dtype=float64} &#160;&#160;(0.000s,0.118%) -->
<g id="node17" class="node"><title>Sum{acc_dtype=float64} &#160;&#160;(0.000s,0.118%)</title>
<ellipse fill="none" stroke="black" cx="1003" cy="-194" rx="170.402" ry="18"/>
<text text-anchor="middle" x="1003" y="-190.3" font-family="Times,serif" font-size="14.00">Sum{acc_dtype=float64} &#160;&#160;(0.000s,0.118%)</text>
</g>
<!-- Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.000s,0.912%)&#45;&gt;Sum{acc_dtype=float64} &#160;&#160;(0.000s,0.118%) -->
<g id="edge17" class="edge"><title>Elemwise{ScalarSigmoid}[(0, 0)] &#160;&#160;(0.000s,0.912%)&#45;&gt;Sum{acc_dtype=float64} &#160;&#160;(0.000s,0.118%)</title>
<path fill="none" stroke="black" d="M911.523,-264.009C928.932,-250.876 953.215,-232.557 972.387,-218.094"/>
<polygon fill="black" stroke="black" points="974.649,-220.772 980.524,-211.956 970.433,-215.184 974.649,-220.772"/>
<text text-anchor="middle" x="1036" y="-234.3" font-family="Times,serif" font-size="14.00">TensorType(float64, matrix)</text>
</g>
<!-- Sum{acc_dtype=float64} &#160;&#160;(0.000s,0.118%)&#45;&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] &#160;&#160;(0.000s,0.008%) -->
<g id="edge18" class="edge"><title>Sum{acc_dtype=float64} &#160;&#160;(0.000s,0.118%)&#45;&gt;Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] &#160;&#160;(0.000s,0.008%)</title>
<path fill="none" stroke="red" d="M910.677,-178.847C812.449,-163.789 657.083,-139.972 552.439,-123.93"/>
<polygon fill="red" stroke="red" points="552.889,-120.458 542.474,-122.402 551.828,-127.377 552.889,-120.458"/>
<text text-anchor="middle" x="856.5" y="-146.3" font-family="Times,serif" font-size="14.00">0 TensorType(float64, scalar)</text>
</g>
<!-- TensorType(float64, scalar) id=16 -->
<g id="node19" class="node"><title>TensorType(float64, scalar) id=16</title>
<polygon fill="blue" stroke="black" points="546,-36 338,-36 338,-0 546,-0 546,-36"/>
<text text-anchor="middle" x="442" y="-14.3" font-family="Times,serif" font-size="14.00">TensorType(float64, scalar) id=16</text>
</g>
<!-- Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] &#160;&#160;(0.000s,0.008%)&#45;&gt;TensorType(float64, scalar) id=16 -->
<g id="edge21" class="edge"><title>Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)] &#160;&#160;(0.000s,0.008%)&#45;&gt;TensorType(float64, scalar) id=16</title>
<path fill="none" stroke="black" d="M442,-87.5966C442,-75.7459 442,-59.8169 442,-46.2917"/>
<polygon fill="black" stroke="black" points="445.5,-46.084 442,-36.084 438.5,-46.084 445.5,-46.084"/>
<text text-anchor="middle" x="520" y="-58.3" font-family="Times,serif" font-size="14.00">TensorType(float64, scalar)</text>
</g>
</g>
</svg>
digraph G {
graph [bb="0,0,1055,672"];
node [label="\N"];
"Shape_i{1}" [fillcolor=cyan,
height=0.5,
pos="427,458",
shape=ellipse,
style=filled,
type=colored,
width=1.4763];
MakeVector [height=0.5,
pos="250,370",
shape=ellipse,
width=1.5402];
"Shape_i{1}" -> MakeVector [label="1 TensorType(int64, scalar)",
lp="433,414",
pos="e,279.57,385.37 397.77,442.8 368.01,428.34 321.7,405.84 288.87,389.89"];
"TensorType(float64, matrix)" [fillcolor=limegreen,
height=0.5,
pos="464,566",
shape=box,
style=filled,
width=2.4444];
"TensorType(float64, matrix)" -> "Shape_i{1}" [label="TensorType(float64, matrix)",
lp="504,512",
pos="e,422.08,476.18 437.6,547.65 432.1,542.66 427.05,536.72 424,530 417.83,516.39 418.16,499.77 420.24,486.03"];
"Dot22 id=6" [height=0.5,
pos="716,370",
shape=ellipse,
width=1.4534];
"TensorType(float64, matrix)" -> "Dot22 id=6" [label="1 TensorType(float64, matrix)",
lp="692,458",
pos="e,682.81,383.97 552,551.07 563.93,546.03 575.1,539.2 584,530 612.7,500.32 582.73,473.4 607,440 623.72,416.99 650.68,399.83 673.6,\
388.37"];
"Shape_i{0}" [fillcolor=cyan,
height=0.5,
pos="229,512",
shape=ellipse,
style=filled,
type=colored,
width=1.4763];
"Shape_i{0}" -> MakeVector [label="0 TensorType(int64, scalar)",
lp="287,458",
pos="e,236.58,387.68 217.14,494.33 213.83,488.77 210.69,482.36 209,476 204.89,460.54 204.76,455.43 209,440 213.31,424.32 222.2,408.6 \
230.61,396.13"];
"name=X TensorType(float64, matrix)" [fillcolor=limegreen,
height=0.5,
pos="334,654",
shape=box,
style=filled,
width=3.1667];
"name=X TensorType(float64, matrix)" -> "Shape_i{0}" [label="TensorType(float64, matrix)",
lp="344,610",
pos="e,230.68,530.25 286.71,635.8 278.29,631.06 270.23,625.19 264,618 244.98,596.07 236.22,563.46 232.23,540.41"];
Dot22 [height=0.5,
pos="645,566",
shape=ellipse,
width=0.92774];
"name=X TensorType(float64, matrix)" -> Dot22 [label="0 TensorType(float64, matrix)",
lp="556,610",
pos="e,614.28,573.23 377.6,635.91 410.55,623.16 453.06,607.1 471,602 510.24,590.85 521.01,592.05 561,584 575.06,581.17 590.45,578.06 \
604.17,575.28"];
"Elemwise{ScalarSigmoid}[(0, 0)]" [fillcolor="#FFAABB",
height=0.5,
pos="921,458",
shape=ellipse,
style=filled,
type=colored,
width=3.7297];
Dot22 -> "Elemwise{ScalarSigmoid}[(0, 0)]" [color=red,
label="TensorType(float64, matrix)",
lp="903,512",
pos="e,879,475.13 671.46,554.84 716.96,537.36 810.78,501.33 869.53,478.77"];
"TensorType(float64, matrix) id=4" [fillcolor=limegreen,
height=0.5,
pos="645,654",
shape=box,
style=filled,
width=2.8403];
"TensorType(float64, matrix) id=4" -> Dot22 [label="1 TensorType(float64, matrix)",
lp="730,610",
pos="e,645,584.08 645,635.6 645,623.75 645,607.82 645,594.29"];
"Elemwise{Cast{float64}}" [fillcolor="#FFAABB",
height=0.5,
pos="250,282",
shape=ellipse,
style=filled,
type=colored,
width=2.9207];
MakeVector -> "Elemwise{Cast{float64}}" [label="TensorType(int64, vector)",
lp="324,326",
pos="e,250,300.08 250,351.6 250,339.75 250,323.82 250,310.29"];
"Elemwise{ScalarSigmoid}[(0, 0)]" -> "Dot22 id=6" [label="0 TensorType(float64, matrix)",
lp="921,414",
pos="e,747.84,384.36 881.96,440.62 846.23,425.63 793.55,403.53 757.17,388.27"];
"Subtensor{int64}" [fillcolor="#FFAAFF",
height=0.5,
pos="317,194",
shape=ellipse,
style=filled,
type=colored,
width=2.0659];
"Elemwise{Cast{float64}}" -> "Subtensor{int64}" [color=dodgerblue,
label="0 TensorType(float64, vector)",
lp="374.5,238",
pos="e,303.79,211.96 263.24,264.01 273.06,251.41 286.6,234.03 297.63,219.86"];
"Subtensor{int64} id=8" [fillcolor="#FFAAFF",
height=0.5,
pos="103,194",
shape=ellipse,
style=filled,
type=colored,
width=2.5916];
"Elemwise{Cast{float64}}" -> "Subtensor{int64} id=8" [color=dodgerblue,
label="0 TensorType(float64, vector)",
lp="189.5,238",
pos="e,98.802,212.45 169.53,270.28 141.06,264.73 113.86,256.82 105,246 99.708,239.54 98.04,230.93 98.046,222.62"];
"Elemwise{ScalarSigmoid}[(0, 0)] id=9" [fillcolor="#FFAABB",
height=0.5,
pos="716,282",
shape=ellipse,
style=filled,
type=colored,
width=4.2783];
"Dot22 id=6" -> "Elemwise{ScalarSigmoid}[(0, 0)] id=9" [color=red,
label="TensorType(float64, matrix)",
lp="796,326",
pos="e,716,300.08 716,351.6 716,339.75 716,323.82 716,310.29"];
"Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]" [fillcolor="#FFAABB",
height=0.5,
pos="317,106",
shape=ellipse,
style=filled,
type=colored,
width=4.8998];
"Subtensor{int64}" -> "Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]" [label="2 TensorType(float64, scalar)",
lp="400.5,150",
pos="e,317,124.08 317,175.6 317,163.75 317,147.82 317,134.29"];
"val=1 int64" [fillcolor=limegreen,
height=0.5,
pos="487,282",
shape=box,
style=filled,
width=1.1181];
"val=1 int64" -> "Subtensor{int64}" [label="1 int64",
lp="496,238",
pos="e,378.35,204.25 483.08,263.92 479.63,252.68 473.47,238.52 463,230 451.1,220.31 419.25,212.13 388.33,206.12"];
"Subtensor{int64} id=8" -> "Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]" [label="1 TensorType(float64, scalar)",
lp="229.5,150",
pos="e,201.3,119.69 113.23,175.69 120.84,164.35 132.26,150.16 146,142 159.92,133.73 175.47,127.39 191.37,122.53"];
"val=0 int64" [fillcolor=limegreen,
height=0.5,
pos="40,282",
shape=box,
style=filled,
width=1.1181];
"val=0 int64" -> "Subtensor{int64} id=8" [label="1 int64",
lp="61,238",
pos="e,61.928,210.23 36.259,263.76 34.929,253.28 35.008,240.04 41,230 44.243,224.57 48.669,219.91 53.673,215.93"];
"TensorType(float64, matrix) id=14" [fillcolor=dodgerblue,
height=0.5,
pos="539,194",
shape=box,
style=filled,
width=2.9444];
"Elemwise{ScalarSigmoid}[(0, 0)] id=9" -> "TensorType(float64, matrix) id=14" [label="TensorType(float64, matrix)",
lp="653,238",
pos="e,546.35,212.14 619.81,267.9 603.25,262.81 586.92,255.76 573,246 563.98,239.68 556.7,230.13 551.22,221"];
"Sum{acc_dtype=float64}" [height=0.5,
pos="766,194",
shape=ellipse,
width=2.8658];
"Elemwise{ScalarSigmoid}[(0, 0)] id=9" -> "Sum{acc_dtype=float64}" [label="TensorType(float64, matrix)",
lp="826,238",
pos="e,756.14,211.96 725.88,264.01 733.07,251.64 742.93,234.68 751.08,220.66"];
"Sum{acc_dtype=float64}" -> "Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]" [color=red,
label="0 TensorType(float64, scalar)",
lp="665.5,150",
pos="e,396.23,122.17 699.26,180.22 621.48,165.32 492.61,140.64 406.28,124.1"];
"TensorType(float64, scalar) id=16" [fillcolor=dodgerblue,
height=0.5,
pos="317,18",
shape=box,
style=filled,
width=2.8889];
"Elemwise{Composite{((i0 / i1) / i2)}}[(0, 0)]" -> "TensorType(float64, scalar) id=16" [label="TensorType(float64, scalar)",
lp="395,62",
pos="e,317,36.084 317,87.597 317,75.746 317,59.817 317,46.292"];
}
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<script type='text/javascript' src="http://cpettitt.github.io/project/dagre-d3/v0.1.5/dagre-d3.min.js"></script>
<script type='text/javascript' src="http://cpettitt.github.io/project/graphlib-dot/v0.4.10/graphlib-dot.min.js"></script>
<link rel="stylesheet" href="d3-context-menu.css" />
<script src="d3-context-menu.js"></script>
</head>
<body>
<style>
svg {
margin-left:auto;
margin-right:auto;
display:block;
position: fixed;
border: 0px solid black;
top:5%; left:0%; right:0% bottom=10%
}
.nodeRect {
stroke: black;
border: 3px solid black;
}
.nodeEllipse {
stroke: black;
border: 3px solid black;
}
.nodeText {
color: black;
}
.edge {
stroke-width: 3px;
cursor: pointer;
opacity: 0.4;
}
.edgeLabelRect {
stroke: black;
border: 1px solid black;
fill: skyblue;
opacity: 0.9;
}
.edgeLabelText {
fill: black;
text-anchor: start;
}
.arrowHead {
stroke: green;
stroke-width: 1px;
}
.arrowHead_n {
stroke: green;
}
.arrowHead_r {
stroke-width: 3px;
fill: red;
stroke: red;
}
.arrowHead_b {
stroke: dodgerblue;
}
.edgeTooltip {
position: absolute;
text-align: center;
vertical-align: middle;
min-width: 10px;
min-height: 10px;
padding: 5px;
background: lightsteelblue;
border: 1px solid black;
border-radius: 8px;
pointer-events: none;
}
.nodeTooltip {
position: absolute;
text-align: left;
vertical-align: middle;
min-width: 10px;
min-height: 10px;
padding: 5px;
background: lightsteelblue;
border: 1px solid black;
border-radius: 8px;
pointer-events: none;
}
</style>
<div id='menu'>
<input name="resetNodes"
type="button"
value="Reset nodes"
onclick="resetNodes()"/>
<input name="releaseNodes"
type="button"
value="Release nodes"
onclick="releaseNodes()"/>
</div>
<script type="text/javascript">
var path = 'predict_unprofiled.dot';
var isProfiled = false;
var colorProfile = false;
var maxProfilePer = 0;
var profileColors = ["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15"];
// Global attributes
var pad = 10;
d3.select('body').select('svg').remove();
var svg = d3.select('body').append('svg')
.attr('width', '100%')
.attr('height', '95%');
var pane = svg.append('g');
var edgeDiv = d3.select('body').append('div')
.attr('class', 'edgeTooltip')
.style('opacity', 0.0);
var nodeDiv = d3.select('body').append('div')
.attr('class', 'nodeTooltip')
.style('opacity', 0.0);
// Definition head of edges
var markerData = [
{'id': 'n', 'color': 'black'},
{'id': 'r', 'color': 'red'},
{'id': 'b', 'color': 'dodgerblue'}];
svg.append("defs").selectAll('marker').data(markerData).enter().append("marker")
.attr("id", function(d) { return 'edgeArrow_' + d.id;})
.attr("markerWidth", 4)
.attr("markerHeight", 4)
.attr("refX", 2)
.attr("refY", 2)
.attr("orient", "auto")
.append("path")
.attr("d", "M0,0 L4,2 L0,4 Z")
.attr('fill', function(d) { return d.color;});
function toggleColors() {
colorProfile = !colorProfile;
updateNodes();
updateGraph();
}
function textSize(text, attr) {
var t = svg.append('text').text(text);
if (typeof(attr) != 'undefined') {
for (a in attr) {
t.attr(a, attr[a]);
}
}
var bbox = t.node().getBBox();
t.remove();
return bbox;
}
function exists(x) {
return typeof(x) != 'undefined';
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
}
function parseProfile(profile) {
if (typeof(profile) == 'undefined') {
return [];
}
profile = profile.replace('[', '');
profile = profile.replace(']', '');
profile = replaceAll(profile, ' ', '');
profile = profile.split(',');
if (profile.length < 2) {
return [];
}
profile = profile.map(function(x) { return parseFloat(x); });
return profile;
}
function linspace(start, end, len) {
var d = (end - start) / (len - 1);
var rv = [start];
for (i = 1; i < len; ++i) {
rv.push(rv[i - 1] + d);
}
return rv;
}
function profileColor(per) {
var s = d3.scale.linear()
.domain(linspace(0, maxProfilePer, profileColors.length))
.range(profileColors)
.interpolate(d3.interpolateRgb);
return s(per);
}
function fillColor(d) {
if (colorProfile && d.value.profile.length) {
if (d.value.shape == 'ellipse') {
return profileColor(d.value.profile[0] / d.value.profile[1]);
} else {
return 'white';
}
} else {
return typeof(d.value.fillcolor) == 'undefined' ? 'white' : d.value.fillcolor;
}
}
function formatTime(sec) {
var s;
if (sec < 0.1) {
s = (sec * 1000).toFixed(1) + 'ms';
} else {
s = sec.toFixed(1) + 's';
}
return s;
}
function nodeDetails(node) {
var s = '<b>' + node.value.label + '</b>';
var p = node.value.profile;
if (p.length) {
s += '<br>Time: ' + formatTime(p[0]);
s += '<br>Time: ' + (p[0] / p[1] * 100).toFixed(1) + '%';
}
return s;
}
function updateNode(d, node) {
var shape;
if (d.value.shape == 'ellipse') {
node.selectAll('ellipse').remove();
shape = node.append('ellipse')
.attr('class', 'nodeEllipse')
.attr('cx', d.value.cx)
.attr('cy', d.value.cy)
.attr('rx', d.value.width * 0.6)
.attr('ry', d.value.height * 0.6);
} else {
node.selectAll('rect').remove();
shape = node.append('rect')
.attr('class', 'nodeRect')
.attr('width', d.value.width)
.attr('height', d.value.height);
}
shape.attr('fill', fillColor(d));
node.selectAll('text').remove();
var text = node.append('text')
.attr('class', 'nodeText')
.attr('x', pad)
.attr('dy', function(d) {return d.value.height - pad - 5;})
.text(function(d) {return d.value.label;});
}
function updateNodes() {
nodes.each(function(d) {var node = d3.select(this); updateNode(d, node);});
}
function hideNodeDiv() {
nodeDiv.transition()
.duration(200)
.style('opacity', 0);
}
function setNodeSize(node) {
var size = textSize(node.value.label, {'class': 'nodeText'});
node.value.width = size.width + 2 * pad;
node.value.height = size.height + 2 * pad;
node.value.cx = node.value.width / 2;
node.value.cy = node.value.height / 2;
}
var isEditNode = false;
function editNode(elm, d) {
var node = d3.select(elm);
var pos = elm.getBBox();
if (d3.event.defaultPrevented) return;
isEditNode = true;
hideNodeDiv();
var form = node.append('foreignObject')
.attr('x', pos.x)
.attr('y', pos.y)
.attr('width', d.value.width)
.attr('height', 25);
var input = form.append('xhtml:form').append('input')
.attr('style', 'width: ' + d.value.width + 'px')
.attr('value', function() {
this.focus();
return d.value.label;
})
.on('blur', function() {
d.value.label = input.node().value;
setNodeSize(d);
updateNode(d, node);
form.remove(); // TODO: check this
isEditNode = false;
})
.on('keypress', function() {
if (!d3.event) {
d3.event = window.event;
}
var event = d3.event;
if (event.keyCode == 13) {
if (typeof(event.cancelBubble)) {
event.cancelBubble = true;
}
if (event.stopPropagation) {
event.stopPropagation();
}
event.preventDefault();
d.value.label = input.node().value;
setNodeSize(d);
updateNode(d, node);
form.remove(); // TODO: check this
isEditNode = false;
}
});
}
function releaseNode(d) {
d.fixed = false;
layout.start();
}
function releaseNodes() {
graph['nodes'].forEach (function (d) {
d.fixed = false;
});
layout.start();
}
function resetNodes() {
layout.stop();
var nodes = graph['nodes'];
nodes.forEach(function (node, i){
nodes[i].x = scaleDotX(node.value.pos[0]);
nodes[i].y = scaleDotY(dotHeight - (node.value.pos[1] + node.value.height));
nodes[i].px = nodes[i].x;
nodes[i].py = nodes[i].y;
nodes[i].fixed = true;
});
updateGraph();
layout.start();
}
var menuItems = [
{
title: 'Edit',
action: function(elm, d, i) {
editNode(elm, d);
}
},
{
title: 'Release',
action: function(elm, d, i) {
releaseNode(d);
}
}
];
var dotGraph;
var graph = {};
var nodes = [];
var edges = [];
var layout;
var scaleDotX;
var scaleDotY;
d3.text(path, function(data) {
dotGraph = graphlibDot.parse(data);
// Calculate width and height
var posMax = [0, 0];
for (var nodeId in dotGraph._nodes) {
var node = dotGraph._nodes[nodeId];
node.value.label = node.id;
node.value.pos = node.value.pos.split(',').map(function(d) {return parseInt(d);});
node.value.width = parseInt(node.value.width);
node.value.height = parseInt(node.value.height);
posMax[0] = Math.max(posMax[0], node.value.pos[0] + node.value.width);
posMax[1] = Math.max(posMax[1], node.value.pos[1] + node.value.height);
}
dotWidth = posMax[0];
dotHeight = posMax[1];
//svg.attr('viewBox', '0,0,' + dotWidth + ',' + dotHeight);
scaleDotX = d3.scale.linear().domain([0, dotWidth]).range([20, dotWidth * 1.2]);
scaleDotY = d3.scale.linear().domain([0, dotHeight]).range([20, dotHeight * 1.2]);
// Parse nodes
var i = 0;
for (nodeId in dotGraph._nodes) {
var node = dotGraph._nodes[nodeId];
node.index = i++;
// x, y is center of node (not corner)
node.x = scaleDotX(node.value.pos[0]);
node.y = scaleDotY(dotHeight - (node.value.pos[1] + node.value.height));
var size = textSize(node.value.label, {'class': 'nodeText'});
node.value.width = size.width + 2 * pad;
node.value.height = size.height + 2 * pad;
node.value.cx = node.value.width / 2;
node.value.cy = node.value.height / 2;
node.value.profile = parseProfile(node.value.profile);
if (node.value.profile.length) {
isProfiled = true;
}
node.fixed = true;
nodes.push(node);
dotGraph._nodes[nodeId] = node;
}
if (isProfiled) {
d3.select('body').select('#menu').append('input')
.attr('name', 'tColors')
.attr('type', 'button')
.attr('value', 'Toggle profile colors')
.attr('onclick', "toggleColors()");
maxProfilePer = 0;
for (i in nodes) {
var p = nodes[i].value.profile;
if (p.length) {
maxProfilePer = Math.max(maxProfilePer, p[0] / p[1]);
}
}
}
// Parse edges
for (edgeId in dotGraph._edges) {
var edge = dotGraph._edges[edgeId];
edge.source = dotGraph._nodes[edge.u].index;
edge.target = dotGraph._nodes[edge.v].index;
var size = textSize(edge.value.label, {'class': 'edgeLabelText'});
edge.value.width = size.width + 2 * pad;
edge.value.height = size.height + 2 * pad;
if (!exists(edge.value.color)) {
edge.value.color = 'black';
}
switch (edge.value.color) {
case 'dodgerblue':
edge.value.type = 'b';
break;
case 'red':
edge.value.type = 'r';
break;
default:
edge.value.type = 'n';
}
edges.push(edge);
dotGraph._edges[edgeId] = edge;
}
// Setup graph
graph['nodes'] = nodes;
graph['edges'] = edges;
var isEdgeOver = false;
var isEdgeLabelOver = false;
// Add edges
edges = pane.append('g').attr('id', 'edges').selectAll('path').data(graph['edges']).enter().append('path')
.attr('class', 'edge')
.attr('stroke', function(d) {return d.value.color;})
.attr('marker-mid', function(d) { return 'url(#edgeArrow_' + d.value.type + ')';})
.on('mouseover', function(d) {
var edge = d3.select(this);
edge.transition()
.duration(200)
.style('opacity', 1.0);
edgeDiv.transition()
.duration(200)
.style('opacity', .9);
edgeDiv
.html(d.value.label)
.style('left', (d3.event.pageX) + 'px')
.style('top', (d3.event.pageY - 28) + 'px');
})
.on('mouseout', function(d) {
var edge = d3.select(this);
edge.transition()
.duration(200)
.style('opacity', 0.4);
edgeDiv.transition()
.duration(200)
.style('opacity', 0);
});
// Add nodes
nodes = pane.append('g').attr('id', 'nodes').selectAll('g').data(graph['nodes']).enter().append('g');
updateNodes();
nodes.on('dblclick', function(d) {editNode(this, d);});
nodes.on('mouseover', function(node) {
if (isEditNode || typeof(node.value.profile) == 'undefined') {
return;
}
edges.each(function (d, i) {
var edge = d3.select(this);
if (d.source == node || d.target == node) {
edge.transition()
.duration(200)
.style('opacity', 1.0);
}
});
nodeDiv.transition()
.duration(200)
.style('opacity', .9);
nodeDiv
.html(nodeDetails(node))
.style('left', (d3.event.pageX) + 30 + 'px')
.style('top', (d3.event.pageY - 28) + 'px');
});
nodes.on('mouseout', function(node) {
edges.each(function (d, i) {
var edge = d3.select(this);
if (d.source.index == node.index || d.target.index == node.index) {
edge.transition()
.duration(200)
.style('opacity', 0.4);
}
});
hideNodeDiv();
});
nodes.on('contextmenu', d3.contextMenu(menuItems));
// Zoom and translate event handler
function zoom(d) {
pane.attr('transform', 'translate(' + d3.event.translate + ') scale(' + d3.event.scale + ')');
}
// Force layout
layout = d3.layout.force()
.nodes(graph['nodes'])
.links(graph['edges'])
.size([dotWidth, dotHeight])
.charge(-3000)
.linkDistance(50)
.linkStrength(0.1)
.on('tick', updateGraph);
// Drag behavour
var drag = layout.drag()
.on('dragstart', function(d) {
d3.event.sourceEvent.stopPropagation();
d3.event.sourceEvent.preventDefault();
d.fixed = true;
});
nodes.call(drag);
// Zoom behaviour
var bZoom = d3.behavior.zoom()
.scaleExtent([0.2, 8])
//.on("dblclick.zoom", null)
.on('zoom', zoom);
svg.call(bZoom);
svg.on("dblclick.zoom", null);
// Start force layout
layout.start();
});
function length(x1, y1, x2, y2) {
return Math.sqrt(Math.pow(x1-x2, 2) + Math.pow(y1-y2, 2));
}
function pathPos(x1, y1, x2, y2, c) {
x = (1 - c) * x1 + c * x2;
y = (1 - c) * y1 + c * y2;
p = x + ',' + y;
return p;
}
// Update graph
function updateGraph() {
// Update nodes
nodes.attr('transform', function(d) { return 'translate(' + (d.x - d.value.cx) + ' ' + (d.y - d.value.cy) + ')'; });
// Update edges
edges.attr('d', function(d) {
var dist = 100;
var l = length(d.source.x, d.source.y, d.target.x, d.target.y);
var n = Math.max(2, Math.floor(l / dist));
var marker = [];
for (var i = 1; i < n; ++i) {
marker.push(i / n);
}
var markerPos = marker.map(function(c) {return pathPos(d.source.x, d.source.y, d.target.x, d.target.y, c);});
var markerPos = ' L' + markerPos.join(' L');
return 'M' + d.source.x + ',' + d.source.y + markerPos + ' L' + d.target.x + ',' + d.target.y;
});
}
</script>
</body>
</html>
...@@ -17,6 +17,7 @@ from theano.compile import Function ...@@ -17,6 +17,7 @@ from theano.compile import Function
_logger = logging.getLogger("theano.printing") _logger = logging.getLogger("theano.printing")
class GraphFormatter(object): class GraphFormatter(object):
def __init__(self): def __init__(self):
...@@ -304,27 +305,13 @@ class GraphFormatter(object): ...@@ -304,27 +305,13 @@ class GraphFormatter(object):
if node in self.apply_name_cache: if node in self.apply_name_cache:
return self.apply_name_cache[node] return self.apply_name_cache[node]
prof = None prof = ''
if mode: if mode:
time = mode.profile_stats[fct].apply_time.get(node, 0) profile = mode.profile_stats[fct]
# second, % total time in profiler, %fct time in profiler if profile:
if mode.local_time == 0:
pt = 0
else:
pt = time * 100 / mode.local_time
if mode.profile_stats[fct].fct_callcount == 0:
pf = 0
else:
pf = time * 100 / mode.profile_stats[fct].fct_call_time
prof = [time, pt, pf]
elif profile:
time = profile.apply_time.get(node, 0) time = profile.apply_time.get(node, 0)
# second, %fct time in profiler call_time = profile.fct_call_time
if profile.fct_callcount == 0: prof = str([time, call_time])
pf = 0
else:
pf = time * 100 / profile.fct_call_time
prof = [time, None, pf]
applystr = str(node.op).replace(':', '_') applystr = str(node.op).replace(':', '_')
if (applystr in self.all_strings) or self.with_ids: if (applystr in self.all_strings) or self.with_ids:
...@@ -343,10 +330,6 @@ class GraphFormatter(object): ...@@ -343,10 +330,6 @@ class GraphFormatter(object):
applystr = (applystr[:self.max_label_size - 3 - len(suffix)] + applystr = (applystr[:self.max_label_size - 3 - len(suffix)] +
'...' + '...' +
suffix) suffix)
if prof is not None:
prof = str(prof)
else:
prof = ''
self.all_strings.add(applystr) self.all_strings.add(applystr)
self.apply_name_cache[node] = (applystr, prof) self.apply_name_cache[node] = (applystr, prof)
......
.d3-context-menu {
position: absolute;
display: none;
background-color: #f2f2f2;
border-radius: 4px;
font-family: Arial, sans-serif;
font-size: 14px;
min-width: 50px;
border: 1px solid #d4d4d4;
z-index:1200;
}
.d3-context-menu ul {
list-style-type: none;
margin: 4px 0px;
padding: 0px;
cursor: default;
}
.d3-context-menu ul li {
padding: 4px 16px;
}
.d3-context-menu ul li:hover {
background-color: #4677f8;
color: #fefefe;
}
d3.contextMenu = function (menu, openCallback) {
// create the div element that will hold the context menu
d3.selectAll('.d3-context-menu').data([1])
.enter()
.append('div')
.attr('class', 'd3-context-menu');
// close menu
d3.select('body').on('click.d3-context-menu', function() {
d3.select('.d3-context-menu').style('display', 'none');
});
// this gets executed when a contextmenu event occurs
return function(data, index) {
var elm = this;
d3.selectAll('.d3-context-menu').html('');
var list = d3.selectAll('.d3-context-menu').append('ul');
list.selectAll('li').data(menu).enter()
.append('li')
.html(function(d) {
return d.title;
})
.on('click', function(d, i) {
d.action(elm, data, index);
d3.select('.d3-context-menu').style('display', 'none');
});
// the openCallback allows an action to fire before the menu is displayed
// an example usage would be closing a tooltip
if (openCallback) openCallback(data, index);
// display context menu
d3.select('.d3-context-menu')
.style('left', (d3.event.pageX - 2) + 'px')
.style('top', (d3.event.pageY - 2) + 'px')
.style('display', 'block');
d3.event.preventDefault();
};
};
This source diff could not be displayed because it is too large. You can view the blob instead.
(function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var j=typeof require=="function"&&require;if(!h&&j)return j(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}var f=typeof require=="function"&&require;for(var g=0;g<d.length;g++)e(d[g]);return e})({1:[function(a,b,c){var d=self;d.dagreD3=a("./index")},{"./index":2}],2:[function(a,b,c){b.exports={Digraph:a("graphlib").Digraph,Renderer:a("./lib/Renderer"),json:a("graphlib").converter.json,layout:a("dagre").layout,version:a("./lib/version")}},{"./lib/Renderer":3,"./lib/version":4,dagre:11,graphlib:28}],3:[function(a,b,c){function g(){this._layout=d(),this.drawNodes(k),this.drawEdgeLabels(l),this.drawEdgePaths(m),this.positionNodes(n),this.positionEdgeLabels(o),this.positionEdgePaths(p),this.transition(q),this.postLayout(r),this.postRender(s),this.edgeInterpolate("bundle"),this.edgeTension(.95)}function h(a){var b=a.copy();return b.nodes().forEach(function(a){var c=b.node(a);c===undefined&&(c={},b.node(a,c)),"label"in c||(c.label="")}),b.edges().forEach(function(a){var c=b.edge(a);c===undefined&&(c={},b.edge(a,c)),"label"in c||(c.label="")}),b}function i(a,b){var c=a.getBBox();b.width=c.width,b.height=c.height}function j(a,b){var c=b.run(a);return a.eachNode(function(a,b){c.node(a).label=b.label}),a.eachEdge(function(a,b,d,e){c.edge(a).label=e.label}),c}function k(a,b){var c=a.nodes().filter(function(b){return!z(a,b)}),d=b.selectAll("g.node").classed("enter",!1).data(c,function(a){return a});return d.selectAll("*").remove(),d.enter().append("g").style("opacity",0).attr("class","node enter"),d.each(function(b){t(a.node(b),e.select(this),10,10)}),this._transition(d.exit()).style("opacity",0).remove(),d}function l(a,b){var c=b.selectAll("g.edgeLabel").classed("enter",!1).data(a.edges(),function(a){return a});return c.selectAll("*").remove(),c.enter().append("g").style("opacity",0).attr("class","edgeLabel enter"),c.each(function(b){t(a.edge(b),e.select(this),0,0)}),this._transition(c.exit()).style("opacity",0).remove(),c}function n(a,b,c){function d(b){var c=a.node(b);return"translate("+c.x+","+c.y+")"}b.filter(".enter").attr("transform",d),this._transition(b).style("opacity",1).attr("transform",d)}function o(a,b){function c(b){var c=a.edge(b),d=x(c.points);return"translate("+d.x+","+d.y+")"}b.filter(".enter").attr("transform",c),this._transition(b).style("opacity",1).attr("transform",c)}function p(a,b){function f(b){var f=a.edge(b),g=a.node(a.incidentNodes(b)[0]),h=a.node(a.incidentNodes(b)[1]),i=f.points.slice(),j=i.length===0?h:i[0],k=i.length===0?g:i[i.length-1];return i.unshift(y(g,j)),i.push(y(h,k)),e.svg.line().x(function(a){return a.x}).y(function(a){return a.y}).interpolate(c).tension(d)(i)}var c=this._edgeInterpolate,d=this._edgeTension;b.filter(".enter").selectAll("path").attr("d",f),this._transition(b.selectAll("path")).attr("d",f).style("opacity",1)}function q(a){return a}function r(){}function s(a,b){a.isDirected()&&b.select("#arrowhead").empty()&&b.append("svg:defs").append("svg:marker").attr("id","arrowhead").attr("viewBox","0 0 10 10").attr("refX",8).attr("refY",5).attr("markerUnits","strokewidth").attr("markerWidth",8).attr("markerHeight",5).attr("orient","auto").attr("style","fill: #333").append("svg:path").attr("d","M 0 0 L 10 5 L 0 10 z")}function t(a,b,c,d){var e=a.label,f=b.append("rect"),g=b.append("g");e[0]==="<"?(u(e,g),c=d=0):v(e,g,Math.floor(a.labelCols),a.labelCut);var h=b.node().getBBox();g.attr("transform","translate("+ -h.width/2+","+ -h.height/2+")"),f.attr("rx",5).attr("ry",5).attr("x",-(h.width/2+c)).attr("y",-(h.height/2+d)).attr("width",h.width+2*c).attr("height",h.height+2*d)}function u(a,b){var c=b.append("foreignObject").attr("width","100000"),d,e;c.append("xhtml:div").style("float","left").html(function(){return a}).each(function(){d=this.clientWidth,e=this.clientHeight}),c.attr("width",d).attr("height",e)}function v(a,b,c,d){d===undefined&&(d="false"),d=d.toString().toLowerCase()==="true";var e=b.append("text").attr("text-anchor","left");a=a.replace(/\\n/g,"\n");var f=c?w(a,c,d):a;f=f.split("\n");for(var g=0;g<f.length;g++)e.append("tspan").attr("dy","1em").attr("x","1").text(f[g])}function w(a,b,c,d){d=d||"\n",b=b||75,c=c||!1;if(!a)return a;var e=".{1,"+b+"}(\\s|$)"+(c?"|.{"+b+"}|.+$":"|\\S+?(\\s|$)");return a.match(RegExp(e,"g")).join(d)}function x(a){var b=a.length/2;if(a.length%2)return a[Math.floor(b)];var c=a[b-1],d=a[b];return{x:(c.x+d.x)/2,y:(c.y+d.y)/2}}function y(a,b){var c=a.x,d=a.y,e=b.x-c,f=b.y-d,g=a.width/2,h=a.height/2,i,j;return Math.abs(f)*g>Math.abs(e)*h?(f<0&&(h=-h),i=f===0?0:h*e/f,j=h):(e<0&&(g=-g),i=g,j=e===0?0:g*f/e),{x:c+i,y:d+j}}function z(a,b){return"children"in a&&a.children(b).length}function A(a,b){return a.bind?a.bind(b):function(){return a.apply(b,arguments)}}var d=a("dagre").layout,e;try{e=a("d3")}catch(f){e=window.d3}b.exports=g,g.prototype.layout=function(a){return arguments.length?(this._layout=a,this):this._layout},g.prototype.drawNodes=function(a){return arguments.length?(this._drawNodes=A(a,this),this):this._drawNodes},g.prototype.drawEdgeLabels=function(a){return arguments.length?(this._drawEdgeLabels=A(a,this),this):this._drawEdgeLabels},g.prototype.drawEdgePaths=function(a){return arguments.length?(this._drawEdgePaths=A(a,this),this):this._drawEdgePaths},g.prototype.positionNodes=function(a){return arguments.length?(this._positionNodes=A(a,this),this):this._positionNodes},g.prototype.positionEdgeLabels=function(a){return arguments.length?(this._positionEdgeLabels=A(a,this),this):this._positionEdgeLabels},g.prototype.positionEdgePaths=function(a){return arguments.length?(this._positionEdgePaths=A(a,this),this):this._positionEdgePaths},g.prototype.transition=function(a){return arguments.length?(this._transition=A(a,this),this):this._transition},g.prototype.postLayout=function(a){return arguments.length?(this._postLayout=A(a,this),this):this._postLayout},g.prototype.postRender=function(a){return arguments.length?(this._postRender=A(a,this),this):this._postRender},g.prototype.edgeInterpolate=function(a){return arguments.length?(this._edgeInterpolate=a,this):this._edgeInterpolate},g.prototype.edgeTension=function(a){return arguments.length?(this._edgeTension=a,this):this._edgeTension},g.prototype.run=function(a,b){a=h(a),b.selectAll("g.edgePaths, g.edgeLabels, g.nodes").data(["edgePaths","edgeLabels","nodes"]).enter().append("g").attr("class",function(a){return a});var c=this._drawNodes(a,b.select("g.nodes")),d=this._drawEdgeLabels(a,b.select("g.edgeLabels"));c.each(function(b){i(this,a.node(b))}),d.each(function(b){i(this,a.edge(b))});var e=j(a,this._layout);this._postLayout(e,b);var f=this._drawEdgePaths(a,b.select("g.edgePaths"));return this._positionNodes(e,c),this._positionEdgeLabels(e,d),this._positionEdgePaths(e,f),this._postRender(e,b),e};var m=function(a,b){var c=b.selectAll("g.edgePath").classed("enter",!1).data(a.edges(),function(a){return a});return c.enter().append("g").attr("class","edgePath enter").append("path").style("opacity",0).attr("marker-end","url(#arrowhead)"),this._transition(c.exit()).style("opacity",0).remove(),c}},{d3:10,dagre:11}],4:[function(a,b,c){b.exports="0.1.5"},{}],5:[function(a,b,c){c.Set=a("./lib/Set"),c.PriorityQueue=a("./lib/PriorityQueue"),c.version=a("./lib/version")},{"./lib/PriorityQueue":6,"./lib/Set":7,"./lib/version":9}],6:[function(a,b,c){function d(){this._arr=[],this._keyIndices={}}b.exports=d,d.prototype.size=function(){return this._arr.length},d.prototype.keys=function(){return this._arr.map(function(a){return a.key})},d.prototype.has=function(a){return a in this._keyIndices},d.prototype.priority=function(a){var b=this._keyIndices[a];if(b!==undefined)return this._arr[b].priority},d.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},d.prototype.add=function(a,b){var c=this._keyIndices;if(a in c)return!1;var d=this._arr,e=d.length;return c[a]=e,d.push({key:a,priority:b}),this._decrease(e),!0},d.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var a=this._arr.pop();return delete this._keyIndices[a.key],this._heapify(0),a.key},d.prototype.decrease=function(a,b){var c=this._keyIndices[a];if(b>this._arr[c].priority)throw new Error("New priority is greater than current priority. Key: "+a+" Old: "+this._arr[c].priority+" New: "+b);this._arr[c].priority=b,this._decrease(c)},d.prototype._heapify=function(a){var b=this._arr,c=2*a,d=c+1,e=a;c<b.length&&(e=b[c].priority<b[e].priority?c:e,d<b.length&&(e=b[d].priority<b[e].priority?d:e),e!==a&&(this._swap(a,e),this._heapify(e)))},d.prototype._decrease=function(a){var b=this._arr,c=b[a].priority,d;while(a!==0){d=a>>1;if(b[d].priority<c)break;this._swap(a,d),a=d}},d.prototype._swap=function(a,b){var c=this._arr,d=this._keyIndices,e=c[a],f=c[b];c[a]=f,c[b]=e,d[f.key]=a,d[e.key]=b}},{}],7:[function(a,b,c){function e(a){this._size=0,this._keys={};if(a)for(var b=0,c=a.length;b<c;++b)this.add(a[b])}function f(a){var b=Object.keys(a),c=b.length,d=new Array(c),e;for(e=0;e<c;++e)d[e]=a[b[e]];return d}var d=a("./util");b.exports=e,e.intersect=function(a){if(a.length===0)return new e;var b=new e(d.isArray(a[0])?a[0]:a[0].keys());for(var c=1,f=a.length;c<f;++c){var g=b.keys(),h=d.isArray(a[c])?new e(a[c]):a[c];for(var i=0,j=g.length;i<j;++i){var k=g[i];h.has(k)||b.remove(k)}}return b},e.union=function(a){var b=d.reduce(a,function(a,b){return a+(b.size?b.size():b.length)},0),c=new Array(b),f=0;for(var g=0,h=a.length;g<h;++g){var i=a[g],j=d.isArray(i)?i:i.keys();for(var k=0,l=j.length;k<l;++k)c[f++]=j[k]}return new e(c)},e.prototype.size=function(){return this._size},e.prototype.keys=function(){return f(this._keys)},e.prototype.has=function(a){return a in this._keys},e.prototype.add=function(a){return a in this._keys?!1:(this._keys[a]=a,++this._size,!0)},e.prototype.remove=function(a){return a in this._keys?(delete this._keys[a],--this._size,!0):!1}},{"./util":8}],8:[function(a,b,c){Array.isArray?c.isArray=Array.isArray:c.isArray=function(a){return Object.prototype.toString.call(a)==="[object Array]"},"function"!=typeof Array.prototype.reduce?c.reduce=function(a,b,c){"use strict";if(null===a||"undefined"==typeof a)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof b)throw new TypeError(b+" is not a function");var d,e,f=a.length>>>0,g=!1;1<arguments.length&&(e=c,g=!0);for(d=0;f>d;++d)a.hasOwnProperty(d)&&(g?e=b(e,a[d],d,a):(e=a[d],g=!0));if(!g)throw new TypeError("Reduce of empty array with no initial value");return e}:c.reduce=function(a,b,c){return a.reduce(b,c)}},{}],9:[function(a,b,c){b.exports="1.1.3"},{}],10:[function(a,b,c){a("./d3"),b.exports=d3,function(){delete this.d3}()},{}],11:[function(a,b,c){c.Digraph=a("graphlib").Digraph,c.Graph=a("graphlib").Graph,c.layout=a("./lib/layout"),c.version=a("./lib/version")},{"./lib/layout":12,"./lib/version":27,graphlib:28}],12:[function(a,b,c){var d=a("./util"),e=a("./rank"),f=a("./order"),g=a("graphlib").CGraph,h=a("graphlib").CDigraph;b.exports=function(){function j(a){var c=new h;a.eachNode(function(a,b){b===undefined&&(b={}),c.addNode(a,{width:b.width,height:b.height}),b.hasOwnProperty("rank")&&(c.node(a).prefRank=b.rank)}),a.parent&&a.nodes().forEach(function(b){c.parent(b,a.parent(b))}),a.eachEdge(function(a,b,d,e){e===undefined&&(e={});var f={e:a,minLen:e.minLen||1,width:e.width||0,height:e.height||0,points:[]};c.addEdge(null,b,d,f)});var d=a.graph()||{};return c.graph({rankDir:d.rankDir||b.rankDir,orderRestarts:d.orderRestarts}),c}function k(a){var g=i.rankSep(),h;try{return h=d.time("initLayoutGraph",j)(a),h.order()===0?h:(h.eachEdge(function(a,b,c,d){d.minLen*=2}),i.rankSep(g/2),d.time("rank.run",e.run)(h,b.rankSimplex),d.time("normalize",l)(h),d.time("order",f)(h,b.orderMaxSweeps),d.time("position",c.run)(h),d.time("undoNormalize",m)(h),d.time("fixupEdgePoints",n)(h),d.time("rank.restoreEdges",e.restoreEdges)(h),d.time("createFinalGraph",o)(h,a.isDirected()))}finally{i.rankSep(g)}}function l(a){var b=0;a.eachEdge(function(c,d,e,f){var g=a.node(d).rank,h=a.node(e).rank;if(g+1<h){for(var i=d,j=g+1,k=0;j<h;++j,++k){var l="_D"+ ++b,m={width:f.width,height:f.height,edge:{id:c,source:d,target:e,attrs:f},rank:j,dummy:!0};k===0?m.index=0:j+1===h&&(m.index=1),a.addNode(l,m),a.addEdge(null,i,l,{}),i=l}a.addEdge(null,i,e,{}),a.delEdge(c)}})}function m(a){a.eachNode(function(b,c){if(c.dummy){if("index"in c){var d=c.edge;a.hasEdge(d.id)||a.addEdge(d.id,d.source,d.target,d.attrs);var e=a.edge(d.id).points;e[c.index]={x:c.x,y:c.y,ul:c.ul,ur:c.ur,dl:c.dl,dr:c.dr}}a.delNode(b)}})}function n(a){a.eachEdge(function(a,b,c,d){d.reversed&&d.points.reverse()})}function o(a,b){var c=b?new h:new g;c.graph(a.graph()),a.eachNode(function(a,b){c.addNode(a,b)}),a.eachNode(function(b){c.parent(b,a.parent(b))}),a.eachEdge(function(a,b,d,e){c.addEdge(e.e,b,d,e)});var d=0,e=0;return a.eachNode(function(b,c){a.children(b).length||(d=Math.max(d,c.x+c.width/2),e=Math.max(e,c.y+c.height/2))}),a.eachEdge(function(a,b,c,f){var g=Math.max.apply(Math,f.points.map(function(a){return a.x})),h=Math.max.apply(Math,f.points.map(function(a){return a.y}));d=Math.max(d,g+f.width/2),e=Math.max(e,h+f.height/2)}),c.graph().width=d,c.graph().height=e,c}function p(a){return function(){return arguments.length?(a.apply(null,arguments),i):a()}}var b={debugLevel:0,orderMaxSweeps:f.DEFAULT_MAX_SWEEPS,rankSimplex:!1,rankDir:"TB"},c=a("./position")(),i={};return i.orderIters=d.propertyAccessor(i,b,"orderMaxSweeps"),i.rankSimplex=d.propertyAccessor(i,b,"rankSimplex"),i.nodeSep=p(c.nodeSep),i.edgeSep=p(c.edgeSep),i.universalSep=p(c.universalSep),i.rankSep=p(c.rankSep),i.rankDir=d.propertyAccessor(i,b,"rankDir"),i.debugAlignment=p(c.debugAlignment),i.debugLevel=d.propertyAccessor(i,b,"debugLevel",function(a){d.log.level=a,c.debugLevel(a)}),i.run=d.time("Total layout",k),i._normalize=l,i}},{"./order":13,"./position":18,"./rank":19,"./util":26,graphlib:28}],13:[function(a,b,c){function k(a,b){function o(){a.eachNode(function(a,b){m[a]=b.order})}arguments.length<2&&(b=j);var c=a.graph().orderRestarts||0,h=f(a);h.forEach(function(b){b=b.filterNodes(function(b){return!a.children(b).length})});var i=0,k,l=Number.MAX_VALUE,m={};for(var p=0;p<Number(c)+1&&l!==0;++p){k=Number.MAX_VALUE,g(a,c>0),d.log(2,"Order phase start cross count: "+a.graph().orderInitCC);var q,r,s;for(q=0,r=0;r<4&&q<b&&k>0;++q,++r,++i)n(a,h,q),s=e(a),s<k&&(r=0,k=s,s<l&&(o(),l=s)),d.log(3,"Order phase start "+p+" iter "+q+" cross count: "+s)}Object.keys(m).forEach(function(b){if(!a.children||!a.children(b).length)a.node(b).order=m[b]}),a.graph().orderCC=l,d.log(2,"Order iterations: "+i),d.log(2,"Order phase best cross count: "+a.graph().orderCC)}function l(a,b){var c={};return b.forEach(function(b){c[b]=a.inEdges(b).map(function(b){return a.node(a.source(b)).order})}),c}function m(a,b){var c={};return b.forEach(function(b){c[b]=a.outEdges(b).map(function(b){return a.node(a.target(b)).order})}),c}function n(a,b,c){c%2===0?o(a,b,c):p(a,b,c)}function o(a,b){var c;for(i=1;i<b.length;++i)c=h(b[i],c,l(a,b[i].nodes()))}function p(a,b){var c;for(i=b.length-2;i>=0;--i)h(b[i],c,m(a,b[i].nodes()))}var d=a("./util"),e=a("./order/crossCount"),f=a("./order/initLayerGraphs"),g=a("./order/initOrder"),h=a("./order/sortLayer");b.exports=k;var j=24;k.DEFAULT_MAX_SWEEPS=j},{"./order/crossCount":14,"./order/initLayerGraphs":15,"./order/initOrder":16,"./order/sortLayer":17,"./util":26}],14:[function(a,b,c){function e(a){var b=0,c=d.ordering(a);for(var e=1;e<c.length;++e)b+=f(a,c[e-1],c[e]);return b}function f(a,b,c){var d=[];b.forEach(function(b){var c=[];a.outEdges(b).forEach(function(b){c.push(a.node(a.target(b)).order)}),c.sort(function(a,b){return a-b}),d=d.concat(c)});var e=1;while(e<c.length)e<<=1;var f=2*e-1;e-=1;var g=[];for(var h=0;h<f;++h)g[h]=0;var i=0;return d.forEach(function(a){var b=a+e;++g[b];while(b>0)b%2&&(i+=g[b+1]),b=b-1>>1,++g[b]}),i}var d=a("../util");b.exports=e},{"../util":26}],15:[function(a,b,c){function f(a){function c(d){if(d===null){a.children(d).forEach(function(a){c(a)});return}var f=a.node(d);f.minRank="rank"in f?f.rank:Number.MAX_VALUE,f.maxRank="rank"in f?f.rank:Number.MIN_VALUE;var h=new e;return a.children(d).forEach(function(b){var d=c(b);h=e.union([h,d]),f.minRank=Math.min(f.minRank,a.node(b).minRank),f.maxRank=Math.max(f.maxRank,a.node(b).maxRank)}),"rank"in f&&h.add(f.rank),h.keys().forEach(function(a){a in b||(b[a]=[]),b[a].push(d)}),h}var b=[];c(null);var f=[];return b.forEach(function(b,c){f[c]=a.filterNodes(d(b))}),f}var d=a("graphlib").filter.nodesFromList,e=a("cp-data").Set;b.exports=f},{"cp-data":5,graphlib:28}],16:[function(a,b,c){function f(a,b){var c=[];a.eachNode(function(b,d){var e=c[d.rank];if(a.children&&a.children(b).length>0)return;e||(e=c[d.rank]=[]),e.push(b)}),c.forEach(function(c){b&&e.shuffle(c),c.forEach(function(b,c){a.node(b).order=c})});var f=d(a);a.graph().orderInitCC=f,a.graph().orderCC=Number.MAX_VALUE}var d=a("./crossCount"),e=a("../util");b.exports=f},{"../util":26,"./crossCount":14}],17:[function(a,b,c){function e(a,b,c){var e=[],f={};a.eachNode(function(a,b){e[b.order]=a;var g=c[a];g.length&&(f[a]=d.sum(g)/g.length)});var g=a.nodes().filter(function(a){return f[a]!==undefined});g.sort(function(b,c){return f[b]-f[c]||a.node(b).order-a.node(c).order});for(var h=0,i=0,j=g.length;i<j;++h)f[e[h]]!==undefined&&(a.node(g[i++]).order=h)}var d=a("../util");b.exports=e},{"../util":26}],18:[function(a,b,c){var d=a("./util");b.exports=function(){function c(b){b=b.filterNodes(d.filterNonSubgraphs(b));var c=d.ordering(b),e=f(b,c),i={};["u","d"].forEach(function(d){d==="d"&&c.reverse(),["l","r"].forEach(function(f){f==="r"&&m(c);var j=d+f,k=g(b,c,e,d==="u"?"predecessors":"successors");i[j]=h(b,c,k.pos,k.root,k.align),a.debugLevel>=3&&t(d+f,b,c,i[j]),f==="r"&&l(i[j]),f==="r"&&m(c)}),d==="d"&&c.reverse()}),k(b,c,i),b.eachNode(function(a){var c=[];for(var d in i){var e=i[d][a];r(d,b,a,e),c.push(e)}c.sort(function(a,b){return a-b}),q(b,a,(c[1]+c[2])/2)});var j=0,p=b.graph().rankDir==="BT"||b.graph().rankDir==="RL";c.forEach(function(c){var e=d.max(c.map(function(a){return o(b,a)}));j+=e/2,c.forEach(function(a){s(b,a,p?-j:j)}),j+=e/2+a.rankSep});var u=d.min(b.nodes().map(function(a){return q(b,a)-n(b,a)/2})),v=d.min(b.nodes().map(function(a){return s(b,a)-o(b,a)/2}));b.eachNode(function(a){q(b,a,q(b,a)-u),s(b,a,s(b,a)-v)})}function e(a,b){return a<b?a.toString().length+":"+a+"-"+b:b.toString().length+":"+b+"-"+a}function f(a,b){function k(a){var b=d[a];if(b<h||b>j)c[e(g[i],a)]=!0}var c={},d={},f,g,h,i,j;if(b.length<=2)return c;b[1].forEach(function(a,b){d[a]=b});for(var l=1;l<b.length-1;++l){f=b[l],g=b[l+1],h=0,i=0;for(var m=0;m<g.length;++m){var n=g[m];d[n]=m,j=undefined;if(a.node(n).dummy){var o=a.predecessors(n)[0];o!==undefined&&a.node(o).dummy&&(j=d[o])}j===undefined&&m===g.length-1&&(j=f.length-1);if(j!==undefined){for(;i<=m;++i)a.predecessors(g[i]).forEach(k);h=j}}}return c}function g(a,b,c,d){var f={},g={},h={};return b.forEach(function(a){a.forEach(function(a,b){g[a]=a,h[a]=a,f[a]=b})}),b.forEach(function(b){var i=-1;b.forEach(function(b){var j=a[d](b),k;j.length>0&&(j.sort(function(a,b){return f[a]-f[b]}),k=(j.length-1)/2,j.slice(Math.floor(k),Math.ceil(k)+1).forEach(function(a){h[b]===b&&!c[e(a,b)]&&i<f[a]&&(h[a]=b,h[b]=g[b]=g[a],i=f[a])}))})}),{pos:f,root:g,align:h}}function h(a,b,c,e,f){function l(a,b,c){b in h[a]?h[a][b]=Math.min(h[a][b],c):h[a][b]=c}function m(b){if(!(b in k)){k[b]=0;var d=b;do{if(c[d]>0){var h=e[j[d]];m(h),g[b]===b&&(g[b]=g[h]);var i=p(a,j[d])+p(a,d);g[b]!==g[h]?l(g[h],g[b],k[b]-k[h]-i):k[b]=Math.max(k[b],k[h]+i)}d=f[d]}while(d!==b)}}var g={},h={},i={},j={},k={};return b.forEach(function(a){a.forEach(function(b,c){g[b]=b,h[b]={},c>0&&(j[b]=a[c-1])})}),d.values(e).forEach(function(a){m(a)}),b.forEach(function(a){a.forEach(function(a){k[a]=k[e[a]];if(a===e[a]&&a===g[a]){var b=0;a in h&&Object.keys(h[a]).length>0&&(b=d.min(Object.keys(h[a]).map(function(b){return h[a][b]+(b in i?i[b]:0)}))),i[a]=b}})}),b.forEach(function(a){a.forEach(function(a){k[a]+=i[g[e[a]]]||0})}),k}function i(a,b,c){return d.min(b.map(function(a){var b=a[0];return c[b]}))}function j(a,b,c){return d.max(b.map(function(a){var b=a[a.length-1];return c[b]}))}function k(a,b,c){function h(a){c[l][a]+=g[l]}var d={},e={},f,g={},k=Number.POSITIVE_INFINITY;for(var l in c){var m=c[l];d[l]=i(a,b,m),e[l]=j(a,b,m);var n=e[l]-d[l];n<k&&(k=n,f=l)}["u","d"].forEach(function(a){["l","r"].forEach(function(b){var c=a+b;g[c]=b==="l"?d[f]-d[c]:e[f]-e[c]})});for(l in c)a.eachNode(h)}function l(a){for(var b in a)a[b]=-a[b]}function m(a){a.forEach(function(a){a.reverse()})}function n(a,b){switch(a.graph().rankDir){case"LR":return a.node(b).height;case"RL":return a.node(b).height;default:return a.node(b).width}}function o(a,b){switch(a.graph().rankDir){case"LR":return a.node(b).width;case"RL":return a.node(b).width;default:return a.node(b).height}}function p(b,c){if(a.universalSep!==null)return a.universalSep;var d=n(b,c),e=b.node(c).dummy?a.edgeSep:a.nodeSep;return(d+e)/2}function q(a,b,c){if(a.graph().rankDir==="LR"||a.graph().rankDir==="RL"){if(arguments.length<3)return a.node(b).y;a.node(b).y=c}else{if(arguments.length<3)return a.node(b).x;a.node(b).x=c}}function r(a,b,c,d){if(b.graph().rankDir==="LR"||b.graph().rankDir==="RL"){if(arguments.length<3)return b.node(c)[a];b.node(c)[a]=d}else{if(arguments.length<3)return b.node(c)[a];b.node(c)[a]=d}}function s(a,b,c){if(a.graph().rankDir==="LR"||a.graph().rankDir==="RL"){if(arguments.length<3)return a.node(b).x;a.node(b).x=c}else{if(arguments.length<3)return a.node(b).y;a.node(b).y=c}}function t(a,b,c,d){c.forEach(function(c,e){var f,g;c.forEach(function(c){var h=d[c];if(f){var i=p(b,f)+p(b,c);h-g<i&&console.log("Position phase: sep violation. Align: "+a+". Layer: "+e+". "+"U: "+f+" V: "+c+". Actual sep: "+(h-g)+" Expected sep: "+i)}f=c,g=h})})}var a={nodeSep:50,edgeSep:10,universalSep:null,rankSep:30},b={};return b.nodeSep=d.propertyAccessor(b,a,"nodeSep"),b.edgeSep=d.propertyAccessor(b,a,"edgeSep"),b.universalSep=d.propertyAccessor(b,a,"universalSep"),b.rankSep=d.propertyAccessor(b,a,"rankSep"),b.debugLevel=d.propertyAccessor(b,a,"debugLevel"),b.run=c,b}},{"./util":26}],19:[function(a,b,c){function l(a,b){n(a),d.time("constraints.apply",h.apply)(a),o(a),d.time("acyclic",e)(a);var c=a.filterNodes(d.filterNonSubgraphs(a));f(c),j(c).forEach(function(a){var d=c.filterNodes(k.nodesFromList(a));r(d,b)}),d.time("constraints.relax",h.relax(a)),d.time("reorientEdges",q)(a)}function m(a){e.undo(a)}function n(a){a.eachEdge(function(b,c,d,e){if(c===d){var f=p(a,b,c,d,e,0,!1),g=p(a,b,c,d,e,1,!0),h=p(a,b,c,d,e,2,!1);a.addEdge(null,f,c,{minLen:1,selfLoop:!0}),a.addEdge(null,f,g,{minLen:1,selfLoop:!0}),a.addEdge(null,c,h,{minLen:1,selfLoop:!0}),a.addEdge(null,g,h,{minLen:1,selfLoop:!0}),a.delEdge(b)}})}function o(a){a.eachEdge(function(b,c,d,e){if(c===d){var f=e.originalEdge,g=p(a,f.e,f.u,f.v,f.value,0,!0);a.addEdge(null,c,g,{minLen:1}),a.addEdge(null,g,d,{minLen:1}),a.delEdge(b)}})}function p(a,b,c,d,e,f,g){return a.addNode(null,{width:g?e.width:0,height:g?e.height:0,edge:{id:b,source:c,target:d,attrs:e},dummy:!0,index:f})}function q(a){a.eachEdge(function(b,c,d,e){a.node(c).rank>a.node(d).rank&&(a.delEdge(b),e.reversed=!0,a.addEdge(b,d,c,e))})}function r(a,b){var c=g(a);b&&(d.log(1,"Using network simplex for ranking"),i(a,c)),s(a)}function s(a){var b=d.min(a.nodes().map(function(b){return a.node(b).rank}));a.eachNode(function(a,c){c.rank-=b})}var d=a("./util"),e=a("./rank/acyclic"),f=a("./rank/initRank"),g=a("./rank/feasibleTree"),h=a("./rank/constraints"),i=a("./rank/simplex"),j=a("graphlib").alg.components,k=a("graphlib").filter;c.run=l,c.restoreEdges=m},{"./rank/acyclic":20,"./rank/constraints":21,"./rank/feasibleTree":22,"./rank/initRank":23,"./rank/simplex":25,"./util":26,graphlib:28}],20:[function(a,b,c){function e(a){function f(d){if(d in c)return;c[d]=b[d]=!0,a.outEdges(d).forEach(function(c){var h=a.target(c),i;d===h?console.error('Warning: found self loop "'+c+'" for node "'+d+'"'):h in b?(i=a.edge(c),a.delEdge(c),i.reversed=!0,++e,a.addEdge(c,h,d,i)):f(h)}),delete b[d]}var b={},c={},e=0;return a.eachNode(function(a){f(a)}),d.log(2,"Acyclic Phase: reversed "+e+" edge(s)"),e}function f(a){a.eachEdge(function(b,c,d,e){e.reversed&&(delete e.reversed,a.delEdge(b),a.addEdge(b,d,c,e))})}var d=a("../util");b.exports=e,b.exports.undo=f},{"../util":26}],21:[function(a,b,c){function d(a){return a!=="min"&&a!=="max"&&a.indexOf("same_")!==0?(console.error("Unsupported rank type: "+a),!1):!0}function e(a,b,c,d){a.inEdges(b).forEach(function(b){var e=a.edge(b),f;e.originalEdge?f=e:f={originalEdge:{e:b,u:a.source(b),v:a.target(b),value:e},minLen:a.edge(b).minLen},e.selfLoop&&(d=!1),d?(a.addEdge(null,c,a.source(b),f),f.reversed=!0):a.addEdge(null,a.source(b),c,f)})}function f(a,b,c,d){a.outEdges(b).forEach(function(b){var e=a.edge(b),f;e.originalEdge?f=e:f={originalEdge:{e:b,u:a.source(b),v:a.target(b),value:e},minLen:a.edge(b).minLen},e.selfLoop&&(d=!1),d?(a.addEdge(null,a.target(b),c,f),f.reversed=!0):a.addEdge(null,c,a.target(b),f)})}function g(a,b,c){c!==undefined&&a.children(b).forEach(function(b){b!==c&&!a.outEdges(c,b).length&&!a.node(b).dummy&&a.addEdge(null,c,b,{minLen:0})})}function h(a,b,c){c!==undefined&&a.children(b).forEach(function(b){b!==c&&!a.outEdges(b,c).length&&!a.node(b).dummy&&a.addEdge(null,b,c,{minLen:0})})}c.apply=function(a){function b(c){var i={};a.children(c).forEach(function(g){if(a.children(g).length){b(g);return}var h=a.node(g),j=h.prefRank;if(j!==undefined){if(!d(j))return;j in i?i.prefRank.push(g):i.prefRank=[g];var k=i[j];k===undefined&&(k=i[j]=a.addNode(null,{originalNodes:[]}),a.parent(k,c)),e(a,g,k,j==="min"),f(a,g,k,j==="max"),a.node(k).originalNodes.push({u:g,value:h,parent:c}),a.delNode(g)}}),g(a,c,i.min),h(a,c,i.max)}b(null)},c.relax=function(a){var b=[];a.eachEdge(function(a,c,d,e){var f=e.originalEdge;f&&b.push(f)}),a.eachNode(function(b,c){var d=c.originalNodes;d&&(d.forEach(function(b){b.value.rank=c.rank,a.addNode(b.u,b.value),a.parent(b.u,b.parent)}),a.delNode(b))}),b.forEach(function(b){a.addEdge(b.e,b.u,b.v,b.value)})}},{}],22:[function(a,b,c){function g(a){function g(d){var e=!0;return a.predecessors(d).forEach(function(f){b.has(f)&&!h(a,f,d)&&(b.has(d)&&(c.addNode(d,{}),b.remove(d),c.graph({root:d})),c.addNode(f,{}),c.addEdge(null,f,d,{reversed:!0}),b.remove(f),g(f),e=!1)}),a.successors(d).forEach(function(f){b.has(f)&&!h(a,d,f)&&(b.has(d)&&(c.addNode(d,{}),b.remove(d),c.graph({root:d})),c.addNode(f,{}),c.addEdge(null,d,f,{}),b.remove(f),g(f),e=!1)}),e}function i(){var d=Number.MAX_VALUE;b.keys().forEach(function(c){a.predecessors(c).forEach(function(e){if(!b.has(e)){var f=h(a,e,c);Math.abs(f)<Math.abs(d)&&(d=-f)}}),a.successors(c).forEach(function(e){if(!b.has(e)){var f=h(a,c,e);Math.abs(f)<Math.abs(d)&&(d=f)}})}),c.eachNode(function(b){a.node(b).rank-=d})}var b=new d(a.nodes()),c=new e;if(b.size()===1){var f=a.nodes()[0];return c.addNode(f,{}),c.graph({root:f}),c}while(b.size()){var j=c.order()?c.nodes():b.keys();for(var k=0,l=j.length;k<l&&g(j[k]);++k);b.size()&&i()}return c}function h(a,b,c){var d=a.node(c).rank-a.node(b).rank,e=f.max(a.outEdges(b,c).map(function(b){return a.edge(b).minLen}));return d-e}var d=a("cp-data").Set,e=a("graphlib").Digraph,f=a("../util");b.exports=g},{"../util":26,"cp-data":5,graphlib:28}],23:[function(a,b,c){function f(a){var b=e(a);b.forEach(function(b){var c=a.inEdges(b);if(c.length===0){a.node(b).rank=0;return}var e=c.map(function(b){return a.node(a.source(b)).rank+a.edge(b).minLen});a.node(b).rank=d.max(e)})}var d=a("../util"),e=a("graphlib").alg.topsort;b.exports=f},{"../util":26,graphlib:28}],24:[function(a,b,c){function d(a,b,c,d){return Math.abs(a.node(b).rank-a.node(c).rank)-d}b.exports={slack:d}},{}],25:[function(a,b,c){function f(a,b){g(a,b);for(;;){var c=k(b);if(c===null)break;var d=l(a,b,c);m(a,b,c,d)}}function g(a,b){function c(d){var e=b.successors(d);for(var f in e){var g=e[f];c(g)}d!==b.graph().root&&i(a,b,d)}h(b),b.eachEdge(function(a,b,c,d){d.cutValue=0}),c(b.graph().root)}function h(a){function c(d){var e=a.successors(d),f=b;for(var g in e){var h=e[g];c(h),f=Math.min(f,a.node(h).low)}a.node(d).low=f,a.node(d).lim=b++}var b=0;c(a.graph().root)}function i(a,b,c){var d=b.inEdges(c)[0],e=[],f=b.outEdges(c);for(var g in f)e.push(b.target(f[g]));var h=0,i=0,k=0,l=0,m=0,n=a.outEdges(c),o;for(var p in n){var q=a.target(n[p]);for(o in e)j(b,q,e[o])&&i++;j(b,q,c)||l++}var r=a.inEdges(c);for(var s in r){var t=a.source(r[s]);for(o in e)j(b,t,e[o])&&k++;j(b,t,c)||m++}var u=0;for(o in e){var v=b.edge(f[o]).cutValue;b.edge(f[o]).reversed?u-=v:u+=v}b.edge(d).reversed?h-=u-i+k-l+m:h+=u-i+k-l+m,b.edge(d).cutValue=h}function j(a,b,c){return a.node(c).low<=a.node(b).lim&&a.node(b).lim<=a.node(c).lim}function k(a){var b=a.edges();for(var c in b){var d=b[c],e=a.edge(d);if(e.cutValue<0)return d}return null}function l(a,b,c){var d=b.source(c),f=b.target(c),g=b.node(f).lim<b.node(d).lim?f:d,h=!b.edge(c).reversed,i=Number.POSITIVE_INFINITY,k;h?a.eachEdge(function(d,f,h,l){if(d!==c&&j(b,f,g)&&!j(b,h,g)){var m=e.slack(a,f,h,l.minLen);m<i&&(i=m,k=d)}}):a.eachEdge(function(d,f,h,l){if(d!==c&&!j(b,f,g)&&j(b,h,g)){var m=e.slack(a,f,h,l.minLen);m<i&&(i=m,k=d)}});if(k===undefined){var l=[],m=[];throw a.eachNode(function(a){j(b,a,g)?m.push(a):l.push(a)}),new Error("No edge found from outside of tree to inside")}return k}function m(a,b,c,d){function h(a){var c=b.inEdges(a);for(var d in c){var e=c[d],f=b.source(e),g=b.edge(e);h(f),b.delEdge(e),g.reversed=!g.reversed,b.addEdge(e,a,f,g)}}b.delEdge(c);var e=a.source(d),f=a.target(d);h(f);var i=e,j=b.inEdges(i);while(j.length>0)i=b.source(j[0]),j=b.inEdges(i);b.graph().root=i,b.addEdge(null,e,f,{cutValue:0}),g(a,b),n(a,b)}function n(a,b){function c(d){var e=b.successors(d);e.forEach(function(b){var e=o(a,d,b);a.node(b).rank=a.node(d).rank+e,c(b)})}c(b.graph().root)}function o(a,b,c){var e=a.outEdges(b,c);if(e.length>0)return d.max(e.map(function(b){return a.edge(b).minLen}));var f=a.inEdges(b,c);if(f.length>0)return-d.max(f.map(function(b){return a.edge(b).minLen}))}var d=a("../util"),e=a("./rankUtil");b.exports=f},{"../util":26,"./rankUtil":24}],26:[function(a,b,c){function d(a,b){return function(){var c=(new Date).getTime();try{return b.apply(null,arguments)}finally{e(1,a+" time: "+((new Date).getTime()-c)+"ms")}}}function e(a){e.level>=a&&console.log.apply(console,Array.prototype.slice.call(arguments,1))}c.min=function(a){return Math.min.apply(Math,a)},c.max=function(a){return Math.max.apply(Math,a)},c.all=function(a,b){for(var c=0;c<a.length;++c)if(!b(a[c]))return!1;return!0},c.sum=function(a){return a.reduce(function(a,b){return a+b},0)},c.values=function(a){return Object.keys(a).map(function(b){return a[b]})},c.shuffle=function(a){for(i=a.length-1;i>0;--i){var b=Math.floor(Math.random()*(i+1)),c=a[b];a[b]=a[i],a[i]=c}},c.propertyAccessor=function(a,b,c,d){return function(e){return arguments.length?(b[c]=e,d&&d(e),a):b[c]}},c.ordering=function(a){var b=[];return a.eachNode(function(a,c){var d=b[c.rank]||(b[c.rank]=[]);d[c.order]=a}),b},c.filterNonSubgraphs=function(a){return function(b){return a.children(b).length===0}},d.enabled=!1,c.time=d,e.level=0,c.log=e},{}],27:[function(a,b,c){b.exports="0.4.5"},{}],28:[function(a,b,c){c.Graph=a("./lib/Graph"),c.Digraph=a("./lib/Digraph"),c.CGraph=a("./lib/CGraph"),c.CDigraph=a("./lib/CDigraph"),a("./lib/graph-converters"),c.alg={isAcyclic:a("./lib/alg/isAcyclic"),components:a("./lib/alg/components"),dijkstra:a("./lib/alg/dijkstra"),dijkstraAll:a("./lib/alg/dijkstraAll"),findCycles:a("./lib/alg/findCycles"),floydWarshall:a("./lib/alg/floydWarshall"),postorder:a("./lib/alg/postorder"),preorder:a("./lib/alg/preorder"),prim:a("./lib/alg/prim"),tarjan:a("./lib/alg/tarjan"),topsort:a("./lib/alg/topsort")},c.converter={json:a("./lib/converter/json.js")};var d=a("./lib/filter");c.filter={all:d.all,nodesFromList:d.nodesFromList},c.version=a("./lib/version")},{"./lib/CDigraph":30,"./lib/CGraph":31,"./lib/Digraph":32,"./lib/Graph":33,"./lib/alg/components":34,"./lib/alg/dijkstra":35,"./lib/alg/dijkstraAll":36,"./lib/alg/findCycles":37,"./lib/alg/floydWarshall":38,"./lib/alg/isAcyclic":39,"./lib/alg/postorder":40,"./lib/alg/preorder":41,"./lib/alg/prim":42,"./lib/alg/tarjan":43,"./lib/alg/topsort":44,"./lib/converter/json.js":46,"./lib/filter":47,"./lib/graph-converters":48,"./lib/version":50}],29:[function(a,b,c){function e(){this._value=undefined,this._nodes={},this._edges={},this._nextId=0}function f(a,b,c){(a[b]||(a[b]=new d)).add(
c)}function g(a,b,c){var d=a[b];d.remove(c),d.size()===0&&delete a[b]}var d=a("cp-data").Set;b.exports=e,e.prototype.order=function(){return Object.keys(this._nodes).length},e.prototype.size=function(){return Object.keys(this._edges).length},e.prototype.graph=function(a){if(arguments.length===0)return this._value;this._value=a},e.prototype.hasNode=function(a){return a in this._nodes},e.prototype.node=function(a,b){var c=this._strictGetNode(a);if(arguments.length===1)return c.value;c.value=b},e.prototype.nodes=function(){var a=[];return this.eachNode(function(b){a.push(b)}),a},e.prototype.eachNode=function(a){for(var b in this._nodes){var c=this._nodes[b];a(c.id,c.value)}},e.prototype.hasEdge=function(a){return a in this._edges},e.prototype.edge=function(a,b){var c=this._strictGetEdge(a);if(arguments.length===1)return c.value;c.value=b},e.prototype.edges=function(){var a=[];return this.eachEdge(function(b){a.push(b)}),a},e.prototype.eachEdge=function(a){for(var b in this._edges){var c=this._edges[b];a(c.id,c.u,c.v,c.value)}},e.prototype.incidentNodes=function(a){var b=this._strictGetEdge(a);return[b.u,b.v]},e.prototype.addNode=function(a,b){if(a===undefined||a===null){do a="_"+ ++this._nextId;while(this.hasNode(a))}else if(this.hasNode(a))throw new Error("Graph already has node '"+a+"'");return this._nodes[a]={id:a,value:b},a},e.prototype.delNode=function(a){this._strictGetNode(a),this.incidentEdges(a).forEach(function(a){this.delEdge(a)},this),delete this._nodes[a]},e.prototype._addEdge=function(a,b,c,d,e,g){this._strictGetNode(b),this._strictGetNode(c);if(a===undefined||a===null){do a="_"+ ++this._nextId;while(this.hasEdge(a))}else if(this.hasEdge(a))throw new Error("Graph already has edge '"+a+"'");return this._edges[a]={id:a,u:b,v:c,value:d},f(e[c],b,a),f(g[b],c,a),a},e.prototype._delEdge=function(a,b,c){var d=this._strictGetEdge(a);g(b[d.v],d.u,a),g(c[d.u],d.v,a),delete this._edges[a]},e.prototype.copy=function(){var a=new this.constructor;return a.graph(this.graph()),this.eachNode(function(b,c){a.addNode(b,c)}),this.eachEdge(function(b,c,d,e){a.addEdge(b,c,d,e)}),a._nextId=this._nextId,a},e.prototype.filterNodes=function(a){var b=new this.constructor;return b.graph(this.graph()),this.eachNode(function(c,d){a(c)&&b.addNode(c,d)}),this.eachEdge(function(a,c,d,e){b.hasNode(c)&&b.hasNode(d)&&b.addEdge(a,c,d,e)}),b},e.prototype._strictGetNode=function(a){var b=this._nodes[a];if(b===undefined)throw new Error("Node '"+a+"' is not in graph");return b},e.prototype._strictGetEdge=function(a){var b=this._edges[a];if(b===undefined)throw new Error("Edge '"+a+"' is not in graph");return b}},{"cp-data":5}],30:[function(a,b,c){var d=a("./Digraph"),e=a("./compoundify"),f=e(d);b.exports=f,f.fromDigraph=function(a){var b=new f,c=a.graph();return c!==undefined&&b.graph(c),a.eachNode(function(a,c){c===undefined?b.addNode(a):b.addNode(a,c)}),a.eachEdge(function(a,c,d,e){e===undefined?b.addEdge(null,c,d):b.addEdge(null,c,d,e)}),b},f.prototype.toString=function(){return"CDigraph "+JSON.stringify(this,null,2)}},{"./Digraph":32,"./compoundify":45}],31:[function(a,b,c){var d=a("./Graph"),e=a("./compoundify"),f=e(d);b.exports=f,f.fromGraph=function(a){var b=new f,c=a.graph();return c!==undefined&&b.graph(c),a.eachNode(function(a,c){c===undefined?b.addNode(a):b.addNode(a,c)}),a.eachEdge(function(a,c,d,e){e===undefined?b.addEdge(null,c,d):b.addEdge(null,c,d,e)}),b},f.prototype.toString=function(){return"CGraph "+JSON.stringify(this,null,2)}},{"./Graph":33,"./compoundify":45}],32:[function(a,b,c){function g(){e.call(this),this._inEdges={},this._outEdges={}}var d=a("./util"),e=a("./BaseGraph"),f=a("cp-data").Set;b.exports=g,g.prototype=new e,g.prototype.constructor=g,g.prototype.isDirected=function(){return!0},g.prototype.successors=function(a){return this._strictGetNode(a),Object.keys(this._outEdges[a]).map(function(a){return this._nodes[a].id},this)},g.prototype.predecessors=function(a){return this._strictGetNode(a),Object.keys(this._inEdges[a]).map(function(a){return this._nodes[a].id},this)},g.prototype.neighbors=function(a){return f.union([this.successors(a),this.predecessors(a)]).keys()},g.prototype.sources=function(){var a=this;return this._filterNodes(function(b){return a.inEdges(b).length===0})},g.prototype.sinks=function(){var a=this;return this._filterNodes(function(b){return a.outEdges(b).length===0})},g.prototype.source=function(a){return this._strictGetEdge(a).u},g.prototype.target=function(a){return this._strictGetEdge(a).v},g.prototype.inEdges=function(a,b){this._strictGetNode(a);var c=f.union(d.values(this._inEdges[a])).keys();return arguments.length>1&&(this._strictGetNode(b),c=c.filter(function(a){return this.source(a)===b},this)),c},g.prototype.outEdges=function(a,b){this._strictGetNode(a);var c=f.union(d.values(this._outEdges[a])).keys();return arguments.length>1&&(this._strictGetNode(b),c=c.filter(function(a){return this.target(a)===b},this)),c},g.prototype.incidentEdges=function(a,b){return arguments.length>1?f.union([this.outEdges(a,b),this.outEdges(b,a)]).keys():f.union([this.inEdges(a),this.outEdges(a)]).keys()},g.prototype.toString=function(){return"Digraph "+JSON.stringify(this,null,2)},g.prototype.addNode=function(a,b){return a=e.prototype.addNode.call(this,a,b),this._inEdges[a]={},this._outEdges[a]={},a},g.prototype.delNode=function(a){e.prototype.delNode.call(this,a),delete this._inEdges[a],delete this._outEdges[a]},g.prototype.addEdge=function(a,b,c,d){return e.prototype._addEdge.call(this,a,b,c,d,this._inEdges,this._outEdges)},g.prototype.delEdge=function(a){e.prototype._delEdge.call(this,a,this._inEdges,this._outEdges)},g.prototype._filterNodes=function(a){var b=[];return this.eachNode(function(c){a(c)&&b.push(c)}),b}},{"./BaseGraph":29,"./util":49,"cp-data":5}],33:[function(a,b,c){function g(){e.call(this),this._incidentEdges={}}var d=a("./util"),e=a("./BaseGraph"),f=a("cp-data").Set;b.exports=g,g.prototype=new e,g.prototype.constructor=g,g.prototype.isDirected=function(){return!1},g.prototype.neighbors=function(a){return this._strictGetNode(a),Object.keys(this._incidentEdges[a]).map(function(a){return this._nodes[a].id},this)},g.prototype.incidentEdges=function(a,b){return this._strictGetNode(a),arguments.length>1?(this._strictGetNode(b),b in this._incidentEdges[a]?this._incidentEdges[a][b].keys():[]):f.union(d.values(this._incidentEdges[a])).keys()},g.prototype.toString=function(){return"Graph "+JSON.stringify(this,null,2)},g.prototype.addNode=function(a,b){return a=e.prototype.addNode.call(this,a,b),this._incidentEdges[a]={},a},g.prototype.delNode=function(a){e.prototype.delNode.call(this,a),delete this._incidentEdges[a]},g.prototype.addEdge=function(a,b,c,d){return e.prototype._addEdge.call(this,a,b,c,d,this._incidentEdges,this._incidentEdges)},g.prototype.delEdge=function(a){e.prototype._delEdge.call(this,a,this._incidentEdges,this._incidentEdges)}},{"./BaseGraph":29,"./util":49,"cp-data":5}],34:[function(a,b,c){function e(a){function e(b,d){c.has(b)||(c.add(b),d.push(b),a.neighbors(b).forEach(function(a){e(a,d)}))}var b=[],c=new d;return a.nodes().forEach(function(a){var c=[];e(a,c),c.length>0&&b.push(c)}),b}var d=a("cp-data").Set;b.exports=e},{"cp-data":5}],35:[function(a,b,c){function e(a,b,c,e){function h(b){var d=a.incidentNodes(b),e=d[0]!==i?d[0]:d[1],h=f[e],k=c(b),l=j.distance+k;if(k<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+b+" Weight: "+k);l<h.distance&&(h.distance=l,h.predecessor=i,g.decrease(e,l))}var f={},g=new d;c=c||function(){return 1},e=e||(a.isDirected()?function(b){return a.outEdges(b)}:function(b){return a.incidentEdges(b)}),a.eachNode(function(a){var c=a===b?0:Number.POSITIVE_INFINITY;f[a]={distance:c},g.add(a,c)});var i,j;while(g.size()>0){i=g.removeMin(),j=f[i];if(j.distance===Number.POSITIVE_INFINITY)break;e(i).forEach(h)}return f}var d=a("cp-data").PriorityQueue;b.exports=e},{"cp-data":5}],36:[function(a,b,c){function e(a,b,c){var e={};return a.eachNode(function(f){e[f]=d(a,f,b,c)}),e}var d=a("./dijkstra");b.exports=e},{"./dijkstra":35}],37:[function(a,b,c){function e(a){return d(a).filter(function(a){return a.length>1})}var d=a("./tarjan");b.exports=e},{"./tarjan":43}],38:[function(a,b,c){function d(a,b,c){var d={},e=a.nodes();return b=b||function(){return 1},c=c||(a.isDirected()?function(b){return a.outEdges(b)}:function(b){return a.incidentEdges(b)}),e.forEach(function(f){d[f]={},d[f][f]={distance:0},e.forEach(function(a){f!==a&&(d[f][a]={distance:Number.POSITIVE_INFINITY})}),c(f).forEach(function(c){var e=a.incidentNodes(c),h=e[0]!==f?e[0]:e[1],i=b(c);i<d[f][h].distance&&(d[f][h]={distance:i,predecessor:f})})}),e.forEach(function(a){var b=d[a];e.forEach(function(c){var f=d[c];e.forEach(function(c){var d=f[a],e=b[c],g=f[c],h=d.distance+e.distance;h<g.distance&&(g.distance=h,g.predecessor=e.predecessor)})})}),d}b.exports=d},{}],39:[function(a,b,c){function e(a){try{d(a)}catch(b){if(b instanceof d.CycleException)return!1;throw b}return!0}var d=a("./topsort");b.exports=e},{"./topsort":44}],40:[function(a,b,c){function e(a,b,c){function f(b,d){if(e.has(b))throw new Error("The input graph is not a tree: "+a);e.add(b),a.neighbors(b).forEach(function(a){a!==d&&f(a,b)}),c(b)}var e=new d;if(a.isDirected())throw new Error("This function only works for undirected graphs");f(b)}var d=a("cp-data").Set;b.exports=e},{"cp-data":5}],41:[function(a,b,c){function e(a,b,c){function f(b,d){if(e.has(b))throw new Error("The input graph is not a tree: "+a);e.add(b),c(b),a.neighbors(b).forEach(function(a){a!==d&&f(a,b)})}var e=new d;if(a.isDirected())throw new Error("This function only works for undirected graphs");f(b)}var d=a("cp-data").Set;b.exports=e},{"cp-data":5}],42:[function(a,b,c){function f(a,b){function i(c){var d=a.incidentNodes(c),e=d[0]!==h?d[0]:d[1],i=g.priority(e);if(i!==undefined){var j=b(c);j<i&&(f[e]=h,g.decrease(e,j))}}var c=new d,f={},g=new e,h;if(a.order()===0)return c;a.eachNode(function(a){g.add(a,Number.POSITIVE_INFINITY),c.addNode(a)}),g.decrease(a.nodes()[0],0);var j=!1;while(g.size()>0){h=g.removeMin();if(h in f)c.addEdge(null,h,f[h]);else{if(j)throw new Error("Input graph is not connected: "+a);j=!0}a.incidentEdges(h).forEach(i)}return c}var d=a("../Graph"),e=a("cp-data").PriorityQueue;b.exports=f},{"../Graph":33,"cp-data":5}],43:[function(a,b,c){function d(a){function f(h){var i=d[h]={onStack:!0,lowlink:b,index:b++};c.push(h),a.successors(h).forEach(function(a){a in d?d[a].onStack&&(i.lowlink=Math.min(i.lowlink,d[a].index)):(f(a),i.lowlink=Math.min(i.lowlink,d[a].lowlink))});if(i.lowlink===i.index){var j=[],k;do k=c.pop(),d[k].onStack=!1,j.push(k);while(h!==k);e.push(j)}}if(!a.isDirected())throw new Error("tarjan can only be applied to a directed graph. Bad input: "+a);var b=0,c=[],d={},e=[];return a.nodes().forEach(function(a){a in d||f(a)}),e}b.exports=d},{}],44:[function(a,b,c){function d(a){function f(g){if(g in c)throw new e;g in b||(c[g]=!0,b[g]=!0,a.predecessors(g).forEach(function(a){f(a)}),delete c[g],d.push(g))}if(!a.isDirected())throw new Error("topsort can only be applied to a directed graph. Bad input: "+a);var b={},c={},d=[],g=a.sinks();if(a.order()!==0&&g.length===0)throw new e;return a.sinks().forEach(function(a){f(a)}),d}function e(){}b.exports=d,d.CycleException=e,e.prototype.toString=function(){return"Graph has at least one cycle"}},{}],45:[function(a,b,c){function e(a){function b(){a.call(this),this._parents={},this._children={},this._children[null]=new d}return b.prototype=new a,b.prototype.constructor=b,b.prototype.parent=function(a,b){this._strictGetNode(a);if(arguments.length<2)return this._parents[a];if(a===b)throw new Error("Cannot make "+a+" a parent of itself");b!==null&&this._strictGetNode(b),this._children[this._parents[a]].remove(a),this._parents[a]=b,this._children[b].add(a)},b.prototype.children=function(a){return a!==null&&this._strictGetNode(a),this._children[a].keys()},b.prototype.addNode=function(b,c){return b=a.prototype.addNode.call(this,b,c),this._parents[b]=null,this._children[b]=new d,this._children[null].add(b),b},b.prototype.delNode=function(b){var c=this.parent(b);return this._children[b].keys().forEach(function(a){this.parent(a,c)},this),this._children[c].remove(b),delete this._parents[b],delete this._children[b],a.prototype.delNode.call(this,b)},b.prototype.copy=function(){var b=a.prototype.copy.call(this);return this.nodes().forEach(function(a){b.parent(a,this.parent(a))},this),b},b.prototype.filterNodes=function(b){function f(a){var b=c.parent(a);return b===null||d.hasNode(b)?(e[a]=b,b):b in e?e[b]:f(b)}var c=this,d=a.prototype.filterNodes.call(this,b),e={};return d.eachNode(function(a){d.parent(a,f(a))}),d},b}var d=a("cp-data").Set;b.exports=e},{"cp-data":5}],46:[function(a,b,c){function h(a){return Object.prototype.toString.call(a).slice(8,-1)}var d=a("../Graph"),e=a("../Digraph"),f=a("../CGraph"),g=a("../CDigraph");c.decode=function(a,b,c){c=c||e;if(h(a)!=="Array")throw new Error("nodes is not an Array");if(h(b)!=="Array")throw new Error("edges is not an Array");if(typeof c=="string")switch(c){case"graph":c=d;break;case"digraph":c=e;break;case"cgraph":c=f;break;case"cdigraph":c=g;break;default:throw new Error("Unrecognized graph type: "+c)}var i=new c;return a.forEach(function(a){i.addNode(a.id,a.value)}),i.parent&&a.forEach(function(a){a.children&&a.children.forEach(function(b){i.parent(b,a.id)})}),b.forEach(function(a){i.addEdge(a.id,a.u,a.v,a.value)}),i},c.encode=function(a){var b=[],c=[];a.eachNode(function(c,d){var e={id:c,value:d};if(a.children){var f=a.children(c);f.length&&(e.children=f)}b.push(e)}),a.eachEdge(function(a,b,d,e){c.push({id:a,u:b,v:d,value:e})});var h;if(a instanceof g)h="cdigraph";else if(a instanceof f)h="cgraph";else if(a instanceof e)h="digraph";else if(a instanceof d)h="graph";else throw new Error("Couldn't determine type of graph: "+a);return{nodes:b,edges:c,type:h}}},{"../CDigraph":30,"../CGraph":31,"../Digraph":32,"../Graph":33}],47:[function(a,b,c){var d=a("cp-data").Set;c.all=function(){return function(){return!0}},c.nodesFromList=function(a){var b=new d(a);return function(a){return b.has(a)}}},{"cp-data":5}],48:[function(a,b,c){var d=a("./Graph"),e=a("./Digraph");d.prototype.toDigraph=d.prototype.asDirected=function(){var a=new e;return this.eachNode(function(b,c){a.addNode(b,c)}),this.eachEdge(function(b,c,d,e){a.addEdge(null,c,d,e),a.addEdge(null,d,c,e)}),a},e.prototype.toGraph=e.prototype.asUndirected=function(){var a=new d;return this.eachNode(function(b,c){a.addNode(b,c)}),this.eachEdge(function(b,c,d,e){a.addEdge(b,c,d,e)}),a}},{"./Digraph":32,"./Graph":33}],49:[function(a,b,c){c.values=function(a){var b=Object.keys(a),c=b.length,d=new Array(c),e;for(e=0;e<c;++e)d[e]=a[b[e]];return d}},{}],50:[function(a,b,c){b.exports="0.7.4"},{}]},{},[1]);
\ No newline at end of file
(function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var j=typeof require=="function"&&require;if(!h&&j)return j(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}var f=typeof require=="function"&&require;for(var g=0;g<d.length;g++)e(d[g]);return e})({1:[function(a,b,c){var d=typeof self!="undefined"?self:typeof window!="undefined"?window:{};d.graphlibDot=a("./index")},{"./index":2}],2:[function(a,b,c){var d=a("./lib/parse"),e=a("./lib/write"),f=a("./lib/version");b.exports={DotGraph:a("./lib/DotGraph"),DotDigraph:a("./lib/DotDigraph"),parse:d,decode:d,parseMany:d.parseMany,write:e,encode:e,version:f,type:"dot",buffer:!1}},{"./lib/DotDigraph":3,"./lib/DotGraph":4,"./lib/parse":8,"./lib/version":9,"./lib/write":10}],3:[function(a,b,c){var d=a("graphlib").CDigraph,e=a("./dotify"),f=e(d);b.exports=f,f.fromDigraph=function(a){var b=new f,c=a.graph();return c!==undefined&&b.graph(c),a.eachNode(function(a,c){c===undefined?b.addNode(a):b.addNode(a,c)}),a.eachEdge(function(a,c,d,e){e===undefined?b.addEdge(null,c,d):b.addEdge(null,c,d,e)}),b}},{"./dotify":7,graphlib:11}],4:[function(a,b,c){var d=a("graphlib").CGraph,e=a("./dotify"),f=e(d);b.exports=f,f.fromGraph=function(a){var b=new f,c=a.graph();return c!==undefined&&b.graph(c),a.eachNode(function(a,c){c===undefined?b.addNode(a):b.addNode(a,c)}),a.eachEdge(function(a,c,d,e){e===undefined?b.addEdge(null,c,d):b.addEdge(null,c,d,e)}),b}},{"./dotify":7,graphlib:11}],5:[function(a,b,c){function e(){this._indent="",this._content="",this._shouldIndent=!0}b.exports=e;var d=" ";e.prototype.indent=function(){this._indent+=d},e.prototype.unindent=function(){this._indent=this._indent.slice(d.length)},e.prototype.writeLine=function(a){this.write((a||"")+"\n"),this._shouldIndent=!0},e.prototype.write=function(a){this._shouldIndent&&(this._shouldIndent=!1,this._content+=this._indent),this._content+=a},e.prototype.toString=function(){return this._content}},{}],6:[function(a,b,c){b.exports=function(){function a(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var b={parse:function(b,c){function i(a,b,c){var d=a,e=c-a.length;for(var f=0;f<e;f++)d=b+d;return d}function j(a){var b=a.charCodeAt(0),c,d;return b<=255?(c="x",d=2):(c="u",d=4),"\\"+c+i(b.toString(16).toUpperCase(),"0",d)}function k(a){if(e<g)return;e>g&&(g=e,h=[]),h.push(a)}function l(){var a,b;b=m();if(b!==null){a=[];while(b!==null)a.push(b),b=m()}else a=null;return a}function m(){var a,c,d,g,h,i,j,l,m,o,p,q,r,s,t,u;s=e,t=e,a=[],c=N();while(c!==null)a.push(c),c=N();if(a!==null){u=e,c=J(),c!==null?(d=N(),d!==null?c=[c,d]:(c=null,e=u)):(c=null,e=u),c=c!==null?c:"";if(c!==null){d=K();if(d!==null){g=[],h=N();while(h!==null)g.push(h),h=N();if(g!==null){h=D(),h=h!==null?h:"";if(h!==null){i=[],j=N();while(j!==null)i.push(j),j=N();if(i!==null){b.charCodeAt(e)===123?(j="{",e++):(j=null,f===0&&k('"{"'));if(j!==null){l=[],m=N();while(m!==null)l.push(m),m=N();if(l!==null){m=n(),m=m!==null?m:"";if(m!==null){o=[],p=N();while(p!==null)o.push(p),p=N();if(o!==null){b.charCodeAt(e)===125?(p="}",e++):(p=null,f===0&&k('"}"'));if(p!==null){q=[],r=N();while(r!==null)q.push(r),r=N();q!==null?a=[a,c,d,g,h,i,j,l,m,o,p,q]:(a=null,e=t)}else a=null,e=t}else a=null,e=t}else a=null,e=t}else a=null,e=t}else a=null,e=t}else a=null,e=t}else a=null,e=t}else a=null,e=t}else a=null,e=t}else a=null,e=t}else a=null,e=t;return a!==null&&(a=function(a,b,c,d){return{type:b,id:c,stmts:d}}(s,a[2],a[4],a[8])),a===null&&(e=s),a}function n(){var a,c,d,g,h,i,j,l,m,n,p;m=e,n=e,a=o();if(a!==null){c=[],d=N();while(d!==null)c.push(d),d=N();if(c!==null){b.charCodeAt(e)===59?(d=";",e++):(d=null,f===0&&k('";"')),d=d!==null?d:"";if(d!==null){g=[],p=e,h=[],i=N();while(i!==null)h.push(i),i=N();if(h!==null){i=o();if(i!==null){j=[],l=N();while(l!==null)j.push(l),l=N();j!==null?(b.charCodeAt(e)===59?(l=";",e++):(l=null,f===0&&k('";"')),l=l!==null?l:"",l!==null?h=[h,i,j,l]:(h=null,e=p)):(h=null,e=p)}else h=null,e=p}else h=null,e=p;while(h!==null){g.push(h),p=e,h=[],i=N();while(i!==null)h.push(i),i=N();if(h!==null){i=o();if(i!==null){j=[],l=N();while(l!==null)j.push(l),l=N();j!==null?(b.charCodeAt(e)===59?(l=";",e++):(l=null,f===0&&k('";"')),l=l!==null?l:"",l!==null?h=[h,i,j,l]:(h=null,e=p)):(h=null,e=p)}else h=null,e=p}else h=null,e=p}g!==null?a=[a,c,d,g]:(a=null,e=n)}else a=null,e=n}else a=null,e=n}else a=null,e=n;return a!==null&&(a=function(a,b,c){var d=[b];for(var e=0;e<c.length;++e)d.push(c[e][1]);return d}(m,a[0],a[3])),a===null&&(e=m),a}function o(){var a;return a=p(),a===null&&(a=s(),a===null&&(a=t(),a===null&&(a=q(),a===null&&(a=r())))),a}function p(){var a,b,c,d,f;d=e,f=e,a=G(),a===null&&(a=E(),a===null&&(a=F()));if(a!==null){b=[],c=N();while(c!==null)b.push(c),c=N();b!==null?(c=u(),c!==null?a=[a,b,c]:(a=null,e=f)):(a=null,e=f)}else a=null,e=f;return a!==null&&(a=function(a,b,c){return{type:"attr",attrType:b,attrs:c||{}}}(d,a[0],a[2])),a===null&&(e=d),a}function q(){var a,c,d,g,h,i,j;i=e,j=e,a=D();if(a!==null){c=[],d=N();while(d!==null)c.push(d),d=N();if(c!==null){b.charCodeAt(e)===61?(d="=",e++):(d=null,f===0&&k('"="'));if(d!==null){g=[],h=N();while(h!==null)g.push(h),h=N();g!==null?(h=D(),h!==null?a=[a,c,d,g,h]:(a=null,e=j)):(a=null,e=j)}else a=null,e=j}else a=null,e=j}else a=null,e=j;return a!==null&&(a=function(a,b,c){var d={};return d[b]=c,{type:"inlineAttr",attrs:d}}(i,a[0],a[4])),a===null&&(e=i),a}function r(){var a,b,c,d,f;d=e,f=e,a=A();if(a!==null){b=[],c=N();while(c!==null)b.push(c),c=N();b!==null?(c=u(),c=c!==null?c:"",c!==null?a=[a,b,c]:(a=null,e=f)):(a=null,e=f)}else a=null,e=f;return a!==null&&(a=function(a,b,c){return{type:"node",id:b,attrs:c||{}}}(d,a[0],a[2])),a===null&&(e=d),a}function s(){var a,b,c,d,f,g,h;g=e,h=e,a=z();if(a!==null){b=[],c=N();while(c!==null)b.push(c),c=N();if(b!==null){c=x();if(c!==null){d=[],f=N();while(f!==null)d.push(f),f=N();d!==null?(f=u(),f=f!==null?f:"",f!==null?a=[a,b,c,d,f]:(a=null,e=h)):(a=null,e=h)}else a=null,e=h}else a=null,e=h}else a=null,e=h;return a!==null&&(a=function(a,b,c,d){var e=[b];for(var f=0;f<c.length;++f)e.push(c[f]);return{type:"edge",elems:e,attrs:d||{}}}(g,a[0],a[2],a[4])),a===null&&(e=g),a}function t(){var a,c,d,g,h,i,j,l,m,o;j=e,l=e,m=e,a=I();if(a!==null){c=[],d=N();while(d!==null)c.push(d),d=N();if(c!==null){o=e,d=D();if(d!==null){g=[],h=N();while(h!==null)g.push(h),h=N();g!==null?d=[d,g]:(d=null,e=o)}else d=null,e=o;d=d!==null?d:"",d!==null?a=[a,c,d]:(a=null,e=m)}else a=null,e=m}else a=null,e=m;a=a!==null?a:"";if(a!==null){b.charCodeAt(e)===123?(c="{",e++):(c=null,f===0&&k('"{"'));if(c!==null){d=[],g=N();while(g!==null)d.push(g),g=N();if(d!==null){g=n(),g=g!==null?g:"";if(g!==null){h=[],i=N();while(i!==null)h.push(i),i=N();h!==null?(b.charCodeAt(e)===125?(i="}",e++):(i=null,f===0&&k('"}"')),i!==null?a=[a,c,d,g,h,i]:(a=null,e=l)):(a=null,e=l)}else a=null,e=l}else a=null,e=l}else a=null,e=l}else a=null,e=l;return a!==null&&(a=function(a,b,c){return b=b[2]||[],{type:"subgraph",id:b[0],stmts:c}}(j,a[0],a[3])),a===null&&(e=j),a}function u(){var a,b,c,d,f,g,h;f=e,g=e,a=v();if(a!==null){b=[],h=e,c=[],d=N();while(d!==null)c.push(d),d=N();c!==null?(d=v(),d!==null?c=[c,d]:(c=null,e=h)):(c=null,e=h);while(c!==null){b.push(c),h=e,c=[],d=N();while(d!==null)c.push(d),d=N();c!==null?(d=v(),d!==null?c=[c,d]:(c=null,e=h)):(c=null,e=h)}b!==null?a=[a,b]:(a=null,e=g)}else a=null,e=g;return a!==null&&(a=function(a,b,c){var d=b;for(var e=0;e<c.length;++e)d=R(d,c[e][1]);return d}(f,a[0],a[1])),a===null&&(e=f),a}function v(){var a,c,d,g,h,i,j;i=e,j=e,b.charCodeAt(e)===91?(a="[",e++):(a=null,f===0&&k('"["'));if(a!==null){c=[],d=N();while(d!==null)c.push(d),d=N();if(c!==null){d=w(),d=d!==null?d:"";if(d!==null){g=[],h=N();while(h!==null)g.push(h),h=N();g!==null?(b.charCodeAt(e)===93?(h="]",e++):(h=null,f===0&&k('"]"')),h!==null?a=[a,c,d,g,h]:(a=null,e=j)):(a=null,e=j)}else a=null,e=j}else a=null,e=j}else a=null,e=j;return a!==null&&(a=function(a,b){return b}(i,a[2])),a===null&&(e=i),a}function w(){var a,c,d,g,h,i,j,l,m;j=e,l=e,a=y();if(a!==null){c=[],m=e,d=[],g=N();while(g!==null)d.push(g),g=N();if(d!==null){b.charCodeAt(e)===44?(g=",",e++):(g=null,f===0&&k('","')),g=g!==null?g:"";if(g!==null){h=[],i=N();while(i!==null)h.push(i),i=N();h!==null?(i=y(),i!==null?d=[d,g,h,i]:(d=null,e=m)):(d=null,e=m)}else d=null,e=m}else d=null,e=m;while(d!==null){c.push(d),m=e,d=[],g=N();while(g!==null)d.push(g),g=N();if(d!==null){b.charCodeAt(e)===44?(g=",",e++):(g=null,f===0&&k('","')),g=g!==null?g:"";if(g!==null){h=[],i=N();while(i!==null)h.push(i),i=N();h!==null?(i=y(),i!==null?d=[d,g,h,i]:(d=null,e=m)):(d=null,e=m)}else d=null,e=m}else d=null,e=m}c!==null?a=[a,c]:(a=null,e=l)}else a=null,e=l;return a!==null&&(a=function(a,b,c){var d=b;for(var e=0;e<c.length;++e)d=R(d,c[e][3]);return d}(j,a[0],a[1])),a===null&&(e=j),a}function x(){var a,c,d,g,h,i,j,l;i=e,j=e,l=e,b.substr(e,2)==="--"?(a="--",e+=2):(a=null,f===0&&k('"--"')),a!==null?(c=function(a){return Q}(e)?null:"",c!==null?a=[a,c]:(a=null,e=l)):(a=null,e=l),a===null&&(l=e,b.substr(e,2)==="->"?(a="->",e+=2):(a=null,f===0&&k('"->"')),a!==null?(c=function(a){return Q}(e)?"":null,c!==null?a=[a,c]:(a=null,e=l)):(a=null,e=l));if(a!==null){c=[],d=N();while(d!==null)c.push(d),d=N();if(c!==null){d=z();if(d!==null){g=[],h=N();while(h!==null)g.push(h),h=N();g!==null?(h=x(),h=h!==null?h:"",h!==null?a=[a,c,d,g,h]:(a=null,e=j)):(a=null,e=j)}else a=null,e=j}else a=null,e=j}else a=null,e=j;return a!==null&&(a=function(a,b,c){var d=[b];for(var e=0;e<c.length;++e)d.push(c[e]);return d}(i,a[2],a[4])),a===null&&(e=i),a}function y(){var a,c,d,g,h,i,j,l;i=e,j=e,a=D();if(a!==null){l=e,c=[],d=N();while(d!==null)c.push(d),d=N();if(c!==null){b.charCodeAt(e)===61?(d="=",e++):(d=null,f===0&&k('"="'));if(d!==null){g=[],h=N();while(h!==null)g.push(h),h=N();g!==null?(h=D(),h!==null?c=[c,d,g,h]:(c=null,e=l)):(c=null,e=l)}else c=null,e=l}else c=null,e=l;c=c!==null?c:"",c!==null?a=[a,c]:(a=null,e=j)}else a=null,e=j;return a!==null&&(a=function(a,b,c){var d={};return d[b]=c[3],d}(i,a[0],a[1])),a===null&&(e=i),a}function z(){var a,b;return a=t(),a===null&&(b=e,a=A(),a!==null&&(a=function(a,b){return{type:"node",id:b,attrs:{}}}(b,a)),a===null&&(e=b)),a}function A(){var a,b,c,d,f;d=e,f=e,a=D();if(a!==null){b=[],c=N();while(c!==null)b.push(c),c=N();b!==null?(c=B(),c=c!==null?c:"",c!==null?a=[a,b,c]:(a=null,e=f)):(a=null,e=f)}else a=null,e=f;return a!==null&&(a=function(a,b){return b}(d,a[0])),a===null&&(e=d),a}function B(){var a,c,d,g,h,i,j,l,m;l=e,b.charCodeAt(e)===58?(a=":",e++):(a=null,f===0&&k('":"'));if(a!==null){c=[],d=N();while(d!==null)c.push(d),d=N();if(c!==null){d=D();if(d!==null){g=[],h=N();while(h!==null)g.push(h),h=N();if(g!==null){m=e,b.charCodeAt(e)===58?(h=":",e++):(h=null,f===0&&k('":"'));if(h!==null){i=[],j=N();while(j!==null)i.push(j),j=N();i!==null?(j=C(),j!==null?h=[h,i,j]:(h=null,e=m)):(h=null,e=m)}else h=null,e=m;h=h!==null?h:"",h!==null?a=[a,c,d,g,h]:(a=null,e=l)}else a=null,e=l}else a=null,e=l}else a=null,e=l}else a=null,e=l;return a}function C(){var a;return b.substr(e,2)==="ne"?(a="ne",e+=2):(a=null,f===0&&k('"ne"')),a===null&&(b.substr(e,2)==="se"?(a="se",e+=2):(a=null,f===0&&k('"se"')),a===null&&(b.substr(e,2)==="sw"?(a="sw",e+=2):(a=null,f===0&&k('"sw"')),a===null&&(b.substr(e,2)==="nw"?(a="nw",e+=2):(a=null,f===0&&k('"nw"')),a===null&&(b.charCodeAt(e)===110?(a="n",e++):(a=null,f===0&&k('"n"')),a===null&&(b.charCodeAt(e)===101?(a="e",e++):(a=null,f===0&&k('"e"')),a===null&&(b.charCodeAt(e)===115?(a="s",e++):(a=null,f===0&&k('"s"')),a===null&&(b.charCodeAt(e)===119?(a="w",e++):(a=null,f===0&&k('"w"')),a===null&&(b.charCodeAt(e)===99?(a="c",e++):(a=null,f===0&&k('"c"')),a===null&&(b.charCodeAt(e)===95?(a="_",e++):(a=null,f===0&&k('"_"'))))))))))),a}function D(){var a,c,d,g,h,i,j,l,m;f++,i=e,j=e,/^[a-zA-Z\u0200-\u0377_]/.test(b.charAt(e))?(a=b.charAt(e),e++):(a=null,f===0&&k("[a-zA-Z\\u0200-\\u0377_]"));if(a!==null){c=[],/^[a-zA-Z\u0200-\u0377_0-9]/.test(b.charAt(e))?(d=b.charAt(e),e++):(d=null,f===0&&k("[a-zA-Z\\u0200-\\u0377_0-9]"));while(d!==null)c.push(d),/^[a-zA-Z\u0200-\u0377_0-9]/.test(b.charAt(e))?(d=b.charAt(e),e++):(d=null,f===0&&k("[a-zA-Z\\u0200-\\u0377_0-9]"));c!==null?a=[a,c]:(a=null,e=j)}else a=null,e=j;a!==null&&(a=function(a,b,c){return b+c.join("")}(i,a[0],a[1])),a===null&&(e=i);if(a===null){i=e,j=e,b.charCodeAt(e)===45?(a="-",e++):(a=null,f===0&&k('"-"')),a=a!==null?a:"";if(a!==null){b.charCodeAt(e)===46?(c=".",e++):(c=null,f===0&&k('"."'));if(c!==null){/^[0-9]/.test(b.charAt(e))?(g=b.charAt(e),e++):(g=null,f===0&&k("[0-9]"));if(g!==null){d=[];while(g!==null)d.push(g),/^[0-9]/.test(b.charAt(e))?(g=b.charAt(e),e++):(g=null,f===0&&k("[0-9]"))}else d=null;d!==null?a=[a,c,d]:(a=null,e=j)}else a=null,e=j}else a=null,e=j;a!==null&&(a=function(a,b,c,d){return b+c+d.join("")}(i,a[0],a[1],a[2])),a===null&&(e=i);if(a===null){i=e,j=e,b.charCodeAt(e)===45?(a="-",e++):(a=null,f===0&&k('"-"')),a=a!==null?a:"";if(a!==null){/^[0-9]/.test(b.charAt(e))?(d=b.charAt(e),e++):(d=null,f===0&&k("[0-9]"));if(d!==null){c=[];while(d!==null)c.push(d),/^[0-9]/.test(b.charAt(e))?(d=b.charAt(e),e++):(d=null,f===0&&k("[0-9]"))}else c=null;if(c!==null){l=e,b.charCodeAt(e)===46?(d=".",e++):(d=null,f===0&&k('"."'));if(d!==null){g=[],/^[0-9]/.test(b.charAt(e))?(h=b.charAt(e),e++):(h=null,f===0&&k("[0-9]"));while(h!==null)g.push(h),/^[0-9]/.test(b.charAt(e))?(h=b.charAt(e),e++):(h=null,f===0&&k("[0-9]"));g!==null?d=[d,g]:(d=null,e=l)}else d=null,e=l;d=d!==null?d:"",d!==null?a=[a,c,d]:(a=null,e=j)}else a=null,e=j}else a=null,e=j;a!==null&&(a=function(a,b,c,d){return b+c.join("")+(d[0]||"")+(d[1]||[]).join("")}(i,a[0],a[1],a[2])),a===null&&(e=i);if(a===null){i=e,j=e,b.charCodeAt(e)===34?(a='"',e++):(a=null,f===0&&k('"\\""'));if(a!==null){c=[],l=e,b.substr(e,2)==='\\"'?(d='\\"',e+=2):(d=null,f===0&&k('"\\\\\\""')),d!==null&&(d=function(a){return'"'}(l)),d===null&&(e=l),d===null&&(l=e,m=e,b.charCodeAt(e)===92?(d="\\",e++):(d=null,f===0&&k('"\\\\"')),d!==null?(/^[^"]/.test(b.charAt(e))?(g=b.charAt(e),e++):(g=null,f===0&&k('[^"]')),g!==null?d=[d,g]:(d=null,e=m)):(d=null,e=m),d!==null&&(d=function(a,b){return"\\"+b}(l,d[1])),d===null&&(e=l),d===null&&(/^[^"]/.test(b.charAt(e))?(d=b.charAt(e),e++):(d=null,f===0&&k('[^"]'))));while(d!==null)c.push(d),l=e,b.substr(e,2)==='\\"'?(d='\\"',e+=2):(d=null,f===0&&k('"\\\\\\""')),d!==null&&(d=function(a){return'"'}(l)),d===null&&(e=l),d===null&&(l=e,m=e,b.charCodeAt(e)===92?(d="\\",e++):(d=null,f===0&&k('"\\\\"')),d!==null?(/^[^"]/.test(b.charAt(e))?(g=b.charAt(e),e++):(g=null,f===0&&k('[^"]')),g!==null?d=[d,g]:(d=null,e=m)):(d=null,e=m),d!==null&&(d=function(a,b){return"\\"+b}(l,d[1])),d===null&&(e=l),d===null&&(/^[^"]/.test(b.charAt(e))?(d=b.charAt(e),e++):(d=null,f===0&&k('[^"]'))));c!==null?(b.charCodeAt(e)===34?(d='"',e++):(d=null,f===0&&k('"\\""')),d!==null?a=[a,c,d]:(a=null,e=j)):(a=null,e=j)}else a=null,e=j;a!==null&&(a=function(a,b){return b.join("")}(i,a[1])),a===null&&(e=i)}}}return f--,f===0&&a===null&&k("identifier"),a}function E(){var a,c;return c=e,b.substr(e,4).toLowerCase()==="node"?(a=b.substr(e,4),e+=4):(a=null,f===0&&k('"node"')),a!==null&&(a=function(a,b){return b.toLowerCase()}(c,a)),a===null&&(e=c),a}function F(){var a,c;return c=e,b.substr(e,4).toLowerCase()==="edge"?(a=b.substr(e,4),e+=4):(a=null,f===0&&k('"edge"')),a!==null&&(a=function(a,b){return b.toLowerCase()}(c,a)),a===null&&(e=c),a}function G(){var a,c;return c=e,b.substr(e,5).toLowerCase()==="graph"?(a=b.substr(e,5),e+=5):(a=null,f===0&&k('"graph"')),a!==null&&(a=function(a,b){return b.toLowerCase()}(c,a)),a===null&&(e=c),a}function H(){var a,c;return c=e,b.substr(e,7).toLowerCase()==="digraph"?(a=b.substr(e,7),e+=7):(a=null,f===0&&k('"digraph"')),a!==null&&(a=function(a,b){return b.toLowerCase()}(c,a)),a===null&&(e=c),a}function I(){var a,c;return c=e,b.substr(e,8).toLowerCase()==="subgraph"?(a=b.substr(e,8),e+=8):(a=null,f===0&&k('"subgraph"')),a!==null&&(a=function(a,b){return b.toLowerCase()}(c,a)),a===null&&(e=c),a}function J(){var a,c;return c=e,b.substr(e,6).toLowerCase()==="strict"?(a=b.substr(e,6),e+=6):(a=null,f===0&&k('"strict"')),a!==null&&(a=function(a,b){return b.toLowerCase()}(c,a)),a===null&&(e=c),a}function K(){var a,b;return a=G(),a===null&&(b=e,a=H(),a!==null&&(a=function(a,b){return Q=b==="digraph",b}(b,a)),a===null&&(e=b)),a}function L(){var a,c;f++,/^[ \t\r\n]/.test(b.charAt(e))?(c=b.charAt(e),e++):(c=null,f===0&&k("[ \\t\\r\\n]"));if(c!==null){a=[];while(c!==null)a.push(c),/^[ \t\r\n]/.test(b.charAt(e))?(c=b.charAt(e),e++):(c=null,f===0&&k("[ \\t\\r\\n]"))}else a=null;return f--,f===0&&a===null&&k("whitespace"),a}function M(){var a,c,d,g,h,i,j;f++,h=e,b.substr(e,2)==="//"?(a="//",e+=2):(a=null,f===0&&k('"//"'));if(a!==null){c=[],/^[^\n]/.test(b.charAt(e))?(d=b.charAt(e),e++):(d=null,f===0&&k("[^\\n]"));while(d!==null)c.push(d),/^[^\n]/.test(b.charAt(e))?(d=b.charAt(e),e++):(d=null,f===0&&k("[^\\n]"));c!==null?a=[a,c]:(a=null,e=h)}else a=null,e=h;if(a===null){h=e,b.substr(e,2)==="/*"?(a="/*",e+=2):(a=null,f===0&&k('"/*"'));if(a!==null){c=[],i=e,j=e,f++,b.substr(e,2)==="*/"?(d="*/",e+=2):(d=null,f===0&&k('"*/"')),f--,d===null?d="":(d=null,e=j),d!==null?(b.length>e?(g=b.charAt(e),e++):(g=null,f===0&&k("any character")),g!==null?d=[d,g]:(d=null,e=i)):(d=null,e=i);while(d!==null)c.push(d),i=e,j=e,f++,b.substr(e,2)==="*/"?(d="*/",e+=2):(d=null,f===0&&k('"*/"')),f--,d===null?d="":(d=null,e=j),d!==null?(b.length>e?(g=b.charAt(e),e++):(g=null,f===0&&k("any character")),g!==null?d=[d,g]:(d=null,e=i)):(d=null,e=i);c!==null?(b.substr(e,2)==="*/"?(d="*/",e+=2):(d=null,f===0&&k('"*/"')),d!==null?a=[a,c,d]:(a=null,e=h)):(a=null,e=h)}else a=null,e=h}return f--,f===0&&a===null&&k("comment"),a}function N(){var a;return a=L(),a===null&&(a=M()),a}function O(a){a.sort();var b=null,c=[];for(var d=0;d<a.length;d++)a[d]!==b&&(c.push(a[d]),b=a[d]);return c}function P(){var a=1,c=1,d=!1;for(var f=0;f<Math.max(e,g);f++){var h=b.charAt(f);h==="\n"?(d||a++,c=1,d=!1):h==="\r"||h==="\u2028"||h==="\u2029"?(a++,c=1,d=!0):(c++,d=!1)}return{line:a,column:c}}function R(a,b){var c={};for(var d in a)c[d]=a[d];for(var d in b)c[d]=b[d];return c}var d={start:l,graphStmt:m,stmtList:n,stmt:o,attrStmt:p,inlineAttrStmt:q,nodeStmt:r,edgeStmt:s,subgraphStmt:t,attrList:u,attrListBlock:v,aList:w,edgeRHS:x,idDef:y,nodeIdOrSubgraph:z,nodeId:A,port:B,compassPt:C,id:D,node:E,edge:F,graph:G,digraph:H,subgraph:I,strict:J,graphType:K,whitespace:L,comment:M,_:N};if(c!==undefined){if(d[c]===undefined)throw new Error("Invalid rule name: "+a(c)+".")}else c="start";var e=0,f=0,g=0,h=[],Q,S=d[c]();if(S===null||e!==b.length){var T=Math.max(e,g),U=T<b.length?b.charAt(T):null,V=P();throw new this.SyntaxError(O(h),U,T,V.line,V.column)}return S},toSource:function(){return this._source}};return b.SyntaxError=function(b,c,d,e,f){function g(b,c){var d,e;switch(b.length){case 0:d="end of input";break;case 1:d=b[0];break;default:d=b.slice(0,b.length-1).join(", ")+" or "+b[b.length-1]}return e=c?a(c):"end of input","Expected "+d+" but "+e+" found."}this.name="SyntaxError",this.expected=b,this.found=c,this.message=g(b,c),this.offset=d,this.line=e,this.column=f},b.SyntaxError.prototype=Error.prototype,b}()},{}],7:[function(a,b,c){function d(a){function b(){a.call(this),this.graph({})}return b.prototype=new a,b.prototype.constructor=b,b.prototype.graph=function(b){return arguments.length<1?a.prototype.graph.call(this):(this._checkValueType(b),a.prototype.graph.call(this,b))},b.prototype.node=function(b,c){return arguments.length<2?a.prototype.node.call(this,b):(this._checkValueType(c),a.prototype.node.call(this,b,c))},b.prototype.addNode=function(b,c){return arguments.length<2&&(c={}),this._checkValueType(c),a.prototype.addNode.call(this,b,c)},b.prototype.edge=function(b,c){return arguments.length<2?a.prototype.edge.call(this,b):(this._checkValueType(c),a.prototype.edge.call(this,b,c))},b.prototype.addEdge=function(b,c,d,e){return arguments.length<4&&(e={}),this._checkValueType(e),a.prototype.addEdge.call(this,b,c,d,e)},b.prototype._checkValueType=function(a){if(a===null||typeof a!="object")throw new Error("Value must be non-null and of type 'object'")},b}b.exports=d},{}],8:[function(a,b,c){function g(a){var b=f.parse(a,"graphStmt");return i(b)}function h(a){var b=f.parse(a);return b.map(function(a){return i(a)})}function i(a){function c(a,c,d){b.hasNode(a)||(b.addNode(a,h.get("node",{})),b.node(a).label===undefined&&(b.node(a).label=a),d!==null&&b.parent(a,d)),c&&j(c,b.node(a))}function f(a,c,d){var e={};j(h.get("edge",d),e);var f=d.id?d.id:null;b.addEdge(f,a,c,e)}function g(a){function e(a){c.push(a)}var b={},c=[],d;e(a);while(c.length!==0){d=c.pop();switch(d.type){case"node":b[d.id]=!0;break;case"edge":d.elems.forEach(e);break;case"subgraph":d.stmts.forEach(e)}}return Object.keys(b)}function i(a,d){var e=a.attrs;switch(a.type){case"node":c(a.id,e,d);break;case"edge":var k,l;a.elems.forEach(function(a){i(a,d);switch(a.type){case"node":l=[a.id];break;case"subgraph":l=g(a);break;default:throw new Error("Unsupported type incident on edge: "+a.type)}k&&k.forEach(function(a){l.forEach(function(b){f(a,b,e)})}),k=l});break;case"subgraph":h.enterSubDigraph(),a.id=b.addNode(a.id),d!==null&&b.parent(a.id,d),a.stmts&&a.stmts.forEach(function(b){i(b,a.id)}),b.children(a.id).length===0&&b.delNode(a.id),h.exitSubDigraph();break;case"attr":h.set(a.attrType,e);break;case"inlineAttr":a.attrs&&j(e,d===null?b.graph():b.node(d));break;default:throw new Error("Unsupported statement type: "+a.type)}}var b=a.type==="graph"?new e:new d,h={_default:{},get:function(b,c){if(typeof this._default[b]!="undefined"){var d={};return j(this._default[b],d),j(c,d),d}return c},set:function(b,c){this._default[b]=this.get(b,c)},enterSubDigraph:function(){function a(){}a.prototype=this._default;var b=new a;this._default=b},exitSubDigraph:function(){this._default=Object.getPrototypeOf(this._default)}};return a.stmts&&a.stmts.forEach(function(a){i(a,null)}),b}function j(a,b){Object.keys(a).forEach(function(c){b[c]=a[c]})}var d=a("./DotDigraph"),e=a("./DotGraph"),f=a("./dot-grammar");b.exports=g,b.exports.parseMany=h},{"./DotDigraph":3,"./DotGraph":4,"./dot-grammar":6}],9:[function(a,b,c){b.exports="0.4.10"},{}],10:[function(a,b,c){function f(a){var b=a.isDirected()?"->":"--",c=new d;c.writeLine((a.isDirected()?"digraph":"graph")+" {"),c.indent();var e=a.graph();return e&&Object.keys(e).map(function(a){c.writeLine(h(a)+"="+h(e[a])+";")}),g(a,null,c),a.edges().forEach(function(d){j(a,d,b,c)}),c.unindent(),c.writeLine("}"),c.toString()}function g(a,b,c){var d=a.children?a.children(b):b===null?a.nodes():[];d.forEach(function(b){if(!a.children||a.children(b).length===0)i(a,b,c);else{c.writeLine("subgraph "+h(b)+" {"),c.indent();var d=a.node(b);Object.keys(d).map(function(a){c.writeLine(h(a)+"="+h(d[a])+";")}),g(a,b,c),c.unindent(),c.writeLine("}")}})}function h(a){return typeof a=="number"||a.toString().match(e)?a:'"'+a.toString().replace(/"/g,'\\"')+'"'}function i(a,b,c){var d=a.node(b);c.write(h(b));if(d){var e=Object.keys(d).map(function(a){return h(a)+"="+h(d[a])});e.length&&c.write(" ["+e.join(",")+"]")}c.writeLine()}function j(a,b,c,d){var e=a.edge(b),f=a.incidentNodes(b),g=f[0],i=f[1];d.write(h(g)+" "+c+" "+h(i));if(e){var j=Object.keys(e).map(function(a){return h(a)+"="+h(e[a])});j.length&&d.write(" ["+j.join(",")+"]")}d.writeLine()}var d=a("./Writer");b.exports=f;var e=/^[a-zA-Z\200-\377_][a-zA-Z\200-\377_0-9]*$/},{"./Writer":5}],11:[function(a,b,c){c.Graph=a("./lib/Graph"),c.Digraph=a("./lib/Digraph"),c.CGraph=a("./lib/CGraph"),c.CDigraph=a("./lib/CDigraph"),a("./lib/graph-converters"),c.alg={isAcyclic:a("./lib/alg/isAcyclic"),components:a("./lib/alg/components"),dijkstra:a("./lib/alg/dijkstra"),dijkstraAll:a("./lib/alg/dijkstraAll"),findCycles:a("./lib/alg/findCycles"),floydWarshall:a("./lib/alg/floydWarshall"),postorder:a("./lib/alg/postorder"),preorder:a("./lib/alg/preorder"),prim:a("./lib/alg/prim"),tarjan:a("./lib/alg/tarjan"),topsort:a("./lib/alg/topsort")},c.converter={json:a("./lib/converter/json.js")};var d=a("./lib/filter");c.filter={all:d.all,nodesFromList:d.nodesFromList},c.version=a("./lib/version")},{"./lib/CDigraph":13,"./lib/CGraph":14,"./lib/Digraph":15,"./lib/Graph":16,"./lib/alg/components":17,"./lib/alg/dijkstra":18,"./lib/alg/dijkstraAll":19,"./lib/alg/findCycles":20,"./lib/alg/floydWarshall":21,"./lib/alg/isAcyclic":22,"./lib/alg/postorder":23,"./lib/alg/preorder":24,"./lib/alg/prim":25,"./lib/alg/tarjan":26,"./lib/alg/topsort":27,"./lib/converter/json.js":29,"./lib/filter":30,"./lib/graph-converters":31,"./lib/version":33}],12:[function(a,b,c){function e(){this._value=undefined,this._nodes={},this._edges={},this._nextId=0}function f(a,b,c){(a[b]||(a[b]=new d)).add(c)}function g(a,b,c){var d=a[b];d.remove(c),d.size()===0&&delete a[b]}var d=a("cp-data").Set;b.exports=e,e.prototype.order=function(){return Object.keys(this._nodes).length},e.prototype.size=function(){return Object.keys(this._edges).length},e.prototype.graph=function(a){if(arguments.length===0)return this._value;this._value=a},e.prototype.hasNode=function(a){return a in this._nodes},e.prototype.node=function(a,b){var c=this._strictGetNode(a);if(arguments.length===1)return c.value;c.value=b},e.prototype.nodes=function(){var a=[];return this.eachNode(function(b){a.push(b)}),a},e.prototype.eachNode=function(a){for(var b in this._nodes){var c=this._nodes[b];a(c.id,c.value)}},e.prototype.hasEdge=function(a){return a in this._edges},e.prototype.edge=function(a,b){var c=this._strictGetEdge(a);if(arguments.length===1)return c.value;c.value=b},e.prototype.edges=function(){var a=[];return this.eachEdge(function(b){a.push(b)}),a},e.prototype.eachEdge=function(a){for(var b in this._edges){var c=this._edges[b];a(c.id,c.u,c.v,c.value)}},e.prototype.incidentNodes=function(a){var b=this._strictGetEdge(a);return[b.u,b.v]},e.prototype.addNode=function(a,b){if(a===undefined||a===null){do a="_"+ ++this._nextId;while(this.hasNode(a))}else if(this.hasNode(a))throw new Error("Graph already has node '"+a+"'");return this._nodes[a]={id:a,value:b},a},e.prototype.delNode=function(a){this._strictGetNode(a),this.incidentEdges(a).forEach(function(a){this.delEdge(a)},this),delete this._nodes[a]},e.prototype._addEdge=function(a,b,c,d,e,g){this._strictGetNode(b),this._strictGetNode(c);if(a===undefined||a===null){do a="_"+ ++this._nextId;while(this.hasEdge(a))}else if(this.hasEdge(a))throw new Error("Graph already has edge '"+a+"'");return this._edges[a]={id:a,u:b,v:c,value:d},f(e[c],b,a),f(g[b],c,a),a},e.prototype._delEdge=function(a,b,c){var d=this._strictGetEdge(a);g(b[d.v],d.u,a),g(c[d.u],d.v,a),delete this._edges[a]},e.prototype.copy=function(){var a=new this.constructor;return a.graph(this.graph()),this.eachNode(function(b,c){a.addNode(b,c)}),this.eachEdge(function(b,c,d,e){a.addEdge(b,c,d,e)}),a._nextId=this._nextId,a},e.prototype.filterNodes=function(a){var b=new this.constructor;return b.graph(this.graph()),this.eachNode(function(c,d){a(c)&&b.addNode(c,d)}),this.eachEdge(function(a,c,d,e){b.hasNode(c)&&b.hasNode(d)&&b.addEdge(a,c,d,e)}),b},e.prototype._strictGetNode=function(a){var b=this._nodes[a];if(b===undefined)throw new Error("Node '"+a+"' is not in graph");return b},e.prototype._strictGetEdge=function(a){var b=this._edges[a];if(b===undefined)throw new Error("Edge '"+a+"' is not in graph");return b}},{"cp-data":34}],13:[function(a,b,c){var d=a("./Digraph"),e=a("./compoundify"),f=e(d);b.exports=f,f.fromDigraph=function(a){var b=new f,c=a.graph();return c!==undefined&&b.graph(c),a.eachNode(function(a,c){c===undefined?b.addNode(a):b.addNode(a,c)}),a.eachEdge(function(a,c,d,e){e===undefined?b.addEdge(null,c,d):b.addEdge(null,c,d,e)}),b},f.prototype.toString=function(){return"CDigraph "+JSON.stringify(this,null,2)}},{"./Digraph":15,"./compoundify":28}],14:[function(a,b,c){var d=a("./Graph"),e=a("./compoundify"),f=e(d);b.exports=f,f.fromGraph=function(a){var b=new f,c=a.graph();return c!==undefined&&b.graph(c),a.eachNode(function(a,c){c===undefined?b.addNode(a):b.addNode(a,c)}),a.eachEdge(function(a,c,d,e){e===undefined?b.addEdge(null,c,d):b.addEdge(null,c,d,e)}),b},f.prototype.toString=function(){return"CGraph "+JSON.stringify(this,null,2)}},{"./Graph":16,"./compoundify":28}],15:[function(a,b,c){function g(){e.call(this),this._inEdges={},this._outEdges={}}var d=a("./util"),e=a("./BaseGraph"),f=a("cp-data").Set;b.exports=g,g.prototype=new e,g.prototype.constructor=g,g.prototype.isDirected=function(){return!0},g.prototype.successors=function(a){return this._strictGetNode(a),Object.keys(this._outEdges[a]).map(function(a){return this._nodes[a].id},this)},g.prototype.predecessors=function(a){return this._strictGetNode(a),Object.keys(this._inEdges[a]).map(function(a){return this._nodes[a].id},this)},g.prototype.neighbors=function(a){return f.union([this.successors(a),this.predecessors(a)]).keys()},g.prototype.sources=function(){var a=this;return this._filterNodes(function(b){return a.inEdges(b).length===0})},g.prototype.sinks=function(){var a=this;return this._filterNodes(function(b){return a.outEdges(b).length===0})},g.prototype.source=function(a){return this._strictGetEdge(a).u},g.prototype.target=function(a){return this._strictGetEdge(a).v},g.prototype.inEdges=function(a,b){this._strictGetNode(a);var c=f.union(d.values(this._inEdges[a])).keys();return arguments.length>1&&(this._strictGetNode(b),c=c.filter(function(a){return this.source(a)===b},this)),c},g.prototype.outEdges=function(a,b){this._strictGetNode(a);var c=f.union(d.values(this._outEdges[a])).keys();return arguments.length>1&&(this._strictGetNode(b),c=c.filter(function(a){return this.target(a)===b},this)),c},g.prototype.incidentEdges=function(a,b){return arguments.length>1?f.union([this.outEdges(a,b),this.outEdges(b,a)]).keys():f.union([this.inEdges(a),this.outEdges(a)]).keys()},g.prototype.toString=function(){return"Digraph "+JSON.stringify(this,null,2)},g.prototype.addNode=function(a,b){return a=e.prototype.addNode.call(this,a,b),this._inEdges[a]={},this._outEdges[a]={},a},g.prototype.delNode=function(a){e.prototype.delNode.call(this,a),delete this._inEdges[a],delete this._outEdges[a]},g.prototype.addEdge=function(a,b,c,d){return e.prototype._addEdge.call(this,a,b,c,d,this._inEdges,this._outEdges)},g.prototype.delEdge=function(a){e.prototype._delEdge.call(this,a,this._inEdges,this._outEdges)},g.prototype._filterNodes=function(a){var b=[];return this.eachNode(function(c){a(c)&&b.push(c)}),b}},{"./BaseGraph":12,"./util":32,"cp-data":34}],16:[function(a,b,c){function g(){e.call(this),this._incidentEdges={}}var d=a("./util"),e=a("./BaseGraph"),f=a("cp-data").Set;b.exports=g,g.prototype=new e,g.prototype.constructor=g,g.prototype.isDirected=function(){return!1},g.prototype.neighbors=function(a){return this._strictGetNode(a),Object.keys(this._incidentEdges[a]).map(function(a){return this._nodes[a].id},this)},g.prototype.incidentEdges=function(a,b){return this._strictGetNode(a),arguments.length>1?(this._strictGetNode(b),b in this._incidentEdges[a]?this._incidentEdges[a][b].keys():[]):f.union(d.values(this._incidentEdges[a])).keys()},g.prototype.toString=function(){return"Graph "+JSON.stringify(this,null,2)},g.prototype.addNode=function(a,b){return a=e.prototype.addNode.call(this,a,b),this._incidentEdges[a]={},a},g.prototype.delNode=function(a){e.prototype.delNode.call(this,a),delete this._incidentEdges[a]},g.prototype.addEdge=function(a,b,c,d){return e.prototype._addEdge.call(this,a,b,c,d,this._incidentEdges,this._incidentEdges)},g.prototype.delEdge=function(a){e.prototype._delEdge.call(this,a,this._incidentEdges,this._incidentEdges)}},{"./BaseGraph":12,"./util":32,"cp-data":34}],17:[function(a,b,c){function e(a){function e(b,d){c.has(b)||(c.add(b),d.push(b),a.neighbors(b).forEach(function(a){e(a,d)}))}var b=[],c=new d;return a.nodes().forEach(function(a){var c=[];e(a,c),c.length>0&&b.push(c)}),b}var d=a("cp-data").Set;b.exports=e},{"cp-data":34}],18:[function(a,b,c){function e(a,b,c,e){function h(b){var d=a.incidentNodes(b),e=d[0]!==i?d[0]:d[1],h=f[e],k=c(b),l=j.distance+k;if(k<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+b+" Weight: "+k);l<h.distance&&(h.distance=l,h.predecessor=i,g.decrease(e,l))}var f={},g=new d;c=c||function(){return 1},e=e||(a.isDirected()?function(b){return a.outEdges(b)}:function(b){return a.incidentEdges(b)}),a.eachNode(function(a){var c=a===b?0:Number.POSITIVE_INFINITY;f[a]={distance:c},g.add(a,c)});var i,j;while(g.size
()>0){i=g.removeMin(),j=f[i];if(j.distance===Number.POSITIVE_INFINITY)break;e(i).forEach(h)}return f}var d=a("cp-data").PriorityQueue;b.exports=e},{"cp-data":34}],19:[function(a,b,c){function e(a,b,c){var e={};return a.eachNode(function(f){e[f]=d(a,f,b,c)}),e}var d=a("./dijkstra");b.exports=e},{"./dijkstra":18}],20:[function(a,b,c){function e(a){return d(a).filter(function(a){return a.length>1})}var d=a("./tarjan");b.exports=e},{"./tarjan":26}],21:[function(a,b,c){function d(a,b,c){var d={},e=a.nodes();return b=b||function(){return 1},c=c||(a.isDirected()?function(b){return a.outEdges(b)}:function(b){return a.incidentEdges(b)}),e.forEach(function(f){d[f]={},d[f][f]={distance:0},e.forEach(function(a){f!==a&&(d[f][a]={distance:Number.POSITIVE_INFINITY})}),c(f).forEach(function(c){var e=a.incidentNodes(c),h=e[0]!==f?e[0]:e[1],i=b(c);i<d[f][h].distance&&(d[f][h]={distance:i,predecessor:f})})}),e.forEach(function(a){var b=d[a];e.forEach(function(c){var f=d[c];e.forEach(function(c){var d=f[a],e=b[c],g=f[c],h=d.distance+e.distance;h<g.distance&&(g.distance=h,g.predecessor=e.predecessor)})})}),d}b.exports=d},{}],22:[function(a,b,c){function e(a){try{d(a)}catch(b){if(b instanceof d.CycleException)return!1;throw b}return!0}var d=a("./topsort");b.exports=e},{"./topsort":27}],23:[function(a,b,c){function e(a,b,c){function f(b,d){if(e.has(b))throw new Error("The input graph is not a tree: "+a);e.add(b),a.neighbors(b).forEach(function(a){a!==d&&f(a,b)}),c(b)}var e=new d;if(a.isDirected())throw new Error("This function only works for undirected graphs");f(b)}var d=a("cp-data").Set;b.exports=e},{"cp-data":34}],24:[function(a,b,c){function e(a,b,c){function f(b,d){if(e.has(b))throw new Error("The input graph is not a tree: "+a);e.add(b),c(b),a.neighbors(b).forEach(function(a){a!==d&&f(a,b)})}var e=new d;if(a.isDirected())throw new Error("This function only works for undirected graphs");f(b)}var d=a("cp-data").Set;b.exports=e},{"cp-data":34}],25:[function(a,b,c){function f(a,b){function i(c){var d=a.incidentNodes(c),e=d[0]!==h?d[0]:d[1],i=g.priority(e);if(i!==undefined){var j=b(c);j<i&&(f[e]=h,g.decrease(e,j))}}var c=new d,f={},g=new e,h;if(a.order()===0)return c;a.eachNode(function(a){g.add(a,Number.POSITIVE_INFINITY),c.addNode(a)}),g.decrease(a.nodes()[0],0);var j=!1;while(g.size()>0){h=g.removeMin();if(h in f)c.addEdge(null,h,f[h]);else{if(j)throw new Error("Input graph is not connected: "+a);j=!0}a.incidentEdges(h).forEach(i)}return c}var d=a("../Graph"),e=a("cp-data").PriorityQueue;b.exports=f},{"../Graph":16,"cp-data":34}],26:[function(a,b,c){function d(a){function f(h){var i=d[h]={onStack:!0,lowlink:b,index:b++};c.push(h),a.successors(h).forEach(function(a){a in d?d[a].onStack&&(i.lowlink=Math.min(i.lowlink,d[a].index)):(f(a),i.lowlink=Math.min(i.lowlink,d[a].lowlink))});if(i.lowlink===i.index){var j=[],k;do k=c.pop(),d[k].onStack=!1,j.push(k);while(h!==k);e.push(j)}}if(!a.isDirected())throw new Error("tarjan can only be applied to a directed graph. Bad input: "+a);var b=0,c=[],d={},e=[];return a.nodes().forEach(function(a){a in d||f(a)}),e}b.exports=d},{}],27:[function(a,b,c){function d(a){function f(g){if(g in c)throw new e;g in b||(c[g]=!0,b[g]=!0,a.predecessors(g).forEach(function(a){f(a)}),delete c[g],d.push(g))}if(!a.isDirected())throw new Error("topsort can only be applied to a directed graph. Bad input: "+a);var b={},c={},d=[],g=a.sinks();if(a.order()!==0&&g.length===0)throw new e;return a.sinks().forEach(function(a){f(a)}),d}function e(){}b.exports=d,d.CycleException=e,e.prototype.toString=function(){return"Graph has at least one cycle"}},{}],28:[function(a,b,c){function e(a){function b(){a.call(this),this._parents={},this._children={},this._children[null]=new d}return b.prototype=new a,b.prototype.constructor=b,b.prototype.parent=function(a,b){this._strictGetNode(a);if(arguments.length<2)return this._parents[a];if(a===b)throw new Error("Cannot make "+a+" a parent of itself");b!==null&&this._strictGetNode(b),this._children[this._parents[a]].remove(a),this._parents[a]=b,this._children[b].add(a)},b.prototype.children=function(a){return a!==null&&this._strictGetNode(a),this._children[a].keys()},b.prototype.addNode=function(b,c){return b=a.prototype.addNode.call(this,b,c),this._parents[b]=null,this._children[b]=new d,this._children[null].add(b),b},b.prototype.delNode=function(b){var c=this.parent(b);return this._children[b].keys().forEach(function(a){this.parent(a,c)},this),this._children[c].remove(b),delete this._parents[b],delete this._children[b],a.prototype.delNode.call(this,b)},b.prototype.copy=function(){var b=a.prototype.copy.call(this);return this.nodes().forEach(function(a){b.parent(a,this.parent(a))},this),b},b.prototype.filterNodes=function(b){function f(a){var b=c.parent(a);return b===null||d.hasNode(b)?(e[a]=b,b):b in e?e[b]:f(b)}var c=this,d=a.prototype.filterNodes.call(this,b),e={};return d.eachNode(function(a){d.parent(a,f(a))}),d},b}var d=a("cp-data").Set;b.exports=e},{"cp-data":34}],29:[function(a,b,c){function h(a){return Object.prototype.toString.call(a).slice(8,-1)}var d=a("../Graph"),e=a("../Digraph"),f=a("../CGraph"),g=a("../CDigraph");c.decode=function(a,b,c){c=c||e;if(h(a)!=="Array")throw new Error("nodes is not an Array");if(h(b)!=="Array")throw new Error("edges is not an Array");if(typeof c=="string")switch(c){case"graph":c=d;break;case"digraph":c=e;break;case"cgraph":c=f;break;case"cdigraph":c=g;break;default:throw new Error("Unrecognized graph type: "+c)}var i=new c;return a.forEach(function(a){i.addNode(a.id,a.value)}),i.parent&&a.forEach(function(a){a.children&&a.children.forEach(function(b){i.parent(b,a.id)})}),b.forEach(function(a){i.addEdge(a.id,a.u,a.v,a.value)}),i},c.encode=function(a){var b=[],c=[];a.eachNode(function(c,d){var e={id:c,value:d};if(a.children){var f=a.children(c);f.length&&(e.children=f)}b.push(e)}),a.eachEdge(function(a,b,d,e){c.push({id:a,u:b,v:d,value:e})});var h;if(a instanceof g)h="cdigraph";else if(a instanceof f)h="cgraph";else if(a instanceof e)h="digraph";else if(a instanceof d)h="graph";else throw new Error("Couldn't determine type of graph: "+a);return{nodes:b,edges:c,type:h}}},{"../CDigraph":13,"../CGraph":14,"../Digraph":15,"../Graph":16}],30:[function(a,b,c){var d=a("cp-data").Set;c.all=function(){return function(){return!0}},c.nodesFromList=function(a){var b=new d(a);return function(a){return b.has(a)}}},{"cp-data":34}],31:[function(a,b,c){var d=a("./Graph"),e=a("./Digraph");d.prototype.toDigraph=d.prototype.asDirected=function(){var a=new e;return this.eachNode(function(b,c){a.addNode(b,c)}),this.eachEdge(function(b,c,d,e){a.addEdge(null,c,d,e),a.addEdge(null,d,c,e)}),a},e.prototype.toGraph=e.prototype.asUndirected=function(){var a=new d;return this.eachNode(function(b,c){a.addNode(b,c)}),this.eachEdge(function(b,c,d,e){a.addEdge(b,c,d,e)}),a}},{"./Digraph":15,"./Graph":16}],32:[function(a,b,c){c.values=function(a){var b=Object.keys(a),c=b.length,d=new Array(c),e;for(e=0;e<c;++e)d[e]=a[b[e]];return d}},{}],33:[function(a,b,c){b.exports="0.7.4"},{}],34:[function(a,b,c){c.Set=a("./lib/Set"),c.PriorityQueue=a("./lib/PriorityQueue"),c.version=a("./lib/version")},{"./lib/PriorityQueue":35,"./lib/Set":36,"./lib/version":38}],35:[function(a,b,c){function d(){this._arr=[],this._keyIndices={}}b.exports=d,d.prototype.size=function(){return this._arr.length},d.prototype.keys=function(){return this._arr.map(function(a){return a.key})},d.prototype.has=function(a){return a in this._keyIndices},d.prototype.priority=function(a){var b=this._keyIndices[a];if(b!==undefined)return this._arr[b].priority},d.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},d.prototype.add=function(a,b){var c=this._keyIndices;if(a in c)return!1;var d=this._arr,e=d.length;return c[a]=e,d.push({key:a,priority:b}),this._decrease(e),!0},d.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var a=this._arr.pop();return delete this._keyIndices[a.key],this._heapify(0),a.key},d.prototype.decrease=function(a,b){var c=this._keyIndices[a];if(b>this._arr[c].priority)throw new Error("New priority is greater than current priority. Key: "+a+" Old: "+this._arr[c].priority+" New: "+b);this._arr[c].priority=b,this._decrease(c)},d.prototype._heapify=function(a){var b=this._arr,c=2*a,d=c+1,e=a;c<b.length&&(e=b[c].priority<b[e].priority?c:e,d<b.length&&(e=b[d].priority<b[e].priority?d:e),e!==a&&(this._swap(a,e),this._heapify(e)))},d.prototype._decrease=function(a){var b=this._arr,c=b[a].priority,d;while(a!==0){d=a>>1;if(b[d].priority<c)break;this._swap(a,d),a=d}},d.prototype._swap=function(a,b){var c=this._arr,d=this._keyIndices,e=c[a],f=c[b];c[a]=f,c[b]=e,d[f.key]=a,d[e.key]=b}},{}],36:[function(a,b,c){function e(a){this._size=0,this._keys={};if(a)for(var b=0,c=a.length;b<c;++b)this.add(a[b])}function f(a){var b=Object.keys(a),c=b.length,d=new Array(c),e;for(e=0;e<c;++e)d[e]=a[b[e]];return d}var d=a("./util");b.exports=e,e.intersect=function(a){if(a.length===0)return new e;var b=new e(d.isArray(a[0])?a[0]:a[0].keys());for(var c=1,f=a.length;c<f;++c){var g=b.keys(),h=d.isArray(a[c])?new e(a[c]):a[c];for(var i=0,j=g.length;i<j;++i){var k=g[i];h.has(k)||b.remove(k)}}return b},e.union=function(a){var b=d.reduce(a,function(a,b){return a+(b.size?b.size():b.length)},0),c=new Array(b),f=0;for(var g=0,h=a.length;g<h;++g){var i=a[g],j=d.isArray(i)?i:i.keys();for(var k=0,l=j.length;k<l;++k)c[f++]=j[k]}return new e(c)},e.prototype.size=function(){return this._size},e.prototype.keys=function(){return f(this._keys)},e.prototype.has=function(a){return a in this._keys},e.prototype.add=function(a){return a in this._keys?!1:(this._keys[a]=a,++this._size,!0)},e.prototype.remove=function(a){return a in this._keys?(delete this._keys[a],--this._size,!0):!1}},{"./util":37}],37:[function(a,b,c){Array.isArray?c.isArray=Array.isArray:c.isArray=function(a){return Object.prototype.toString.call(a)==="[object Array]"},"function"!=typeof Array.prototype.reduce?c.reduce=function(a,b,c){"use strict";if(null===a||"undefined"==typeof a)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof b)throw new TypeError(b+" is not a function");var d,e,f=a.length>>>0,g=!1;1<arguments.length&&(e=c,g=!0);for(d=0;f>d;++d)a.hasOwnProperty(d)&&(g?e=b(e,a[d],d,a):(e=a[d],g=!0));if(!g)throw new TypeError("Reduce of empty array with no initial value");return e}:c.reduce=function(a,b,c){return a.reduce(b,c)}},{}],38:[function(a,b,c){b.exports="1.1.3"},{}]},{},[1]);
\ No newline at end of file
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script> <script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<script type='text/javascript' src="http://cpettitt.github.io/project/dagre-d3/v0.1.5/dagre-d3.min.js"></script> <script type='text/javascript' src="http://cpettitt.github.io/project/dagre-d3/v0.1.5/dagre-d3.min.js"></script>
<script type='text/javascript' src="http://cpettitt.github.io/project/graphlib-dot/v0.4.10/graphlib-dot.min.js"></script> <script type='text/javascript' src="http://cpettitt.github.io/project/graphlib-dot/v0.4.10/graphlib-dot.min.js"></script>
<link rel="stylesheet" href="d3-context-menu.css" />
<script src="d3-context-menu.js"></script>
</head> </head>
<body> <body>
...@@ -98,9 +99,12 @@ ...@@ -98,9 +99,12 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var path='%% DOT_FILE %%'; var path = '%% DOT_FILE %%';
var isProfiled = false; var isProfiled = false;
var colorProfile = false; var colorProfile = false;
var maxProfilePer = 0;
var profileColors = ["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15"];
// Global attributes // Global attributes
var pad = 10; var pad = 10;
...@@ -162,7 +166,7 @@ ...@@ -162,7 +166,7 @@
function parseProfile(profile) { function parseProfile(profile) {
if (typeof(profile) == 'undefined') { if (typeof(profile) == 'undefined') {
return; return [];
} }
profile = profile.replace('[', ''); profile = profile.replace('[', '');
profile = profile.replace(']', ''); profile = profile.replace(']', '');
...@@ -175,17 +179,31 @@ ...@@ -175,17 +179,31 @@
return profile; return profile;
} }
function linspace(start, end, len) {
var d = (end - start) / (len - 1);
var rv = [start];
for (i = 1; i < len; ++i) {
rv.push(rv[i - 1] + d);
}
return rv;
}
function profileColor(per) { function profileColor(per) {
var colors = ["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"];
var s = d3.scale.linear() var s = d3.scale.linear()
.domain([0, 100]) .domain(linspace(0, maxProfilePer, profileColors.length))
.range([0, colors.length - 1]); .range(profileColors)
return colors[Math.round(s(per))]; .interpolate(d3.interpolateRgb);
return s(per);
} }
function fillColor(d) { function fillColor(d) {
if (colorProfile && typeof(d.value.profile) != 'undefined') { if (colorProfile && d.value.profile.length) {
return profileColor(d.value.profile[2]); if (d.value.shape == 'ellipse') {
return profileColor(d.value.profile[0] / d.value.profile[1]);
} else {
return 'white';
}
} else { } else {
return typeof(d.value.fillcolor) == 'undefined' ? 'white' : d.value.fillcolor; return typeof(d.value.fillcolor) == 'undefined' ? 'white' : d.value.fillcolor;
} }
...@@ -204,14 +222,9 @@ ...@@ -204,14 +222,9 @@
function nodeDetails(node) { function nodeDetails(node) {
var s = '<b>' + node.value.label + '</b>'; var s = '<b>' + node.value.label + '</b>';
var p = node.value.profile; var p = node.value.profile;
if (!isNaN(p[0])) { if (p.length) {
s += '<br>Total time: ' + formatTime(p[0]); s += '<br>Time: ' + formatTime(p[0]);
} s += '<br>Time: ' + (p[0] / p[1] * 100).toFixed(1) + '%';
if (!isNaN(p[1])) {
s += '<br>Total time: ' + p[1].toFixed(1) + '%';
}
if (!isNaN(p[2])) {
s += '<br>Profile time: ' + p[2].toFixed(1) + '%';
} }
return s; return s;
} }
...@@ -248,6 +261,111 @@ ...@@ -248,6 +261,111 @@
nodes.each(function(d) {var node = d3.select(this); updateNode(d, node);}); nodes.each(function(d) {var node = d3.select(this); updateNode(d, node);});
} }
function hideNodeDiv() {
nodeDiv.transition()
.duration(200)
.style('opacity', 0);
}
function setNodeSize(node) {
var size = textSize(node.value.label, {'class': 'nodeText'});
node.value.width = size.width + 2 * pad;
node.value.height = size.height + 2 * pad;
node.value.cx = node.value.width / 2;
node.value.cy = node.value.height / 2;
}
var isEditNode = false;
function editNode(elm, d) {
var node = d3.select(elm);
var pos = elm.getBBox();
if (d3.event.defaultPrevented) return;
isEditNode = true;
hideNodeDiv();
var form = node.append('foreignObject')
.attr('x', pos.x)
.attr('y', pos.y)
.attr('width', d.value.width)
.attr('height', 25);
var input = form.append('xhtml:form').append('input')
.attr('style', 'width: ' + d.value.width + 'px')
.attr('value', function() {
this.focus();
return d.value.label;
})
.on('blur', function() {
d.value.label = input.node().value;
setNodeSize(d);
updateNode(d, node);
form.remove(); // TODO: check this
isEditNode = false;
})
.on('keypress', function() {
if (!d3.event) {
d3.event = window.event;
}
var event = d3.event;
if (event.keyCode == 13) {
if (typeof(event.cancelBubble)) {
event.cancelBubble = true;
}
if (event.stopPropagation) {
event.stopPropagation();
}
event.preventDefault();
d.value.label = input.node().value;
setNodeSize(d);
updateNode(d, node);
form.remove(); // TODO: check this
isEditNode = false;
}
});
}
function releaseNode(d) {
d.fixed = false;
layout.start();
}
function releaseNodes() {
graph['nodes'].forEach (function (d) {
d.fixed = false;
});
layout.start();
}
function resetNodes() {
layout.stop();
var nodes = graph['nodes'];
nodes.forEach(function (node, i){
nodes[i].x = scaleDotX(node.value.pos[0]);
nodes[i].y = scaleDotY(dotHeight - (node.value.pos[1] + node.value.height));
nodes[i].px = nodes[i].x;
nodes[i].py = nodes[i].y;
nodes[i].fixed = true;
});
updateGraph();
layout.start();
}
var menuItems = [
{
title: 'Edit',
action: function(elm, d, i) {
editNode(elm, d);
}
},
{
title: 'Release',
action: function(elm, d, i) {
releaseNode(d);
}
}
];
var dotGraph; var dotGraph;
var graph = {}; var graph = {};
var nodes = []; var nodes = [];
...@@ -291,10 +409,9 @@ ...@@ -291,10 +409,9 @@
node.value.cx = node.value.width / 2; node.value.cx = node.value.width / 2;
node.value.cy = node.value.height / 2; node.value.cy = node.value.height / 2;
node.value.profile = parseProfile(node.value.profile); node.value.profile = parseProfile(node.value.profile);
if (typeof(node.value.profile) != 'undefined') { if (node.value.profile.length) {
isProfiled = true; isProfiled = true;
} }
node.fixed = true; node.fixed = true;
nodes.push(node); nodes.push(node);
dotGraph._nodes[nodeId] = node; dotGraph._nodes[nodeId] = node;
...@@ -306,6 +423,14 @@ ...@@ -306,6 +423,14 @@
.attr('type', 'button') .attr('type', 'button')
.attr('value', 'Toggle profile colors') .attr('value', 'Toggle profile colors')
.attr('onclick', "toggleColors()"); .attr('onclick', "toggleColors()");
maxProfilePer = 0;
for (i in nodes) {
var p = nodes[i].value.profile;
if (p.length) {
maxProfilePer = Math.max(maxProfilePer, p[0] / p[1]);
}
}
} }
// Parse edges // Parse edges
...@@ -372,76 +497,13 @@ ...@@ -372,76 +497,13 @@
// Add nodes // Add nodes
nodes = pane.append('g').attr('id', 'nodes').selectAll('g').data(graph['nodes']).enter().append('g'); nodes = pane.append('g').attr('id', 'nodes').selectAll('g').data(graph['nodes']).enter().append('g');
function setNodeSize(node) {
var size = textSize(node.value.label, {'class': 'nodeText'});
node.value.width = size.width + 2 * pad;
node.value.height = size.height + 2 * pad;
node.value.cx = node.value.width / 2;
node.value.cy = node.value.height / 2;
}
updateNodes(); updateNodes();
nodes.on('dblclick', function(d) {editNode(this, d);});
function hideNodeDiv() {
nodeDiv.transition()
.duration(200)
.style('opacity', 0);
}
var editNode = false;
nodes.on('dblclick', function(d) {
var pos = this.getBBox();
var node = d3.select(this);
if (d3.event.defaultPrevented) return;
editNode = true;
hideNodeDiv();
var form = node.append('foreignObject')
.attr('x', pos.x)
.attr('y', pos.y)
.attr('width', d.value.width)
.attr('height', 25);
var input = form.append('xhtml:form').append('input')
.attr('style', 'width: ' + d.value.width + 'px')
.attr('value', function() {
this.focus();
return d.value.label;
})
.on('blur', function() {
d.value.label = input.node().value;
setNodeSize(d);
updateNode(d, node);
form.remove(); // TODO: check this
editNode = false;
})
.on('keypress', function() {
if (!d3.event) {
d3.event = window.event;
}
var event = d3.event;
if (event.keyCode == 13) {
if (typeof(event.cancelBubble)) {
event.cancelBubble = true;
}
if (event.stopPropagation) {
event.stopPropagation();
}
event.preventDefault();
d.value.label = input.node().value;
setNodeSize(d);
updateNode(d, node);
form.remove(); // TODO: check this
editNode = false;
}
});
});
nodes.on('mouseover', function(node) { nodes.on('mouseover', function(node) {
if (editNode || typeof(node.value.profile) == 'undefined') { if (isEditNode || typeof(node.value.profile) == 'undefined') {
return; return;
} }
...@@ -475,10 +537,7 @@ ...@@ -475,10 +537,7 @@
hideNodeDiv(); hideNodeDiv();
}); });
nodes.on('contextmenu', function(d) { nodes.on('contextmenu', d3.contextMenu(menuItems));
releaseNode(d);
});
// Zoom and translate event handler // Zoom and translate event handler
function zoom(d) { function zoom(d) {
...@@ -545,31 +604,6 @@ ...@@ -545,31 +604,6 @@
}); });
} }
function releaseNode(d) {
d.fixed = false;
layout.start();
}
function releaseNodes() {
graph['nodes'].forEach (function (d) {
d.fixed = false;
});
layout.start();
}
function resetNodes() {
layout.stop();
var nodes = graph['nodes'];
nodes.forEach(function (node, i){
nodes[i].x = scaleDotX(node.value.pos[0]);
nodes[i].y = scaleDotY(dotHeight - (node.value.pos[1] + node.value.height));
nodes[i].px = nodes[i].x;
nodes[i].py = nodes[i].y;
nodes[i].fixed = true;
});
updateGraph();
layout.start();
}
</script> </script>
</body> </body>
</html> </html>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论