@@ -351,38 +351,15 @@ class MiniStats {
351351 // update opacity based on size (larger sizes have higher default opacity)
352352 this . opacity = value > 0 ? 0.85 : 0.7 ;
353353
354- // delete GPU pass graphs when switching below threshold
354+ // delete sub-stat graphs when switching below their thresholds
355355 if ( value < this . gpuTimingMinSize && this . gpuPassGraphs ) {
356- for ( const passData of this . gpuPassGraphs . values ( ) ) {
357- const index = this . graphs . indexOf ( passData . graph ) ;
358- if ( index !== - 1 ) {
359- this . graphs . splice ( index , 1 ) ;
360- }
361- this . freeRow ( passData . graph ) ;
362- passData . graph . destroy ( ) ;
363- }
364- this . gpuPassGraphs . clear ( ) ;
365-
366- // keep main GPU graph in GPU color group
367- const gpuGraph = this . graphs . find ( g => g . name === 'GPU' ) ;
368- if ( gpuGraph ) gpuGraph . graphType = 0.33 ;
356+ this . clearSubGraphs ( this . gpuPassGraphs , 'GPU' , 0.33 ) ;
369357 }
370-
371- // delete CPU sub-timing graphs when switching below threshold
372358 if ( value < this . cpuTimingMinSize && this . cpuGraphs ) {
373- for ( const statData of this . cpuGraphs . values ( ) ) {
374- const index = this . graphs . indexOf ( statData . graph ) ;
375- if ( index !== - 1 ) {
376- this . graphs . splice ( index , 1 ) ;
377- }
378- this . freeRow ( statData . graph ) ;
379- statData . graph . destroy ( ) ;
380- }
381- this . cpuGraphs . clear ( ) ;
382-
383- // keep main CPU graph in CPU color group
384- const cpuGraph = this . graphs . find ( g => g . name === 'CPU' ) ;
385- if ( cpuGraph ) cpuGraph . graphType = 0.66 ;
359+ this . clearSubGraphs ( this . cpuGraphs , 'CPU' , 0.66 ) ;
360+ }
361+ if ( value < this . vramTimingMinSize && this . vramGraphs ) {
362+ this . clearSubGraphs ( this . vramGraphs ) ;
386363 }
387364 }
388365
@@ -777,6 +754,31 @@ class MiniStats {
777754 }
778755 }
779756
757+ /**
758+ * Remove all sub-stat graphs from a tracking map when collapsing below a size threshold.
759+ *
760+ * @param {Map } subGraphs - The sub-graph map to clear.
761+ * @param {string } [mainGraphName] - If provided, reset the main graph's graphType.
762+ * @param {number } [graphType] - The graphType value to restore on the main graph.
763+ * @private
764+ */
765+ clearSubGraphs ( subGraphs , mainGraphName , graphType ) {
766+ for ( const statData of subGraphs . values ( ) ) {
767+ const index = this . graphs . indexOf ( statData . graph ) ;
768+ if ( index !== - 1 ) {
769+ this . graphs . splice ( index , 1 ) ;
770+ }
771+ this . freeRow ( statData . graph ) ;
772+ statData . graph . destroy ( ) ;
773+ }
774+ subGraphs . clear ( ) ;
775+
776+ if ( mainGraphName ) {
777+ const mainGraph = this . graphs . find ( g => g . name === mainGraphName ) ;
778+ if ( mainGraph ) mainGraph . graphType = graphType ;
779+ }
780+ }
781+
780782 /**
781783 * Ensures the texture has enough rows. Only grows, never shrinks.
782784 *
0 commit comments