-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
271 lines (233 loc) · 8.9 KB
/
index.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Budget Iris / RainbowViz</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre.min.css">
<link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre-icons.min.css">
<link rel="icon" href="./icon.png">
</head>
<body>
<header class="navbar" style="padding:1rem;">
<section class="navbar-section">
</section>
<section class="navbar-center">
<h1 class="text-center" style="margin-bottom:0; margin-right:1rem">Budget Iris </h1>
</section>
<section class="navbar-section ">
<a href="https://github.com/rainbowViz/simpleRainbowViz/" class="btn">Dépôt GitHub</a>
</section>
</header>
<div class="container" style="padding:1rem;">
<!-- <h1 class="text-center">Budget Iris</h1>
<br> -->
<div class="columns">
<section class="column col">
</section>
<section class="column col">
<div id="chartDiff" >
<svg id="svg1" width="800" height="800"></svg>
</div>
</section>
<section class="column col">
<div class="columns" >
<!-- <div class=" column col" style="margin-bottom:0.2rem"> -->
<div class="panel column col" style="margin:0.2rem" >
<div class="panel-header">
<button class="btn btn-primary btn-block" id="plfbtn">PLF 2019</button>
</div>
<div class="panel-body">
<br>
<p>Visualisation complete du projet de loi de finance 2019 par type de mission, mission, action, programme et sous-action</p>
<br><br>
</div>
<div class="panel-footer">
</div>
</div>
<!-- </div> -->
<div class="panel column col" style="margin:0.2rem">
<div class="panel-header">
<button class="btn btn-block" id="diffbtn">Comparaison 2018/2019</button>
</div>
<div class="panel-body">
<br>
<p>Visualisation de la comparaison entre le projet de loi de finance 2018 et 2019.</p>
<p><span style="color:darkred">■</span> -100% (suppression)</p>
<p><span style="color:darkgreen">■</span> +1000%</p>
<p><span style="color:turquoise">■</span> Création</p>
<br><br>
</div>
<div class="panel-footer">
</div>
</div>
</div> <!-- columns interne-->
</section>
</div> <!-- columns -->
</div> <!-- container-->
<!-- <script src="./data_plf_2019.js"></script> -->
<script src="https://d3js.org/d3.v5.min.js"></script>
<script>
//COLORS
// Theme
let colorz = d3.scaleOrdinal(d3.schemeSet3);
//Red to Green interpolateRdYlGn
let colorGreens = d3.scaleSequential(d3.interpolateGreens)
.domain([0,100])
let colorReds = d3.scaleSequential(d3.interpolateReds)
.domain([0,100])
let colorGreys = d3.scaleSequential(d3.interpolateGreys)
let tooltip = d3.select("body")
.append("div")
.style("position", "absolute")
.style("z-index", "10")
.style("visibility", "hidden")
.style("color", "white")
.style("padding", "8px")
.style("background-color", "rgba(0, 0, 0, 0.75)")
.style("border-radius", "6px")
.style("font", "12px sans-serif")
.text("tooltip");
// GRAPH
d3.json("./data_plf_2019.json").then(function(data) {
let svg = d3.select("#svg1"),
margin = 10,
diameter = +svg.attr("width"),
g = svg.append("g").attr("transform", "translate(" + diameter / 2 + "," + diameter / 2 + ")");
let pack = d3.pack()
.size([diameter - margin, diameter - margin])
.padding(1);
let root = d3.hierarchy(data)
.sum(function(d) { return d.size; })
.sort(function(a, b) { return b.value - a.value; });
let focus = root,
nodes = pack(root).descendants(),
view;
let circle = g.selectAll("circle")
.data(nodes)
.enter().append("circle")
.attr("class", function(d) { return d.parent ? d.children ? "node" : "node node--leaf" : "node node--root"; })
// .style("fill", function(d) { return colorz(d.value%1+1); })
.style("fill", function(d) { return colorz(d.value+1); })
.on("click", function(d) { if (focus !== d) zoom(d), d3.event.stopPropagation(); })
.on("mouseover", function(d) {
let b = Math.round(d.value/1000000)
if (b>2000)
tooltip.text(d.data.name + "\n " + Math.round(b/1000)+' Mds€')
else
tooltip.text(d.data.name + "\n " + b+' Mlls€');
tooltip.style("visibility", "visible");
})
.on("mousemove", function() {
return tooltip.style("top", (d3.event.pageY-10)+"px").style("left",(d3.event.pageX+10)+"px");
})
.on("mouseout", function(){return tooltip.style("visibility", "hidden");});
let text = g.selectAll("text")
.data(nodes)
.enter().append("text")
.attr("class", "label")
.style("fill-opacity", function(d) { return d.parent === root ? 1 : 0.5; })
.style("display", function(d) { return d.parent === root ? "inline" : "none"; })
.text(function(d) { return d.data.name; });
let node = g.selectAll("circle,text");
svg
.style("background", "#EEE")
.on("click", function() { zoom(root); });
zoomTo([root.x, root.y, root.r * 2 + margin]);
function zoom(d) {
let focus0 = focus; focus = d;
let transition = d3.transition()
.duration(d3.event.altKey ? 7500 : 750)
.tween("zoom", function(d) {
let i = d3.interpolateZoom(view, [focus.x, focus.y, focus.r * 2 + margin]);
return function(t) { zoomTo(i(t)); };
});
transition.selectAll("text")
.filter(function(d) { return d.parent === focus || this.style.display === "inline"; })
.style("fill-opacity", function(d) { return d.parent === focus ? 1 : 0; })
.on("start", function(d) { if (d.parent === focus) this.style.display = "inline"; })
.on("end", function(d) { if (d.parent !== focus) this.style.display = "none"; });
}
function zoomTo(v) {
let k = diameter / v[2]; view = v;
node.attr("transform", function(d) { return "translate(" + (d.x - v[0]) * k + "," + (d.y - v[1]) * k + ")"; });
circle.attr("r", function(d) { return d.r * k; });
}
d3.select("#plfbtn")
.on('click',function() {
circle.transition().style("fill", function(d) { return colorz(d.value+1); })
document.querySelector("#plfbtn").classList.add("btn-primary");
document.querySelector("#diffbtn").classList.remove("btn-primary");
})
d3.select("#diffbtn")
.on('click',function() {
circle.transition()
.style("fill", function(d) {
if(d.data.color)
{
if(parseInt(d.data.color)>=0 && parseInt(d.data.color)<1000)
// 1000: ligne correspondante à 0 en 2018
return colorGreens(parseInt(d.data.color))
if(parseInt(d.data.color)<0)
return colorReds(-parseInt(d.data.color))
if(d.data.color ==='FALSE')
// FALSE: Non trouvé en 2018, probablement création
return 'rgb(64,224,208)';
} else {
return colorGreys(d.depth/5);
}
})
document.querySelector("#plfbtn").classList.remove("btn-primary");
document.querySelector("#diffbtn").classList.add("btn-primary");
})
})
function wrap(text, width) {
text.each(function() {
let text = d3.select(this),
words = text.text().split(/\s+/).reverse(),
word,
line = [],
lineNumber = 0,
lineHeight = 1.1, // ems
y = text.attr("y"),
dy = parseFloat(text.attr("dy")),
tspan = text.text(null).append("tspan").attr("x", 0).attr("y", y).attr("dy", dy + "em");
while (word = words.pop()) {
line.push(word);
tspan.text(line.join(" "));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
tspan = text.append("tspan").attr("x", 0).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word);
}
}
});
}
</script>
<style>
.node {
cursor: pointer;
}
.node:hover {
stroke: #000;
stroke-width: 1.5px;
}
.node--leaf {
fill: white;
}
.label {
font: 13px "Helvetica Neue", Helvetica, Arial, sans-serif;
text-anchor: middle;
text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff, 0 -1px 0 #fff;
}
.label,
.node--root,
.node--leaf {
pointer-events: none;
}
</style>
</body>
</html>