layerchart 2.0.0-next.4 → 2.0.0-next.40

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.
Files changed (179) hide show
  1. package/dist/components/AnnotationLine.svelte +15 -2
  2. package/dist/components/AnnotationPoint.svelte +29 -11
  3. package/dist/components/AnnotationRange.svelte +18 -4
  4. package/dist/components/Arc.svelte +5 -5
  5. package/dist/components/Area.svelte +10 -2
  6. package/dist/components/Axis.svelte +175 -58
  7. package/dist/components/Axis.svelte.d.ts +23 -6
  8. package/dist/components/Bar.svelte +20 -15
  9. package/dist/components/Bar.svelte.d.ts +2 -2
  10. package/dist/components/Bars.svelte +4 -4
  11. package/dist/components/Blur.svelte +7 -6
  12. package/dist/components/Blur.svelte.d.ts +2 -5
  13. package/dist/components/BrushContext.svelte +45 -45
  14. package/dist/components/Calendar.svelte +31 -10
  15. package/dist/components/Calendar.svelte.d.ts +2 -1
  16. package/dist/components/Chart.svelte +76 -27
  17. package/dist/components/Chart.svelte.d.ts +26 -8
  18. package/dist/components/ChartClipPath.svelte +1 -1
  19. package/dist/components/Circle.svelte +44 -3
  20. package/dist/components/CircleClipPath.svelte +8 -1
  21. package/dist/components/ClipPath.svelte +1 -2
  22. package/dist/components/ColorRamp.svelte +1 -1
  23. package/dist/components/ComputedStyles.svelte +9 -2
  24. package/dist/components/Connector.svelte +3 -3
  25. package/dist/components/Connector.svelte.d.ts +1 -1
  26. package/dist/components/Ellipse.svelte +228 -0
  27. package/dist/components/Ellipse.svelte.d.ts +64 -0
  28. package/dist/components/ForceSimulation.svelte +184 -50
  29. package/dist/components/ForceSimulation.svelte.d.ts +95 -21
  30. package/dist/components/Frame.svelte +1 -1
  31. package/dist/components/GeoCircle.svelte +1 -1
  32. package/dist/components/GeoEdgeFade.svelte +1 -1
  33. package/dist/components/GeoPath.svelte +30 -8
  34. package/dist/components/GeoPoint.svelte +4 -5
  35. package/dist/components/GeoSpline.svelte +5 -5
  36. package/dist/components/GeoSpline.svelte.d.ts +1 -1
  37. package/dist/components/GeoTile.svelte +1 -1
  38. package/dist/components/Graticule.svelte +5 -5
  39. package/dist/components/Grid.svelte +60 -63
  40. package/dist/components/Group.svelte +13 -8
  41. package/dist/components/Group.svelte.d.ts +10 -3
  42. package/dist/components/Highlight.svelte +55 -28
  43. package/dist/components/Highlight.svelte.d.ts +4 -0
  44. package/dist/components/Hull.svelte +12 -5
  45. package/dist/components/Labels.svelte +24 -13
  46. package/dist/components/Labels.svelte.d.ts +12 -5
  47. package/dist/components/Legend.svelte +143 -70
  48. package/dist/components/Legend.svelte.d.ts +12 -8
  49. package/dist/components/Line.svelte +40 -3
  50. package/dist/components/LinearGradient.svelte +35 -4
  51. package/dist/components/Link.svelte +1 -1
  52. package/dist/components/Marker.svelte +37 -26
  53. package/dist/components/MonthPath.svelte +26 -12
  54. package/dist/components/MonthPath.svelte.d.ts +4 -3
  55. package/dist/components/MotionPath.svelte +1 -1
  56. package/dist/components/Pack.svelte.d.ts +10 -3
  57. package/dist/components/Partition.svelte.d.ts +10 -3
  58. package/dist/components/Pattern.svelte +5 -5
  59. package/dist/components/Pie.svelte +1 -2
  60. package/dist/components/Points.svelte +11 -72
  61. package/dist/components/Points.svelte.d.ts +1 -8
  62. package/dist/components/Polygon.svelte +309 -0
  63. package/dist/components/Polygon.svelte.d.ts +115 -0
  64. package/dist/components/RadialGradient.svelte +4 -6
  65. package/dist/components/Rect.svelte +55 -5
  66. package/dist/components/Rect.svelte.d.ts +2 -2
  67. package/dist/components/RectClipPath.svelte +4 -3
  68. package/dist/components/RectClipPath.svelte.d.ts +2 -2
  69. package/dist/components/Rule.svelte +167 -77
  70. package/dist/components/Rule.svelte.d.ts +7 -2
  71. package/dist/components/Spline.svelte +59 -28
  72. package/dist/components/Spline.svelte.d.ts +12 -4
  73. package/dist/components/Text.svelte +121 -73
  74. package/dist/components/Text.svelte.d.ts +6 -0
  75. package/dist/components/TileImage.svelte +19 -4
  76. package/dist/components/TransformContext.svelte +9 -3
  77. package/dist/components/TransformControls.svelte +89 -38
  78. package/dist/components/Tree.svelte.d.ts +10 -3
  79. package/dist/components/Treemap.svelte +63 -26
  80. package/dist/components/Treemap.svelte.d.ts +21 -14
  81. package/dist/components/Voronoi.svelte +12 -13
  82. package/dist/components/charts/ArcChart.svelte +43 -71
  83. package/dist/components/charts/ArcChart.svelte.d.ts +10 -3
  84. package/dist/components/charts/AreaChart.svelte +29 -59
  85. package/dist/components/charts/AreaChart.svelte.d.ts +10 -3
  86. package/dist/components/charts/BarChart.svelte +79 -71
  87. package/dist/components/charts/BarChart.svelte.d.ts +10 -3
  88. package/dist/components/charts/DefaultTooltip.svelte +3 -3
  89. package/dist/components/charts/DefaultTooltip.svelte.d.ts +1 -1
  90. package/dist/components/charts/LineChart.svelte +69 -75
  91. package/dist/components/charts/LineChart.svelte.d.ts +21 -8
  92. package/dist/components/charts/PieChart.svelte +44 -71
  93. package/dist/components/charts/PieChart.svelte.d.ts +10 -3
  94. package/dist/components/charts/ScatterChart.svelte +10 -39
  95. package/dist/components/charts/ScatterChart.svelte.d.ts +10 -3
  96. package/dist/components/charts/utils.svelte.d.ts +1 -19
  97. package/dist/components/charts/utils.svelte.js +7 -35
  98. package/dist/components/index.d.ts +4 -0
  99. package/dist/components/index.js +5 -1
  100. package/dist/components/layout/Canvas.svelte +96 -69
  101. package/dist/components/layout/Canvas.svelte.d.ts +6 -0
  102. package/dist/components/layout/Html.svelte +15 -9
  103. package/dist/components/layout/Layer.svelte +6 -4
  104. package/dist/components/layout/Layer.svelte.d.ts +6 -4
  105. package/dist/components/layout/Svg.svelte +19 -11
  106. package/dist/components/layout/WebGL.svelte +26 -6
  107. package/dist/components/layout/WebGL.svelte.d.ts +5 -2
  108. package/dist/components/tooltip/Tooltip.svelte +65 -27
  109. package/dist/components/tooltip/Tooltip.svelte.d.ts +10 -3
  110. package/dist/components/tooltip/TooltipContext.svelte +167 -54
  111. package/dist/components/tooltip/TooltipContext.svelte.d.ts +19 -5
  112. package/dist/components/tooltip/TooltipHeader.svelte +32 -18
  113. package/dist/components/tooltip/TooltipHeader.svelte.d.ts +3 -3
  114. package/dist/components/tooltip/TooltipItem.svelte +46 -37
  115. package/dist/components/tooltip/TooltipItem.svelte.d.ts +3 -3
  116. package/dist/components/tooltip/TooltipList.svelte +12 -10
  117. package/dist/components/tooltip/TooltipSeparator.svelte +18 -10
  118. package/dist/components/tooltip/tooltipMetaContext.d.ts +2 -2
  119. package/dist/docs/Blockquote.svelte +6 -4
  120. package/dist/docs/Blockquote.svelte.d.ts +4 -19
  121. package/dist/docs/Code.svelte +70 -28
  122. package/dist/docs/Code.svelte.d.ts +9 -24
  123. package/dist/docs/Header1.svelte +4 -2
  124. package/dist/docs/Header1.svelte.d.ts +4 -28
  125. package/dist/docs/Json.svelte +11 -3
  126. package/dist/docs/Json.svelte.d.ts +9 -21
  127. package/dist/docs/Layout.svelte +10 -7
  128. package/dist/docs/Layout.svelte.d.ts +4 -19
  129. package/dist/docs/Link.svelte +7 -3
  130. package/dist/docs/Link.svelte.d.ts +4 -38
  131. package/dist/docs/Preview.svelte +22 -23
  132. package/dist/docs/Preview.svelte.d.ts +5 -6
  133. package/dist/docs/TilesetField.svelte +20 -19
  134. package/dist/docs/TilesetField.svelte.d.ts +5 -22
  135. package/dist/docs/ViewSourceButton.svelte +10 -7
  136. package/dist/docs/ViewSourceButton.svelte.d.ts +7 -21
  137. package/dist/states/series.svelte.d.ts +30 -0
  138. package/dist/states/series.svelte.js +54 -0
  139. package/dist/styles/daisyui-5.css +6 -0
  140. package/dist/styles/shadcn-svelte.css +11 -0
  141. package/dist/styles/skeleton-3.css +15 -0
  142. package/dist/utils/arcText.svelte.js +4 -4
  143. package/dist/utils/array.d.ts +11 -0
  144. package/dist/utils/array.js +23 -0
  145. package/dist/utils/array.test.d.ts +1 -0
  146. package/dist/utils/array.test.js +200 -0
  147. package/dist/utils/attributes.d.ts +3 -13
  148. package/dist/utils/attributes.js +4 -18
  149. package/dist/utils/canvas.d.ts +77 -0
  150. package/dist/utils/canvas.js +105 -41
  151. package/dist/utils/common.d.ts +9 -0
  152. package/dist/utils/common.js +18 -1
  153. package/dist/utils/common.test.js +26 -1
  154. package/dist/utils/genData.d.ts +22 -8
  155. package/dist/utils/genData.js +34 -14
  156. package/dist/utils/graph/dagre.d.ts +4 -4
  157. package/dist/utils/graph/dagre.js +5 -7
  158. package/dist/utils/index.d.ts +1 -0
  159. package/dist/utils/index.js +1 -0
  160. package/dist/utils/math.d.ts +17 -0
  161. package/dist/utils/math.js +17 -0
  162. package/dist/utils/path.d.ts +10 -0
  163. package/dist/utils/path.js +30 -0
  164. package/dist/utils/rect.svelte.d.ts +2 -2
  165. package/dist/utils/rect.svelte.js +73 -1
  166. package/dist/utils/scales.svelte.d.ts +9 -3
  167. package/dist/utils/scales.svelte.js +47 -4
  168. package/dist/utils/shape.d.ts +43 -0
  169. package/dist/utils/shape.js +59 -0
  170. package/dist/utils/stack.js +1 -1
  171. package/dist/utils/string.d.ts +49 -0
  172. package/dist/utils/string.js +4 -2
  173. package/dist/utils/ticks.d.ts +15 -4
  174. package/dist/utils/ticks.js +140 -159
  175. package/dist/utils/ticks.test.js +16 -26
  176. package/dist/utils/treemap.d.ts +1 -1
  177. package/dist/utils/types.d.ts +15 -2
  178. package/package.json +35 -35
  179. package/dist/utils/object.js +0 -2
