layerchart 2.0.0-next.50 → 2.0.0-next.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Arc.svelte +12 -4
- package/dist/components/Arc.svelte.d.ts +4 -0
- package/dist/components/ArcLabel.svelte +259 -0
- package/dist/components/ArcLabel.svelte.d.ts +73 -0
- package/dist/components/ArcLabel.svelte.test.d.ts +1 -0
- package/dist/components/ArcLabel.svelte.test.js +235 -0
- package/dist/components/Axis.svelte +25 -0
- package/dist/components/Axis.svelte.d.ts +10 -0
- package/dist/components/Circle.svelte +82 -59
- package/dist/components/CircleLegend.svelte +389 -0
- package/dist/components/CircleLegend.svelte.d.ts +114 -0
- package/dist/components/Ellipse.svelte +83 -64
- package/dist/components/GeoLegend.svelte +404 -0
- package/dist/components/GeoLegend.svelte.d.ts +106 -0
- package/dist/components/GeoRaster.svelte +311 -0
- package/dist/components/GeoRaster.svelte.d.ts +61 -0
- package/dist/components/Grid.svelte +15 -0
- package/dist/components/Grid.svelte.d.ts +5 -0
- package/dist/components/Image.svelte +2 -2
- package/dist/components/Labels.svelte +46 -11
- package/dist/components/Labels.svelte.d.ts +7 -3
- package/dist/components/Legend.svelte +58 -3
- package/dist/components/Legend.svelte.d.ts +7 -0
- package/dist/components/Line.svelte +82 -62
- package/dist/components/Points.svelte +2 -2
- package/dist/components/Polygon.svelte +92 -56
- package/dist/components/Rect.svelte +113 -64
- package/dist/components/Rule.svelte +2 -0
- package/dist/components/Sankey.svelte +0 -2
- package/dist/components/Text.svelte +83 -52
- package/dist/components/__screenshots__/ArcLabel.svelte.test.ts/ArcLabel-defaults-placement-to-centroid--x-y-at-the-centroid--middle-anchors--1.png +0 -0
- package/dist/components/__screenshots__/ArcLabel.svelte.test.ts/ArcLabel-defaults-placement-to-centroid--x-y-at-the-centroid--middle-anchors--2.png +0 -0
- package/dist/components/charts/ArcChart.svelte +39 -2
- package/dist/components/charts/ArcChart.svelte.d.ts +12 -1
- package/dist/components/charts/PieChart.svelte +40 -2
- package/dist/components/charts/PieChart.svelte.d.ts +10 -0
- package/dist/components/index.d.ts +8 -0
- package/dist/components/index.js +8 -0
- package/dist/components/layers/Canvas.svelte +65 -48
- package/dist/components/layers/Canvas.svelte.d.ts +10 -0
- package/dist/contexts/canvas.d.ts +3 -0
- package/dist/server/ContextCapture.svelte +30 -0
- package/dist/server/ContextCapture.svelte.d.ts +8 -0
- package/dist/server/ServerChart.svelte +26 -0
- package/dist/server/ServerChart.svelte.d.ts +11 -0
- package/dist/server/TestBarChart.svelte +35 -0
- package/dist/server/TestBarChart.svelte.d.ts +14 -0
- package/dist/server/TestLineChart.svelte +35 -0
- package/dist/server/TestLineChart.svelte.d.ts +14 -0
- package/dist/server/captureStore.d.ts +8 -0
- package/dist/server/captureStore.js +18 -0
- package/dist/server/index.d.ts +137 -0
- package/dist/server/index.js +141 -0
- package/dist/server/renderChart.ssr.test.d.ts +1 -0
- package/dist/server/renderChart.ssr.test.js +205 -0
- package/dist/server/renderTree.d.ts +8 -0
- package/dist/server/renderTree.js +29 -0
- package/dist/states/__screenshots__/chart.svelte.test.ts/ChartState-geo-projection-skips-markInfo-should-not-derive-x-y-accessors-from-marks-when-geo-projection-is-active-1.png +0 -0
- package/dist/states/__screenshots__/chart.svelte.test.ts/ChartState-geo-projection-skips-markInfo-should-not-derive-x-y-accessors-from-marks-when-geo-projection-is-active-2.png +0 -0
- package/dist/states/chart.svelte.d.ts +5 -1
- package/dist/states/chart.svelte.js +18 -3
- package/dist/states/chart.svelte.test.js +110 -0
- package/dist/states/geo.svelte.d.ts +5 -1
- package/dist/states/geo.svelte.js +80 -68
- package/dist/utils/arcText.svelte.d.ts +7 -1
- package/dist/utils/arcText.svelte.js +8 -4
- package/dist/utils/canvas.js +29 -10
- package/dist/utils/canvas.svelte.test.js +2 -2
- package/dist/utils/motion.svelte.js +14 -0
- package/package.json +7 -1
|
@@ -77,6 +77,14 @@
|
|
|
77
77
|
*/
|
|
78
78
|
selected?: string[];
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Value to indicate on the ramp (e.g. the currently hovered data point).
|
|
82
|
+
* When set, a downward-pointing arrow is drawn above the bar at this value's
|
|
83
|
+
* position. Defaults to auto-detecting from `ctx.tooltip.data` via the
|
|
84
|
+
* chart's color accessor (`ctx.c`).
|
|
85
|
+
*/
|
|
86
|
+
value?: number | string | null;
|
|
87
|
+
|
|
80
88
|
/**
|
|
81
89
|
* Classes to apply to the elements.
|
|
82
90
|
*
|
|
@@ -149,6 +157,7 @@
|
|
|
149
157
|
onpointerleave: onpointerleaveProp,
|
|
150
158
|
variant: variantProp,
|
|
151
159
|
selected: selectedProp,
|
|
160
|
+
value: valueProp,
|
|
152
161
|
classes = {},
|
|
153
162
|
ref: refProp = $bindable(),
|
|
154
163
|
class: className,
|
|
@@ -345,6 +354,36 @@
|
|
|
345
354
|
const variant = $derived(variantProp ?? (seriesItems ? 'swatches' : 'ramp'));
|
|
346
355
|
const selected = $derived(selectedProp ?? ctx.series?.selectedKeys?.current ?? []);
|
|
347
356
|
|
|
357
|
+
// Position indicator for the currently hovered value on the ramp. If `value`
|
|
358
|
+
// is explicitly provided, use it; otherwise fall back to `ctx.tooltip.data`
|
|
359
|
+
// piped through the chart's color accessor (`ctx.c`).
|
|
360
|
+
const indicatorX = $derived.by(() => {
|
|
361
|
+
if (variant !== 'ramp' || !scale) return null;
|
|
362
|
+
let value: any = valueProp;
|
|
363
|
+
if (value == null) {
|
|
364
|
+
const data = ctx.tooltip?.data;
|
|
365
|
+
if (data == null) return null;
|
|
366
|
+
value = ctx.c?.(data);
|
|
367
|
+
}
|
|
368
|
+
if (value == null) return null;
|
|
369
|
+
|
|
370
|
+
// Threshold / quantize / quantile scales — scaleConfig.xScale maps swatch
|
|
371
|
+
// *indices* to pixels, not the raw domain value. Find which bucket the
|
|
372
|
+
// value falls into and center on that swatch.
|
|
373
|
+
if ((scale as any).invertExtent) {
|
|
374
|
+
const i = scale.range().indexOf(scale(value));
|
|
375
|
+
if (i < 0) return null;
|
|
376
|
+
const x0 = scaleConfig.xScale?.(i - 1);
|
|
377
|
+
const x1 = scaleConfig.xScale?.(i);
|
|
378
|
+
if (typeof x0 !== 'number' || typeof x1 !== 'number') return null;
|
|
379
|
+
return (x0 + x1) / 2;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const x = scaleConfig.xScale?.(value);
|
|
383
|
+
if (typeof x !== 'number' || !Number.isFinite(x)) return null;
|
|
384
|
+
return x + scaleConfig.tickLabelOffset;
|
|
385
|
+
});
|
|
386
|
+
|
|
348
387
|
const swatchItems = $derived.by(() => {
|
|
349
388
|
if (seriesItems) {
|
|
350
389
|
// Series-based legend items
|
|
@@ -397,10 +436,13 @@
|
|
|
397
436
|
seriesItems,
|
|
398
437
|
})}
|
|
399
438
|
{:else if variant === 'ramp'}
|
|
439
|
+
{@const indicatorSize = 6}
|
|
440
|
+
{@const tickLabelY = height + tickLengthProp + tickFontSize}
|
|
441
|
+
{@const svgHeight = tickLabelY}
|
|
400
442
|
<svg
|
|
401
443
|
{width}
|
|
402
|
-
height={
|
|
403
|
-
viewBox="0 0 {width} {
|
|
444
|
+
height={svgHeight}
|
|
445
|
+
viewBox="0 0 {width} {svgHeight}"
|
|
404
446
|
class={cls('lc-legend-ramp-svg')}
|
|
405
447
|
>
|
|
406
448
|
<g class="lc-legend-ramp-g">
|
|
@@ -423,7 +465,7 @@
|
|
|
423
465
|
<text
|
|
424
466
|
text-anchor="middle"
|
|
425
467
|
x={scaleConfig.xScale?.(tick) + scaleConfig.tickLabelOffset}
|
|
426
|
-
y={
|
|
468
|
+
y={tickLabelY}
|
|
427
469
|
style:font-size={tickFontSize}
|
|
428
470
|
class={cls('lc-legend-tick-text', classes.label)}
|
|
429
471
|
>
|
|
@@ -442,6 +484,15 @@
|
|
|
442
484
|
{/if}
|
|
443
485
|
{/each}
|
|
444
486
|
</g>
|
|
487
|
+
|
|
488
|
+
{#if indicatorX != null}
|
|
489
|
+
<path
|
|
490
|
+
d="M{indicatorX - 4},{height + indicatorSize + 1} L{indicatorX + 4},{height +
|
|
491
|
+
indicatorSize +
|
|
492
|
+
1} L{indicatorX},{height} Z"
|
|
493
|
+
class={cls('lc-legend-indicator')}
|
|
494
|
+
/>
|
|
495
|
+
{/if}
|
|
445
496
|
</svg>
|
|
446
497
|
{:else if variant === 'swatches'}
|
|
447
498
|
<div class={cls('lc-legend-swatch-group', classes.items)} data-orientation={orientation}>
|
|
@@ -537,6 +588,10 @@
|
|
|
537
588
|
stroke: var(--color-surface-content, currentColor);
|
|
538
589
|
}
|
|
539
590
|
|
|
591
|
+
:where(.lc-legend-indicator) {
|
|
592
|
+
fill: var(--color-surface-content, currentColor);
|
|
593
|
+
}
|
|
594
|
+
|
|
540
595
|
:where(.lc-legend-swatch-group) {
|
|
541
596
|
display: flex;
|
|
542
597
|
gap: 0.25rem 1rem;
|
|
@@ -64,6 +64,13 @@ export type LegendPropsWithoutHTML = {
|
|
|
64
64
|
* An array of selected items. If provided, the legend fades unselected items.
|
|
65
65
|
*/
|
|
66
66
|
selected?: string[];
|
|
67
|
+
/**
|
|
68
|
+
* Value to indicate on the ramp (e.g. the currently hovered data point).
|
|
69
|
+
* When set, a downward-pointing arrow is drawn above the bar at this value's
|
|
70
|
+
* position. Defaults to auto-detecting from `ctx.tooltip.data` via the
|
|
71
|
+
* chart's color accessor (`ctx.c`).
|
|
72
|
+
*/
|
|
73
|
+
value?: number | string | null;
|
|
67
74
|
/**
|
|
68
75
|
* Classes to apply to the elements.
|
|
69
76
|
*
|
|
@@ -125,7 +125,13 @@
|
|
|
125
125
|
import { getLayerContext } from '../contexts/layer.js';
|
|
126
126
|
import { getChartContext } from '../contexts/chart.js';
|
|
127
127
|
import { createDataMotionMap } from '../utils/motion.svelte.js';
|
|
128
|
-
import {
|
|
128
|
+
import {
|
|
129
|
+
hasAnyDataProp,
|
|
130
|
+
resolveDataProp,
|
|
131
|
+
resolveColorProp,
|
|
132
|
+
resolveGeoDataPair,
|
|
133
|
+
resolveStyleProp,
|
|
134
|
+
} from '../utils/dataProp.js';
|
|
129
135
|
import { getGeoContext } from '../contexts/geo.js';
|
|
130
136
|
import { chartDataArray } from '../utils/common.js';
|
|
131
137
|
|
|
@@ -167,9 +173,7 @@
|
|
|
167
173
|
const geo = getGeoContext();
|
|
168
174
|
|
|
169
175
|
// Data to iterate over in data mode
|
|
170
|
-
const resolvedData: any[] = $derived(
|
|
171
|
-
dataMode ? (dataProp ?? chartDataArray(chartCtx.data)) : []
|
|
172
|
-
);
|
|
176
|
+
const resolvedData: any[] = $derived(dataMode ? (dataProp ?? chartDataArray(chartCtx.data)) : []);
|
|
173
177
|
|
|
174
178
|
// Resolve a single data item to pixel coordinates
|
|
175
179
|
function resolveLine(d: any) {
|
|
@@ -233,29 +237,21 @@
|
|
|
233
237
|
const _initialX2 = initialX2 ?? (typeof x2 === 'number' ? x2 : 0);
|
|
234
238
|
const _initialY2 = initialY2 ?? (typeof y2 === 'number' ? y2 : 0);
|
|
235
239
|
|
|
236
|
-
const motionX1 = createMotion(
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
);
|
|
241
|
-
const motionY1 = createMotion(
|
|
242
|
-
_initialY1,
|
|
243
|
-
() => (typeof y1 === 'number' ? y1 : 0),
|
|
244
|
-
motion
|
|
245
|
-
);
|
|
246
|
-
const motionX2 = createMotion(
|
|
247
|
-
_initialX2,
|
|
248
|
-
() => (typeof x2 === 'number' ? x2 : 0),
|
|
249
|
-
motion
|
|
250
|
-
);
|
|
251
|
-
const motionY2 = createMotion(
|
|
252
|
-
_initialY2,
|
|
253
|
-
() => (typeof y2 === 'number' ? y2 : 0),
|
|
254
|
-
motion
|
|
255
|
-
);
|
|
240
|
+
const motionX1 = createMotion(_initialX1, () => (typeof x1 === 'number' ? x1 : 0), motion);
|
|
241
|
+
const motionY1 = createMotion(_initialY1, () => (typeof y1 === 'number' ? y1 : 0), motion);
|
|
242
|
+
const motionX2 = createMotion(_initialX2, () => (typeof x2 === 'number' ? x2 : 0), motion);
|
|
243
|
+
const motionY2 = createMotion(_initialY2, () => (typeof y2 === 'number' ? y2 : 0), motion);
|
|
256
244
|
|
|
257
245
|
const layerCtx = getLayerContext();
|
|
258
246
|
|
|
247
|
+
const staticFill = $derived(typeof fill === 'string' ? fill : undefined);
|
|
248
|
+
const staticStroke = $derived(typeof stroke === 'string' ? stroke : undefined);
|
|
249
|
+
const staticFillOpacity = $derived(typeof fillOpacity === 'number' ? fillOpacity : undefined);
|
|
250
|
+
const staticStrokeWidth = $derived(typeof strokeWidth === 'number' ? strokeWidth : undefined);
|
|
251
|
+
const staticOpacity = $derived(typeof opacity === 'number' ? opacity : undefined);
|
|
252
|
+
const staticClassName = $derived(typeof className === 'string' ? className : undefined);
|
|
253
|
+
const staticHeight = $derived(typeof strokeWidth === 'number' ? `${strokeWidth}px` : '1px');
|
|
254
|
+
|
|
259
255
|
function getStyleOptions(
|
|
260
256
|
styleOverrides: ComputedStylesOptions | undefined,
|
|
261
257
|
itemFill?: string | undefined,
|
|
@@ -266,16 +262,29 @@
|
|
|
266
262
|
itemClass?: string | undefined
|
|
267
263
|
) {
|
|
268
264
|
return styleOverrides
|
|
269
|
-
? merge(
|
|
265
|
+
? merge(
|
|
266
|
+
{
|
|
267
|
+
styles: {
|
|
268
|
+
strokeWidth:
|
|
269
|
+
itemStrokeWidth ?? (typeof strokeWidth === 'number' ? strokeWidth : undefined),
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
styleOverrides
|
|
273
|
+
)
|
|
270
274
|
: {
|
|
271
275
|
styles: {
|
|
272
276
|
fill: itemFill ?? fill,
|
|
273
|
-
fillOpacity:
|
|
277
|
+
fillOpacity:
|
|
278
|
+
itemFillOpacity ?? (typeof fillOpacity === 'number' ? fillOpacity : undefined),
|
|
274
279
|
stroke: itemStroke ?? stroke,
|
|
275
|
-
strokeWidth:
|
|
280
|
+
strokeWidth:
|
|
281
|
+
itemStrokeWidth ?? (typeof strokeWidth === 'number' ? strokeWidth : undefined),
|
|
276
282
|
opacity: itemOpacity ?? (typeof opacity === 'number' ? opacity : undefined),
|
|
277
283
|
},
|
|
278
|
-
classes: cls(
|
|
284
|
+
classes: cls(
|
|
285
|
+
'lc-line',
|
|
286
|
+
itemClass ?? (typeof className === 'string' ? className : undefined)
|
|
287
|
+
),
|
|
279
288
|
style: restProps.style as string | undefined,
|
|
280
289
|
};
|
|
281
290
|
}
|
|
@@ -292,7 +301,15 @@
|
|
|
292
301
|
const resolvedStrokeWidth = resolveStyleProp(strokeWidth, item.d);
|
|
293
302
|
const resolvedOpacity = resolveStyleProp(opacity, item.d);
|
|
294
303
|
const resolvedClass = resolveStyleProp(className, item.d);
|
|
295
|
-
const styleOpts = getStyleOptions(
|
|
304
|
+
const styleOpts = getStyleOptions(
|
|
305
|
+
styleOverrides,
|
|
306
|
+
resolvedFill,
|
|
307
|
+
resolvedStroke,
|
|
308
|
+
resolvedFillOpacity,
|
|
309
|
+
resolvedStrokeWidth,
|
|
310
|
+
resolvedOpacity,
|
|
311
|
+
resolvedClass
|
|
312
|
+
);
|
|
296
313
|
const pathData = `M ${item.x1},${item.y1} L ${item.x2},${item.y2}`;
|
|
297
314
|
renderPathData(ctx, pathData, styleOpts);
|
|
298
315
|
}
|
|
@@ -318,29 +335,32 @@
|
|
|
318
335
|
color: typeof stroke === 'string' ? stroke : typeof fill === 'string' ? fill : undefined,
|
|
319
336
|
};
|
|
320
337
|
},
|
|
321
|
-
canvasRender:
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
338
|
+
canvasRender:
|
|
339
|
+
layerCtx === 'canvas'
|
|
340
|
+
? {
|
|
341
|
+
render,
|
|
342
|
+
events: {
|
|
343
|
+
click: restProps.onclick,
|
|
344
|
+
pointerenter: restProps.onpointerenter,
|
|
345
|
+
pointermove: restProps.onpointermove,
|
|
346
|
+
pointerleave: restProps.onpointerleave,
|
|
347
|
+
},
|
|
348
|
+
deps: () => [
|
|
349
|
+
dataMode,
|
|
350
|
+
dataMode ? resolvedItems : null,
|
|
351
|
+
motionX1.current,
|
|
352
|
+
motionY1.current,
|
|
353
|
+
motionX2.current,
|
|
354
|
+
motionY2.current,
|
|
355
|
+
fillKey!.current,
|
|
356
|
+
strokeKey!.current,
|
|
357
|
+
strokeWidth,
|
|
358
|
+
opacity,
|
|
359
|
+
className,
|
|
360
|
+
restProps.style,
|
|
361
|
+
],
|
|
362
|
+
}
|
|
363
|
+
: undefined,
|
|
344
364
|
});
|
|
345
365
|
</script>
|
|
346
366
|
|
|
@@ -380,15 +400,15 @@
|
|
|
380
400
|
y1={motionY1.current}
|
|
381
401
|
x2={motionX2.current}
|
|
382
402
|
y2={motionY2.current}
|
|
383
|
-
fill={
|
|
384
|
-
stroke={
|
|
385
|
-
fill-opacity={
|
|
386
|
-
stroke-width={
|
|
387
|
-
opacity={
|
|
403
|
+
fill={staticFill}
|
|
404
|
+
stroke={staticStroke}
|
|
405
|
+
fill-opacity={staticFillOpacity}
|
|
406
|
+
stroke-width={staticStrokeWidth}
|
|
407
|
+
opacity={staticOpacity}
|
|
388
408
|
marker-start={markerStartId ? `url(#${markerStartId})` : undefined}
|
|
389
409
|
marker-mid={markerMidId ? `url(#${markerMidId})` : undefined}
|
|
390
410
|
marker-end={markerEndId ? `url(#${markerEndId})` : undefined}
|
|
391
|
-
class={cls('lc-line',
|
|
411
|
+
class={cls('lc-line', staticClassName)}
|
|
392
412
|
{...restProps}
|
|
393
413
|
/>
|
|
394
414
|
<MarkerWrapper id={markerStartId} marker={markerStart ?? marker} />
|
|
@@ -431,12 +451,12 @@
|
|
|
431
451
|
style:left="{motionX1.current}px"
|
|
432
452
|
style:top="{motionY1.current}px"
|
|
433
453
|
style:width="{length}px"
|
|
434
|
-
style:height=
|
|
454
|
+
style:height={staticHeight}
|
|
435
455
|
style:transform="translateY(-50%) rotate({angle}deg)"
|
|
436
456
|
style:transform-origin="0 50%"
|
|
437
|
-
style:opacity={
|
|
438
|
-
style:background-color={
|
|
439
|
-
class={cls('lc-line',
|
|
457
|
+
style:opacity={staticOpacity}
|
|
458
|
+
style:background-color={staticStroke}
|
|
459
|
+
class={cls('lc-line', staticClassName)}
|
|
440
460
|
style={restProps.style}
|
|
441
461
|
></div>
|
|
442
462
|
{/if}
|
|
@@ -137,8 +137,8 @@
|
|
|
137
137
|
const scaledX: number = ctx.xScale(xVal);
|
|
138
138
|
const scaledY: number = ctx.yScale(yVal);
|
|
139
139
|
|
|
140
|
-
const x = scaledX + getOffset(scaledX, offsetX, ctx.xScale, ctx.x1Scale);
|
|
141
|
-
const y = scaledY + getOffset(scaledY, offsetY, ctx.yScale, ctx.y1Scale);
|
|
140
|
+
const x = scaledX + getOffset(scaledX, offsetX, ctx.xScale, ctx.x1Scale ?? undefined);
|
|
141
|
+
const y = scaledY + getOffset(scaledY, offsetY, ctx.yScale, ctx.y1Scale ?? undefined);
|
|
142
142
|
|
|
143
143
|
const radialPoint = pointRadial(x, y);
|
|
144
144
|
|
|
@@ -168,7 +168,13 @@
|
|
|
168
168
|
type ResolvedMotion,
|
|
169
169
|
} from '../utils/motion.svelte.js';
|
|
170
170
|
import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
171
|
-
import {
|
|
171
|
+
import {
|
|
172
|
+
hasAnyDataProp,
|
|
173
|
+
resolveDataProp,
|
|
174
|
+
resolveColorProp,
|
|
175
|
+
resolveGeoDataPair,
|
|
176
|
+
resolveStyleProp,
|
|
177
|
+
} from '../utils/dataProp.js';
|
|
172
178
|
import { getGeoContext } from '../contexts/geo.js';
|
|
173
179
|
import { chartDataArray } from '../utils/common.js';
|
|
174
180
|
import { createKey } from '../utils/key.svelte.js';
|
|
@@ -219,9 +225,7 @@
|
|
|
219
225
|
const dataMode = $derived(hasAnyDataProp(cx, cy, r));
|
|
220
226
|
|
|
221
227
|
// Data to iterate over in data mode
|
|
222
|
-
const resolvedData: any[] = $derived(
|
|
223
|
-
dataMode ? (dataProp ?? chartDataArray(chartCtx.data)) : []
|
|
224
|
-
);
|
|
228
|
+
const resolvedData: any[] = $derived(dataMode ? (dataProp ?? chartDataArray(chartCtx.data)) : []);
|
|
225
229
|
|
|
226
230
|
// Resolve a single data item to a polygon path string
|
|
227
231
|
function resolvePolygon(d: any) {
|
|
@@ -234,22 +238,23 @@
|
|
|
234
238
|
}
|
|
235
239
|
const resolvedR = resolveDataProp(r, d, chartCtx.rScale, typeof r === 'number' ? r : 1);
|
|
236
240
|
|
|
237
|
-
const pts =
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
241
|
+
const pts =
|
|
242
|
+
typeof points === 'number'
|
|
243
|
+
? polygon({
|
|
244
|
+
cx: resolvedCx,
|
|
245
|
+
cy: resolvedCy,
|
|
246
|
+
count: points,
|
|
247
|
+
radius: resolvedR,
|
|
248
|
+
rotate,
|
|
249
|
+
inset,
|
|
250
|
+
scaleX,
|
|
251
|
+
scaleY,
|
|
252
|
+
skewX,
|
|
253
|
+
skewY,
|
|
254
|
+
tiltX,
|
|
255
|
+
tiltY,
|
|
256
|
+
})
|
|
257
|
+
: points;
|
|
253
258
|
|
|
254
259
|
return roundedPolygonPath(pts, cornerRadius);
|
|
255
260
|
}
|
|
@@ -350,6 +355,13 @@
|
|
|
350
355
|
|
|
351
356
|
const layerCtx = getLayerContext();
|
|
352
357
|
|
|
358
|
+
const staticFill = $derived(typeof fill === 'string' ? fill : undefined);
|
|
359
|
+
const staticFillOpacity = $derived(typeof fillOpacity === 'number' ? fillOpacity : undefined);
|
|
360
|
+
const staticStroke = $derived(typeof stroke === 'string' ? stroke : undefined);
|
|
361
|
+
const staticStrokeWidth = $derived(typeof strokeWidth === 'number' ? strokeWidth : undefined);
|
|
362
|
+
const staticOpacity = $derived(typeof opacity === 'number' ? opacity : undefined);
|
|
363
|
+
const staticClassName = $derived(typeof className === 'string' ? className : undefined);
|
|
364
|
+
|
|
353
365
|
function getStyleOptions(
|
|
354
366
|
styleOverrides: ComputedStylesOptions | undefined,
|
|
355
367
|
itemFill?: string | undefined,
|
|
@@ -360,16 +372,29 @@
|
|
|
360
372
|
itemClass?: string | undefined
|
|
361
373
|
) {
|
|
362
374
|
return styleOverrides
|
|
363
|
-
? merge(
|
|
375
|
+
? merge(
|
|
376
|
+
{
|
|
377
|
+
styles: {
|
|
378
|
+
strokeWidth:
|
|
379
|
+
itemStrokeWidth ?? (typeof strokeWidth === 'number' ? strokeWidth : undefined),
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
styleOverrides
|
|
383
|
+
)
|
|
364
384
|
: {
|
|
365
385
|
styles: {
|
|
366
386
|
fill: itemFill ?? fill,
|
|
367
|
-
fillOpacity:
|
|
387
|
+
fillOpacity:
|
|
388
|
+
itemFillOpacity ?? (typeof fillOpacity === 'number' ? fillOpacity : undefined),
|
|
368
389
|
stroke: itemStroke ?? stroke,
|
|
369
|
-
strokeWidth:
|
|
390
|
+
strokeWidth:
|
|
391
|
+
itemStrokeWidth ?? (typeof strokeWidth === 'number' ? strokeWidth : undefined),
|
|
370
392
|
opacity: itemOpacity ?? (typeof opacity === 'number' ? opacity : undefined),
|
|
371
393
|
},
|
|
372
|
-
classes: cls(
|
|
394
|
+
classes: cls(
|
|
395
|
+
'lc-polygon',
|
|
396
|
+
itemClass ?? (typeof className === 'string' ? className : undefined)
|
|
397
|
+
),
|
|
373
398
|
style: restProps.style as string | undefined,
|
|
374
399
|
};
|
|
375
400
|
}
|
|
@@ -387,7 +412,15 @@
|
|
|
387
412
|
const resolvedStrokeWidth = resolveStyleProp(strokeWidth, d);
|
|
388
413
|
const resolvedOpacity = resolveStyleProp(opacity, d);
|
|
389
414
|
const resolvedClass = resolveStyleProp(className, d);
|
|
390
|
-
const styleOpts = getStyleOptions(
|
|
415
|
+
const styleOpts = getStyleOptions(
|
|
416
|
+
styleOverrides,
|
|
417
|
+
resolvedFill,
|
|
418
|
+
resolvedStroke,
|
|
419
|
+
resolvedFillOpacity,
|
|
420
|
+
resolvedStrokeWidth,
|
|
421
|
+
resolvedOpacity,
|
|
422
|
+
resolvedClass
|
|
423
|
+
);
|
|
391
424
|
renderPathData(ctx, pathData, styleOpts);
|
|
392
425
|
}
|
|
393
426
|
} else {
|
|
@@ -412,31 +445,34 @@
|
|
|
412
445
|
color: typeof fill === 'string' ? fill : typeof stroke === 'string' ? stroke : undefined,
|
|
413
446
|
};
|
|
414
447
|
},
|
|
415
|
-
canvasRender:
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
448
|
+
canvasRender:
|
|
449
|
+
layerCtx === 'canvas'
|
|
450
|
+
? {
|
|
451
|
+
render,
|
|
452
|
+
events: {
|
|
453
|
+
click: restProps.onclick,
|
|
454
|
+
pointerenter: restProps.onpointerenter,
|
|
455
|
+
pointermove: restProps.onpointermove,
|
|
456
|
+
pointerleave: restProps.onpointerleave,
|
|
457
|
+
pointerdown: restProps.onpointerdown,
|
|
458
|
+
pointerover: restProps.onpointerover,
|
|
459
|
+
pointerout: restProps.onpointerout,
|
|
460
|
+
touchmove: restProps.ontouchmove,
|
|
461
|
+
},
|
|
462
|
+
deps: () => [
|
|
463
|
+
dataMode,
|
|
464
|
+
dataMode ? resolvedItems : null,
|
|
465
|
+
fillKey!.current,
|
|
466
|
+
fillOpacity,
|
|
467
|
+
strokeKey!.current,
|
|
468
|
+
strokeWidth,
|
|
469
|
+
opacity,
|
|
470
|
+
className,
|
|
471
|
+
tweenedState.current,
|
|
472
|
+
restProps.style,
|
|
473
|
+
],
|
|
474
|
+
}
|
|
475
|
+
: undefined,
|
|
440
476
|
});
|
|
441
477
|
</script>
|
|
442
478
|
|
|
@@ -464,12 +500,12 @@
|
|
|
464
500
|
{:else}
|
|
465
501
|
<path
|
|
466
502
|
d={tweenedState.current}
|
|
467
|
-
fill={
|
|
468
|
-
fill-opacity={
|
|
469
|
-
stroke={
|
|
470
|
-
stroke-width={
|
|
471
|
-
opacity={
|
|
472
|
-
class={cls('lc-polygon',
|
|
503
|
+
fill={staticFill}
|
|
504
|
+
fill-opacity={staticFillOpacity}
|
|
505
|
+
stroke={staticStroke}
|
|
506
|
+
stroke-width={staticStrokeWidth}
|
|
507
|
+
opacity={staticOpacity}
|
|
508
|
+
class={cls('lc-polygon', staticClassName)}
|
|
473
509
|
{...restProps}
|
|
474
510
|
bind:this={ref}
|
|
475
511
|
/>
|