@@ -87,20 +87,25 @@ export class CFDRenderer extends UIControlsRenderer {
8787 * @param {string } graphElementSelector - Selector of the DOM element to render the graph.
8888 */
8989 renderGraph ( graphElementSelector ) {
90+ console . log ( 'setupBrush-b-selectedTimeRange' , this . selectedTimeRange ) ;
9091 this . graphElementSelector = graphElementSelector ;
9192 this . #drawSvg( graphElementSelector ) ;
9293 this . svg . append ( 'g' ) . attr ( 'transform' , `translate(${ this . margin . left } , ${ this . margin . top } )` ) ;
9394 this . #stackedData = this . #computeStackData( ) ;
9495 this . #drawAxes( ) ;
9596 this . #drawArea( ) ;
97+ console . log ( 'setupBrush-a-selectedTimeRange' , this . selectedTimeRange ) ;
98+
9699 }
97100
98101 /**
99102 * Renders a brush component with the time range selection.
100103 */
101104 renderBrush ( ) {
102105 const svgBrush = this . #drawBrushSvg( this . brushSelector ) ;
103- const defaultSelectionRange = this . defaultTimeRange . map ( ( d ) => this . x ( d ) ) ;
106+ console . log ( 'selectedTimeRange' , this . selectedTimeRange ) ;
107+ console . log ( 'defaultTimeRange' , this . defaultTimeRange ) ;
108+ const defaultSelectionRange = this . selectedTimeRange . map ( ( d ) => this . x ( d ) ) ;
104109 this . brush = d3
105110 . brushX ( )
106111 . extent ( [
@@ -109,6 +114,7 @@ export class CFDRenderer extends UIControlsRenderer {
109114 ] )
110115 . on ( 'brush' , ( { selection } ) => {
111116 this . selectedTimeRange = selection . map ( this . x ?. invert , this . x ) ;
117+ console . log ( 'inside-selectedTimeRange---------' , this . selectedTimeRange ) ;
112118 this . updateGraph ( this . selectedTimeRange ) ;
113119 if ( this . isManualBrushUpdate && this . eventBus ) {
114120 this . eventBus ?. emitEvents ( `change-time-range-${ this . chartName } ` , this . selectedTimeRange ) ;
@@ -133,17 +139,51 @@ export class CFDRenderer extends UIControlsRenderer {
133139 }
134140
135141 /**
136- * Clears the CFD graph and brush from the specified DOM elements.
137- * @param {string } graphElementSelector - Selector of the DOM element to clear the graph.
138- * @param {string } cfdBrushElementSelector - Selector of the DOM element to clear the brush.
142+ * Updates the renderer's data and re-renders the graph, preserving persistent props.
143+ * @param {Array } newData - The new data to render.
144+ */
145+ updateData ( newData ) {
146+ this . data = newData ;
147+ // After updating this.data
148+ const dataDates = this . data . map ( d => new Date ( d . date ) ) ;
149+ const minDate = d3 . min ( dataDates ) ;
150+ const maxDate = d3 . max ( dataDates ) ;
151+
152+ if ( this . selectedTimeRange ) {
153+ let [ selectedStart , selectedEnd ] = this . selectedTimeRange ;
154+ selectedStart = selectedStart < minDate ? minDate : selectedStart ;
155+ selectedEnd = selectedEnd > maxDate ? maxDate : selectedEnd ;
156+ this . selectedTimeRange = [ selectedStart , selectedEnd ] ;
157+ } else {
158+ this . selectedTimeRange = [ minDate , maxDate ] ;
159+ }
160+ // Preserve persistent props like selectedTimeRange, reportingRangeDays, etc.
161+ // Re-render the graph with the new data
162+ if ( this . graphElementSelector ) {
163+ this . clearGraph ( this . graphElementSelector , this . brushSelector ) ;
164+ this . renderGraph ( this . graphElementSelector ) ;
165+ this . renderBrush ( this . brushSelector ) ;
166+ }
167+ }
168+
169+ /**
170+ * Clears the graph and brush SVGs, removes listeners, and handles missing event bus gracefully.
139171 */
140172 clearGraph ( graphElementSelector , cfdBrushElementSelector ) {
141- this . eventBus . removeAllListeners ( 'change-time-range-scatterplot' ) ;
142- this . eventBus . removeAllListeners ( 'scatterplot-mousemove' ) ;
143- this . eventBus . removeAllListeners ( 'scatterplot-mouseleave' ) ;
144- this . eventBus . removeAllListeners ( 'change-time-interval-scatterplot' ) ;
173+ console . log ( 'clearGraph-selectedTimeRange' , this . selectedTimeRange ) ;
174+ if ( this . eventBus && typeof this . eventBus . removeAllListeners === 'function' ) {
175+ this . eventBus . removeAllListeners ( 'change-time-range-scatterplot' ) ;
176+ this . eventBus . removeAllListeners ( 'scatterplot-mousemove' ) ;
177+ this . eventBus . removeAllListeners ( 'scatterplot-mouseleave' ) ;
178+ this . eventBus . removeAllListeners ( 'change-time-interval-scatterplot' ) ;
179+ }
180+ // Remove all children from the SVG elements
181+ d3 . select ( graphElementSelector ) . selectAll ( '*' ) . remove ( ) ;
182+ d3 . select ( cfdBrushElementSelector ) . selectAll ( '*' ) . remove ( ) ;
183+
145184 this . #drawBrushSvg( cfdBrushElementSelector ) ;
146185 this . #drawSvg( graphElementSelector ) ;
186+ console . log ( 'clearGraph-after-selectedTimeRange' , this . selectedTimeRange ) ;
147187 }
148188
149189 /**
@@ -372,7 +412,7 @@ export class CFDRenderer extends UIControlsRenderer {
372412 g . selectAll ( 'text' ) . attr ( 'y' , 30 ) . style ( 'fill' , 'black' ) ;
373413 g . attr ( 'clip-path' , `url(#${ clipId } )` ) ;
374414 } else {
375- axis = this . createXAxis ( x , 'months ' ) ;
415+ axis = this . createXAxis ( x , 'quarters ' ) ;
376416 g . call ( axis ) . attr ( 'transform' , `translate(0, ${ height } )` ) ;
377417 }
378418 }
0 commit comments