|
2 | 2 | import type { IconName } from '$lib/holocene/icon'; |
3 | 3 | import Icon from '$lib/holocene/icon/icon.svelte'; |
4 | 4 |
|
5 | | - import type { GraphConfig } from '../constants'; |
| 5 | + import { |
| 6 | + getTextOffset, |
| 7 | + type GraphConfig, |
| 8 | + textBackdropOffset, |
| 9 | + textBackdropOffsetWithIcon, |
| 10 | + } from '../constants'; |
6 | 11 |
|
7 | 12 | import Line from './line.svelte'; |
8 | 13 |
|
9 | 14 | export let point: [number, number] = [0, 0]; |
10 | 15 | export let category: string | undefined = undefined; |
| 16 | + export let status: string | undefined = 'none'; |
11 | 17 | export let fontSize = '14px'; |
12 | 18 | export let fontWeight = '400'; |
13 | 19 | export let textAnchor = 'start'; |
|
16 | 22 | export let icon: IconName | undefined = undefined; |
17 | 23 | export let config: GraphConfig | undefined = undefined; |
18 | 24 | export let label = false; |
| 25 | + export let textWidth = 0; |
| 26 | + export let noOffset = false; |
| 27 | + export let dark = false; |
19 | 28 |
|
20 | 29 | $: [x, y] = point; |
21 | 30 |
|
22 | 31 | let textElement: SVGTextElement; |
23 | 32 |
|
24 | 33 | $: showIcon = icon && config; |
25 | 34 | $: textWidth = textElement?.getBBox()?.width || 0; |
26 | | - $: backdropWidth = showIcon ? textWidth + 36 : textWidth + 12; |
| 35 | + $: backdropWidth = |
| 36 | + showIcon && !noOffset |
| 37 | + ? textWidth + textBackdropOffsetWithIcon |
| 38 | + : textWidth + textBackdropOffset; |
27 | 39 | $: textX = showIcon && textAnchor === 'start' ? x + config.radius * 2 : x; |
| 40 | + $: offset = noOffset ? getTextOffset(config.radius || 0) : 0; |
28 | 41 | </script> |
29 | 42 |
|
30 | 43 | {#if backdrop} |
31 | 44 | <Line |
32 | 45 | startPoint={[x - backdropHeight, y]} |
33 | 46 | endPoint={[x + backdropWidth, y]} |
34 | | - status="none" |
| 47 | + {status} |
35 | 48 | strokeWidth={backdropHeight} |
36 | 49 | /> |
37 | 50 | {/if} |
38 | 51 | {#if showIcon && textAnchor === 'start'} |
39 | | - <Icon name={icon} {x} y={y - 8} class="text-white" /> |
| 52 | + <Icon |
| 53 | + name={icon} |
| 54 | + x={x - offset} |
| 55 | + y={y - 8} |
| 56 | + class={dark ? 'text-black' : 'text-white'} |
| 57 | + /> |
40 | 58 | {/if} |
41 | 59 | <text |
42 | 60 | bind:this={textElement} |
43 | 61 | class="cursor-pointer select-none outline-none {category} text-primary" |
44 | 62 | class:label |
45 | 63 | class:backdrop |
46 | | - x={textX} |
| 64 | + class:dark |
| 65 | + x={textX - offset} |
47 | 66 | {y} |
48 | 67 | font-size={fontSize} |
49 | 68 | font-weight={fontWeight} |
|
54 | 73 | {#if showIcon && textAnchor === 'end'} |
55 | 74 | <Icon |
56 | 75 | name={icon} |
57 | | - x={x - textWidth - config.radius * 1.5} |
| 76 | + x={x - offset} |
58 | 77 | y={y - 8} |
59 | | - class="text-white" |
| 78 | + class={dark ? 'text-black' : 'text-white'} |
60 | 79 | /> |
61 | 80 | {/if} |
62 | 81 |
|
|
112 | 131 | fill: #ff4518; |
113 | 132 | } |
114 | 133 |
|
| 134 | + text.dark, |
115 | 135 | text.none { |
116 | | - fill: #141414; |
| 136 | + fill: theme('colors.space-black'); |
117 | 137 | } |
118 | 138 | </style> |
0 commit comments