Skip to content

Commit 1b81ef7

Browse files
author
Ivona Stojanovic
committed
Improve heatmap colors
Previously, colors were generated in HeatmapCollector based on intensity, and the same colors were used for both light and dark themes. As a result, the displayed colors didn’t always match the color legend for the selected theme. To fix this, we now compute only the intensity for both self and total samples in HeatmapCollector. The actual color is chosen later based on that intensity and the active theme, ensuring the lines correctly follow the theme-specific color legend.
1 parent 8801c6d commit 1b81ef7

5 files changed

Lines changed: 116 additions & 147 deletions

File tree

Lib/profiling/sampling/_heatmap_assets/heatmap.css

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,18 +1094,34 @@
10941094
}
10951095

10961096
#scroll_marker .marker.cold {
1097+
background: var(--heat-1);
1098+
}
1099+
1100+
#scroll_marker .marker.cool {
10971101
background: var(--heat-2);
10981102
}
10991103

1104+
#scroll_marker .marker.mild {
1105+
background: var(--heat-3);
1106+
}
1107+
11001108
#scroll_marker .marker.warm {
1101-
background: var(--heat-5);
1109+
background: var(--heat-4);
11021110
}
11031111

11041112
#scroll_marker .marker.hot {
1113+
background: var(--heat-5);
1114+
}
1115+
1116+
#scroll_marker .marker.very-hot {
1117+
background: var(--heat-6);
1118+
}
1119+
1120+
#scroll_marker .marker.intense {
11051121
background: var(--heat-7);
11061122
}
11071123

1108-
#scroll_marker .marker.vhot {
1124+
#scroll_marker .marker.extreme {
11091125
background: var(--heat-8);
11101126
}
11111127

Lib/profiling/sampling/_heatmap_assets/heatmap.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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();
@@ -161,10 +162,14 @@ function getSampleCount(line) {
161162
}
162163

163164
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';
165+
if (ratio <= 0.125) return 'cold';
166+
if (ratio <= 0.25) return 'cool';
167+
if (ratio <= 0.375) return 'mild';
168+
if (ratio <= 0.5) return 'warm';
169+
if (ratio <= 0.625) return 'hot';
170+
if (ratio <= 0.75) return 'very-hot';
171+
if (ratio <= 0.875) return 'intense';
172+
return 'extreme';
168173
}
169174

170175
// ============================================================================
@@ -212,6 +217,21 @@ function buildScrollMarker() {
212217
document.body.appendChild(scrollMarker);
213218
}
214219

220+
function applyLineColors() {
221+
const lines = document.querySelectorAll('.code-line');
222+
lines.forEach(line => {
223+
let intensity;
224+
if (colorMode === 'self') {
225+
intensity = parseFloat(line.getAttribute('data-self-intensity')) || 0;
226+
} else {
227+
intensity = parseFloat(line.getAttribute('data-cumulative-intensity')) || 0;
228+
}
229+
230+
const color = intensityToColor(intensity);
231+
line.style.background = color;
232+
});
233+
}
234+
215235
// ============================================================================
216236
// Toggle Controls
217237
// ============================================================================
@@ -264,20 +284,7 @@ function applyHotFilter() {
264284

265285
function toggleColorMode() {
266286
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-
});
287+
applyLineColors();
281288

282289
updateToggleUI('toggle-color-mode', colorMode === 'cumulative');
283290

@@ -295,14 +302,7 @@ function toggleColorMode() {
295302
document.addEventListener('DOMContentLoaded', function() {
296303
// Restore UI state (theme, etc.)
297304
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-
});
305+
applyLineColors();
306306

307307
// Initialize navigation buttons
308308
document.querySelectorAll('.nav-btn').forEach(button => {

Lib/profiling/sampling/_heatmap_assets/heatmap_index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
// Tachyon Profiler - Heatmap Index JavaScript
22
// Index page specific functionality
33

4+
// ============================================================================
5+
// Heatmap Bar Coloring
6+
// ============================================================================
7+
8+
function applyHeatmapBarColors() {
9+
const bars = document.querySelectorAll('.heatmap-bar[data-intensity]');
10+
bars.forEach(bar => {
11+
const intensity = parseFloat(bar.getAttribute('data-intensity')) || 0;
12+
const color = intensityToColor(intensity);
13+
bar.style.backgroundColor = color;
14+
});
15+
}
16+
417
// ============================================================================
518
// Theme Support
619
// ============================================================================
@@ -17,6 +30,8 @@ function toggleTheme() {
1730
if (btn) {
1831
btn.innerHTML = next === 'dark' ? '&#9788;' : '&#9790;'; // sun or moon
1932
}
33+
34+
applyHeatmapBarColors();
2035
}
2136

2237
function restoreUIState() {
@@ -108,4 +123,5 @@ function collapseAll() {
108123

109124
document.addEventListener('DOMContentLoaded', function() {
110125
restoreUIState();
126+
applyHeatmapBarColors();
111127
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Tachyon Profiler - Shared Heatmap JavaScript
2+
// Common utilities shared between index and file views
3+
4+
// ============================================================================
5+
// Color Mapping (Intensity to Heat Color)
6+
// ============================================================================
7+
8+
function intensityToColor(intensity) {
9+
if (intensity <= 0) {
10+
return 'transparent';
11+
}
12+
13+
const rootStyle = getComputedStyle(document.documentElement);
14+
15+
if (intensity <= 0.125) {
16+
return rootStyle.getPropertyValue('--heat-1').trim();
17+
} else if (intensity <= 0.25) {
18+
return rootStyle.getPropertyValue('--heat-2').trim();
19+
} else if (intensity <= 0.375) {
20+
return rootStyle.getPropertyValue('--heat-3').trim();
21+
} else if (intensity <= 0.5) {
22+
return rootStyle.getPropertyValue('--heat-4').trim();
23+
} else if (intensity <= 0.625) {
24+
return rootStyle.getPropertyValue('--heat-5').trim();
25+
} else if (intensity <= 0.75) {
26+
return rootStyle.getPropertyValue('--heat-6').trim();
27+
} else if (intensity <= 0.875) {
28+
return rootStyle.getPropertyValue('--heat-7').trim();
29+
} else {
30+
return rootStyle.getPropertyValue('--heat-8').trim();
31+
}
32+
}

0 commit comments

Comments
 (0)