-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacking.js
124 lines (81 loc) · 2.64 KB
/
packing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var node;
var currentRoot;
var makePackingViz = function(targetTree) {
currentRoot = targetTree;
var width = 700;
var height = 600;
d3.selectAll('svg').remove();
d3.selectAll('text').remove();
// d3.selectAll('node').remove();
d3.selectAll('.tooltip').remove();
// d3.selectAll('circle').remove();
var canvas = d3.select('.wrapper').append('svg').attr("class", "canvas")
// .attr('width', width)
// .attr('height', height)
.append('g')
.attr('transform', 'translate(50, 50)');
var pack = d3.layout.pack()
.size([width, height - 50])
.padding(1);
var nodes = pack.nodes(targetTree);
node = canvas.selectAll(".node")
.data(nodes)
.enter()
.append('g')//.transition().duration(500)
.attr("class", "node")
.attr("transform", function (d) {return "translate(" + d.x + "," + d.y + ")";} )
node.append("circle").transition().duration(500)
.attr("r", function(d) {return d.r})
// if (d === currentRoot){ return 200} else if (d.children) {return d.children.length * 6 + 1;} else {return 1};
.attr("fill",
function(d) { return "rgba(00, 100, 150, .9)"})
.attr("opacity", 0.25)
.attr("stroke", "#ADADAD")
.attr("stroke-width", "2");
var diagonal = d3.svg.diagonal();
d3.selectAll('circle')
.on('mouseover', function() {
d3.select(this)
.attr("fill", "yellow")
})
.on ('mouseout', function() {
d3.select(this).attr("fill", "blue")
});
// d3.selectAll('.node')
// .on('mouseover', function(){
// d3.select(this)
// .append("text").text(function(d) {return d.name })
// }).attr("class", "bork")
// // .on('mouseout', function(){
// // d3.select(this).select("text")
// // .text(function(d) {return " "})
// // })
var tooltip = d3.select("body")
.append("div")
.attr('class', 'tooltip')
.style("position", "absolute")
.style("z-index", "10")
.style("visibility", "hidden")
.style("color", "black")
.style("font-size", "3em")
.text("a simple tooltip");
var sidebar = d3.selectAll(".sideBar");
node
.on("mouseover", function(d){
sidebar.text(d.name);
tooltip.text(d.name);
tooltip.style("visibility", "visible");
})
.on("mousemove", function(){return tooltip.style("top",
(d3.event.pageY-200)+"px").style("left",(d3.event.pageX+10)+"px");})
.on("mouseout", function(){return tooltip.style("visibility", "hidden");});
node.on("click", function(d){
if ( (d === currentRoot) && (currentRoot.parent) ) {
currentRoot = currentRoot.parent;
makePackingViz( currentRoot);
} else {
currentRoot = d;
makePackingViz( d);
}
})
}