@@ -3,19 +3,32 @@ formatChange = d3.format("+,d"),
33formatDate = d3 . time . format ( "%B %d, %Y" ) ,
44formatTime = d3 . time . format ( "%I:%M %p" ) ;
55
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+
617function render ( method ) {
718 d3 . select ( this ) . call ( method ) ;
819}
920
1021function renderAll ( ) {
1122 chart . each ( render ) ;
23+ list . each ( render ) ;
1224 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
1426 pctWins = Math . round ( 1000.0 * numWins / gr_all . value ( ) ) / 10.0 ;
15- // console.log("wins:", numWins, pctWins);
27+ // console.log("wins:", numWins, pctWins);
1628 d3 . select ( "#winrate" ) . text ( pctWins ) ;
1729}
1830
31+ // not currently used, was from the original crossfilter demo
1932window . filter = function ( filters ) {
2033 filters . forEach ( function ( d , i ) { charts [ i ] . filter ( d ) ; } ) ;
2134 renderAll ( ) ;
@@ -26,6 +39,24 @@ window.reset = function(i) {
2639 renderAll ( ) ;
2740} ;
2841
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+ }
2960
3061function barChart ( ) {
3162 if ( ! barChart . id ) barChart . id = 0 ;
@@ -53,12 +84,29 @@ function barChart() {
5384
5485 // Create the skeletal chart.
5586 if ( g . empty ( ) ) {
87+ // RESET link, hidden at first
5688 div . select ( ".title" ) . append ( "a" )
5789 . attr ( "href" , "javascript:reset(" + id + ")" )
5890 . attr ( "class" , "reset" )
91+ . attr ( "class" , "filtered" )
5992 . text ( "reset" )
6093 . style ( "display" , "none" ) ;
6194
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+
62110 g = div . append ( "svg" )
63111 . attr ( "width" , width + margin . left + margin . right )
64112 . attr ( "height" , height + margin . top + margin . bottom )
@@ -95,7 +143,7 @@ function barChart() {
95143 if ( brushDirty ) {
96144 brushDirty = false ;
97145 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 ) ;
99147 if ( brush . empty ( ) ) {
100148 g . selectAll ( "#clip-" + id + " rect" )
101149 . attr ( "x" , 0 )
@@ -141,7 +189,7 @@ function barChart() {
141189
142190 brush . on ( "brushstart.chart" , function ( ) {
143191 var div = d3 . select ( this . parentNode . parentNode . parentNode ) ;
144- div . select ( ".title a " ) . style ( "display" , null ) ;
192+ div . selectAll ( ".title .filtered " ) . style ( "display" , null ) ;
145193 } ) ;
146194
147195 brush . on ( "brush.chart" , function ( ) {
@@ -155,12 +203,15 @@ function barChart() {
155203 . attr ( "x" , x ( extent [ 0 ] ) )
156204 . attr ( "width" , x ( extent [ 1 ] ) - x ( extent [ 0 ] ) ) ;
157205 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 ] ) ) ;
158209 } ) ;
159210
160211 brush . on ( "brushend.chart" , function ( ) {
161212 if ( brush . empty ( ) ) {
162213 var div = d3 . select ( this . parentNode . parentNode . parentNode ) ;
163- div . select ( ".title a " ) . style ( "display" , "none" ) ;
214+ div . selectAll ( ".title .filtered " ) . style ( "display" , "none" ) ;
164215 div . select ( "#clip-" + id + " rect" ) . attr ( "x" , null ) . attr ( "width" , "100%" ) ;
165216 dimension . filterAll ( ) ;
166217 }
@@ -219,6 +270,28 @@ function barChart() {
219270 return d3 . rebind ( chart , brush , "on" ) ;
220271} ;
221272
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+
222295function scout_init ( ) {
223296 var start = Date . now ( ) ;
224297
@@ -230,15 +303,15 @@ function scout_init() {
230303
231304 entity_non_numerics = [ "race" , "chosen_race" , "win" ]
232305
233- d3 . csv ( "http://localhost:3000/matches.csv" , function ( error , csv_matches ) {
306+ d3 . csv ( matches_url ( ) , function ( error , csv_matches ) {
234307 csv_matches . forEach ( function ( match , index ) {
235308 match . play_date = new Date ( match . play_date ) ;
236309 match . id = + match . id
237310 match . average_league = + match . average_league
238311 match . duration_minutes = + match . duration_minutes
239312 matches [ match . id ] = match
240313 } ) ;
241- d3 . csv ( "http://localhost:3000/ents.csv" , function ( error , csv_ents ) {
314+ d3 . csv ( entities_url ( ) , function ( error , csv_ents ) {
242315 csv_ents . forEach ( function ( entity , index ) {
243316 for ( var key in entity ) {
244317 if ( ! ( _ . contains ( entity_non_numerics , key ) ) ) {
@@ -278,7 +351,7 @@ function scout_init() {
278351 winGrp = winDim . group ( ) ;
279352
280353 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 } ) ;
282355
283356 dateDim = gr_cf . dimension ( function ( gr ) { return gr . match . play_date } ) ;
284357 dateGrp = dateDim . group ( ) ;
@@ -290,10 +363,10 @@ function scout_init() {
290363 oasGrp = oasDim . group ( function ( d ) { return Math . floor ( d / 100 ) * 100 } ) ;
291364
292365 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 } ) ;
294367
295368 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 } ) ;
297370
298371 mb2Dim = gr_cf . dimension ( function ( gr ) { return Math . floor ( gr . player . miningbase_2 / 60 ) } ) ;
299372 mb2Grp = mb2Dim . group ( function ( d ) { return d ; } )
@@ -333,28 +406,28 @@ function scout_init() {
333406 . group ( wsGrp )
334407 . x ( d3 . scale . linear ( )
335408 . domain ( [ 0 , 50 ] )
336- . rangeRound ( [ 0 , 10 * 20 ] ) ) ,
409+ . rangeRound ( [ 0 , 10 * 15 ] ) ) ,
337410
338411 barChart ( )
339412 . dimension ( owsDim )
340413 . group ( owsGrp )
341414 . x ( d3 . scale . linear ( )
342415 . domain ( [ 0 , 50 ] )
343- . rangeRound ( [ 0 , 10 * 20 ] ) ) ,
416+ . rangeRound ( [ 0 , 10 * 15 ] ) ) ,
344417
345418 barChart ( )
346419 . dimension ( mb2Dim )
347420 . group ( mb2Grp )
348421 . x ( d3 . scale . linear ( )
349422 . domain ( [ 0 , 15 ] )
350- . rangeRound ( [ 0 , 10 * 20 ] ) ) ,
423+ . rangeRound ( [ 0 , 10 * 15 ] ) ) ,
351424
352425 barChart ( )
353426 . dimension ( omb2Dim )
354427 . group ( omb2Grp )
355428 . x ( d3 . scale . linear ( )
356429 . domain ( [ 0 , 15 ] )
357- . rangeRound ( [ 0 , 10 * 20 ] ) ) ,
430+ . rangeRound ( [ 0 , 10 * 15 ] ) ) ,
358431
359432 barChart ( )
360433 . dimension ( durDim )
@@ -376,22 +449,13 @@ function scout_init() {
376449 . data ( charts )
377450 . each ( function ( chart ) { chart . on ( "brush" , renderAll ) . on ( "brushend" , renderAll ) ; } ) ;
378451
452+ // Render the initial lists.
453+ list = d3 . selectAll ( ".list tbody" )
454+ . data ( [ matchList ] ) ;
455+
379456 d3 . selectAll ( "#total" )
380457 . text ( formatNumber ( gr_cf . size ( ) ) ) ;
381458
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-
395459 renderAll ( ) ;
396460
397461 var end = Date . now ( ) ;
0 commit comments