Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>GC Solution Tree</title>
- <link rel="stylesheet" type="text/css" href="styles.css"/>
- <script src="d3.js"></script>
- <script type="text/javascript" src="desc.js"></script>
- <style type="text/css">
- .node circle {
- cursor: pointer;
- fill: #fff;
- stroke: steelblue;
- stroke-width: 1.5px;
- }
- .node text {
- font-size: 13px;
- }
- path.link {
- fill: none;
- stroke: #ccc;
- stroke-width: 2.0px;
- }
- </style>
- </head>
- <body onload="simpleFlare()">
- <script type="text/javascript">
- function tree() {
- var _chart = {};
- var _width = 1000, _height = 1100,
- _margins = {top: 30, left: 120, right: 30, bottom: 30},
- _svg,
- _nodes,
- _i = 0,
- _tree,
- _diagonal,
- _bodyG;
- _chart.render = function () {
- if (!_svg) {
- _svg = d3.select("body").append("svg")
- .attr("height", _height)
- .attr("width", _width);
- }
- renderBody(_svg);
- };
- function renderBody(svg) {
- if (!_bodyG) {
- _bodyG = svg.append("g")
- .attr("class", "body")
- .attr("transform", function (d) {
- return "translate(" + _margins.left
- + "," + _margins.top + ")";
- });
- }
- _tree = d3.layout.tree()
- .size([
- (_height - _margins.top - _margins.bottom),
- (_width - _margins.left - _margins.right)
- ]);
- _diagonal = d3.svg.diagonal()
- .projection(function (d) {
- return [d.y, d.x];
- });
- _nodes.x0 = (_height - _margins.top - _margins.bottom) / 2;
- _nodes.y0 = 0;
- render(_nodes);
- }
- function startcontext(){
- d3.select("svg").append("foreignObject")
- .attr("id","infobox")
- .attr("width", 400)
- .attr("height", 500)
- .attr("x",1).attr("y",10)
- .append("xhtml:body")
- .style("font", "16px 'Helvetica Neue'")
- .html("<B>Click on any Solution Node For Information</b>");
- }
- //** Main Entry ***
- function render(source) {
- startcontext();
- var nodes = _tree.nodes(_nodes).reverse();
- renderNodes(nodes, source);
- renderLinks(nodes, source);
- }
- function renderNodes(nodes, source) {
- nodes.forEach(function (d) {
- d.y = d.depth * 180;
- });
- var node = _bodyG.selectAll("g.node")
- .data(nodes, function (d) {
- return d.id || (d.id = ++_i);
- });
- var nodeEnter = node.enter().append("svg:g")
- .attr("class", "node")
- .attr("transform", function (d) {
- return "translate(" + source.y0
- + "," + source.x0 + ")";
- })
- .on("click", function (d) {
- //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- //toggle(d);
- //render(d);
- d3.selectAll("#infobox").remove();
- //var mytext="...<a href=\"http:\\\\www.google.com\">google</a>..."+d.KI;
- var index=d.GID
- if(index>12)index=14;
- console.log("GID: "+d.GID+" Index:"+index);
- console.log("E[index]: "+sdata[index][0]);
- console.log("indexOf(Digital): "+d.name.indexOf("Digital"));
- var prestr="";
- if (index==14)prestr=d.name+" : ";
- if(d.name.indexOf("Digital")>=0)index=13;
- var htstr="<table border=\"0\" style=\"width:100%\" bgcolor=\"#72a0c1\" ><tr><td><B>"+prestr+sdata[index][0]+"</B>";
- htstr += "<p><i>"+sdata[index][1]+"</i>"+sdata[index][2]+"</p></td></tr></table>";
- d3.select("svg").append("foreignObject")
- .attr("id","infobox")
- .attr("width", 400)
- .attr("height", 500)
- .attr("x",1).attr("y",function(){return((d3.event.pageY)-80);})
- .append("xhtml:body")
- .style("font", "17px 'Verdana'")
- .html(htstr);
- });
- nodeEnter.append("svg:circle")
- .attr("r", 1e-6)
- // .style("stroke", function(d) { if(d.name=="Digital Strategy") return "red"; })
- // .style("stroke", function(d) { if(d.name=="Strategy") return "blue"; })
- .style("fill", function(d) { return d.type; })
- //style("fill", function(d) { return d.level; });
- // .style("fill", function (d) { return d._children ? "lightsteelblue" : "#ff0"; });
- var nodeUpdate = node.transition()
- .attr("transform", function (d) {
- return "translate(" + d.y + "," + d.x + ")";
- });
- nodeUpdate.select("circle")
- .attr("r", 8.0)
- //.style("fill", function(d) { return d.type; })
- //.style("fill", function (d) { return d._children ? "lightsteelblue" : "#fff";
- .style("fill", function(d) { return d.type;
- // .style("fill", function (d) { return d._children ? "lightsteelblue" : d.type;
- });
- var nodeExit = node.exit().transition()
- .attr("transform", function (d) {
- return "translate(" + source.y
- + "," + source.x + ")";
- })
- .remove();
- nodeExit.select("circle")
- .attr("r", 1e-6);
- renderLabels(nodeEnter, nodeUpdate, nodeExit);
- nodes.forEach(function (d) {
- d.x0 = d.x;
- d.y0 = d.y;
- });
- }
- function renderLabels(nodeEnter, nodeUpdate, nodeExit) {
- nodeEnter.append("svg:text")
- .attr("x", function (d) {
- return d.children || d._children ? -10 : 10;
- })
- .attr("dy", ".35em")
- .attr("text-anchor", function (d) {
- return d.children || d._children ? "end" : "start";
- })
- .text(function (d) {
- return d.name;
- })
- .style("fill-opacity", 1e-6);
- nodeUpdate.select("text")
- .style("fill-opacity", 1);
- nodeExit.select("text")
- .style("fill-opacity", 1e-6);
- }
- function renderLinks(nodes, source) {
- var link = _bodyG.selectAll("path.link")
- .data(_tree.links(nodes), function (d) {
- return d.target.id;
- });
- link.enter().insert("svg:path", "g")
- .attr("class", "link")
- .style("stroke-width",function(d){ return d.type; })
- .style("stroke",function(d){ return d.type;})
- .attr("d", function (d) {
- var o = {x: source.x0, y: source.y0};
- return _diagonal({source: o, target: o});
- });
- link.transition()
- .attr("d", _diagonal);
- link.exit().transition()
- .attr("d", function (d) {
- var o = {x: source.x, y: source.y};
- return _diagonal({source: o, target: o});
- })
- .remove();
- }
- function toggle(d) {
- if (d.children) {
- d._children = d.children;
- d.children = null;
- } else {
- d.children = d._children;
- d._children = null;
- }
- }
- function toggleAll(d) {
- if (d.children) {
- d.children.forEach(toggleAll);
- toggle(d);
- }
- }
- _chart.width = function (w) {
- if (!arguments.length) return _width;
- _width = w;
- return _chart;
- };
- _chart.height = function (h) {
- if (!arguments.length) return _height;
- _height = h;
- return _chart;
- };
- _chart.margins = function (m) {
- if (!arguments.length) return _margins;
- _margins = m;
- return _chart;
- };
- _chart.nodes = function (n) {
- if (!arguments.length) return _nodes;
- _nodes = n;
- return _chart;
- };
- return _chart;
- }
- var chart = tree();
- function largeFlare() {
- // play.json and flare.json
- d3.json("ptestx.json", function (nodes) {
- console.log(nodes);
- chart.nodes(nodes).render();
- });
- d3.selectAll("#foreignObject").remove();
- }
- function simpleFlare() {
- d3.json("ptestx.json", function (nodes) {
- console.log(nodes);
- chart.nodes(nodes).render();
- });
- d3.selectAll("#foreignObject").remove();
- }
- </script>
- <div class="control-group">
- <button onclick="largeFlare()">ORG KI View</button>
- <button onclick="simpleFlare()">Business View</button>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement