|
1 | 1 | <script lang="ts" module> |
2 | 2 | import type { CommonStyleProps, Without } from '$lib/utils/types.js'; |
3 | | - import type { ComponentProps, Snippet } from 'svelte'; |
| 3 | + import type { Snippet } from 'svelte'; |
4 | 4 |
|
5 | 5 | export type Point = { x: number; y: number; r: number; xValue: any; yValue: any; data: any }; |
6 | 6 | type Offset = number | ((value: number, context: any) => number) | undefined; |
|
37 | 37 | */ |
38 | 38 | offsetY?: Offset; |
39 | 39 |
|
40 | | - /** |
41 | | - * Enable showing links between related points (array x/y accessors) |
42 | | - * |
43 | | - * @default false |
44 | | - */ |
45 | | - links?: boolean | Partial<ComponentProps<typeof Link>>; |
46 | | -
|
47 | 40 | children?: Snippet<[{ points: Point[] }]>; |
48 | 41 | } & CommonStyleProps; |
49 | 42 |
|
|
71 | 64 | r = 5, |
72 | 65 | offsetX, |
73 | 66 | offsetY, |
74 | | - links = false, |
75 | 67 | fill, |
76 | 68 | fillOpacity, |
77 | 69 | stroke, |
|
136 | 128 | return []; |
137 | 129 | }) as Point[] |
138 | 130 | ); |
139 | | -
|
140 | | - const _links = $derived( |
141 | | - pointsData.flatMap((d: any) => { |
142 | | - const xValue = xAccessor(d); |
143 | | - const yValue = yAccessor(d); |
144 | | -
|
145 | | - if (Array.isArray(xValue)) { |
146 | | - /* |
147 | | - x={["prop1" ,"prop2"]} |
148 | | - y="prop3" |
149 | | - */ |
150 | | - const [xMin, xMax] = extent(ctx.xGet(d)) as unknown as [number, number]; |
151 | | - const y = ctx.yGet(d) + getOffset(ctx.yGet(d), offsetY, ctx.yScale); |
152 | | - return { |
153 | | - source: { |
154 | | - x: xMin + getOffset(xMin, offsetX, ctx.xScale) + (ctx.config.r ? ctx.rGet(d) : r), |
155 | | - y, |
156 | | - }, |
157 | | - target: { |
158 | | - x: xMax + getOffset(xMax, offsetX, ctx.xScale) - (ctx.config.r ? ctx.rGet(d) : r), |
159 | | - y: y, |
160 | | - }, |
161 | | - data: d, |
162 | | - }; |
163 | | - } else if (Array.isArray(yValue)) { |
164 | | - /* |
165 | | - x="prop1" |
166 | | - y={["prop2" ,"prop3"]} |
167 | | - */ |
168 | | - const x = ctx.xGet(d) + getOffset(ctx.xGet(d), offsetX, ctx.xScale); |
169 | | - const [yMin, yMax] = extent(ctx.yGet(d)) as unknown as [number, number]; |
170 | | - return { |
171 | | - source: { |
172 | | - x: x, |
173 | | - y: yMin + getOffset(yMin, offsetY, ctx.yScale), |
174 | | - }, |
175 | | - target: { |
176 | | - x: x, |
177 | | - y: yMax + getOffset(yMax, offsetY, ctx.yScale), |
178 | | - }, |
179 | | - data: d, |
180 | | - }; |
181 | | - } |
182 | | - }) |
183 | | - ); |
184 | 131 | </script> |
185 | 132 |
|
186 | 133 | {#if children} |
187 | 134 | {@render children({ points })} |
188 | 135 | {:else} |
189 | | - {#if links} |
190 | | - {#each _links as link} |
191 | | - <Link |
192 | | - data={link} |
193 | | - stroke={fill ?? (ctx.config.c ? ctx.cGet(link.data) : null)} |
194 | | - {...extractLayerProps(links, 'points-link')} |
195 | | - /> |
196 | | - {/each} |
197 | | - {/if} |
198 | | - |
199 | 136 | {#each points as point} |
200 | 137 | <Circle |
201 | 138 | cx={point.x} |
|
0 commit comments