@@ -1,34 +1,32 @@
1
1
  <script lang="ts">
2
2
  import { slide } from 'svelte/transition';
3
- // TODO: No longer copy from svelte-ux after prismjs is migrated to ESM (commonjs causes issue with Vite from another library)
4
- import Prism from 'prismjs';
5
- import 'prism-svelte';
6
- import { mdiCodeTags, mdiTable } from '@mdi/js';
3
+ import LucideCode from '~icons/lucide/code';
4
+ import LucideTable from '~icons/lucide/table';
7
5
 
8
6
  import { Button, CopyButton, Dialog, Toggle, Tooltip } from 'svelte-ux';
9
7
  import { cls } from '@layerstack/tailwind';
10
8
 
11
9
  import Code from './Code.svelte';
12
10
  import Json from './Json.svelte';
11
+ import type { HTMLAttributes } from 'svelte/elements';
13
12
  import type { Snippet } from 'svelte';
14
13
 
15
- let {
16
- code,
17
- data,
18
- language = 'svelte',
19
- highlightedCode = code ? Prism.highlight(code, Prism.languages.svelte, language) : '',
20
- showCode = false,
21
- class: className,
22
- children,
23
- }: {
14
+ interface Props {
15
+ children: Snippet;
24
16
  code?: string;
25
17
  data?: any;
26
18
  language?: string;
27
- highlightedCode?: string;
28
19
  showCode?: boolean;
29
- class?: string | null;
30
- children: Snippet;
31
- } = $props();
20
+ }
21
+
22
+ let {
23
+ children,
24
+ code = undefined,
25
+ data = undefined,
26
+ language = 'svelte',
27
+ showCode = false,
28
+ class: className,
29
+ }: Props & HTMLAttributes<HTMLDivElement> = $props();
32
30
 
