|
1
|
|
|
var filename_status = '/api/current', |
|
2
|
|
|
WIDTH = 300, |
|
3
|
|
|
HEIGHT = 200, |
|
4
|
|
|
MARGINS = {top: 10, left: 20, right: 20, bottom: 20}, |
|
5
|
|
|
sugarloaf = {}; |
|
6
|
|
|
|
|
7
|
|
|
sugarloaf.difficulty_order = { |
|
8
|
|
|
'beginner': 1, |
|
9
|
|
|
'intermediate': 2, |
|
10
|
|
|
'black': 3, |
|
11
|
|
|
'double-black': 4, |
|
12
|
|
|
'terrain-park': 5 |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
View Code Duplication |
function buildCharts() { |
|
|
|
|
|
|
16
|
|
|
sugarloaf.ndx = crossfilter(sugarloaf.data.trails); |
|
17
|
|
|
|
|
18
|
|
|
sugarloaf.openDim = sugarloaf.ndx.dimension(function(d) { |
|
19
|
|
|
if (d.open) { |
|
20
|
|
|
return 'Open'; |
|
21
|
|
|
} else { |
|
22
|
|
|
return 'Closed'; |
|
23
|
|
|
}; |
|
24
|
|
|
}); |
|
25
|
|
|
sugarloaf.openGroup = sugarloaf.openDim.group().reduceCount(function(d) { |
|
26
|
|
|
return d.open; |
|
27
|
|
|
}); |
|
28
|
|
|
sugarloaf.openChart = dc.rowChart('#chart-row-open'); |
|
|
|
|
|
|
29
|
|
|
sugarloaf.openChart |
|
30
|
|
|
.width(WIDTH) |
|
31
|
|
|
.height(HEIGHT/2) |
|
32
|
|
|
.margins(MARGINS) |
|
33
|
|
|
.dimension(sugarloaf.openDim) |
|
34
|
|
|
.group(sugarloaf.openGroup) |
|
35
|
|
|
.elasticX(true); |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
sugarloaf.groomedDim = sugarloaf.ndx.dimension(function(d) { |
|
39
|
|
|
if (d.groomed) { |
|
40
|
|
|
return 'Groomed'; |
|
41
|
|
|
} else { |
|
42
|
|
|
return 'Ungroomed'; |
|
43
|
|
|
} |
|
44
|
|
|
}); |
|
45
|
|
|
sugarloaf.groomedGroup = sugarloaf.groomedDim.group().reduceCount(function(d) { |
|
46
|
|
|
return d.groomed; |
|
47
|
|
|
}) |
|
48
|
|
|
sugarloaf.groomedChart = dc.rowChart('#chart-row-groomed'); |
|
|
|
|
|
|
49
|
|
|
sugarloaf.groomedChart |
|
50
|
|
|
.width(WIDTH) |
|
51
|
|
|
.height(HEIGHT/2) |
|
52
|
|
|
.margins(MARGINS) |
|
53
|
|
|
.dimension(sugarloaf.groomedDim) |
|
54
|
|
|
.group(sugarloaf.groomedGroup) |
|
55
|
|
|
.elasticX(true); |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
sugarloaf.snowmakingDim = sugarloaf.ndx.dimension(function(d) { |
|
59
|
|
|
if (d.snowmaking) { |
|
60
|
|
|
return 'Snowmaking in progress'; |
|
61
|
|
|
} else { |
|
62
|
|
|
return 'Not snowmaking'; |
|
63
|
|
|
} |
|
64
|
|
|
}); |
|
65
|
|
|
sugarloaf.snowmakingGroup = sugarloaf.snowmakingDim.group().reduceCount(function(d) { |
|
66
|
|
|
return d.snowmaking; |
|
67
|
|
|
}); |
|
68
|
|
|
sugarloaf.snowmakingChart = dc.rowChart('#chart-row-snowmaking'); |
|
|
|
|
|
|
69
|
|
|
sugarloaf.snowmakingChart |
|
70
|
|
|
.width(WIDTH) |
|
71
|
|
|
.height(HEIGHT/2) |
|
72
|
|
|
.margins(MARGINS) |
|
73
|
|
|
.dimension(sugarloaf.snowmakingDim) |
|
74
|
|
|
.group(sugarloaf.snowmakingGroup) |
|
75
|
|
|
.elasticX(true); |
|
76
|
|
|
|
|
77
|
|
|
sugarloaf.difficultyDim = sugarloaf.ndx.dimension(function(d) { |
|
78
|
|
|
return d.difficulty; |
|
79
|
|
|
}); |
|
80
|
|
|
sugarloaf.difficultyGroup = sugarloaf.difficultyDim.group().reduceCount(function(d) { |
|
81
|
|
|
return d.difficulty; |
|
82
|
|
|
}); |
|
83
|
|
|
sugarloaf.difficultyChart = dc.rowChart('#chart-row-difficulty'); |
|
|
|
|
|
|
84
|
|
|
sugarloaf.difficultyChart |
|
85
|
|
|
.width(WIDTH) |
|
86
|
|
|
.height(HEIGHT) |
|
87
|
|
|
.margins(MARGINS) |
|
88
|
|
|
.dimension(sugarloaf.difficultyDim) |
|
89
|
|
|
.group(sugarloaf.difficultyGroup) |
|
90
|
|
|
.ordering(function(d) { |
|
91
|
|
|
return sugarloaf.difficulty_order[d.key]; |
|
92
|
|
|
}) |
|
93
|
|
|
.elasticX(true); |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
sugarloaf.areaDim = sugarloaf.ndx.dimension(function(d) { |
|
97
|
|
|
return d.area; |
|
98
|
|
|
}); |
|
99
|
|
|
sugarloaf.areaGroup = sugarloaf.areaDim.group().reduceCount(function(d) { |
|
100
|
|
|
return d.area; |
|
101
|
|
|
}); |
|
102
|
|
|
sugarloaf.areaChart = dc.rowChart('#chart-row-area'); |
|
|
|
|
|
|
103
|
|
|
sugarloaf.areaChart |
|
104
|
|
|
.width(WIDTH) |
|
105
|
|
|
.height(HEIGHT * 2) |
|
106
|
|
|
.margins(MARGINS) |
|
107
|
|
|
.dimension(sugarloaf.areaDim) |
|
108
|
|
|
.group(sugarloaf.areaGroup) |
|
109
|
|
|
.elasticX(true); |
|
110
|
|
|
|
|
111
|
|
|
dc.renderAll(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
d3.json(filename_status, function(data) { |
|
|
|
|
|
|
115
|
|
|
sugarloaf.data = data; |
|
116
|
|
|
|
|
117
|
|
|
buildCharts(); |
|
118
|
|
|
}); |