@@ -3,19 +3,32 @@ formatChange = d3.format("+,d"),
3
3
formatDate = d3 . time . format ( "%B %d, %Y" ) ,
4
4
formatTime = d3 . time . format ( "%I:%M %p" ) ;
5
5
6
+ // we will keep a list of filter objects
7
+ // each filter object will have:
8
+ // * dim: the crossfilter dimension object
9
+ // * range: the currently filtered range, or null if nothing is currently applied
10
+
11
+ // currently filter settings get changed in the following places:
12
+ // brush.chart calls dimension.filterRange(extent);
13
+ // brushend.chart calls dimension.filterAll();
14
+ // chart.filter() calls both of those
15
+ // our race selectors call raceDim.filter(this.textContent) and oppRaceDim.filter(this.textContext)
16
+
6
17
function render ( method ) {
7
18
d3 . select ( this ) . call ( method ) ;
8
19
}
9
20
10
21
function renderAll ( ) {
11
22
chart . each ( render ) ;
23
+ list . each ( render ) ;
12
24
d3 . select ( "#active" ) . text ( formatNumber ( gr_all . value ( ) ) ) ;
13
- numWins = _ . find ( winGrp . all ( ) , function ( grp ) { return grp . key } ) . value
25
+ numWins = _ . find ( winGrp . all ( ) , function ( grp ) { return grp . key == "true" } ) . value
14
26
pctWins = Math . round ( 1000.0 * numWins / gr_all . value ( ) ) / 10.0 ;
15
- // console.log("wins:", numWins, pctWins);
27
+ // console.log("wins:", numWins, pctWins);
16
28
d3 . select ( "#winrate" ) . text ( pctWins ) ;
17
29
}
18
30
31
+ // not currently used, was from the original crossfilter demo
19
32
window . filter = function ( filters ) {
20
33
filters . forEach ( function ( d , i ) { charts [ i ] . filter ( d ) ; } ) ;
21
34
renderAll ( ) ;
@@ -26,6 +39,24 @@ window.reset = function(i) {
26
39
renderAll ( ) ;
27
40
} ;
28
41
42
+ function matchList ( elem ) {
43
+ var gamerecordsByDate = dateDim . top ( 80 ) ;
44
+
45
+ elem . each ( function ( ) {
46
+ var match = d3 . select ( this ) . selectAll ( ".match" )
47
+ . data ( gamerecordsByDate ) ;
48
+
49
+ var matchEnter = match . enter ( ) . append ( "tr" ) . attr ( "class" , "match" ) ;
50
+ matchEnter . append ( "td" ) . attr ( "class" , "id" ) . append ( "a" ) ;
51
+ matchEnter . append ( "td" ) . attr ( "class" , "result" ) ;
52
+
53
+ match . exit ( ) . remove ( ) ;
54
+
55
+ match . select ( '.id a' ) . text ( function ( gr ) { return gr . match . id } ) ;
56
+ match . select ( '.id a' ) . attr ( "href" , function ( gr ) { return "http://ggtracker.com/matches/" + gr . match . id } ) ;
57
+ match . select ( '.result' ) . text ( function ( gr ) { return gr . player . win == "true" ? "win" : "loss" } ) ;
58
+ } ) ;
59
+ }
29
60
30
61
function barChart ( ) {
31
62
if ( ! barChart . id ) barChart . id = 0 ;
@@ -53,12 +84,29 @@ function barChart() {
53
84
54
85
// Create the skeletal chart.
55
86
if ( g . empty ( ) ) {
87
+ // RESET link, hidden at first
56
88
div . select ( ".title" ) . append ( "a" )
57
89
. attr ( "href" , "javascript:reset(" + id + ")" )
58
90
. attr ( "class" , "reset" )
91
+ . attr ( "class" , "filtered" )
59
92
. text ( "reset" )
60
93
. style ( "display" , "none" ) ;
61
94
95
+ limits = div . select ( ".title" ) . append ( "div" )
96
+ . attr ( "class" , "filtered" )
97
+ . style ( "display" , "none" )
98
+ . text ( "from " ) ;
99
+
100
+ lower_limit = limits . append ( "span" )
101
+ . text ( "-" )
102
+ . attr ( "class" , "lower" ) ;
103
+
104
+ limits . append ( "span" ) . text ( " to " ) ;
105
+
106
+ upper_limit = limits . append ( "span" )
107
+ . text ( "-" )
108
+ . attr ( "class" , "upper" ) ;
109
+
62
110
g = div . append ( "svg" )
63
111
. attr ( "width" , width + margin . left + margin . right )
64
112
. attr ( "height" , height + margin . top + margin . bottom )
@@ -95,7 +143,7 @@ function barChart() {
95
143
if ( brushDirty ) {
96
144
brushDirty = false ;
97
145
g . selectAll ( ".brush" ) . call ( brush ) ;
98
- div . select ( ".title a " ) . style ( "display" , brush . empty ( ) ? "none" : null ) ;
146
+ div . selectAll ( ".title .filtered " ) . style ( "display" , brush . empty ( ) ? "none" : null ) ;
99
147
if ( brush . empty ( ) ) {
100
148
g . selectAll ( "#clip-" + id + " rect" )
101
149
. attr ( "x" , 0 )
@@ -141,7 +189,7 @@ function barChart() {
141
189
142
190
brush . on ( "brushstart.chart" , function ( ) {
143
191
var div = d3 . select ( this . parentNode . parentNode . parentNode ) ;
144
- div . select ( ".title a " ) . style ( "display" , null ) ;
192
+ div . selectAll ( ".title .filtered " ) . style ( "display" , null ) ;
145
193
} ) ;
146
194
147
195
brush . on ( "brush.chart" , function ( ) {
@@ -155,12 +203,15 @@ function barChart() {
155
203
. attr ( "x" , x ( extent [ 0 ] ) )
156
204
. attr ( "width" , x ( extent [ 1 ] ) - x ( extent [ 0 ] ) ) ;
157
205
dimension . filterRange ( extent ) ;
206
+ var div = d3 . select ( this . parentNode . parentNode . parentNode ) ;
207
+ div . select ( ".lower" ) . text ( Math . floor ( extent [ 0 ] ) ) ;
208
+ div . select ( ".upper" ) . text ( Math . floor ( extent [ 1 ] ) ) ;
158
209
} ) ;
159
210
160
211
brush . on ( "brushend.chart" , function ( ) {
161
212
if ( brush . empty ( ) ) {
162
213
var div = d3 . select ( this . parentNode . parentNode . parentNode ) ;
163
- div . select ( ".title a " ) . style ( "display" , "none" ) ;
214
+ div . selectAll ( ".title .filtered " ) . style ( "display" , "none" ) ;
164
215
div . select ( "#clip-" + id + " rect" ) . attr ( "x" , null ) . attr ( "width" , "100%" ) ;
165
216
dimension . filterAll ( ) ;
166
217
}
@@ -219,6 +270,28 @@ function barChart() {
219
270
return d3 . rebind ( chart , brush , "on" ) ;
220
271
} ;
221
272
273
+ function data_host ( ) {
274
+ return "http://localhost:3000" ;
275
+ }
276
+
277
+ function debug_suffix ( ) {
278
+ debug = true ;
279
+
280
+ if ( debug ) {
281
+ return "_debug" ;
282
+ } else {
283
+ return "" ;
284
+ }
285
+ }
286
+
287
+ function matches_url ( ) {
288
+ return data_host ( ) + "/matches" + debug_suffix ( ) + ".csv" ;
289
+ }
290
+
291
+ function entities_url ( ) {
292
+ return data_host ( ) + "/ents" + debug_suffix ( ) + ".csv" ;
293
+ }
294
+
222
295
function scout_init ( ) {
223
296
var start = Date . now ( ) ;
224
297
@@ -230,15 +303,15 @@ function scout_init() {
230
303
231
304
entity_non_numerics = [ "race" , "chosen_race" , "win" ]
232
305
233
- d3 . csv ( "http://localhost:3000/matches.csv" , function ( error , csv_matches ) {
306
+ d3 . csv ( matches_url ( ) , function ( error , csv_matches ) {
234
307
csv_matches . forEach ( function ( match , index ) {
235
308
match . play_date = new Date ( match . play_date ) ;
236
309
match . id = + match . id
237
310
match . average_league = + match . average_league
238
311
match . duration_minutes = + match . duration_minutes
239
312
matches [ match . id ] = match
240
313
} ) ;
241
- d3 . csv ( "http://localhost:3000/ents.csv" , function ( error , csv_ents ) {
314
+ d3 . csv ( entities_url ( ) , function ( error , csv_ents ) {
242
315
csv_ents . forEach ( function ( entity , index ) {
243
316
for ( var key in entity ) {
244
317
if ( ! ( _ . contains ( entity_non_numerics , key ) ) ) {
@@ -278,7 +351,7 @@ function scout_init() {
278
351
winGrp = winDim . group ( ) ;
279
352
280
353
durDim = gr_cf . dimension ( function ( gr ) { return Math . min ( 40 , gr . match . duration_minutes ) } ) ;
281
- durGrp = durDim . group ( function ( d ) { return Math . floor ( d / 5 ) * 5 } ) ;
354
+ durGrp = durDim . group ( function ( d ) { return d } ) ;
282
355
283
356
dateDim = gr_cf . dimension ( function ( gr ) { return gr . match . play_date } ) ;
284
357
dateGrp = dateDim . group ( ) ;
@@ -290,10 +363,10 @@ function scout_init() {
290
363
oasGrp = oasDim . group ( function ( d ) { return Math . floor ( d / 100 ) * 100 } ) ;
291
364
292
365
wsDim = gr_cf . dimension ( function ( gr ) { return gr . player . w8 } ) ;
293
- wsGrp = wsDim . group ( function ( d ) { return Math . floor ( d / 5 ) * 5 } ) ;
366
+ wsGrp = wsDim . group ( function ( d ) { return d } ) ;
294
367
295
368
owsDim = gr_cf . dimension ( function ( gr ) { return gr . opponent . w8 } ) ;
296
- owsGrp = owsDim . group ( function ( d ) { return Math . floor ( d / 5 ) * 5 } ) ;
369
+ owsGrp = owsDim . group ( function ( d ) { return d } ) ;
297
370
298
371
mb2Dim = gr_cf . dimension ( function ( gr ) { return Math . floor ( gr . player . miningbase_2 / 60 ) } ) ;
299
372
mb2Grp = mb2Dim . group ( function ( d ) { return d ; } )
@@ -333,28 +406,28 @@ function scout_init() {
333
406
. group ( wsGrp )
334
407
. x ( d3 . scale . linear ( )
335
408
. domain ( [ 0 , 50 ] )
336
- . rangeRound ( [ 0 , 10 * 20 ] ) ) ,
409
+ . rangeRound ( [ 0 , 10 * 15 ] ) ) ,
337
410
338
411
barChart ( )
339
412
. dimension ( owsDim )
340
413
. group ( owsGrp )
341
414
. x ( d3 . scale . linear ( )
342
415
. domain ( [ 0 , 50 ] )
343
- . rangeRound ( [ 0 , 10 * 20 ] ) ) ,
416
+ . rangeRound ( [ 0 , 10 * 15 ] ) ) ,
344
417
345
418
barChart ( )
346
419
. dimension ( mb2Dim )
347
420
. group ( mb2Grp )
348
421
. x ( d3 . scale . linear ( )
349
422
. domain ( [ 0 , 15 ] )
350
- . rangeRound ( [ 0 , 10 * 20 ] ) ) ,
423
+ . rangeRound ( [ 0 , 10 * 15 ] ) ) ,
351
424
352
425
barChart ( )
353
426
. dimension ( omb2Dim )
354
427
. group ( omb2Grp )
355
428
. x ( d3 . scale . linear ( )
356
429
. domain ( [ 0 , 15 ] )
357
- . rangeRound ( [ 0 , 10 * 20 ] ) ) ,
430
+ . rangeRound ( [ 0 , 10 * 15 ] ) ) ,
358
431
359
432
barChart ( )
360
433
. dimension ( durDim )
@@ -376,22 +449,13 @@ function scout_init() {
376
449
. data ( charts )
377
450
. each ( function ( chart ) { chart . on ( "brush" , renderAll ) . on ( "brushend" , renderAll ) ; } ) ;
378
451
452
+ // Render the initial lists.
453
+ list = d3 . selectAll ( ".list tbody" )
454
+ . data ( [ matchList ] ) ;
455
+
379
456
d3 . selectAll ( "#total" )
380
457
. text ( formatNumber ( gr_cf . size ( ) ) ) ;
381
458
382
- $ ( "#player_race .selector" ) . each ( function ( index , raceSelector ) {
383
- $ ( raceSelector ) . click ( function ( ) {
384
- raceDim . filter ( this . textContent ) ;
385
- renderAll ( ) ;
386
- } )
387
- } ) ;
388
- $ ( "#opponent_race .selector" ) . each ( function ( index , raceSelector ) {
389
- $ ( raceSelector ) . click ( function ( ) {
390
- oppRaceDim . filter ( this . textContent ) ;
391
- renderAll ( ) ;
392
- } )
393
- } ) ;
394
-
395
459
renderAll ( ) ;
396
460
397
461
var end = Date . now ( ) ;
0 commit comments