author | Chloe Laisne <chloe.laisne@gmail.com> |
Sun, 12 Jun 2016 22:53:25 +0200 | |
changeset 188 | d2cb39155997 |
parent 142 | 86fcf0c837c0 |
child 198 | 541e26eb356f |
permissions | -rw-r--r-- |
39
c693e8673d5b
add visu-langue with google treemap
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
1 |
import Ember from 'ember'; |
123
4c97e9da1416
Remove use of global variables + remove ember-cli-content-security-policy from package.json to avoid bogus csp violation warnings
ymh <ymh.work@gmail.com>
parents:
95
diff
changeset
|
2 |
import d3 from 'd3'; |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
123
diff
changeset
|
3 |
import ENV from 'app-client/config/environment'; |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
123
diff
changeset
|
4 |
import _ from 'lodash/lodash'; |
39
c693e8673d5b
add visu-langue with google treemap
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
5 |
|
c693e8673d5b
add visu-langue with google treemap
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
6 |
export default Ember.Component.extend({ |
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
7 |
|
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
8 |
constants: Ember.inject.service(), |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
9 |
|
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
10 |
didInsertElement: function(){ |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
11 |
var self = this; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
12 |
var margin = {top: 20, right: 0, bottom: 0, left: 0}, |
95 | 13 |
width = Ember.$("#chart_div").width(), |
84 | 14 |
height = 600 - margin.top - margin.bottom, |
15 |
formatNumber = d3.format(",d"), |
|
16 |
transitioning; |
|
17 |
||
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
18 |
var x = d3.scale.linear() |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
19 |
.domain([0, width]) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
20 |
.range([0, width]); |
84 | 21 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
22 |
var y = d3.scale.linear() |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
23 |
.domain([0, height]) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
24 |
.range([0, height]); |
84 | 25 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
26 |
var treemap = d3.layout.treemap() |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
27 |
.children(function(d, depth) { return depth ? null : d._children; }) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
28 |
.sort(function(a, b) { return a.value - b.value; }) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
29 |
.ratio(height / width * 0.5 * (1 + Math.sqrt(5))) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
30 |
.round(false); |
84 | 31 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
32 |
var svg = d3.select("#chart_div").append("svg") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
33 |
.attr("width", width + margin.left + margin.right) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
34 |
.attr("height", height + margin.bottom + margin.top) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
35 |
.style("margin-left", -margin.left + "px") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
36 |
.style("margin.right", -margin.right + "px") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
37 |
.append("g") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
38 |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
39 |
.style("shape-rendering", "crispEdges"); |
84 | 40 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
41 |
var grandparent = svg.append("g") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
42 |
.attr("class", "grandparent"); |
84 | 43 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
44 |
grandparent.append("rect") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
45 |
.attr("y", -margin.top) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
46 |
.attr("width", width) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
47 |
.attr("height", margin.top); |
84 | 48 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
49 |
grandparent.append("text") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
50 |
.attr("x", 6) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
51 |
.attr("y", 6 - margin.top) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
52 |
.attr("dy", ".75em"); |
84 | 53 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
54 |
var baseurl = ENV.baseURL.replace(/\/$/,"")+'/api/v1'; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
55 |
d3.json(baseurl+"/languages", function(languages) { |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
123
diff
changeset
|
56 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
57 |
var root = _.cloneDeep(self.constants.LANGUAGES_TREEMAP); |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
123
diff
changeset
|
58 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
59 |
initialize(root); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
60 |
accumulate(root); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
61 |
layout(root); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
62 |
display(root); |
84 | 63 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
64 |
function initialize(root) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
65 |
root.x = root.y = 0; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
66 |
root.dx = width; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
67 |
root.dy = height; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
68 |
root.depth = 0; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
69 |
} |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
70 |
|
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
71 |
// Aggregate the values for internal nodes. This is normally done by the |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
72 |
// treemap layout, but not here because of our custom implementation. |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
73 |
// We also take a snapshot of the original children (_children) to avoid |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
74 |
// the children being overwritten when when layout is computed. |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
75 |
function accumulate(d) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
76 |
d._children = d.children; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
77 |
|
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
78 |
if(d.children) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
79 |
d.value = d.children.reduce(function(p, v) { return p + accumulate(v); }, 0); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
80 |
} else if (_.isArray(d.id)) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
81 |
d.value = d.id.reduce(function(s,lid) { return s + (languages[lid]?languages[lid]:0); }, 0); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
82 |
} else { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
83 |
d.value = languages[d.id]?languages[d.id]:0; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
84 |
} |
84 | 85 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
86 |
return d.value; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
87 |
} |
84 | 88 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
89 |
// Compute the treemap layout recursively such that each group of siblings |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
90 |
// uses the same size (1×1) rather than the dimensions of the parent cell. |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
91 |
// This optimizes the layout for the current zoom state. Note that a wrapper |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
92 |
// object is created for the parent node for each group of siblings so that |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
93 |
// the parent’s dimensions are not discarded as we recurse. Since each group |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
94 |
// of sibling was laid out in 1×1, we must rescale to fit using absolute |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
95 |
// coordinates. This lets us use a viewport to zoom. |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
96 |
function layout(d) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
97 |
if (d._children) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
98 |
treemap.nodes({_children: d._children}); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
99 |
d._children.forEach(function(c) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
100 |
c.x = d.x + c.x * d.dx; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
101 |
c.y = d.y + c.y * d.dy; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
102 |
c.dx *= d.dx; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
103 |
c.dy *= d.dy; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
104 |
c.parent = d; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
105 |
layout(c); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
106 |
}); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
107 |
} |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
108 |
} |
84 | 109 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
110 |
function display(d) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
111 |
grandparent |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
112 |
.datum(d.parent) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
113 |
.on("click", transition) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
114 |
.select("text") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
115 |
.text(name(d)); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
116 |
|
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
117 |
var g1 = svg.insert("g", ".grandparent") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
118 |
.datum(d) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
119 |
.attr("class", "depth"); |
39
c693e8673d5b
add visu-langue with google treemap
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
120 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
121 |
var g = g1.selectAll("g") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
122 |
.data(d._children) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
123 |
.enter().append("g"); |
84 | 124 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
125 |
g.classed("bla", true) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
126 |
.on("click", selectHandler); |
84 | 127 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
128 |
g.filter(function(d) { return d._children; }) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
129 |
.classed("children", true) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
130 |
.on("click", transition); |
84 | 131 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
132 |
g.append("rect") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
133 |
.attr("class", "parent") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
134 |
.call(rect) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
135 |
.append("title") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
136 |
.text(function(d) { return formatNumber(d.value); }); |
84 | 137 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
138 |
g.append("text") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
139 |
.attr("dy", ".75em") |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
140 |
.text(function(d) { return d.name; }) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
141 |
.call(text); |
84 | 142 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
143 |
function transition(d) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
144 |
if (transitioning || !d) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
145 |
return; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
146 |
} |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
147 |
|
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
148 |
selectHandler(d); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
149 |
transitioning = true; |
84 | 150 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
151 |
var g2 = display(d), |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
152 |
t1 = g1.transition().duration(750), |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
153 |
t2 = g2.transition().duration(750); |
84 | 154 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
155 |
// Update the domain only after entering new elements. |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
156 |
x.domain([d.x, d.x + d.dx]); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
157 |
y.domain([d.y, d.y + d.dy]); |
39
c693e8673d5b
add visu-langue with google treemap
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
158 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
159 |
// Enable anti-aliasing during the transition. |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
160 |
svg.style("shape-rendering", null); |
84 | 161 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
162 |
// Draw child nodes on top of parent nodes. |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
163 |
svg.selectAll(".depth").sort(function(a, b) { return a.depth - b.depth; }); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
164 |
|
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
165 |
// Fade-in entering text. |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
166 |
g2.selectAll("text").style("fill-opacity", 0); |
84 | 167 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
168 |
// Transition to the new view. |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
169 |
t1.selectAll("text").call(text).style("fill-opacity", 0); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
170 |
t2.selectAll("text").call(text).style("fill-opacity", 1); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
171 |
t1.selectAll("rect").call(rect); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
172 |
t2.selectAll("rect").call(rect); |
84 | 173 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
174 |
// Remove the old node when the transition is finished. |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
175 |
t1.remove().each("end", function() { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
176 |
svg.style("shape-rendering", "crispEdges"); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
177 |
transitioning = false; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
178 |
}); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
179 |
} |
84 | 180 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
181 |
function selectHandler (d){ |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
182 |
if (d.id){ |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
183 |
self.get('setQueryParameters')(d.id); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
184 |
} |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
185 |
} |
84 | 186 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
187 |
return g; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
188 |
} |
84 | 189 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
190 |
function text(text) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
191 |
text.attr("x", function(d) { return x(d.x) + 6; }) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
192 |
.attr("y", function(d) { return y(d.y) + 6; }); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
193 |
} |
84 | 194 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
195 |
function rect(rect) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
196 |
rect.attr("x", function(d) { return x(d.x); }) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
197 |
.attr("y", function(d) { return y(d.y); }) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
198 |
.attr("width", function(d) { return x(d.x + d.dx) - x(d.x); }) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
199 |
.attr("height", function(d) { return y(d.y + d.dy) - y(d.y); }) |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
200 |
.attr("fill", function(d) { return (d.color || "#bbb"); }); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
201 |
} |
84 | 202 |
|
188
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
203 |
function name(d) { |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
204 |
return d.parent ? name(d.parent) + "." + d.name : d.name; |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
205 |
} |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
206 |
|
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
207 |
}); |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
208 |
|
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
209 |
} |
d2cb39155997
/langue endpoint ID querystring parameter
Chloe Laisne <chloe.laisne@gmail.com>
parents:
142
diff
changeset
|
210 |
|
39
c693e8673d5b
add visu-langue with google treemap
nowmad@23.1.168.192.in-addr.arpa
parents:
diff
changeset
|
211 |
}); |