Skip to content

Commit 487c4dd

Browse files
committed
copy tooltip implementation to pie
1 parent 8d06dd4 commit 487c4dd

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lib/components/SChartPie.vue

+40
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,33 @@ function renderChart({
270270
}
271271
}
272272
273+
if (props.tooltip) {
274+
const Tooltip = d3
275+
.select(chartRef.value)
276+
.append('div')
277+
.attr('class', 'tooltip')
278+
279+
function updatePos(event: PointerEvent) {
280+
const [x, y] = d3.pointer(event, chartRef.value)
281+
Tooltip
282+
.style('left', `${x + 14}px`)
283+
.style('top', `${y + 14}px`)
284+
}
285+
286+
arcs
287+
.on('pointerenter', (event: PointerEvent, { data: d }) => {
288+
Tooltip
289+
.html(props.tooltipFormat(d, color(d)))
290+
.style('opacity', '1')
291+
updatePos(event)
292+
})
293+
.on('pointermove', updatePos)
294+
.on('pointerleave', () => {
295+
Tooltip
296+
.style('opacity', '0')
297+
})
298+
}
299+
273300
// Render outline for debugging
274301
if (props.debug) {
275302
d3
@@ -313,4 +340,17 @@ watch(
313340
font-feature-settings: 'tnum' 1;
314341
position: relative;
315342
}
343+
344+
:deep(.tooltip) {
345+
opacity: 0;
346+
pointer-events: none;
347+
position: absolute;
348+
top: 0;
349+
left: 0;
350+
padding: 2px 8px;
351+
background-color: var(--c-bg-elv-2);
352+
border: 1px solid var(--c-divider);
353+
border-radius: 6px;
354+
font-size: 12px;
355+
}
316356
</style>

0 commit comments

Comments
 (0)