@@ -16,9 +16,33 @@ class CwvDistribution {
1616 this . date = this . pageFilters . end || this . root ?. dataset ?. latestDate || '' ;
1717 this . selectedMetric = this . resolveMetric ( new URLSearchParams ( window . location . search ) . get ( 'good-cwv-over-time' ) ) ;
1818
19- // Populate "Latest data" timestamp immediately
20- const tsSlot = this . root ?. querySelector ( '[data-slot="cwv-distribution-timestamp"]' ) ;
21- if ( tsSlot && this . date ) tsSlot . textContent = UIUtils . printMonthYear ( this . date ) ;
19+ const updateDateFromTimeseries = ( newDate ) => {
20+ this . date = newDate ;
21+ const tsSlot = this . root ?. querySelector ( '[data-slot="cwv-distribution-timestamp"]' ) ;
22+ if ( tsSlot && this . date ) tsSlot . textContent = UIUtils . printMonthYear ( this . date ) ;
23+ if ( ! this . distributionData ) {
24+ this . fetchData ( ) ;
25+ }
26+ } ;
27+
28+ if ( ! this . date ) {
29+ // If we don't have a date, see if we can get it from the timeseries component
30+ // If not wait for the event to emit when the date is available
31+ const cwvChartDate = document . querySelector ( '#section-good_cwv_timeseries [data-slot=timestamp]' ) ;
32+ if ( cwvChartDate && cwvChartDate . dataset . date ) {
33+ updateDateFromTimeseries ( cwvChartDate . dataset . date ) ;
34+ } else {
35+ document . addEventListener ( 'timeseries-date-updated' , ( event ) => {
36+ if ( event . detail . id === 'good_cwv_timeseries' ) {
37+ updateDateFromTimeseries ( event . detail . date ) ;
38+ }
39+ } ) ;
40+ }
41+ } else {
42+ // Populate "Latest data" timestamp immediately
43+ const tsSlot = this . root ?. querySelector ( '[data-slot="cwv-distribution-timestamp"]' ) ;
44+ if ( tsSlot && this . date ) tsSlot . textContent = UIUtils . printMonthYear ( this . date ) ;
45+ }
2246
2347 this . updateTitle ( ) ;
2448 this . bindEventListeners ( ) ;
@@ -66,7 +90,11 @@ class CwvDistribution {
6690 if ( show ) {
6791 this . root . classList . remove ( 'hidden' ) ;
6892 if ( btn ) btn . textContent = 'Hide histogram' ;
69- if ( ! this . distributionData ) {
93+ if ( ! this . date ) {
94+ const cwvChartDate = document . querySelector ( '#section-good_cwv_timeseries [data-slot=timestamp]' ) ;
95+ this . date = cwvChartDate . dataset . date ;
96+ }
97+ if ( ! this . distributionData && this . date ) {
7098 this . fetchData ( ) ;
7199 } else if ( this . chart ) {
72100 this . chart . reflow ( ) ;
0 commit comments