@@ 15-112 (lines=98) @@ | ||
12 | 'terrain-park': 5 |
|
13 | } |
|
14 | ||
15 | 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; |
@@ 1-1 (lines=1) @@ | ||
1 | function buildCharts(){sugarloaf.ndx=crossfilter(sugarloaf.data.trails),sugarloaf.openDim=sugarloaf.ndx.dimension(function(r){return r.open?"Open":"Closed"}),sugarloaf.openGroup=sugarloaf.openDim.group().reduceCount(function(r){return r.open}),sugarloaf.openChart=dc.rowChart("#chart-row-open"),sugarloaf.openChart.width(WIDTH).height(HEIGHT/2).margins(MARGINS).dimension(sugarloaf.openDim).group(sugarloaf.openGroup).elasticX(!0),sugarloaf.groomedDim=sugarloaf.ndx.dimension(function(r){return r.groomed?"Groomed":"Ungroomed"}),sugarloaf.groomedGroup=sugarloaf.groomedDim.group().reduceCount(function(r){return r.groomed}),sugarloaf.groomedChart=dc.rowChart("#chart-row-groomed"),sugarloaf.groomedChart.width(WIDTH).height(HEIGHT/2).margins(MARGINS).dimension(sugarloaf.groomedDim).group(sugarloaf.groomedGroup).elasticX(!0),sugarloaf.snowmakingDim=sugarloaf.ndx.dimension(function(r){return r.snowmaking?"Snowmaking in progress":"Not snowmaking"}),sugarloaf.snowmakingGroup=sugarloaf.snowmakingDim.group().reduceCount(function(r){return r.snowmaking}),sugarloaf.snowmakingChart=dc.rowChart("#chart-row-snowmaking"),sugarloaf.snowmakingChart.width(WIDTH).height(HEIGHT/2).margins(MARGINS).dimension(sugarloaf.snowmakingDim).group(sugarloaf.snowmakingGroup).elasticX(!0),sugarloaf.difficultyDim=sugarloaf.ndx.dimension(function(r){return r.difficulty}),sugarloaf.difficultyGroup=sugarloaf.difficultyDim.group().reduceCount(function(r){return r.difficulty}),sugarloaf.difficultyChart=dc.rowChart("#chart-row-difficulty"),sugarloaf.difficultyChart.width(WIDTH).height(HEIGHT).margins(MARGINS).dimension(sugarloaf.difficultyDim).group(sugarloaf.difficultyGroup).ordering(function(r){return sugarloaf.difficulty_order[r.key]}).elasticX(!0),sugarloaf.areaDim=sugarloaf.ndx.dimension(function(r){return r.area}),sugarloaf.areaGroup=sugarloaf.areaDim.group().reduceCount(function(r){return r.area}),sugarloaf.areaChart=dc.rowChart("#chart-row-area"),sugarloaf.areaChart.width(WIDTH).height(2*HEIGHT).margins(MARGINS).dimension(sugarloaf.areaDim).group(sugarloaf.areaGroup).elasticX(!0),dc.renderAll()}var filename_status="/api/current",WIDTH=300,HEIGHT=200,MARGINS={top:10,left:20,right:20,bottom:20},sugarloaf={};sugarloaf.difficulty_order={beginner:1,intermediate:2,black:3,"double-black":4,"terrain-park":5},d3.json(filename_status,function(r){sugarloaf.data=r,buildCharts()}); |