-
Notifications
You must be signed in to change notification settings - Fork 10
/
sketch.js
50 lines (42 loc) · 1.09 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
49
50
var table
function preload(){
table = loadTable('data/totals.csv', 'csv', 'header')
}
function setup(){
createCanvas(3900, 250)
background(127)
noStroke()
textAlign(CENTER)
textSize(16)
// calculate the total number of tests per year (and also the max in any given year)
var years = []
var totals = []
var lowest = 0
var highest = 0
for (var r=0; r<table.getRowCount(); r++){
var sum = 0
var year = table.getString(r, 0)
for (var c=1; c<table.getColumnCount(); c++){
sum += table.getNum(r, c)
}
years.push(year)
totals.push(sum)
highest = Math.max(sum, highest)
}
// draw a box for each year and set its color based on the total number of tests
var x = 100
var y = 100
var dim = 50
var numberOfShades = 9
var palette = Brewer.sequential('BuPu', numberOfShades, lowest, highest)
for (var i=0; i<years.length; i++){
// draw the box
var color = palette.colorForValue(totals[i])
fill(color)
rect(x, y, dim, dim)
// draw the year number on top
fill('white')
text(years[i], x+dim*.5, y+dim*.6)
x+=dim
}
}