Skip to content

Commit c66e552

Browse files
committed
feat: add tooltip functionality for bar chart to display values on hover
1 parent 9f8985c commit c66e552

1 file changed

Lines changed: 45 additions & 4 deletions

File tree

sp-dashboard/index.html

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,16 @@
190190
.bar-col { flex: 0 0 32px; } /* fixed width columns prevent overlap and allow scrolling */
191191
.bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1; height: 100%; }
192192
.bar { width: 100%; max-width: 32px; background: var(--c-primary, #03a9f4); border-radius: 4px 4px 0 0; min-height: 2px; transition: height 0.3s; position: relative; }
193-
.bar:hover::after {
194-
content: attr(data-val); position: absolute; top: -25px; left: 50%; transform: translateX(-50%);
195-
background: var(--card-bg, #1e1e1e); border: 1px solid var(--divider-color, #333); padding: 2px 6px; border-radius: 4px; font-size: 10px; white-space: nowrap; z-index: 10;
196-
}
197193
.bar-label { font-size: 0.7rem; color: var(--text-color-muted, #9e9e9e); margin-top: 0.5rem; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; }
198194

195+
/* Bar chart tooltip positioned at pointer */
196+
.bar-tooltip {
197+
position: fixed; pointer-events: none; background: var(--card-bg, #1e1e1e); border: 1px solid var(--divider-color, #333);
198+
padding: 4px 8px; border-radius: 4px; font-size: 11px; white-space: nowrap; z-index: 1000; display: none;
199+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
200+
}
201+
.bar-tooltip.visible { display: block; }
202+
199203
.pie-wrapper { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; gap: 2rem; }
200204
.pie-chart {
201205
width: 180px; height: 180px; border-radius: 50%; flex-shrink: 0;
@@ -398,6 +402,9 @@ <h3 class="card-title">Project Breakdown</h3>
398402
</div>
399403
</div>
400404

405+
<!-- Bar chart tooltip positioned at cursor -->
406+
<div class="bar-tooltip" id="bar-tooltip"></div>
407+
401408
<script>
402409
console.log("[sp-dashboard] Dashboard script initialized");
403410
// --- UTILITIES ---
@@ -535,6 +542,10 @@ <h3 class="card-title">Project Breakdown</h3>
535542
document.getElementById('stat-tasks').innerText = String(metrics.totalCompleted);
536543
document.getElementById('stat-tasks-total').innerText = `/ ${metrics.totalTasks} total`;
537544

545+
// Progress: completion rate of active tasks in the date range
546+
// totalCompleted = unique tasks completed
547+
// totalTasks = unique tasks with either time logged OR completed (note: table shows entries per-day,
548+
// so one task appearing on multiple days counts as 1 in the denominator)
538549
const progress = metrics.totalTasks > 0 ? (metrics.totalCompleted / metrics.totalTasks) * 100 : 0;
539550
document.getElementById('stat-tasks-progress').style.width = `${progress}%`;
540551

@@ -627,6 +638,31 @@ <h3 class="card-title">Project Breakdown</h3>
627638
`;
628639
container.appendChild(col);
629640
}
641+
642+
// Setup tooltip listeners for bars
643+
setupBarTooltip();
644+
};
645+
646+
const setupBarTooltip = () => {
647+
const tooltip = document.getElementById('bar-tooltip');
648+
const bars = document.querySelectorAll('.bar-chart .bar');
649+
650+
bars.forEach(bar => {
651+
bar.addEventListener('mouseenter', (e) => {
652+
tooltip.textContent = bar.getAttribute('data-val');
653+
tooltip.classList.add('visible');
654+
});
655+
656+
bar.addEventListener('mousemove', (e) => {
657+
// Position tooltip at cursor with small offset
658+
tooltip.style.left = (e.clientX + 8) + 'px';
659+
tooltip.style.top = (e.clientY - 12) + 'px';
660+
});
661+
662+
bar.addEventListener('mouseleave', () => {
663+
tooltip.classList.remove('visible');
664+
});
665+
});
630666
};
631667

632668
const renderNativePieChart = (projectData, formatFn) => {
@@ -1041,6 +1077,11 @@ <h3 class="card-title">Project Breakdown</h3>
10411077
{
10421078
id: "t4", parentId: null, title: "Setup Database", isDone: false, projectId: "p1",
10431079
timeSpentOnDay: { [dates[3]]: 10800000 /* 3h */ }, dueDay: "2026-02-18" // Overdue
1080+
},
1081+
{
1082+
id: "t5", parentId: null, title: "Write Documentation", isDone: false, projectId: "p1",
1083+
timeSpentOnDay: {}, // No time logged in this period – not included in denominator
1084+
dueDay: "2026-02-28" // Future due date
10441085
}
10451086
];
10461087

0 commit comments

Comments
 (0)