File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -270,6 +270,33 @@ function renderChart({
270
270
}
271
271
}
272
272
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
+
273
300
// Render outline for debugging
274
301
if (props .debug ) {
275
302
d3
@@ -313,4 +340,17 @@ watch(
313
340
font-feature-settings : 'tnum' 1 ;
314
341
position : relative;
315
342
}
343
+
344
+ :deep (.tooltip) {
345
+ opacity : 0 ;
346
+ pointer-events : none;
347
+ position : absolute;
348
+ top : 0 ;
349
+ left : 0 ;
350
+ padding : 2 px 8 px ;
351
+ background-color : var (--c-bg-elv-2 );
352
+ border : 1 px solid var (--c-divider );
353
+ border-radius : 6 px ;
354
+ font-size : 12 px ;
355
+ }
316
356
</style >
You can’t perform that action at this time.
0 commit comments