@@ -26,6 +26,7 @@ function toggleTheme() {
2626 if ( btn ) {
2727 btn . innerHTML = next === 'dark' ? '☼' : '☾' ; // sun or moon
2828 }
29+ applyLineColors ( ) ;
2930
3031 // Rebuild scroll marker with new theme colors
3132 buildScrollMarker ( ) ;
@@ -160,13 +161,6 @@ function getSampleCount(line) {
160161 return parseInt ( text ) || 0 ;
161162}
162163
163- function getIntensityClass ( ratio ) {
164- if ( ratio > 0.75 ) return 'vhot' ;
165- if ( ratio > 0.5 ) return 'hot' ;
166- if ( ratio > 0.25 ) return 'warm' ;
167- return 'cold' ;
168- }
169-
170164// ============================================================================
171165// Scroll Minimap
172166// ============================================================================
@@ -194,7 +188,7 @@ function buildScrollMarker() {
194188
195189 const lineTop = Math . floor ( line . offsetTop * markerScale ) ;
196190 const lineNumber = index + 1 ;
197- const intensityClass = maxSamples > 0 ? getIntensityClass ( samples / maxSamples ) : 'cold' ;
191+ const intensityClass = maxSamples > 0 ? ( intensityToClass ( samples / maxSamples ) || 'cold' ) : 'cold' ;
198192
199193 if ( lineNumber === prevLine + 1 && lastMark ?. classList . contains ( intensityClass ) ) {
200194 lastMark . style . height = `${ lineTop + lineHeight - lastTop } px` ;
@@ -212,6 +206,21 @@ function buildScrollMarker() {
212206 document . body . appendChild ( scrollMarker ) ;
213207}
214208
209+ function applyLineColors ( ) {
210+ const lines = document . querySelectorAll ( '.code-line' ) ;
211+ lines . forEach ( line => {
212+ let intensity ;
213+ if ( colorMode === 'self' ) {
214+ intensity = parseFloat ( line . getAttribute ( 'data-self-intensity' ) ) || 0 ;
215+ } else {
216+ intensity = parseFloat ( line . getAttribute ( 'data-cumulative-intensity' ) ) || 0 ;
217+ }
218+
219+ const color = intensityToColor ( intensity ) ;
220+ line . style . background = color ;
221+ } ) ;
222+ }
223+
215224// ============================================================================
216225// Toggle Controls
217226// ============================================================================
@@ -264,20 +273,7 @@ function applyHotFilter() {
264273
265274function toggleColorMode ( ) {
266275 colorMode = colorMode === 'self' ? 'cumulative' : 'self' ;
267- const lines = document . querySelectorAll ( '.code-line' ) ;
268-
269- lines . forEach ( line => {
270- let bgColor ;
271- if ( colorMode === 'self' ) {
272- bgColor = line . getAttribute ( 'data-self-color' ) ;
273- } else {
274- bgColor = line . getAttribute ( 'data-cumulative-color' ) ;
275- }
276-
277- if ( bgColor ) {
278- line . style . background = bgColor ;
279- }
280- } ) ;
276+ applyLineColors ( ) ;
281277
282278 updateToggleUI ( 'toggle-color-mode' , colorMode === 'cumulative' ) ;
283279
@@ -295,14 +291,7 @@ function toggleColorMode() {
295291document . addEventListener ( 'DOMContentLoaded' , function ( ) {
296292 // Restore UI state (theme, etc.)
297293 restoreUIState ( ) ;
298-
299- // Apply background colors
300- document . querySelectorAll ( '.code-line[data-bg-color]' ) . forEach ( line => {
301- const bgColor = line . getAttribute ( 'data-bg-color' ) ;
302- if ( bgColor ) {
303- line . style . background = bgColor ;
304- }
305- } ) ;
294+ applyLineColors ( ) ;
306295
307296 // Initialize navigation buttons
308297 document . querySelectorAll ( '.nav-btn' ) . forEach ( button => {
0 commit comments