@@ -21,7 +21,9 @@ document.addEventListener('DOMContentLoaded', function () {
2121 const primaryDimFilter = d => d . dimension_type === 'sector' ;
2222
2323 // Groups
24+ const moveDays = dateDimension . group ( d3 . timeDay ) ;
2425 const moveMonths = dateDimension . group ( d3 . timeMonth ) ;
26+ const volumeByDayGroup = moveDays . reduceSum ( d => primaryDimFilter ( d ) ? d . total_usd : 0 ) ;
2527 const volumeByMonthGroup = moveMonths . reduceSum ( d => primaryDimFilter ( d ) ? d . total_usd : 0 ) ;
2628 const sectorGroup = sectorDimension . group ( ) . reduceSum ( d => d . dimension_type === 'sector' ? d . total_usd : 0 ) ;
2729 const programGroup = programDimension . group ( ) . reduceSum ( d => d . dimension_type === 'program' ? d . total_usd : 0 ) ;
@@ -56,6 +58,7 @@ document.addEventListener('DOMContentLoaded', function () {
5658 . margins ( { top : 10 , right : 50 , bottom : 30 , left : 90 } )
5759 . dimension ( dateDimension )
5860 . group ( volumeByMonthGroup )
61+ . curve ( d3 . curveMonotoneX )
5962 . transitionDuration ( 500 )
6063 . x ( d3 . scaleTime ( ) . domain ( initialDomain ) ) // Set initial scale
6164 . round ( d3 . timeMonth . round )
@@ -72,37 +75,45 @@ document.addEventListener('DOMContentLoaded', function () {
7275 } )
7376 . on ( 'filtered' , updateTotals ) ;
7477
75- focusChart . yAxis ( ) . tickFormat ( d => d3 . format ( ".2s" ) ( d ) . replace ( 'G' , 'B' ) ) ;
78+ focusChart . yAxis ( ) . tickFormat ( d => '$' + d3 . format ( ".2s" ) ( d ) . replace ( 'G' , 'B' ) ) ;
7679
7780 rangeChart
7881 . width ( null ) . height ( 80 )
79- . margins ( { top : 0 , right : 50 , bottom : 20 , left : 60 } )
82+ . margins ( { top : 0 , right : 50 , bottom : 20 , left : 90 } )
8083 . dimension ( dateDimension )
81- . group ( volumeByMonthGroup )
84+ . group ( volumeByDayGroup )
8285 . centerBar ( true )
83- . gap ( 1 )
86+ . gap ( 2 )
8487 . x ( d3 . scaleTime ( ) . domain ( initialDomain ) ) // Set initial scale
85- . round ( d3 . timeMonth . round )
86- . xUnits ( d3 . timeMonths )
88+ . round ( d3 . timeDay . round )
89+ . xUnits ( d3 . timeDays )
90+ . filterPrinter ( function ( filters ) {
91+ const dateFmt = d3 . timeFormat ( "%b %d, %Y" ) ;
92+ return `[${ dateFmt ( filters [ 0 ] [ 0 ] ) } to ${ dateFmt ( filters [ 0 ] [ 1 ] ) } ]` ;
93+ } )
8794 . yAxis ( ) . ticks ( 0 ) ;
8895
89- sectorChart . width ( null ) . height ( 300 ) . margins ( { top : 10 , right : 10 , bottom : 30 , left : 10 } ) . dimension ( sectorDimension ) . group ( sectorGroup ) . elasticX ( true ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) ) . on ( 'filtered' , updateTotals ) ;
90-
91- countryChart . width ( null ) . height ( 300 ) . margins ( { top : 10 , right : 10 , bottom : 30 , left : 10 } ) . dimension ( countryDimension ) . group ( countryGroup ) . elasticX ( true ) . data ( group => group . top ( 10 ) ) . on ( 'filtered' , updateTotals ) ;
92-
93- adminChart . width ( null ) . height ( 300 ) . margins ( { top : 10 , right : 10 , bottom : 30 , left : 10 } ) . dimension ( adminDimension ) . group ( adminGroup ) . elasticX ( true ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) . slice ( 0 , 10 ) ) . on ( 'filtered' , updateTotals ) ;
96+ const rowChartMargins = { top : 10 , right : 30 , bottom : 30 , left : 180 } ;
9497
95- programChart . width ( null ) . height ( 300 ) . margins ( { top : 10 , right : 10 , bottom : 30 , left : 10 } ) . dimension ( programDimension ) . group ( programGroup ) . elasticX ( true ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) ) . on ( 'filtered' , updateTotals ) ;
96-
97- deliveryChart . width ( null ) . height ( 300 ) . margins ( { top : 10 , right : 10 , bottom : 30 , left : 10 } ) . dimension ( deliveryDimension ) . group ( deliveryGroup ) . elasticX ( true ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) ) . on ( 'filtered' , updateTotals ) ;
98-
99- fspChart . width ( null ) . height ( 300 ) . margins ( { top : 10 , right : 10 , bottom : 30 , left : 10 } ) . dimension ( fspDimension ) . group ( fspGroup ) . elasticX ( true ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) ) . on ( 'filtered' , updateTotals ) ;
100-
101- statusChart . width ( null ) . height ( 300 ) . margins ( { top : 10 , right : 10 , bottom : 30 , left : 10 } ) . dimension ( statusDimension ) . group ( statusGroup ) . elasticX ( true ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) ) . on ( 'filtered' , updateTotals ) ;
98+ [ adminChart , programChart , fspChart ] . forEach ( chart => {
99+ chart . width ( null ) . height ( 750 ) . margins ( rowChartMargins ) . elasticX ( true ) . gap ( 5 ) . data ( group => group . top ( 30 ) ) . on ( 'filtered' , updateTotals ) ;
100+ chart . xAxis ( ) . ticks ( 4 ) . tickFormat ( d => '$' + d3 . format ( ".2s" ) ( d ) . replace ( 'G' , 'B' ) ) ;
101+ } ) ;
102102
103- currencyChart . width ( null ) . height ( 300 ) . margins ( { top : 10 , right : 10 , bottom : 30 , left : 10 } ) . dimension ( currencyDimension ) . group ( currencyGroup ) . elasticX ( true ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) ) . on ( 'filtered' , updateTotals ) ;
103+ [ sectorChart , deliveryChart , statusChart , currencyChart , countryChart , regionChart ] . forEach ( chart => {
104+ chart . width ( null ) . height ( 400 ) . margins ( rowChartMargins ) . elasticX ( true ) . gap ( 10 ) . on ( 'filtered' , updateTotals ) ;
105+ chart . xAxis ( ) . ticks ( 4 ) . tickFormat ( d => '$' + d3 . format ( ".2s" ) ( d ) . replace ( 'G' , 'B' ) ) ;
106+ } ) ;
104107
105- regionChart . width ( null ) . height ( 300 ) . margins ( { top : 10 , right : 10 , bottom : 30 , left : 10 } ) . dimension ( regionDimension ) . group ( regionGroup ) . elasticX ( true ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) . slice ( 0 , 10 ) ) . on ( 'filtered' , updateTotals ) ;
108+ sectorChart . dimension ( sectorDimension ) . group ( sectorGroup ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) ) ;
109+ countryChart . dimension ( countryDimension ) . group ( countryGroup ) . data ( group => group . top ( 10 ) ) ;
110+ adminChart . dimension ( adminDimension ) . group ( adminGroup ) ;
111+ programChart . dimension ( programDimension ) . group ( programGroup ) ;
112+ deliveryChart . dimension ( deliveryDimension ) . group ( deliveryGroup ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) ) ;
113+ fspChart . dimension ( fspDimension ) . group ( fspGroup ) ;
114+ statusChart . dimension ( statusDimension ) . group ( statusGroup ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) ) ;
115+ currencyChart . dimension ( currencyDimension ) . group ( currencyGroup ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) ) ;
116+ regionChart . dimension ( regionDimension ) . group ( regionGroup ) . data ( group => group . all ( ) . filter ( d => d . key !== null && d . value > 0 ) . slice ( 0 , 10 ) ) ;
106117
107118 function updateTotals ( ) {
108119 const totalUsd = ndx . groupAll ( ) . reduceSum ( d => primaryDimFilter ( d ) ? d . total_usd : 0 ) . value ( ) ;
@@ -141,8 +152,12 @@ document.addEventListener('DOMContentLoaded', function () {
141152 d . payment_count = + d . payment_count ;
142153 } ) ;
143154
155+ const now = new Date ( ) ;
156+ now . setHours ( 23 , 59 , 59 , 999 ) ;
157+ const currentData = data . filter ( d => d . date <= now ) ;
158+
144159 ndx . remove ( ) ;
145- ndx . add ( data ) ;
160+ ndx . add ( currentData ) ;
146161
147162 const yearDomain = [ new Date ( year , 0 , 1 ) , new Date ( year , 11 , 31 ) ] ;
148163 focusChart . x ( d3 . scaleTime ( ) . domain ( yearDomain ) ) ;
0 commit comments