-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
615 lines (501 loc) · 16.3 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
<style>
.small-height {
height: 20%;
}
body {
background-color: black;
}
text{
font-size: 16px;
font-family: sans-serif;
fill: white;
}
text.title{
font-size: 24px;
font-weight: 500;
}
text.subTitle{
font-weight: 500;
fill: lightgrey;
}
text.caption{
font-weight: 400;
font-size: 14px;
fill: #777777;
}
text.label{
font-weight: 400;
color: ivory;
fill: white;
}
text.valueLabel{
font-weight: 300;
}
a {
font-family: sans-serif;
font-size: 25px;
color:red;
fill:white;
text-shadow:2px 1px grey;
font-weight: 400;
}
a:link { text-decoration: none; color:white;}
a:visited { text-decoration: none; color:white;}
a:hover { text-decoration: none; color:white;}
a:active { text-decoration: none;color:white; }
text.yearText{
font-size: 64px;
font-weight: 700;
opacity: 0.75;
fill: white;
}
.tick text {
fill: #BBBBBB;
}
.xAxis .tick:nth-child(2) text {
text-anchor: start;
}
.tick line {
shape-rendering: CrispEdges;
stroke: #dddddd;
}
.tick line.origin{
stroke: #aaaaaa;
}
path.domain{
display: none;
}
</style>
</head>
<body >
<centre>
<a href="?dataset=categories";font-size: 15x; > NLP Word Race - Alonso-Pinar/Filippi - Dataviz 2023 Università di Corsica</a>
<div class="small-height" id="barrace"></div>
<div id="container"></div>
<div class="small-height" id="chartword"></div>
<h5 style="font-family:sans-serif;font-weight: 100;color: ivory;">
Proportion de vidéos de 2020 à 2023 comprenant ces mots et thèmes dans les descriptions. Analyse interactive basée sur 1.600.000 vidéos. Vous pouvez cliquer sur les graphe du bas pour choisir une date. Vous pouvez aussi cliquer sur chaque catégorie pour le détail.
<br><a href="?dataset=categories";font-size: 15x; >Revenir aux catégories</a>--<a href="visu_channel.html">Chaines</a>
</h5>
</centre>
<script src="catcolors.js"></script>
<script>
let MaxRowLen=6
dsetfile = "categories";
urlhelper = "dataset=";
const urlParams = new URLSearchParams(window.location.search);
const paramFile = urlParams.get('dataset')
if(paramFile != null){
dsetfile = paramFile
urlhelper = "dataset="
}
// Get the container element where the table will be inserted
let container = document.getElementById("container");
// Create the table element
let table = document.createElement("table");
table.setAttribute('width', "960px");
// Get the keys (column names) of the first object in the JSON data
let cols = Object.keys(catColorsData[0]);
// Create the header element
let tr = null;// document.createElement("tr");
let tCount = 0
// Loop through the column names and create header cells
cols.forEach((item) => {
if(tCount%MaxRowLen==0){
tr = document.createElement("tr");
}
let th = document.createElement("td");
var createA = document.createElement('a');
var createAText = document.createTextNode(item);
createA.setAttribute('href', "?"+urlhelper+item);
createA.setAttribute('font-family','sans-serif');
createA.appendChild(createAText);
th.appendChild(createA);
th.setAttribute('bgcolor', catColorsData[0][item]);
th.setAttribute('align','center');
// th.innerText = "<a href=?"+urlhelper+item+">"+item+"</a>"; // Set the column name as the text of the header cell
tr.appendChild(th); // Append the header cell to the header row
if(tCount%MaxRowLen==(MaxRowLen-1)){
table.append(tr);
tr = null;
}
tCount++
});
if(tr != null){ table.append(tr) // Append the header to the table
}
container.appendChild(table) // Append the table to the container element
</script>
<script>
var svg = d3.select("#barrace").append("svg")
.attr("width", 960)
.attr("height", 400);
var tickDuration = 1000;
var top_n = 12;
var height = 400;
var width = 960;
const margin = {
top: 40,
right: 0,
bottom: 0,
left: 0
};
let barPadding = 0//(height-(margin.bottom+margin.top))/(top_n*10);
let title = svg.append('text')
.attr('class', 'title')
.attr('y', height-80)
.attr('x', width-150)
.html(""+dsetfile);
let subTitle = svg.append("text")
.attr("class", "subTitle")
.attr("y", 15)
.html("Pourcentage de vidéos comprenant ces mots et thèmes dans les descriptions");
let caption = svg.append('text')
.attr('class', 'caption')
.attr('x', width)
.attr('y', height-5)
.style('text-anchor', 'end')
.html('Source: Jellysmack Dataviz 2023 Video Dataset');
let year = 1;
var rectangleYear = null;
dateOps = { year: 'numeric', month: 'long' };
d3.csv("data/"+dsetfile+".csv").then(function(data) {
//if (error) throw error;
let cindexv = 1;
data.forEach(d => {
d.value = +d.value,
d.lastValue = +d.lastValue,
d.value = isNaN(d.value) ? 0 : d.value,
d.year = +d.year,
d.colour = allColors[d.name]//d3.hsl(Math.random()*360,0.75,0.75
});
let yearSlice = data.filter(d => d.year == year && !isNaN(d.value))
.sort((a,b) => b.value - a.value)
.slice(0, top_n);
yearSlice.forEach((d,i) => d.rank = i);
let x = d3.scaleLinear()
.domain([0, d3.max(yearSlice, d => d.value)])
.range([margin.left, width-margin.right-65]);
let y = d3.scaleLinear()
.domain([top_n, 0])
.range([height-margin.bottom, margin.top]);
let xAxis = d3.axisTop()
.scale(x)
.ticks(width > 500 ? 5:2)
.tickSize(-(height-margin.top-margin.bottom))
.tickFormat(d => d3.format(',')(d));
svg.append('g')
.attr('class', 'axis xAxis')
.attr('transform', `translate(0, ${margin.top})`)
.call(xAxis)
.selectAll('.tick line')
.classed('origin', d => d == 0);
svg.selectAll('rect.bar')
.data(yearSlice, d => d.name)
.enter()
.append('rect')
.attr('class', 'bar')
.attr('x', x(0)+1)
.attr('width', d => x(d.value)-x(0)-1)
.attr('y', d => y(d.rank)+5)
.attr('height', y(1)-y(0)-barPadding)
.style('fill', d => d.colour);
svg.selectAll('text.label')
.data(yearSlice, d => d.name)
.enter()
.append('text')
.attr('class', 'label')
.attr('x', d => x(d.value)-8)
.attr('y', d => y(d.rank)+11+((y(1)-y(0))/2))
.style('text-anchor', 'end')
.html(d => "<a href=?"+urlhelper+d.name+">"+d.name+"</a>") ;
svg.selectAll('text.valueLabel')
.data(yearSlice, d => d.name)
.enter()
.append('text')
.attr('class', 'valueLabel')
.attr('x', d => x(d.value)+5)
.attr('y', d => y(d.rank)+5+((y(1)-y(0))/2)+1)
.text(d => d3.format(',.2f')(d.lastValue));
let yearText = svg.append('text')
.attr('class', 'yearText')
.attr('x', width-margin.right)
.attr('y', height-25)
.style('text-anchor', 'end')
.html(~~year);
let ticker = d3.interval(e => {
yearSlice = data.filter(d => d.year == year && !isNaN(d.value))
.sort((a,b) => b.value - a.value)
.slice(0,top_n);
yearSlice.forEach((d,i) => d.rank = i);
//console.log('IntervalYear: ', yearSlice);
x.domain([0, d3.max(yearSlice, d => d.value)]);
svg.select('.xAxis')
.transition()
.duration(tickDuration)
.ease(d3.easeLinear)
.call(xAxis);
let bars = svg.selectAll('.bar').data(yearSlice, d => d.name);
bars
.enter()
.append('rect')
.attr('class', d => `bar ${d.name.replace(/\s/g,'_')}`)
.attr('x', x(0)+1)
.attr( 'width', d => x(d.value)-x(0)-1)
.attr('y', d => y(top_n+1)+5)
.attr('height', y(1)-y(0)-barPadding)
.style('fill', d => d.colour)
.transition()
.duration(tickDuration)
.ease(d3.easeLinear)
.attr('y', d => y(d.rank)+5);
bars
.transition()
.duration(tickDuration)
.ease(d3.easeLinear)
.attr('width', d => x(d.value)-x(0)-1)
.attr('y', d => y(d.rank)+5);
bars
.exit()
.transition()
.duration(tickDuration)
.ease(d3.easeLinear)
.attr('width', d => x(d.value)-x(0)-1)
.attr('y', d => y(top_n+1)+5)
.remove();
let labels = svg.selectAll('.label')
.data(yearSlice, d => d.name);
labels
.enter()
.append('text')
.attr('class', 'label')
.attr('x', d => x(d.value)-8)
.attr('y', d => y(top_n+1)+19+((y(1)-y(0))/2))
.style('text-anchor', 'end')
.html(d => "<a href=?"+urlhelper+d.name+">"+d.name+"</a>")
.transition()
.duration(tickDuration)
.ease(d3.easeLinear)
.attr('y', d => y(d.rank)+5+((y(1)-y(0))/2)+1);
labels
.transition()
.duration(tickDuration)
.ease(d3.easeLinear)
.attr('x', d => x(d.value)-8)
.attr('y', d => y(d.rank)+10+((y(1)-y(0))/2)+1);
labels
.exit()
.transition()
.duration(tickDuration)
.ease(d3.easeLinear)
.attr('x', d => x(d.value)-8)
.attr('y', d => y(top_n+1)+5)
.remove();
let valueLabels = svg.selectAll('.valueLabel').data(yearSlice, d => d.name);
valueLabels
.enter()
.append('text')
.attr('class', 'valueLabel')
.attr('x', d => x(d.value)+5)
.attr('y', d => y(top_n+1)+5)
.text(d => d3.format(',.2f')(d.lastValue))
.transition()
.duration(tickDuration)
.ease(d3.easeLinear)
.attr('y', d => y(d.rank)+5+((y(1)-y(0))/2)+1);
valueLabels
.transition()
.duration(tickDuration)
.ease(d3.easeLinear)
.attr('x', d => x(d.value)+5)
.attr('y', d => y(d.rank)+5+((y(1)-y(0))/2)+1)
.tween("text", function(d) {
let i = d3.interpolateRound(d.lastValue*10, d.value*10);
return function(t) {
this.textContent = d3.format(',.2f')(i(t)/10.);
};
});
valueLabels
.exit()
.transition()
.duration(tickDuration)
.ease(d3.easeLinear)
.attr('x', d => x(d.value)+5)
.attr('y', d => y(top_n+1)+5)
.remove();
infoDate = new Date(2020, 0, (1 + ((2*year)) * 7));
yearText.html(infoDate.toLocaleDateString("fr-FR", dateOps));
if(year == 81) year = 80;
if(rectangleYear != null){
rectangleYear.attr("x", ~~((year/81)*(width*0.82)));
}
year = d3.format('.1f')((+year) + 1);
},tickDuration);
});
var Myheight = 200
// append the svg object to the body of the page
var svg2 = d3.select("#chartword")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", Myheight + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + ")")
.on("click", function() {
var coordinates= d3.mouse(this);
var newD = coordinates[0]*100/width
if(newD<80)
year = ~~newD;
console.log(coordinates[0])
d3.event.stopPropagation();
});
rectanglebg = svg2.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", width)
.attr("height", Myheight)
.attr('fill', 'black');
svg2.append("g")
.attr("width", width)
.attr("height", Myheight);
rectangleYear = svg2.append("rect")
.attr("x", 5)
.attr("y", 0)
.attr("width", 15)
.attr("height", Myheight)
.attr('fill', 'lightblue');
rect1 = svg2.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", 2)
.attr("height", Myheight)
.attr('fill', 'lightblue');
text1 = svg2.append("text")
.text("jan 2020")
.attr("x", 5)
.attr("y", 20)
.attr('fill', 'lightblue');
rect2 = svg2.append("rect")
.attr("x", 250-5)
.attr("y", 0)
.attr("width", 2)
.attr("height", Myheight)
.attr('fill', 'lightblue');
text2 = svg2.append("text")
.text("jan 2021")
.attr("x", 250)
.attr("y", 20)
.attr('fill', 'lightblue');
rect3 = svg2.append("rect")
.attr("x", 250*2-5)
.attr("y", 0)
.attr("width", 2)
.attr("height", Myheight)
.attr('fill', 'lightblue');
text3 = svg2.append("text")
.text("jan 2022")
.attr("x", 250*2)
.attr("y", 20)
.attr('fill', 'lightblue');
rect3 = svg2.append("rect")
.attr("x", 250*3-5)
.attr("y", 0)
.attr("width", 2)
.attr("height", Myheight)
.attr('fill', 'lightblue');
text3 = svg2.append("text")
.text("jan 2023")
.attr("x", 250*3)
.attr("y", 20)
.attr('fill', 'lightblue');
<!-- Row Converter Function -->
function parseRow(d){
let newRow = {}
newRow.name = d.name;
newRow.frequency = +d.frequency;
newRow.year = d.year;
return newRow;
}
<!-- Retrieve data from CSV -->
d3.csv("data/"+dsetfile+"_p.csv", parseRow).then(
function (data){
let vmax = 0;
data.forEach(d => {
if(vmax < d.frequency){
vmax = d.frequency;
}
});
<!-- Setup Scales -->
let xScale = d3.scaleLinear()
.domain(d3.extent(data, function(d) { return d.year; }))
.range([0, 80]);
let yScale = d3.scaleLinear()
.domain([0, vmax])
.range([Myheight, 0]);
<!-- Setup Axis -->
let xAxis = svg2.append("g")
.attr("transform","translate(0,"+Myheight+")")
.call(d3.axisBottom(xScale).tickFormat(d3.format('.0f')));
let yAxis = svg2.append("g")
.call(d3.axisLeft(yScale));
<!-- Line Generator -->
let lineGenerator = d3.line()
.x(function(d) {
return xScale(d.year);})
.y(function(d) {
return yScale(d.frequency);})
.curve(d3.curveMonotoneX)
let nestedData = d3.nest()
.key(function(d) {return d.name;})
.entries(data);
let lines = svg2.append("g");
lines.selectAll(".line")
.data(nestedData)
.enter()
.append("g")
.append("path")
.attr("class", "line")
.attr("d", function(d,i) {
return lineGenerator(d.values);
})
.style("fill","none")
.style("stroke", function(d,i) {
return colors[i];
})
.style("opacity", .9)
.style("stroke-width",4)
.on("mouseover", function(d, i) {
d3.select(this).style("stroke-width", 10);
})
.on("mouseout", function(d, i) {
d3.select(this).style("stroke-width", 4)
});
lines.selectAll(".labels")
.data(nestedData)
.enter()
.append("g")
.append("text")
.attr("x", function(d, i) {
let hori = d.values[d.values.length-1]["year"];
return xScale(hori) + 10;
})
.attr("y", function(d, i) {
let vert = d.values[d.values.length-1]["frequency"];
return yScale(vert) + 5;
})
.attr("font-size", "40px")
.text(function(d,i) {
return(d.key);
})
.style("fill", function(d,i) {
return colors[i];
})
.attr("opacity", 1);
}
); //End CSV
</script>
</body>