33
31
  /**
34
32
  * Custom JSON replacer (to use with JSON.stringify()) to convert `Date` instances to `new Date()`
@@ -54,21 +52,21 @@
54
52
  }
55
53
  </script>
56
54
 
57
- <div class={cls('Preview border rounded-sm bg-surface-100', className)}>
55
+ <div class={cls('Preview border rounded bg-surface-100', className)}>
58
56
  <div class="p-4">
59
- {@render children?.()}
57
+ {@render children()}
60
58
  </div>
61
59
 
62
60
  {#if code && showCode}
63
- <div transition:slide class="bg-surface-200">
64
- <Code source={code} highlightedSource={highlightedCode} classes={{ pre: 'rounded-t-none' }} />
61
+ <div transition:slide class="border-t">
62
+ <Code source={code} {language} />
65
63
  </div>
66
64
  {/if}
67
65
  </div>
68
66
 
69
67
  {#if code}
70
68
  <Button
71
- icon={mdiCodeTags}
69
+ icon={LucideCode}
72
70
  class="text-surface-content/70 py-1"
73
71
  on:click={() => (showCode = !showCode)}
74
72
  >
@@ -78,7 +76,8 @@
78
76
 
79
77
  {#if data}
80
78
  <Toggle let:on={open} let:toggle let:toggleOff>
81
- <Button icon={mdiTable} class="text-surface-content/70 py-1" on:click={toggle}>View data</Button
79
+ <Button icon={LucideTable} class="text-surface-content/70 py-1" on:click={toggle}
80
+ >View data</Button
82
81
  >
83
82
  <Dialog
84
83
  {open}
@@ -1,14 +1,13 @@
1
- import 'prism-svelte';
1
+ import type { HTMLAttributes } from 'svelte/elements';
2
2
  import type { Snippet } from 'svelte';
3
- type $$ComponentProps = {
3
+ interface Props {
4
+ children: Snippet;
4
5
  code?: string;
5
6
  data?: any;
6
7
  language?: string;
7
- highlightedCode?: string;
8
8
  showCode?: boolean;
9
- class?: string | null;
10
- children: Snippet;
11
- };
9
+ }
10
+ type $$ComponentProps = Props & HTMLAttributes<HTMLDivElement>;
12
11
  declare const Preview: import("svelte").Component<$$ComponentProps, {}, "">;
13
12
  type Preview = ReturnType<typeof Preview>;
14
13
  export default Preview;
@@ -1,26 +1,26 @@
1
1
  <script lang="ts">
2
2
  import { SelectField, Switch } from 'svelte-ux';
3
3
 
4
- export let doubleScale = devicePixelRatio > 1;
4
+ let { doubleScale = $bindable(devicePixelRatio > 1), serviceUrl = $bindable() } = $props();
5
5
 
6
6
  // TODO: Access via context, or possibly global state
7
7
  const ACCESS_TOKEN =
8
8
  'pk.eyJ1IjoidGVjaG5pcTM1IiwiYSI6ImNsZTR5cDd0ZjAyNm8zdnFvczhzdnFpcXkifQ.-LAr8sl5BZ3y-H0pDyD1qA';
9
9
 
10
10
  // https://docs.mapbox.com/api/maps/styles/
11
- $: mapboxv1 = (style: string) => (x: number, y: number, z: number) => {
11
+ const mapboxv1 = $derived((style: string) => (x: number, y: number, z: number) => {
12
12
  return `https://api.mapbox.com/styles/v1/mapbox/${style}/tiles/${z}/${x}/${y}${
13
13
  doubleScale ? '@2x' : ''
14
14
  }?access_token=${ACCESS_TOKEN}`;
15
- };
15
+ });
16
16
 
17
17
  // https://docs.mapbox.com/api/maps/raster-tiles/
18
18
  // https://docs.mapbox.com/data/tilesets/reference/mapbox-streets-v8/
19
- $: mapboxv4 = (tileset: string) => (x: number, y: number, z: number) => {
19
+ const mapboxv4 = $derived((tileset: string) => (x: number, y: number, z: number) => {
20
20
  return `https://${'abc'[Math.abs(x + y) % 3]}.tiles.mapbox.com/v4/${tileset}/${z}/${x}/${y}${
21
21
  doubleScale ? '@2x' : ''
22
22
  }.png?access_token=${ACCESS_TOKEN}`;
23
- };
23
+ });
24
24
 
25
25
  // https://apps.nationalmap.gov/services/
26
26
  const nationalmap = (tileset: string) => (x: number, y: number, z: number) => {
@@ -54,7 +54,7 @@
54
54
  return `https://${s}.tile.opentopomap.org/${z}/${x}/${y}.png`;
55
55
  };
56
56
 
57
- $: services = {
57
+ const services = $derived<Record<string, Record<string, Function>>>({
58
58
  'mapbox v1': {
59
59
  'streets-v11': mapboxv1('streets-v11'),
60
60
  'light-v10': mapboxv1('light-v10'),
@@ -100,24 +100,25 @@
100
100
  // 'ArcGIS Vector': {
101
101
  // 'Community Map', url: arcgisVector('World_Basemap_v2'),
102
102
  // }
103
- } as Record<string, Record<string, Function>>;
104
-
105
- $: serviceOptions = Object.entries(services).flatMap(([group, service]) => {
106
- return Object.entries(service).map(([label, value]) => {
107
- return { label, value: `${group}:${label}`, group, serviceUrl: value };
108
- });
109
103
  });
110
104
 
111
- $: defaultServiceUrl = services['mapbox v1']['streets-v11'];
112
- export let serviceUrl = defaultServiceUrl;
105
+ const serviceOptions = $derived(
106
+ Object.entries(services).flatMap(([group, service]) => {
107
+ return Object.entries(service).map(([label, value]) => {
108
+ return { label, value: `${group}:${label}`, group, serviceUrl: value };
109
+ });
110
+ })
111
+ );
113
112
 
114
- $: getServiceUrl = (option: string) => {
113
+ const getServiceUrl = $derived((option: string) => {
115
114
  const [selectedService, selectedTileset] = selected.split(':');
116
115
  return services[selectedService][selectedTileset];
117
- };
116
+ });
118
117
 
119
- let selected = 'mapbox v1:streets-v11';
120
- $: serviceUrl = getServiceUrl(selected);
118
+ let selected = $state('mapbox v1:streets-v11');
119
+ $effect(() => {
120
+ serviceUrl = getServiceUrl(selected);
121
+ });
121
122
  </script>
122
123
 
123
124
  <SelectField
@@ -128,7 +129,7 @@
128
129
  toggleIcon={null}
129
130
  stepper
130
131
  >
131
- <div slot="append" on:click|stopPropagation role="none">
132
+ <div slot="append" onclick={(e) => e.stopPropagation()} role="none">
132
133
  <div class="text-[10px] text-surface-content/50 text-center">2x</div>
133
134
  <Switch bind:checked={doubleScale} size="md" />
134
135
  </div>
@@ -1,23 +1,6 @@
1
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
- $$bindings?: Bindings;
4
- } & Exports;
5
- (internal: unknown, props: Props & {
6
- $$events?: Events;
7
- $$slots?: Slots;
8
- }): Exports & {
9
- $set?: any;
10
- $on?: any;
11
- };
12
- z_$$bindings?: Bindings;
13
- }
14
- declare const TilesetField: $$__sveltets_2_IsomorphicComponent<{
15
- doubleScale?: boolean;
16
- serviceUrl?: Function;
17
- }, {
18
- click: MouseEvent;
19
- } & {
20
- [evt: string]: CustomEvent<any>;
21
- }, {}, {}, string>;
22
- type TilesetField = InstanceType<typeof TilesetField>;
1
+ declare const TilesetField: import("svelte").Component<{
2
+ doubleScale?: any;
3
+ serviceUrl?: any;
4
+ }, {}, "doubleScale" | "serviceUrl">;
5
+ type TilesetField = ReturnType<typeof TilesetField>;
23
6
  export default TilesetField;
@@ -1,14 +1,17 @@
1
1
  <script lang="ts">
2
2
  import type { ComponentProps } from 'svelte';
3
3
  import { Button, Dialog, Toggle, Tooltip } from 'svelte-ux';
4
- import { mdiGithub } from '@mdi/js';
4
+ import LucideGithub from '~icons/lucide/github.svelte';
5
5
 
6
6
  import Code from './Code.svelte';
7
7
 
8
- export let label: string;
9
- export let source: string | undefined = undefined;
10
- export let href: string | undefined = undefined;
11
- export let icon: ComponentProps<Button>['icon'];
8
+ const {
9
+ label,
10
+ source,
11
+ href,
12
+ icon,
13
+ }: { label: string; source?: string; href?: string; icon: ComponentProps<Button>['icon'] } =
14
+ $props();
12
15
  </script>
13
16
 
14
17
  {#if source}
@@ -26,13 +29,13 @@
26
29
  </div>
27
30
 
28
31
  {#if href}
29
- <Button icon={mdiGithub} variant="fill-light" color="primary" {href} target="_blank">
32
+ <Button icon={LucideGithub} variant="fill-light" color="primary" {href} target="_blank">
30
33
  View on Github
31
34
  </Button>
32
35
  {/if}
33
36
  </div>
34
37
 
35
- <div class="overflow-auto">
38
+ <div class="overflow-auto border-t">
36
39
  <Code {source} language={source.startsWith('<script') ? 'svelte' : 'js'} />
37
40
  </div>
38
41
 
@@ -1,25 +1,11 @@
1
1
  import type { ComponentProps } from 'svelte';
2
2
  import { Button } from 'svelte-ux';
3
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
4
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
5
- $$bindings?: Bindings;
6
- } & Exports;
7
- (internal: unknown, props: Props & {
8
- $$events?: Events;
9
- $$slots?: Slots;
10
- }): Exports & {
11
- $set?: any;
12
- $on?: any;
13
- };
14
- z_$$bindings?: Bindings;
15
- }
16
- declare const ViewSourceButton: $$__sveltets_2_IsomorphicComponent<{
3
+ type $$ComponentProps = {
17
4
  label: string;
18
- source?: string | undefined;
19
- href?: string | undefined;
20
- icon: ComponentProps<Button>["icon"];
21
- }, {
22
- [evt: string]: CustomEvent<any>;
23
- }, {}, {}, string>;
24
- type ViewSourceButton = InstanceType<typeof ViewSourceButton>;
5
+ source?: string;
6
+ href?: string;
7
+ icon: ComponentProps<Button>['icon'];
8
+ };
9
+ declare const ViewSourceButton: import("svelte").Component<$$ComponentProps, {}, "">;
10
+ type ViewSourceButton = ReturnType<typeof ViewSourceButton>;
25
11
  export default ViewSourceButton;
@@ -0,0 +1,30 @@
1
+ import type { Component } from 'svelte';
2
+ import type { SeriesData } from '../components/charts/types.js';
3
+ import { SelectionState } from '@layerstack/svelte-state';
4
+ declare class HighlightKey<TData, SeriesComponent extends Component> {
5
+ current: string | null;
6
+ set: (seriesKey: typeof this.current) => void;
7
+ }
8
+ export declare class SeriesState<TData, TComponent extends Component> {
9
+ #private;
10
+ selectedKeys: SelectionState<string, false>;
11
+ highlightKey: HighlightKey<TData, TComponent>;
12
+ constructor(getSeries: () => SeriesData<TData, TComponent>[]);
13
+ get series(): SeriesData<TData, TComponent>[];
14
+ get isDefaultSeries(): boolean;
15
+ get visibleSeries(): SeriesData<TData, TComponent>[];
16
+ /**
17
+ * Check if series is visible
18
+ */
19
+ isVisible(seriesKey: SeriesData<TData, TComponent>['key']): boolean;
20
+ /**
21
+ * Check if series is highlighted
22
+ * Changing default to `true` is useful to determine if series should be faded
23
+ */
24
+ isHighlighted(seriesKey: SeriesData<TData, TComponent>['key'], defaultValue?: boolean): boolean;
25
+ get allSeriesData(): Array<TData & {
26
+ seriesKey: string;
27
+ }>;
28
+ get allSeriesColors(): Array<NonNullable<SeriesData<TData, TComponent>["color"]>>;
29
+ }
30
+ export {};
@@ -0,0 +1,54 @@
1
+ import { SelectionState } from '@layerstack/svelte-state';
2
+ class HighlightKey {
3
+ current = $state(null);
4
+ set = (seriesKey) => {
5
+ this.current = seriesKey;
6
+ };
7
+ }
8
+ export class SeriesState {
9
+ #series = $state.raw([]);
10
+ selectedKeys = new SelectionState();
11
+ highlightKey = new HighlightKey();
12
+ constructor(getSeries) {
13
+ this.#series = getSeries();
14
+ $effect.pre(() => {
15
+ // keep series state in sync with the prop
16
+ this.#series = getSeries();
17
+ });
18
+ }
19
+ get series() {
20
+ return this.#series;
21
+ }
22
+ get isDefaultSeries() {
23
+ return this.#series.length === 1 && this.#series[0].key === 'default';
24
+ }
25
+ get visibleSeries() {
26
+ return this.#series.filter((s) => this.isVisible(s.key));
27
+ }
28
+ /**
29
+ * Check if series is visible
30
+ */
31
+ isVisible(seriesKey) {
32
+ return this.selectedKeys.isEmpty() || this.selectedKeys.isSelected(seriesKey);
33
+ }
34
+ /**
35
+ * Check if series is highlighted
36
+ * Changing default to `true` is useful to determine if series should be faded
37
+ */
38
+ isHighlighted(seriesKey, defaultValue = false) {
39
+ if (this.highlightKey.current === null) {
40
+ return defaultValue;
41
+ }
42
+ else {
43
+ return this.highlightKey.current === seriesKey;
44
+ }
45
+ }
46
+ get allSeriesData() {
47
+ return this.#series
48
+ .flatMap((s) => s.data?.map((d) => ({ seriesKey: s.key, ...d })))
49
+ .filter((d) => d);
50
+ }
51
+ get allSeriesColors() {
52
+ return this.#series.map((s) => s.color).filter((c) => c != null);
53
+ }
54
+ }
@@ -0,0 +1,6 @@
1
+ .lc-root-container {
2
+ --color-surface-100: var(--color-base-100);
3
+ --color-surface-200: var(--color-base-200);
4
+ --color-surface-300: var(--color-base-300);
5
+ --color-surface-content: var(--color-base-content);
6
+ }
@@ -0,0 +1,11 @@
1
+ /*
2
+ When NOT using shadcn-svelte Chart component.
3
+ Not typically needed even when using built-in Chart, as defaults typically are sufficient
4
+ */
5
+ .lc-root-container {
6
+ --color-primary: var(--primary);
7
+ --color-surface-100: var(--card-background);
8
+ --color-surface-200: var(--card-muted);
9
+ /* No direct mapping, should add explicit color (light and dark mode) */
10
+ --color-surface-content: var(--card-foreground);
11
+ }
@@ -0,0 +1,15 @@
1
+ .lc-root-container {
2
+ --color-primary: var(--color-primary-500);
3
+
4
+ --color-surface-100: var(--color-surface-50);
5
+ --color-surface-200: var(--color-surface-100);
6
+ --color-surface-300: var(--color-surface-200);
7
+ --color-surface-content: var(--base-font-color);
8
+
9
+ html.dark & {
10
+ --color-surface-100: var(--color-surface-700);
11
+ --color-surface-200: var(--color-surface-800);
12
+ --color-surface-300: var(--color-surface-900);
13
+ --color-surface-content: var(--base-font-color-dark);
14
+ }
15
+ }
@@ -216,7 +216,7 @@ export function createArcTextProps(props, opts = {}, position) {
216
216
  x: x,
217
217
  y: y,
218
218
  textAnchor,
219
- 'dominant-baseline': 'middle',
219
+ dominantBaseline: 'middle',
220
220
  };
