forked from dsaadesignv/Dataviz-p5js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
48 lines (44 loc) · 1.04 KB
/
sketch.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
let data;
let valeurs
let labels;
let t = 0;
let w = 2000;
function preload() {
data = loadTable(
'data2.csv',
'csv',
'header');
}
function setup() {
createCanvas(800, 600);
// donne le nom des colonnes
console.log(data.columns);
// donne le nombre de lignes
console.log(data.getRowCount());
// donne les valeurs de la colonne Mass (Tt)
years = data.getColumn("Year");
exajouls = data.getColumn("Exajoule (EJ)");
console.log(years);
console.log(exajouls);
noStroke();
}
function draw() {
background(200);
// déplacement du canvas avec translate pour faire défiler le diagramme
let canvasX = map(mouseX,0,width,-20,w-width+20);
translate(-canvasX,0);
// boucle
for (let i = 0; i < exajouls.length; i++) {
let annee = years[i];
let posx = map(annee, 1750, 2008, 20, w);
fill(i * 2, 0, 0);
rect(posx, height - exajouls[i],1, exajouls[i]);
push();
textAlign(RIGHT);
textSize(8);
translate(posx, height - exajouls[i]-5);
rotate(radians(45));
text(annee, 0,0);
pop();
}
}