-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp.js
60 lines (50 loc) · 1.37 KB
/
temp.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
let data;
// preload table data
function preload() {
data = loadTable(
'Data/pal.csv',
'csv',
'header');
}
// using a p5js table object, return an object having
// the values of the given column, plus the minimum value
// and maximum value from that column
function colValsMinMax(tab, colName) {
let vals = data.getColumn(colName);
let obj = {
values: vals,
min: min(vals),
max: max(vals),
}
return obj;
}
function setup() {
createCanvas(640, 480);
// how many rows?
console.log(data.getRowCount());
// what are the columns?
console.log(data.columns);
background(50);
// fetch values and min/max for pm2.5
let pm = colValsMinMax(data, "pm2.5");
console.log(pm.min);
console.log(pm.max);
// fetch values and min/max for temperature
let temps = colValsMinMax(data, "TEMP");
console.log(temps.min);
console.log(temps.max);
// noprotect
for (var i = 0; i < data.getRowCount(); i++) {
// draw pm2.5
stroke(255, 128, 128);
let pmXpos = map(i, 0, data.getRowCount(), 0, width);
let pmYpos = map(pm.values[i], pm.min, pm.max, height, 0);
point(pmXpos, pmYpos);
// draw temps
stroke(128, 128, 255);
let tempXpos = map(i, 0, data.getRowCount(), 0, width);
let tempYpos = map(temps.values[i], temps.min, temps.max,
height, 0);
point(tempXpos, tempYpos);
}
}