-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtech-diversity-race.js
83 lines (65 loc) · 2.15 KB
/
tech-diversity-race.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function TechDiversityRace() {
// Name for the visualisation to appear in the menu bar.
this.name = 'Tech Diversity: Race';
// Each visualisation must have a unique ID with no special
// characters.
this.id = 'tech-diversity-race';
// Property to represent whether 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/tech-diversity/race-2018.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 select DOM element.
//???
this.select = createSelect();
// Set select position.
// ???
this.select.position(width/3, 30);
// Fill the options with all company names.
//???
for (var i = 0; i < this.data.getColumnCount(); i++)
this.select.option(this.data.columns[i])
};
this.destroy = function() {
this.select.remove();
};
// 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);
};
}