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
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { Placement } from './types.js';
|
|
2
|
+
import { type Without } from '../utils/types.js';
|
|
3
|
+
export type CircleLegendPropsWithoutHTML = {
|
|
4
|
+
/**
|
|
5
|
+
* The scale to use for the legend. Defaults to the chart's `rScale`.
|
|
6
|
+
*/
|
|
7
|
+
scale?: AnyScale;
|
|
8
|
+
/**
|
|
9
|
+
* The title of the legend.
|
|
10
|
+
*
|
|
11
|
+
* @default ''
|
|
12
|
+
*/
|
|
13
|
+
title?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The number of ticks to show.
|
|
16
|
+
*
|
|
17
|
+
* @default 4
|
|
18
|
+
*/
|
|
19
|
+
ticks?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Explicit tick values to show. Overrides `ticks`.
|
|
22
|
+
*/
|
|
23
|
+
tickValues?: number[];
|
|
24
|
+
/**
|
|
25
|
+
* Format for the tick labels.
|
|
26
|
+
*/
|
|
27
|
+
tickFormat?: FormatType | FormatConfig;
|
|
28
|
+
/**
|
|
29
|
+
* The font size of the tick labels.
|
|
30
|
+
*
|
|
31
|
+
* @default 10
|
|
32
|
+
*/
|
|
33
|
+
tickFontSize?: number;
|
|
34
|
+
/**
|
|
35
|
+
* The font size of the title.
|
|
36
|
+
*
|
|
37
|
+
* @default 10
|
|
38
|
+
*/
|
|
39
|
+
titleFontSize?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Width reserved for the tick labels next to the circles.
|
|
42
|
+
*
|
|
43
|
+
* @default 40
|
|
44
|
+
*/
|
|
45
|
+
labelWidth?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Gap between the top of each circle and the leader line/label.
|
|
48
|
+
*
|
|
49
|
+
* @default 4
|
|
50
|
+
*/
|
|
51
|
+
labelGap?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Where to render the tick labels.
|
|
54
|
+
* - `'right'` / `'left'`: outside the circles with a leader line
|
|
55
|
+
* - `'inline'`: centered inside each circle, near the top
|
|
56
|
+
*
|
|
57
|
+
* @default 'right'
|
|
58
|
+
*/
|
|
59
|
+
labelPlacement?: 'left' | 'right' | 'inline';
|
|
60
|
+
/**
|
|
61
|
+
* The placement of the legend.
|
|
62
|
+
*/
|
|
63
|
+
placement?: Placement;
|
|
64
|
+
/**
|
|
65
|
+
* The fill color of the circles.
|
|
66
|
+
*
|
|
67
|
+
* @default 'none'
|
|
68
|
+
*/
|
|
69
|
+
fill?: string;
|
|
70
|
+
/**
|
|
71
|
+
* The stroke color of the circles and leader lines.
|
|
72
|
+
*
|
|
73
|
+
* @default 'currentColor'
|
|
74
|
+
*/
|
|
75
|
+
stroke?: string;
|
|
76
|
+
/**
|
|
77
|
+
* The stroke width of the circles.
|
|
78
|
+
*
|
|
79
|
+
* @default 1
|
|
80
|
+
*/
|
|
81
|
+
strokeWidth?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Value to indicate on the legend (e.g. the currently hovered data point).
|
|
84
|
+
* When set, a 50%-opacity filled circle is drawn at this value's radius.
|
|
85
|
+
* Defaults to auto-detecting from `ctx.tooltip.data` via the chart's
|
|
86
|
+
* radius accessor (`ctx.r`).
|
|
87
|
+
*/
|
|
88
|
+
value?: number | null;
|
|
89
|
+
/**
|
|
90
|
+
* Classes to apply to the elements.
|
|
91
|
+
*
|
|
92
|
+
* @default {}
|
|
93
|
+
*/
|
|
94
|
+
classes?: {
|
|
95
|
+
root?: string;
|
|
96
|
+
title?: string;
|
|
97
|
+
circle?: string;
|
|
98
|
+
tick?: string;
|
|
99
|
+
label?: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* A bindable reference to the wrapping `<div>` element.
|
|
103
|
+
*
|
|
104
|
+
* @bindable
|
|
105
|
+
*/
|
|
106
|
+
ref?: HTMLElement;
|
|
107
|
+
};
|
|
108
|
+
export type CircleLegendProps = CircleLegendPropsWithoutHTML & Without<HTMLAttributes<HTMLElement>, CircleLegendPropsWithoutHTML>;
|
|
109
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
110
|
+
import { type FormatType, type FormatConfig } from '@layerstack/utils';
|
|
111
|
+
import type { AnyScale } from '../utils/scales.svelte.js';
|
|
112
|
+
declare const CircleLegend: import("svelte").Component<CircleLegendProps, {}, "ref">;
|
|
113
|
+
type CircleLegend = ReturnType<typeof CircleLegend>;
|
|
114
|
+
export default CircleLegend;
|
|
@@ -108,7 +108,13 @@
|
|
|
108
108
|
import { getChartContext } from '../contexts/chart.js';
|
|
109
109
|
import { createMotion, createDataMotionMap, type MotionProp } from '../utils/motion.svelte.js';
|
|
110
110
|
import { renderEllipse, type ComputedStylesOptions } from '../utils/canvas.js';
|
|
111
|
-
import {
|
|
111
|
+
import {
|
|
112
|
+
hasAnyDataProp,
|
|
113
|
+
resolveDataProp,
|
|
114
|
+
resolveColorProp,
|
|
115
|
+
resolveGeoDataPair,
|
|
116
|
+
resolveStyleProp,
|
|
117
|
+
} from '../utils/dataProp.js';
|
|
112
118
|
import { getGeoContext } from '../contexts/geo.js';
|
|
113
119
|
import { chartDataArray } from '../utils/common.js';
|
|
114
120
|
import type { SVGAttributes } from 'svelte/elements';
|
|
@@ -144,9 +150,7 @@
|
|
|
144
150
|
const geo = getGeoContext();
|
|
145
151
|
|
|
146
152
|
// Data to iterate over in data mode
|
|
147
|
-
const resolvedData: any[] = $derived(
|
|
148
|
-
dataMode ? (dataProp ?? chartDataArray(chartCtx.data)) : []
|
|
149
|
-
);
|
|
153
|
+
const resolvedData: any[] = $derived(dataMode ? (dataProp ?? chartDataArray(chartCtx.data)) : []);
|
|
150
154
|
|
|
151
155
|
// Resolve a single data item to pixel coordinates
|
|
152
156
|
function resolveEllipse(d: any) {
|
|
@@ -217,26 +221,10 @@
|
|
|
217
221
|
|
|
218
222
|
const layerCtx = getLayerContext();
|
|
219
223
|
|
|
220
|
-
const motionCx = createMotion(
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
);
|
|
225
|
-
const motionCy = createMotion(
|
|
226
|
-
initialCy,
|
|
227
|
-
() => (typeof cy === 'number' ? cy : 0),
|
|
228
|
-
motion
|
|
229
|
-
);
|
|
230
|
-
const motionRx = createMotion(
|
|
231
|
-
initialRx,
|
|
232
|
-
() => (typeof rx === 'number' ? rx : 1),
|
|
233
|
-
motion
|
|
234
|
-
);
|
|
235
|
-
const motionRy = createMotion(
|
|
236
|
-
initialRy,
|
|
237
|
-
() => (typeof ry === 'number' ? ry : 1),
|
|
238
|
-
motion
|
|
239
|
-
);
|
|
224
|
+
const motionCx = createMotion(initialCx, () => (typeof cx === 'number' ? cx : 0), motion);
|
|
225
|
+
const motionCy = createMotion(initialCy, () => (typeof cy === 'number' ? cy : 0), motion);
|
|
226
|
+
const motionRx = createMotion(initialRx, () => (typeof rx === 'number' ? rx : 1), motion);
|
|
227
|
+
const motionRy = createMotion(initialRy, () => (typeof ry === 'number' ? ry : 1), motion);
|
|
240
228
|
|
|
241
229
|
function getStyleOptions(
|
|
242
230
|
styleOverrides: ComputedStylesOptions | undefined,
|
|
@@ -248,16 +236,29 @@
|
|
|
248
236
|
itemClass?: string | undefined
|
|
249
237
|
) {
|
|
250
238
|
return styleOverrides
|
|
251
|
-
? merge(
|
|
239
|
+
? merge(
|
|
240
|
+
{
|
|
241
|
+
styles: {
|
|
242
|
+
strokeWidth:
|
|
243
|
+
itemStrokeWidth ?? (typeof strokeWidth === 'number' ? strokeWidth : undefined),
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
styleOverrides
|
|
247
|
+
)
|
|
252
248
|
: {
|
|
253
249
|
styles: {
|
|
254
250
|
fill: itemFill ?? fill,
|
|
255
|
-
fillOpacity:
|
|
251
|
+
fillOpacity:
|
|
252
|
+
itemFillOpacity ?? (typeof fillOpacity === 'number' ? fillOpacity : undefined),
|
|
256
253
|
stroke: itemStroke ?? stroke,
|
|
257
|
-
strokeWidth:
|
|
254
|
+
strokeWidth:
|
|
255
|
+
itemStrokeWidth ?? (typeof strokeWidth === 'number' ? strokeWidth : undefined),
|
|
258
256
|
opacity: itemOpacity ?? (typeof opacity === 'number' ? opacity : undefined),
|
|
259
257
|
},
|
|
260
|
-
classes: cls(
|
|
258
|
+
classes: cls(
|
|
259
|
+
'lc-ellipse',
|
|
260
|
+
itemClass ?? (typeof className === 'string' ? className : undefined)
|
|
261
|
+
),
|
|
261
262
|
};
|
|
262
263
|
}
|
|
263
264
|
|
|
@@ -273,7 +274,15 @@
|
|
|
273
274
|
const resolvedStrokeWidth = resolveStyleProp(strokeWidth, item.d);
|
|
274
275
|
const resolvedOpacity = resolveStyleProp(opacity, item.d);
|
|
275
276
|
const resolvedClass = resolveStyleProp(className, item.d);
|
|
276
|
-
const styleOpts = getStyleOptions(
|
|
277
|
+
const styleOpts = getStyleOptions(
|
|
278
|
+
styleOverrides,
|
|
279
|
+
resolvedFill,
|
|
280
|
+
resolvedStroke,
|
|
281
|
+
resolvedFillOpacity,
|
|
282
|
+
resolvedStrokeWidth,
|
|
283
|
+
resolvedOpacity,
|
|
284
|
+
resolvedClass
|
|
285
|
+
);
|
|
277
286
|
renderEllipse(ctx, item, styleOpts);
|
|
278
287
|
}
|
|
279
288
|
} else {
|
|
@@ -295,6 +304,13 @@
|
|
|
295
304
|
const fillKey = layerCtx === 'canvas' ? createKey(() => fill) : undefined;
|
|
296
305
|
const strokeKey = layerCtx === 'canvas' ? createKey(() => stroke) : undefined;
|
|
297
306
|
|
|
307
|
+
const staticFill = $derived(typeof fill === 'string' ? fill : undefined);
|
|
308
|
+
const staticFillOpacity = $derived(typeof fillOpacity === 'number' ? fillOpacity : undefined);
|
|
309
|
+
const staticStroke = $derived(typeof stroke === 'string' ? stroke : undefined);
|
|
310
|
+
const staticStrokeWidth = $derived(typeof strokeWidth === 'number' ? strokeWidth : undefined);
|
|
311
|
+
const staticOpacity = $derived(typeof opacity === 'number' ? opacity : undefined);
|
|
312
|
+
const staticClassName = $derived(typeof className === 'string' ? className : undefined);
|
|
313
|
+
|
|
298
314
|
chartCtx.registerComponent({
|
|
299
315
|
name: 'Ellipse',
|
|
300
316
|
kind: 'mark',
|
|
@@ -307,30 +323,33 @@
|
|
|
307
323
|
color: typeof fill === 'string' ? fill : typeof stroke === 'string' ? stroke : undefined,
|
|
308
324
|
};
|
|
309
325
|
},
|
|
310
|
-
canvasRender:
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
326
|
+
canvasRender:
|
|
327
|
+
layerCtx === 'canvas'
|
|
328
|
+
? {
|
|
329
|
+
render,
|
|
330
|
+
events: {
|
|
331
|
+
click: restProps.onclick,
|
|
332
|
+
pointerdown: restProps.onpointerdown,
|
|
333
|
+
pointerenter: restProps.onpointerenter,
|
|
334
|
+
pointermove: restProps.onpointermove,
|
|
335
|
+
pointerleave: restProps.onpointerleave,
|
|
336
|
+
},
|
|
337
|
+
deps: () => [
|
|
338
|
+
dataMode,
|
|
339
|
+
dataMode ? resolvedItems : null,
|
|
340
|
+
motionCx.current,
|
|
341
|
+
motionCy.current,
|
|
342
|
+
motionRx.current,
|
|
343
|
+
motionRy.current,
|
|
344
|
+
fillKey!.current,
|
|
345
|
+
fillOpacity,
|
|
346
|
+
strokeKey!.current,
|
|
347
|
+
strokeWidth,
|
|
348
|
+
opacity,
|
|
349
|
+
className,
|
|
350
|
+
],
|
|
351
|
+
}
|
|
352
|
+
: undefined,
|
|
334
353
|
});
|
|
335
354
|
</script>
|
|
336
355
|
|
|
@@ -364,12 +383,12 @@
|
|
|
364
383
|
cy={motionCy.current}
|
|
365
384
|
rx={motionRx.current}
|
|
366
385
|
ry={motionRy.current}
|
|
367
|
-
fill={
|
|
368
|
-
fill-opacity={
|
|
369
|
-
stroke={
|
|
370
|
-
stroke-width={
|
|
371
|
-
opacity={
|
|
372
|
-
class={cls('lc-ellipse',
|
|
386
|
+
fill={staticFill}
|
|
387
|
+
fill-opacity={staticFillOpacity}
|
|
388
|
+
stroke={staticStroke}
|
|
389
|
+
stroke-width={staticStrokeWidth}
|
|
390
|
+
opacity={staticOpacity}
|
|
391
|
+
class={cls('lc-ellipse', staticClassName)}
|
|
373
392
|
{...restProps}
|
|
374
393
|
/>
|
|
375
394
|
{/if}
|
|
@@ -407,13 +426,13 @@
|
|
|
407
426
|
style:width="{motionRx.current * 2}px"
|
|
408
427
|
style:height="{motionRy.current * 2}px"
|
|
409
428
|
style:border-radius="50%"
|
|
410
|
-
style:background-color={
|
|
411
|
-
style:opacity={
|
|
412
|
-
style:border-width={
|
|
413
|
-
style:border-color={
|
|
429
|
+
style:background-color={staticFill}
|
|
430
|
+
style:opacity={staticOpacity}
|
|
431
|
+
style:border-width={staticStrokeWidth}
|
|
432
|
+
style:border-color={staticStroke}
|
|
414
433
|
style:border-style="solid"
|
|
415
434
|
style:transform="translate(-50%, -50%)"
|
|
416
|
-
class={cls('lc-ellipse',
|
|
435
|
+
class={cls('lc-ellipse', staticClassName)}
|
|
417
436
|
{...restProps}
|
|
418
437
|
></div>
|
|
419
438
|
{/if}
|