221
221
  });
222
222
  const current = $derived.by(() => {
@@ -224,21 +224,21 @@ export function createArcTextProps(props, opts = {}, position) {
224
224
  return {
225
225
  path: innerPath.current,
226
226
  ...sharedProps,
227
- 'dominant-baseline': innerDominantBaseline,
227
+ dominantBaseline: innerDominantBaseline,
228
228
  };
229
229
  }
230
230
  else if (position === 'outer') {
231
231
  return {
232
232
  path: outerPath.current,
233
233
  ...sharedProps,
234
- 'dominant-baseline': outerDominantBaseline,
234
+ dominantBaseline: outerDominantBaseline,
235
235
  };
236
236
  }
237
237
  else if (position === 'middle') {
238
238
  return {
239
239
  path: middlePath.current,
240
240
  ...sharedProps,
241
- 'dominant-baseline': 'middle',
241
+ dominantBaseline: 'middle',
242
242
  };
243
243
  }
244
244
  else if (position === 'centroid') {
@@ -1,5 +1,6 @@
1
1
  import type { Numeric } from 'd3-array';
2
2
  import { extent as d3extent } from 'd3-array';
3
+ import { type Accessor } from './common.js';
3
4
  /**
4
5
  * Wrapper around d3-array's `extent()` but remove [undefined, undefined] return type
5
6
  */
@@ -11,3 +12,13 @@ export declare function extent<T extends Numeric>(iterable: Parameters<typeof d3
11
12
  * of making a set
12
13
  */
13
14
  export declare function arraysEqual(arr1: unknown[], arr2: unknown[]): boolean;
15
+ /**
16
+ * Add `lanes` property to each element in the data array support densely packing.
17
+ * This is useful for visualizing overlapping events in a timeline / Gantt chart.
18
+ */
19
+ export declare function applyLanes<T extends Record<string, any>>(data: T[], options?: {
20
+ start: Accessor<T>;
21
+ end: Accessor<T>;
22
+ }): (T & {
23
+ lane: number;
24
+ })[];
@@ -1,4 +1,5 @@
1
1
  import { extent as d3extent } from 'd3-array';
2
+ import { accessor } from './common.js';
2
3
  /**
3
4
  * Wrapper around d3-array's `extent()` but remove [undefined, undefined] return type
4
5
  */
@@ -18,3 +19,25 @@ export function arraysEqual(arr1, arr2) {
18
19
  return arr2.includes(k);
19
20
  });
20
21
  }
22
+ /**
23
+ * Add `lanes` property to each element in the data array support densely packing.
24
+ * This is useful for visualizing overlapping events in a timeline / Gantt chart.
25
+ */
26
+ export function applyLanes(data, options = {
27
+ start: 'start',
28
+ end: 'end',
29
+ }) {
30
+ const result = [];
31
+ let stack = [];
32
+ const startAccessor = accessor(options.start);
33
+ const endAccessor = accessor(options.end);
34
+ for (const d of data) {
35
+ let lane = stack.findIndex((s) => endAccessor(s) <= startAccessor(d) && startAccessor(s) < startAccessor(d));
36
+ if (lane === -1) {
37
+ lane = stack.length;
38
+ }
39
+ result.push({ ...d, lane });
40
+ stack[lane] = d;
41
+ }
42
+ return result;
43
+ }
@@ -0,0 +1 @@
1
+ export {};