Source

brightway2-ui / bw2ui / web / templates / database_tree.html

Full commit
Chris Mutel 59867b3 




































































{% extends "base.html" %}

{% block extrahead %}
<style type="text/css">
.node circle {
  cursor: pointer;
  fill: #fff;
  stroke: steelblue;
  stroke-width: 1.5px;
}

.node text {
  font-size: 11px;
}

path.link {
  fill: none;
  stroke: #ccc;
  stroke-width: 1.5px;
}</style>
{% endblock %}


{% block body %}
<h2>{{ direction }} supply chain for {{ activity }}</h2>
<hr>
<div id="cluster"></div>

<script type="text/javascript">
var root = {{f|tojson|safe}},
  root,
  w = 900,
  h = 700;

var cluster = d3.layout.cluster().size([h, w-160]);

var diagonal = d3.svg.diagonal()
    .projection(function(d) { return [d.y, d.x]; });

var svg = d3.select("#cluster").append("svg")
    .attr("width", w)
    .attr("height", h)
  .append("g")
    .attr("transform", "translate(40,0)");

var nodes = cluster.nodes(root),
    links = cluster.links(nodes);

var link = svg.selectAll(".link")
    .data(links)
  .enter().append("path")
    .attr("class", "link")
    .attr("d", diagonal);

var node = svg.selectAll(".node")
    .data(nodes)
  .enter().append("g")
    .attr("class", "node")
    .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })

node.append("circle")
    .attr("r", 4.5);

node.append("text")
    .attr("dx", function(d) { return d.children ? -8 : 8; })
    .attr("dy", 3)
    .style("text-anchor", function(d) { return d.children ? "end" : "start"; })
    .text(function(d) { return d.name; });
</script>
{% endblock %}