Skip to content

Commit 6981ecb

Browse files
committed
position default tooltip above marker
1 parent 9d56f64 commit 6981ecb

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

src/lib/components/data-vis/line-chart/ValueLabel.svelte

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
activeMarkerId,
44
labelColor = "red",
55
labelTextColor,
6-
tooltipContent,
6+
tooltipContent = activeMarkerId.y,
77
xFunction,
88
yFunction,
99
x,
@@ -15,24 +15,24 @@
1515
let textDimensions = $state();
1616
let verticalPadding = $state(8);
1717
let horizontalPadding = $derived(verticalPadding * 2);
18+
$inspect(markerRect);
1819
</script>
1920

2021
{#if tooltipSnippet === undefined}
2122
<div
2223
style="position:absolute;
23-
top: {markerRect?.y}px;
24-
left: {markerRect?.x}px;
25-
font-size: 24px;
24+
top: {markerRect?.y - (textDimensions?.height ?? 0) - 15}px;
25+
left: {markerRect?.x +
26+
(markerRect?.width ?? 0) / 2 -
27+
(textDimensions?.width ?? 0) / 2}px;
2628
pointer-events: none;
2729
background-color: {labelColor};
2830
padding: 5px;
2931
border-radius: 5px;
30-
height={(textDimensions?.height ?? 0) + verticalPadding}
31-
rx=5;
32-
ry=5;
33-
width={(textDimensions?.width ?? 0) + horizontalPadding}"
32+
height={textDimensions?.height ?? 0}
33+
width={textDimensions?.width ?? 0}"
3434
>
35-
<p bind:contentRect={textDimensions}>tooltipContent is a string</p>
35+
<div bind:contentRect={textDimensions}>{activeMarkerId.y}</div>
3636
</div>
3737
{:else}<div
3838
style="position: absolute; top: {markerRect?.y}px; left: {markerRect?.x}px;"

src/wrappers/components/data-vis/line-chart/LineChartWrapper.svelte

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@
534534
description:
535535
"Background color of the chart. Also used for the 'halo' outline given to lines.",
536536
},
537-
{ name: "tooltipSnippet", category: "tooltip", value: tooltipSnippet },
538537
{
539538
name: "xFunction",
540539
category: "xScale",
@@ -558,7 +557,7 @@
558557
{
559558
name: "tooltipContent",
560559
category: "interactions",
561-
value: "Here's some content for a tooltip",
560+
value: "tooltipContent from Wrapper",
562561
},
563562
{
564563
name: "getLine",
@@ -587,7 +586,7 @@
587586
}
588587
},`,
589588
},
590-
value: function (key, el) {
589+
value: function (tier, el) {
591590
let primaryLines = [
592591
"E07000224",
593592
"E07000225",
@@ -596,16 +595,16 @@
596595
englandMedian,
597596
similarAreas,
598597
];
599-
if (key === "primary") {
598+
if (tier === "primary") {
600599
return primaryLines.includes(el[series]);
601600
}
602-
if (key === "secondary" && !primaryLines.includes(el[series])) {
601+
if (tier === "secondary" && !primaryLines.includes(el[series])) {
603602
return true;
604603
}
605-
if (key === "hover") {
604+
if (tier === "hover") {
606605
return [hoveredSeries, hoveredSeries].includes(el[series]);
607606
}
608-
if (key === "clicked") {
607+
if (tier === "clicked") {
609608
return [clickedSeries, clickedSeries].includes(el[series]);
610609
}
611610
},
@@ -928,7 +927,3 @@ DONOTTOUCH *
928927
<div id="examples" data-role="examples-section">
929928
<Examples {data}></Examples>
930929
</div>
931-
932-
{#snippet tooltipSnippet(activeMarkerId)}
933-
{@html `<div style="border: 1px solid black; padding: 0.5rem; background-color: white; pointer-events: none">${activeMarkerId.y}</div>`}
934-
{/snippet}

src/wrappers/components/data-vis/line-chart/line-chart/Examples.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,13 @@
144144
{/snippet}
145145

146146
{#snippet tooltipSnippet(activeMarkerId)}
147-
{@html `<div style="border: 1px solid black; padding: 0.5rem; background-color: white; pointer-events: none"><i>Value:</i> ${activeMarkerId.y}<br><i>Year:</i> ${activeMarkerId.x}</div>`}
147+
<div
148+
style="border: 1px solid black; padding: 0.5rem; background-color: white; pointer-events: none"
149+
>
150+
<i>Value:</i>
151+
{activeMarkerId.y}<br /><i>Year:</i>
152+
{activeMarkerId.x}
153+
</div>
148154
{/snippet}
149155

150156
{#snippet Example4()}

0 commit comments

Comments
 (0)