-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathNetflixDistBarTooltip.vue
59 lines (55 loc) · 1.74 KB
/
NetflixDistBarTooltip.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<script setup lang="ts">
/**
* This component implements the tooltip with v-show. Another way of drawing tooltip is through a-tooltip (see NetflixTable.vue).
* However, a-tooltip cannot wrap a shape element in SVG.
* Certain workarounds are available, such as overlaying another div on the svg.
* Yet, they are too complicated and less practical than this simple tooltip.
*/
import { ref, computed } from 'vue';
import { useConfig } from '../stores/vaConfig';
const vaConfig = useConfig();
const props = defineProps<{
svgWidth: number;
tooltipMouseY: number;
tooltipDisplay: any;
x: any;
y: any;
}>();
// computed variables from the root variables
const tooltipMessage = computed(() => {
if (props.tooltipDisplay === null) return '';
return props.tooltipDisplay.dtype + ': ' + props.tooltipDisplay.count;
});
const tooltipWidth = computed(() => {
return tooltipMessage.value.length * 8; // 16 is the font size
});
const tooltipHeight = ref<number>(16 * 1.5);
const tooltipX = computed(() => {
if (props.tooltipDisplay === null) return 0;
const _x = props.x(props.tooltipDisplay.dtype.toString()) as number;
const rightHandSide = _x + props.x.bandwidth() + 2;
return rightHandSide + tooltipWidth.value > props.svgWidth
? _x - 2 - tooltipWidth.value
: rightHandSide;
});
const tooltipY = computed(() => {
return props.tooltipMouseY - tooltipHeight.value / 2;
});
</script>
<template>
<g>
<rect
:x="tooltipX"
:y="tooltipY"
:rx="10"
:ry="10"
:height="tooltipHeight"
:width="tooltipWidth"
:fill="vaConfig.color.com_dark"
:fill-opacity="0.95"
/>
<text :x="tooltipX + tooltipWidth / 16" :y="tooltipMouseY + 4" fill="white">
{{ tooltipMessage }}
</text>
</g>
</template>