-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattitudes-towards-food.js
64 lines (50 loc) · 1.78 KB
/
attitudes-towards-food.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
61
62
63
64
function TechDiversityRace() {
// Name for the visualisation to appear in the menu bar.
this.name = 'Attitudes towards British food purchases';
// Each visualisation must have a unique ID with no special
// characters.
this.id = 'food-attitudes';
// Property to represent data has been loaded.
this.loaded = false;
// Preload the data. This function is called automatically by the
// gallery when a visualisation is added.
this.preload = function() {
var self = this;
this.data = loadTable(
'./data/attitudes-towards-food/foodstatistics.csv', 'csv', 'header',
// Callback function to set the value
// this.loaded to true.
function(table) {
self.loaded = true; });
};
this.setup = function() {
if (!this.loaded) {
console.log('Data not yet loaded');
return;
}
// Create a new pie chart object.
this.pie = new PieChart(width / 2, height / 2, width * 0.4);
this.draw = function() {
if (!this.loaded) {
console.log('Data not yet loaded');
return;
}
// Get the value of the company we're interested in from the
// select item.
// Use a temporary hard-code example for now.
//???
var companyName = this.select.value();
// Get the column of raw data for companyName.
var col = this.data.getColumn(companyName);
// Convert all data strings to numbers.
col = stringsToNumbers(col);
// Copy the row labels from the table (the first item of each row).
var labels = this.data.getColumn(0);
// Colour to use for each category.
var colours = ['blue', 'red', 'green', 'pink', 'purple', 'yellow'];
// Make a title.
var title = 'Employee diversity at ' + companyName;
// Draw the pie chart!
this.pie.draw(col, labels, colours, title);
};
}