GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( e33679...05b234 )
by Alex
13s queued 11s
created

loaf.table.dimension.renderlet   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
var filename_status = '/api/current',
2
    filename_summary = '/api/summary',
3
    WIDTH = 300,
4
    HEIGHT = 200,
5
    MARGINS = {top: 10, left: 30, right: 20, bottom: 20},
6
    sugarloaf = {};
7
8
sugarloaf.difficulty_order = {
9
    'beginner': 1,
10
    'intermediate': 2,
11
    'black': 3,
12
    'double-black': 4,
13
    'terrain-park': 5
14
}
15
sugarloaf.parseDate = d3.time.format('%Y-%m-%dT%H:%M:%S');
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
16
sugarloaf.summary_color = d3.scale.ordinal()
17
    //     green,      blue,     black, double-black, terrain-park closed
18
    .range(['#00A64B', '#2D2D94', '#6D6D6D', '#000', '#F6AE3B', '#FFF'])
19
    .domain(['green', 'blue', 'black', 'double-black', 'terrain-park', 'closed']);
20
21
function buildCharts() {
22
    sugarloaf.ndx = crossfilter(sugarloaf.data.trails);
23
24
    sugarloaf.openDim = sugarloaf.ndx.dimension(function(d) {
25
        if (d.open) {
26
            return 'Open';
27
        } else {
28
            return 'Closed';
29
        };
30
    });
31
    sugarloaf.openGroup = sugarloaf.openDim.group().reduceCount(function(d) {
32
        return d.open;
33
    });
34
    sugarloaf.openChart = dc.rowChart('#chart-row-open');
0 ignored issues
show
Bug introduced by
The variable dc seems to be never declared. If this is a global, consider adding a /** global: dc */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
35
    sugarloaf.openChart
36
        .width(WIDTH)
37
        .height(HEIGHT/2)
38
        .margins(MARGINS)
39
        .dimension(sugarloaf.openDim)
40
        .group(sugarloaf.openGroup)
41
        .elasticX(true);
42
43
44
    sugarloaf.groomedDim = sugarloaf.ndx.dimension(function(d) {
45
        if (d.groomed) {
46
            return 'Groomed';
47
        } else {
48
            return 'Ungroomed';
49
        }
50
    });
51
    sugarloaf.groomedGroup = sugarloaf.groomedDim.group().reduceCount(function(d) {
52
        return d.groomed;
53
    })
54
    sugarloaf.groomedChart = dc.rowChart('#chart-row-groomed');
0 ignored issues
show
Bug introduced by
The variable dc seems to be never declared. If this is a global, consider adding a /** global: dc */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
55
    sugarloaf.groomedChart
56
        .width(WIDTH)
57
        .height(HEIGHT/2)
58
        .margins(MARGINS)
59
        .dimension(sugarloaf.groomedDim)
60
        .group(sugarloaf.groomedGroup)
61
        .elasticX(true);
62
    
63
64
    sugarloaf.snowmakingDim = sugarloaf.ndx.dimension(function(d) {
65
        if (d.snowmaking) {
66
            return 'Snowmaking in progress';
67
        } else {
68
            return 'Not snowmaking';
69
        }
70
    });
71
    sugarloaf.snowmakingGroup = sugarloaf.snowmakingDim.group().reduceCount(function(d) {
72
        return d.snowmaking;
73
    });
74
    sugarloaf.snowmakingChart = dc.rowChart('#chart-row-snowmaking');
0 ignored issues
show
Bug introduced by
The variable dc seems to be never declared. If this is a global, consider adding a /** global: dc */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
75
    sugarloaf.snowmakingChart
76
        .width(WIDTH)
77
        .height(HEIGHT/2)
78
        .margins(MARGINS)
79
        .dimension(sugarloaf.snowmakingDim)
80
        .group(sugarloaf.snowmakingGroup)
81
        .elasticX(true);
82
83
    sugarloaf.difficultyDim = sugarloaf.ndx.dimension(function(d) {
84
        return d.difficulty;
85
    });
86
    sugarloaf.difficultyGroup = sugarloaf.difficultyDim.group().reduceCount(function(d) {
87
        return d.difficulty;
88
    });
89
    sugarloaf.difficultyChart = dc.rowChart('#chart-row-difficulty');
0 ignored issues
show
Bug introduced by
The variable dc seems to be never declared. If this is a global, consider adding a /** global: dc */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
90
    sugarloaf.difficultyChart
91
        .width(WIDTH)
92
        .height(HEIGHT)
93
        .margins(MARGINS)
94
        .dimension(sugarloaf.difficultyDim)
95
        .group(sugarloaf.difficultyGroup)
96
        .colors(sugarloaf.summary_color)
97
        .colorAccessor(function(d) {
98
            return d.key;
99
        })
100
        .ordering(function(d) {
101
            return sugarloaf.difficulty_order[d.key];
102
        })
103
        .elasticX(true);
104
    
105
    
106
    sugarloaf.areaDim = sugarloaf.ndx.dimension(function(d) {
107
        return d.area;
108
    });
109
    sugarloaf.areaGroup = sugarloaf.areaDim.group().reduceCount(function(d) {
110
        return d.area;
111
    });
112
    sugarloaf.areaChart = dc.rowChart('#chart-row-area');
0 ignored issues
show
Bug introduced by
The variable dc seems to be never declared. If this is a global, consider adding a /** global: dc */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
113
    sugarloaf.areaChart
114
        .width(WIDTH)
115
        .height(HEIGHT * 2)
116
        .margins(MARGINS)
117
        .dimension(sugarloaf.areaDim)
118
        .group(sugarloaf.areaGroup)
119
        .elasticX(true);
120
    
121
122
    sugarloaf.allDim = sugarloaf.ndx.dimension(function(d) {return d;});
123
124
    sugarloaf.table = dc.dataTable('#trail-list');
0 ignored issues
show
Bug introduced by
The variable dc seems to be never declared. If this is a global, consider adding a /** global: dc */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
125
    sugarloaf.table
126
        .dimension(sugarloaf.allDim)
127
        .group(function(d) { return "Trail table"; })
0 ignored issues
show
Unused Code introduced by
The parameter d is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
128
        .columns([
129
            'name',
130
            'difficulty'
131
        ])
132
        .size(250)
133
        .sortBy(function(d) { return d.name })
134
        .order(d3.ascending)
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
135
        .on('renderlet', function(table) {
136
            // each time the table is rendered remove the extra thing
137
            table.select('tr.dc-table-group').remove();
138
        });
139
    
140
    d3.selectAll('a#open').on('click', function() {
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
141
        sugarloaf.openChart.filterAll();
142
        dc.renderAll();
0 ignored issues
show
Bug introduced by
The variable dc seems to be never declared. If this is a global, consider adding a /** global: dc */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
143
    });
144
    d3.selectAll('a#groomed').on('click', function() {
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
145
        sugarloaf.groomedChart.filterAll();
146
        dc.renderAll();
0 ignored issues
show
Bug introduced by
The variable dc seems to be never declared. If this is a global, consider adding a /** global: dc */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
147
    });
148
    d3.selectAll('a#snowmaking').on('click', function() {
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
149
        sugarloaf.snowmakingChart.filterAll();
150
        dc.renderAll();
0 ignored issues
show
Bug introduced by
The variable dc seems to be never declared. If this is a global, consider adding a /** global: dc */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
151
    });
152
    d3.selectAll('a#difficulty').on('click', function() {
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
153
        sugarloaf.difficultyChart.filterAll();
154
        dc.renderAll();
0 ignored issues
show
Bug introduced by
The variable dc seems to be never declared. If this is a global, consider adding a /** global: dc */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
155
    });
156
    d3.selectAll('a#area').on('click', function() {
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
157
        sugarloaf.areaChart.filterAll();
158
        dc.renderAll();
0 ignored issues
show
Bug introduced by
The variable dc seems to be never declared. If this is a global, consider adding a /** global: dc */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
159
    });
160
161
    dc.renderAll();
162
163
164
}
165
166
function summaryToDates(summary) {
167
    var dates = {};
168
169
    summary.conditions.forEach(function(c) {
170
        // set our initial date if unknown
171
        if (undefined === dates[c.datetime]) {
172
            dates[c.datetime] = {};
173
        }
174
175
        // make our difficulties
176
        if (c.open && undefined === dates[c.datetime][c.difficulty]) {
177
            dates[c.datetime][c.difficulty] = c.trail_count;
178
        } else if (c.open) {
179
            dates[c.datetime][c.difficulty] += c.trail_count;
180
        } else if (undefined === dates[c.datetime]['closed']) {
181
            dates[c.datetime]['closed'] = c.trail_count;
182
        } else {
183
            dates[c.datetime]['closed'] += c.trail_count;
184
        };
185
    });
186
187
    var dates_list = [];
188
189
    Object.keys(dates).forEach(function(key) {
190
        var date = dates[key];
191
        date['datetime'] = sugarloaf.parseDate.parse(key);
192
        dates_list.push(date);
193
    });
194
195
    dates_list.sort(function(a, b) {
196
        if (a.datetime < b.datetime) {
197
            return -1;
198
        } else {
199
            return 1;
200
        }
201
    });
202
203
    return dates_list;
204
};
205
206
// takes the output of summaryToDates and returns a list of lists ordered by
207
// Object.keys(sugarloaf.difficulty_order)
208
function datesToDataset(dates) {
209
    var output = [];
210
211
    Object.keys(sugarloaf.difficulty_order).forEach(function(difficulty) {
212
        var diff_array = [];
213
214
        dates.forEach(function(date) {
215
            var date_diff_obj = {'x': date.datetime}
216
            if (undefined === date[difficulty]) {
217
                date_diff_obj['y'] = 0;
218
            } else {
219
                date_diff_obj['y'] = date[difficulty];
220
            }
221
            diff_array.push(date_diff_obj)
222
        })
223
224
        output.push(diff_array);
225
    })
226
    return output;
227
}
228
229
function countDate(date) {
230
    var count = 0;
231
    for (var key in date) {
232
        if (date.hasOwnProperty(key) && key !== 'datetime') {
233
            count += date[key];
234
        }
235
    }
236
    return count;
237
}
238
239
function buildSummaryChart(summary) {
240
    sugarloaf.dates = summaryToDates(summary);
241
242
243
    MARGINS.left = 35;
244
    // get the width of the parent container
245
    var maxWidth = d3.select('#chart-summary')[0][0].clientWidth;
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
246
    var width = maxWidth - MARGINS.left - MARGINS.right,
247
        height = 200 - MARGINS.top - MARGINS.bottom;
248
    sugarloaf.dataset = datesToDataset(sugarloaf.dates);
249
    
250
    sugarloaf.summary_x = d3.time.scale()
251
        .range([0, width])
252
        .domain(d3.extent(sugarloaf.dates.map(function(d) {
253
            return d.datetime;
254
        })));
255
    
256
    sugarloaf.summary_y = d3.scale.linear()
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
257
        .rangeRound([height, 0])
258
        .domain([0, d3.max(sugarloaf.dates, function(d) { return countDate(d)})]);
259
    
260
    sugarloaf.summary_stack = d3.layout.stack();
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
261
    
262
    sugarloaf.summary_stack_layers = sugarloaf.summary_stack(sugarloaf.dataset);
263
    
264
    sugarloaf.summary_area = d3.svg.area()
265
        .interpolate('cardinal')
266
        .x(function(d) { return sugarloaf.summary_x(d.x)})
267
        .y0(function(d) { return sugarloaf.summary_y(d.y0)})
268
        .y1(function(d) { return sugarloaf.summary_y(d.y0 + d.y)});
269
270
    sugarloaf.summary_xAxis = d3.svg.axis()
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
271
        .scale(sugarloaf.summary_x)
272
        .orient('bottom')
273
        //.ticks(d3.time.sundays, 1)
274
        .ticks(10)
275
        //.tickSubdivide(true)
276
        .tickFormat(d3.time.format("%b %e"));
277
    
278
    sugarloaf.summary_yAxis = d3.svg.axis()
279
        .scale(sugarloaf.summary_y)
280
        .orient('left');
281
282
    var svg = d3.select('#chart-summary').append('svg')
283
        .attr('width', width + MARGINS.left + MARGINS.right)
284
        .attr('height', height + MARGINS.top + MARGINS.bottom)
285
      .append('g')
286
        .attr('transform', 'translate(' + MARGINS.left + ',' + MARGINS.top +')');
287
    
288
    var selection = svg.selectAll('.series')
0 ignored issues
show
Unused Code introduced by
The variable selection seems to be never used. Consider removing it.
Loading history...
289
        .data(sugarloaf.summary_stack_layers)
290
      .enter().append('path')
291
          .attr('class', 'layer')
292
          .attr('d', function(d) { return sugarloaf.summary_area(d);})
293
          .style('fill', function(d, i) { return sugarloaf.summary_color(Object.keys(sugarloaf.difficulty_order)[i]) });
294
    
295
    svg.append('g')
296
        .attr('class', 'x axis')
297
        .attr('transform', 'translate(0,' + height + ')')
298
        .call(sugarloaf.summary_xAxis);
299
    
300
    svg.append('g')
301
        .attr('class', 'y axis')
302
        .call(sugarloaf.summary_yAxis);
303
    
304
    svg.append('text')
305
       .attr('class', 'y label')
306
       .attr('text-anchor', 'end')
307
       .attr('y', 6)
308
       .attr('dy', '.75em')
309
       .attr('transform', 'rotate(-90)')
310
       .text('Trail count');
311
}
312
313
d3.json(filename_status, function(data) {
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
314
    sugarloaf.data = data;
315
316
    d3.select('#report')
0 ignored issues
show
Bug introduced by
The variable d3 seems to be never declared. If this is a global, consider adding a /** global: d3 */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
317
        .html(data.report);
318
319
    buildCharts();
320
});
321
322
d3.json(filename_summary, function(data) {
323
    sugarloaf.summary = data;
324
325
    buildSummaryChart(sugarloaf.summary);
326
});