Skip to content

Commit d726488

Browse files
committed
use toggles
1 parent cca0057 commit d726488

3 files changed

Lines changed: 91 additions & 34 deletions

File tree

Lib/profiling/sampling/_heatmap_assets/heatmap.css

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -521,40 +521,76 @@ footer {
521521
align-items: center;
522522
}
523523

524-
#toggle-color-mode,
525-
#toggle-cold {
526-
padding: 8px 16px;
527-
background: var(--color-primary);
528-
border: 1px solid var(--color-primary-dark);
529-
border-radius: var(--radius-sm);
530-
color: var(--color-text-inverse);
524+
/* Toggle Switch Styles */
525+
.toggle-switch {
526+
display: inline-flex;
527+
align-items: center;
528+
gap: 8px;
531529
cursor: pointer;
532-
font-size: 0.9em;
533-
transition: all var(--transition-base);
534-
white-space: nowrap;
530+
user-select: none;
531+
font-family: var(--font-family-base);
532+
}
533+
534+
.toggle-switch .toggle-label {
535+
font-size: 0.85em;
535536
font-weight: 500;
537+
color: var(--color-text-secondary);
538+
min-width: 65px;
539+
text-align: right;
540+
}
541+
542+
.toggle-switch .toggle-label:last-child {
543+
text-align: left;
544+
}
545+
546+
.toggle-switch .toggle-label.active {
547+
color: var(--color-primary);
548+
font-weight: 600;
536549
}
537550

551+
/* Push first toggle to the right */
538552
#toggle-color-mode {
539553
margin-left: auto;
540554
}
541555

542-
#toggle-color-mode:hover,
543-
#toggle-cold:hover {
544-
background: var(--color-primary-dark);
545-
transform: translateY(-1px);
546-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
556+
.toggle-track {
557+
position: relative;
558+
width: 44px;
559+
height: 24px;
560+
background: #ccc;
561+
border-radius: 12px;
562+
transition: background 0.3s ease;
563+
}
564+
565+
.toggle-track.on {
566+
background: var(--color-primary);
547567
}
548568

549-
#toggle-color-mode.cumulative {
550-
background: #9b59b6; /* Purple for cumulative mode */
551-
border-color: #8e44ad;
569+
.toggle-track::after {
570+
content: '';
571+
position: absolute;
572+
top: 2px;
573+
left: 2px;
574+
width: 20px;
575+
height: 20px;
576+
background: white;
577+
border-radius: 50%;
578+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
579+
transition: transform 0.3s ease;
552580
}
553581

554-
#toggle-cold.active {
555-
background: var(--color-accent);
556-
color: var(--color-text-primary);
557-
border-color: var(--color-accent);
582+
.toggle-track.on::after {
583+
transform: translateX(20px);
584+
}
585+
586+
/* Color mode toggle specific */
587+
#toggle-color-mode .toggle-track.on {
588+
background: #8e44ad;
589+
}
590+
591+
/* Cold code toggle specific */
592+
#toggle-cold .toggle-track.on {
593+
background: #e67e22;
558594
}
559595

560596
.code-header h1 {

Lib/profiling/sampling/_heatmap_assets/heatmap.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ window.addEventListener('resize', buildScrollMarker);
211211
function toggleColdCode() {
212212
coldCodeHidden = !coldCodeHidden;
213213
const lines = document.querySelectorAll('.code-line');
214-
const toggleBtn = document.getElementById('toggle-cold');
214+
const toggle = document.getElementById('toggle-cold');
215215

216216
lines.forEach(line => {
217217
// Check both self and cumulative samples
@@ -228,9 +228,18 @@ function toggleColdCode() {
228228
}
229229
});
230230

231-
if (toggleBtn) {
232-
toggleBtn.textContent = coldCodeHidden ? '🔥 Show Cold' : '❄️ Hide Cold';
233-
toggleBtn.classList.toggle('active', coldCodeHidden);
231+
if (toggle) {
232+
const track = toggle.querySelector('.toggle-track');
233+
const labels = toggle.querySelectorAll('.toggle-label');
234+
if (coldCodeHidden) {
235+
track.classList.add('on');
236+
labels[0].classList.remove('active');
237+
labels[1].classList.add('active');
238+
} else {
239+
track.classList.remove('on');
240+
labels[0].classList.add('active');
241+
labels[1].classList.remove('active');
242+
}
234243
}
235244
}
236245

@@ -249,7 +258,7 @@ document.addEventListener('DOMContentLoaded', () => {
249258
function toggleColorMode() {
250259
colorMode = colorMode === 'self' ? 'cumulative' : 'self';
251260
const lines = document.querySelectorAll('.code-line');
252-
const toggleBtn = document.getElementById('toggle-color-mode');
261+
const toggle = document.getElementById('toggle-color-mode');
253262

254263
lines.forEach(line => {
255264
let bgColor;
@@ -264,13 +273,17 @@ function toggleColorMode() {
264273
}
265274
});
266275

267-
if (toggleBtn) {
276+
if (toggle) {
277+
const track = toggle.querySelector('.toggle-track');
278+
const labels = toggle.querySelectorAll('.toggle-label');
268279
if (colorMode === 'self') {
269-
toggleBtn.textContent = '🎨 Color: Self';
270-
toggleBtn.classList.remove('cumulative');
280+
track.classList.remove('on');
281+
labels[0].classList.add('active');
282+
labels[1].classList.remove('active');
271283
} else {
272-
toggleBtn.textContent = '📊 Color: Cumulative';
273-
toggleBtn.classList.add('cumulative');
284+
track.classList.add('on');
285+
labels[0].classList.remove('active');
286+
labels[1].classList.add('active');
274287
}
275288
}
276289

Lib/profiling/sampling/_heatmap_assets/heatmap_pyfile_template.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,16 @@ <h1>📄 <!-- FILENAME --></h1>
5252
<span></span>
5353
<span>Hot (Max)</span>
5454
</div>
55-
<button id="toggle-color-mode" title="Toggle between self and cumulative coloring">🎨 Color: Self</button>
56-
<button id="toggle-cold" title="Hide lines with zero samples">❄️ Hide Cold</button>
55+
<div class="toggle-switch" id="toggle-color-mode" title="Toggle between self time and total time coloring">
56+
<span class="toggle-label active">Self Time</span>
57+
<div class="toggle-track"></div>
58+
<span class="toggle-label">Total Time</span>
59+
</div>
60+
<div class="toggle-switch" id="toggle-cold" title="Toggle visibility of lines with zero samples">
61+
<span class="toggle-label active">Show All</span>
62+
<div class="toggle-track"></div>
63+
<span class="toggle-label">Hot Only</span>
64+
</div>
5765
</div>
5866
</div>
5967

0 commit comments

Comments
 (0)