%PDF- %PDF-
Direktori : /home/opti/workflow/src/public/app-assets/js/scripts/charts/d3/tree/ |
Current File : /home/opti/workflow/src/public/app-assets/js/scripts/charts/d3/tree/collapsible.min.js |
/*! * stack-admin-theme (https://pixinvent.com/bootstrap-admin-template/stack) * Copyright 2018 PIXINVENT * Licensed under the Themeforest Standard Licenses */ $(window).on("load",function(){function update(source){function resize(){width=ele.node().getBoundingClientRect().width-margin.left-margin.right,nodes=tree.nodes(root),links=tree.links(nodes),container.attr("width",width+margin.left+margin.right),svg.attr("width",width+margin.left+margin.right),tree.size([height,width-180]),diagonal.projection(function(d){return[d.y,d.x]}),svg.selectAll(".d3-tree-link").attr("d",diagonal),svg.selectAll(".d3-tree-node").attr("transform",function(d){return"translate("+d.y+","+d.x+")"})}var duration=d3.event&&d3.event.altKey?5e3:500,nodes=tree.nodes(root).reverse(),node=svg.selectAll(".d3-tree-node").data(nodes,function(d){return d.id||(d.id=++i)}),nodeEnter=node.enter().append("g").attr("class","d3-tree-node").attr("transform",function(d){return"translate("+source.y0+","+source.x0+")"}).on("click",function(d){toggle(d),update(d)});nodeEnter.append("circle").attr("r",1e-6).style("fill","#fff").style("stroke","#E84A5F").style("stroke-width",1.5).style("cursor","pointer").style("fill",function(d){return d._children?"#E84A5F":"#fff"}),nodeEnter.append("text").attr("x",function(d){return d.children||d._children?-10:10}).attr("dy",".35em").style("text-anchor",function(d){return d.children||d._children?"end":"start"}).style("font-size",12).style("fill-opacity",1e-6).text(function(d){return d.name});var nodeUpdate=node.transition().duration(duration).attr("transform",function(d){return"translate("+d.y+","+d.x+")"});nodeUpdate.select("circle").attr("r",4.5).style("fill",function(d){return d._children?"#E84A5F":"#fff"}),nodeUpdate.select("text").style("fill-opacity",1);var nodeExit=node.exit().transition().duration(duration).attr("transform",function(d){return"translate("+source.y+","+source.x+")"}).remove();nodeExit.select("circle").attr("r",1e-6),nodeExit.select("text").style("fill-opacity",1e-6);var link=svg.selectAll(".d3-tree-link").data(tree.links(nodes),function(d){return d.target.id});link.enter().insert("path","g").attr("class","d3-tree-link").style("fill","none").style("stroke","#e3e3e3").style("stroke-width",1.5).attr("d",function(d){var o={x:source.x0,y:source.y0};return diagonal({source:o,target:o})}).transition().duration(duration).attr("d",diagonal),link.transition().duration(duration).attr("d",diagonal),link.exit().transition().duration(duration).attr("d",function(d){var o={x:source.x,y:source.y};return diagonal({source:o,target:o})}).remove(),nodes.forEach(function(d){d.x0=d.x,d.y0=d.y}),$(window).on("resize",resize),$(".menu-toggle, .d3-tree-node circle").on("click",resize)}function toggle(d){d.children?(d._children=d.children,d.children=null):(d.children=d._children,d._children=null)}var root,ele=d3.select("#collapsible-tree"),margin={top:20,right:20,bottom:30,left:50},width=ele.node().getBoundingClientRect().width-margin.left-margin.right,height=600-margin.top-margin.bottom,i=0,container=ele.append("svg"),svg=container.attr("width",width+margin.left+margin.right).attr("height",height+margin.top+margin.bottom).append("g").attr("transform","translate("+margin.left+","+margin.top+")"),tree=d3.layout.tree().size([height,width-180]),diagonal=d3.svg.diagonal().projection(function(d){return[d.y,d.x]});d3.json("../../../app-assets/data/d3/tree/collapsible-tree.json",function(error,json){function toggleAll(d){d.children&&(d.children.forEach(toggleAll),toggle(d))}root=json,root.x0=height/2,root.y0=0,root.children.forEach(toggleAll),toggle(root.children[1]),toggle(root.children[1].children[2]),toggle(root.children[9]),toggle(root.children[9].children[0]),update(root)})});