layerchart 0.42.0 → 0.43.1

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 (114) hide show
  1. package/dist/components/Arc.svelte +27 -20
  2. package/dist/components/Arc.svelte.d.ts +2 -2
  3. package/dist/components/Area.svelte +11 -7
  4. package/dist/components/Area.svelte.d.ts +3 -3
  5. package/dist/components/AreaStack.svelte +3 -2
  6. package/dist/components/Axis.svelte +38 -41
  7. package/dist/components/Axis.svelte.d.ts +5 -4
  8. package/dist/components/Bar.svelte +6 -5
  9. package/dist/components/Bar.svelte.d.ts +3 -2
  10. package/dist/components/Bars.svelte +5 -4
  11. package/dist/components/Bars.svelte.d.ts +3 -2
  12. package/dist/components/Bounds.svelte +7 -5
  13. package/dist/components/Bounds.svelte.d.ts +8 -8
  14. package/dist/components/Brush.svelte +8 -6
  15. package/dist/components/Brush.svelte.d.ts +2 -2
  16. package/dist/components/Calendar.svelte +4 -3
  17. package/dist/components/Chart.svelte +71 -85
  18. package/dist/components/Chart.svelte.d.ts +216 -24
  19. package/dist/components/ChartClipPath.svelte +6 -6
  20. package/dist/components/ChartContext.svelte +19 -0
  21. package/dist/components/ChartContext.svelte.d.ts +89 -0
  22. package/dist/components/Circle.svelte +1 -0
  23. package/dist/components/ClipPath.svelte +1 -0
  24. package/dist/components/ForceSimulation.svelte +4 -3
  25. package/dist/components/ForceSimulation.svelte.d.ts +1 -2
  26. package/dist/components/Frame.svelte +8 -7
  27. package/dist/components/Frame.svelte.d.ts +1 -1
  28. package/dist/components/GeoCircle.svelte.d.ts +1 -2
  29. package/dist/components/GeoContext.svelte +2 -1
  30. package/dist/components/GeoContext.svelte.d.ts +5 -5
  31. package/dist/components/GeoEdgeFade.svelte +2 -5
  32. package/dist/components/GeoPath.svelte +9 -5
  33. package/dist/components/GeoPath.svelte.d.ts +7 -4
  34. package/dist/components/GeoPoint.svelte +0 -1
  35. package/dist/components/GeoSpline.svelte +2 -11
  36. package/dist/components/GeoTile.svelte +3 -1
  37. package/dist/components/Group.svelte +4 -2
  38. package/dist/components/Highlight.svelte +16 -10
  39. package/dist/components/Highlight.svelte.d.ts +16 -15
  40. package/dist/components/HitCanvas.svelte +5 -2
  41. package/dist/components/HitCanvas.svelte.d.ts +1 -1
  42. package/dist/components/Hull.svelte +6 -3
  43. package/dist/components/Labels.svelte +5 -4
  44. package/dist/components/Labels.svelte.d.ts +0 -1
  45. package/dist/components/Legend.svelte +4 -4
  46. package/dist/components/Legend.svelte.d.ts +2 -2
  47. package/dist/components/Line.svelte +1 -0
  48. package/dist/components/Link.svelte +3 -1
  49. package/dist/components/Pack.svelte +4 -3
  50. package/dist/components/Partition.svelte +3 -3
  51. package/dist/components/Partition.svelte.d.ts +2 -1
  52. package/dist/components/Pie.svelte +7 -6
  53. package/dist/components/Pie.svelte.d.ts +2 -4
  54. package/dist/components/Point.svelte +2 -2
  55. package/dist/components/Points.svelte +4 -3
  56. package/dist/components/RadialGradient.svelte +2 -2
  57. package/dist/components/RadialGradient.svelte.d.ts +0 -1
  58. package/dist/components/Rect.svelte +1 -0
  59. package/dist/components/Rule.svelte +3 -3
  60. package/dist/components/Sankey.svelte +9 -3
  61. package/dist/components/Sankey.svelte.d.ts +2 -2
  62. package/dist/components/Spline.svelte +9 -6
  63. package/dist/components/Spline.svelte.d.ts +2 -2
  64. package/dist/components/Text.svelte +1 -2
  65. package/dist/components/Threshold.svelte +2 -2
  66. package/dist/components/Threshold.svelte.d.ts +2 -2
  67. package/dist/components/TileImage.svelte +4 -1
  68. package/dist/components/Tooltip.svelte +3 -3
  69. package/dist/components/TooltipContext.svelte +46 -15
  70. package/dist/components/TooltipContext.svelte.d.ts +1 -1
  71. package/dist/components/TooltipItem.svelte.d.ts +1 -1
  72. package/dist/components/TransformContext.svelte +17 -6
  73. package/dist/components/TransformControls.svelte +1 -0
  74. package/dist/components/Tree.svelte +4 -3
  75. package/dist/components/Tree.svelte.d.ts +3 -3
  76. package/dist/components/Treemap.svelte +11 -12
  77. package/dist/components/Treemap.svelte.d.ts +6 -6
  78. package/dist/components/Voronoi.svelte +8 -3
  79. package/dist/components/layout/Canvas.svelte +5 -3
  80. package/dist/components/layout/Html.svelte +3 -3
  81. package/dist/components/layout/Svg.svelte +6 -3
  82. package/dist/docs/Code.svelte +2 -3
  83. package/dist/docs/GeoDebug.svelte +4 -4
  84. package/dist/docs/Link.svelte +2 -4
  85. package/dist/docs/Link.svelte.d.ts +14 -5
  86. package/dist/docs/Preview.svelte +1 -1
  87. package/dist/docs/TilesetField.svelte +1 -1
  88. package/dist/docs/TilesetField.svelte.d.ts +1 -1
  89. package/dist/docs/ViewSourceButton.svelte +4 -4
  90. package/dist/docs/ViewSourceButton.svelte.d.ts +5 -3
  91. package/dist/stores/motionStore.d.ts +2 -2
  92. package/dist/stores/motionStore.js +4 -2
  93. package/dist/utils/array.d.ts +5 -0
  94. package/dist/utils/array.js +7 -0
  95. package/dist/utils/common.d.ts +2 -0
  96. package/dist/utils/common.js +18 -0
  97. package/dist/utils/genData.d.ts +23 -23
  98. package/dist/utils/genData.js +3 -2
  99. package/dist/utils/geo.d.ts +3 -3
  100. package/dist/utils/geo.js +2 -0
  101. package/dist/utils/graph.d.ts +1 -1
  102. package/dist/utils/graph.js +3 -3
  103. package/dist/utils/hierarchy.d.ts +1 -1
  104. package/dist/utils/hierarchy.js +1 -0
  105. package/dist/utils/rect.d.ts +5 -3
  106. package/dist/utils/rect.js +7 -11
  107. package/dist/utils/scales.d.ts +21 -12
  108. package/dist/utils/scales.js +3 -1
  109. package/dist/utils/stack.d.ts +5 -2
  110. package/dist/utils/stack.js +20 -7
  111. package/dist/utils/threshold.js +1 -0
  112. package/dist/utils/treemap.d.ts +5 -2
  113. package/dist/utils/treemap.js +1 -1
  114. package/package.json +5 -2
@@ -1,6 +1,7 @@
1
- <script>import { createEventDispatcher, getContext } from 'svelte';
1
+ <script>import { createEventDispatcher } from 'svelte';
2
2
  import { forceSimulation } from 'd3-force';
3
- const { data } = getContext('LayerCake');
3
+ import { chartContext } from './ChartContext.svelte';
4
+ const { data } = chartContext();
4
5
  const dispatch = createEventDispatcher();
5
6
  export let forces;
6
7
  export let alpha = 1;
@@ -8,7 +9,7 @@ export let alphaTarget = 0;
8
9
  export let alphaDecay = 1 - Math.pow(0.001, 1 / 300);
9
10
  export let alphaMin = 0.001;
10
11
  export let velocityDecay = 0.4;
11
- export let alphaResponse = undefined;
12
+ /** Stop simulation */
12
13
  export let stopped = false;
13
14
  let _static = false;
14
15
  /** If true, will only update nodes after simulation has completed */
@@ -8,8 +8,7 @@ declare const __propDef: {
8
8
  alphaDecay?: number;
9
9
  alphaMin?: number;
10
10
  velocityDecay?: number;
11
- alphaResponse?: ((alpha: number, alphaTarget: number) => number) | undefined;
12
- stopped?: boolean;
11
+ /** Stop simulation */ stopped?: boolean;
13
12
  /** If true, will only update nodes after simulation has completed */ static?: boolean;
14
13
  /** Clone data since simulation mutates original */ cloneData?: boolean;
15
14
  };
@@ -1,16 +1,17 @@
1
- <script>import { getContext } from 'svelte';
2
- const { width, height, padding } = getContext('LayerCake');
1
+ <script>import { chartContext } from './ChartContext.svelte';
2
+ const { width, height, padding } = chartContext();
3
3
  /** Include padding area */
4
4
  export let full = false;
5
5
  /** Access underlying `<rect>` element */
6
- export let rectEl;
6
+ export let rectEl = undefined;
7
7
  </script>
8
8
 
9
+ <!-- svelte-ignore a11y-no-static-element-interactions -->
9
10
  <rect
10
- x={full ? -$padding.left : 0}
11
- y={full ? -$padding.top : 0}
12
- width={$width + (full ? $padding.left + $padding.right : 0)}
13
- height={$height + (full ? $padding.top + $padding.bottom : 0)}
11
+ x={full && $padding?.left ? -$padding.left : 0}
12
+ y={full && $padding?.top ? -$padding.top : 0}
13
+ width={$width + (full ? ($padding?.left ?? 0) + ($padding?.right ?? 0) : 0)}
14
+ height={$height + (full ? ($padding?.top ?? 0) + ($padding?.bottom ?? 0) : 0)}
14
15
  on:click
15
16
  on:pointerdown
16
17
  on:dblclick
@@ -3,7 +3,7 @@ declare const __propDef: {
3
3
  props: {
4
4
  [x: string]: any;
5
5
  full?: boolean;
6
- rectEl: SVGRectElement;
6
+ rectEl?: SVGRectElement | undefined;
7
7
  };
8
8
  events: {
9
9
  click: MouseEvent;
@@ -1,5 +1,4 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import GeoPath from './GeoPath.svelte';
3
2
  declare const __propDef: {
4
3
  props: {
5
4
  [x: string]: any;
@@ -11,7 +10,7 @@ declare const __propDef: {
11
10
  pointermove: PointerEvent;
12
11
  pointerleave: PointerEvent;
13
12
  click: CustomEvent<{
14
- geoPath: GeoPath;
13
+ geoPath: ReturnType<typeof import("..").geoCurvePath>;
15
14
  event: MouseEvent;
16
15
  }>;
17
16
  } & {
@@ -1,6 +1,7 @@
1
1
  <script context="module">import { getContext, setContext } from 'svelte';
2
2
  import { writable } from 'svelte/store';
3
3
  import {} from 'd3-geo';
4
+ import { chartContext } from './ChartContext.svelte';
4
5
  import { transformContext } from './TransformContext.svelte';
5
6
  export const geoContextKey = Symbol();
6
7
  export function geoContext() {
@@ -11,7 +12,7 @@ function setGeoContext(geo) {
11
12
  }
12
13
  </script>
13
14
 
14
- <script>const { width, height } = getContext('LayerCake');
15
+ <script>const { width, height } = chartContext();
15
16
  /** @type {Function} projection - A d3 projection function. Pass this in as an uncalled function, e.g. `projection={geoAlbersUsa}`. */
16
17
  export let projection = undefined;
17
18
  export let fitGeojson = undefined;
@@ -1,12 +1,12 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import { type Writable } from 'svelte/store';
3
- import { type GeoIdentityTransform, type GeoPermissibleObjects, type GeoProjection } from 'd3-geo';
3
+ import { type GeoPermissibleObjects, type GeoProjection } from 'd3-geo';
4
4
  export declare const geoContextKey: unique symbol;
5
- export type GeoContext = Writable<GeoProjection | GeoIdentityTransform>;
5
+ export type GeoContext = Writable<GeoProjection>;
6
6
  export declare function geoContext(): GeoContext;
7
7
  declare const __propDef: {
8
8
  props: {
9
- /** @type {Function} projection - A d3 projection function. Pass this in as an uncalled function, e.g. `projection={geoAlbersUsa}`. */ projection?: (() => GeoProjection | GeoIdentityTransform) | undefined;
9
+ /** @type {Function} projection - A d3 projection function. Pass this in as an uncalled function, e.g. `projection={geoAlbersUsa}`. */ projection?: (() => GeoProjection) | undefined;
10
10
  fitGeojson?: GeoPermissibleObjects | undefined;
11
11
  /** By default, the map fills to fit the $width and $height. If instead you want a fixed-aspect ratio, like for a server-side rendered map, set that here. */ fixedAspectRatio?: number | undefined;
12
12
  clipAngle?: number | undefined;
@@ -25,14 +25,14 @@ declare const __propDef: {
25
25
  /** Apply TransformContext to the selected properties. Typically `translate` or `rotate` are mutually selected */ applyTransform?: ("scale" | "translate" | "rotate")[];
26
26
  reflectX?: boolean | undefined;
27
27
  reflectY?: boolean | undefined;
28
- /** Exposed to allow binding in Chart */ geo?: Writable<GeoProjection | GeoIdentityTransform>;
28
+ /** Exposed to allow binding in Chart */ geo?: Writable<GeoProjection>;
29
29
  };
30
30
  events: {
31
31
  [evt: string]: CustomEvent<any>;
32
32
  };
33
33
  slots: {
34
34
  default: {
35
- projection: GeoProjection | GeoIdentityTransform;
35
+ projection: GeoProjection;
36
36
  };
37
37
  };
38
38
  };
@@ -1,14 +1,11 @@
1
- <script>import { getContext } from 'svelte';
2
- import { scaleLinear } from 'd3-scale';
1
+ <script>import { scaleLinear } from 'd3-scale';
3
2
  import { geoDistance } from 'd3-geo';
4
3
  import { geoContext } from './GeoContext.svelte';
5
4
  export let link;
6
- const { width, height } = getContext('LayerCake');
7
5
  const geo = geoContext();
8
6
  const fade = scaleLinear().domain([-0.1, 0]).range([0, 0.1]);
9
7
  const clamper = scaleLinear().domain([0, 1]).range([0, 1]).clamp(true);
10
- // $: center = $geo.invert([$width / 2, $height / 2]);
11
- $: center = $geo.invert($geo.translate());
8
+ $: center = $geo.invert?.($geo.translate()) ?? [0, 0];
12
9
  $: source = link.source;
13
10
  $: target = link.target;
14
11
  $: startDistance = 1.57 - geoDistance(source, center);
@@ -1,6 +1,7 @@
1
1
  <script>import { createEventDispatcher, getContext } from 'svelte';
2
2
  import { geoTransform as d3geoTransform, } from 'd3-geo';
3
3
  import { cls } from 'svelte-ux';
4
+ import { chartContext } from './ChartContext.svelte';
4
5
  import { geoContext } from './GeoContext.svelte';
5
6
  import { curveLinearClosed } from 'd3-shape';
6
7
  import { geoCurvePath } from '../utils/geo.js';
@@ -27,7 +28,7 @@ export let curve = curveLinearClosed;
27
28
  let className = undefined;
28
29
  export { className as class };
29
30
  const dispatch = createEventDispatcher();
30
- const { containerWidth, containerHeight, padding } = getContext('LayerCake');
31
+ const { containerWidth, containerHeight, padding } = chartContext();
31
32
  const canvas = getContext('canvas');
32
33
  const geo = geoContext();
33
34
  /**
@@ -58,25 +59,28 @@ $: if (renderContext === 'canvas' && $ctx) {
58
59
  $ctx.beginPath();
59
60
  // Set the context here since setting it in `$: geoPath` is a circular reference
60
61
  geoPath = geoCurvePath(_projection, curve, $ctx);
61
- geoPath(geojson);
62
+ if (geojson) {
63
+ geoPath(geojson);
64
+ }
62
65
  $ctx.fillStyle =
63
66
  fill ??
64
67
  (computedStyles.fill !== DEFAULT_FILL ? computedStyles.fill : undefined) ??
65
68
  'transparent';
66
69
  $ctx.fill();
67
- $ctx.lineWidth = strokeWidth;
70
+ $ctx.lineWidth = Number(strokeWidth ?? 0);
68
71
  $ctx.strokeStyle =
69
- stroke ?? computedStyles.stroke === 'none' ? 'transparent' : computedStyles.stroke;
72
+ stroke ?? computedStyles.stroke === 'none' ? 'transparent' : computedStyles.stroke ?? '';
70
73
  $ctx.stroke();
71
74
  }
72
75
  }
73
76
  </script>
74
77
 
78
+ <!-- svelte-ignore a11y-no-static-element-interactions -->
75
79
  {#if renderContext === 'svg'}
76
80
  <slot {geoPath}>
77
81
  <path
78
82
  {...$$restProps}
79
- d={geoPath(geojson)}
83
+ d={geojson ? geoPath(geojson) : ''}
80
84
  {fill}
81
85
  {stroke}
82
86
  stroke-width={strokeWidth}
@@ -2,11 +2,14 @@ import { SvelteComponentTyped } from "svelte";
2
2
  import { type GeoIdentityTransform, type GeoPermissibleObjects, type GeoProjection, type GeoTransformPrototype } from 'd3-geo';
3
3
  import type { TooltipContextValue } from './TooltipContext.svelte';
4
4
  import { type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
5
+ import { geoCurvePath } from '../utils/geo.js';
5
6
  declare const __propDef: {
6
7
  props: {
7
8
  [x: string]: any;
8
- geojson?: GeoPermissibleObjects;
9
- render?: ((ctx: CanvasRenderingContext2D, { geoPath: GeoPath }: any) => any) | undefined;
9
+ geojson?: GeoPermissibleObjects | null | undefined;
10
+ render?: ((ctx: CanvasRenderingContext2D, options: {
11
+ geoPath: ReturnType<typeof geoCurvePath>;
12
+ }) => any) | undefined;
10
13
  fill?: string | undefined;
11
14
  stroke?: string | undefined;
12
15
  strokeWidth?: number | string | undefined;
@@ -21,7 +24,7 @@ declare const __propDef: {
21
24
  pointerleave: PointerEvent;
22
25
  pointerdown: PointerEvent;
23
26
  click: CustomEvent<{
24
- geoPath: GeoPath;
27
+ geoPath: ReturnType<typeof geoCurvePath>;
25
28
  event: MouseEvent;
26
29
  }>;
27
30
  } & {
@@ -29,7 +32,7 @@ declare const __propDef: {
29
32
  };
30
33
  slots: {
31
34
  default: {
32
- geoPath: (object: GeoPermissibleObjects) => string | undefined;
35
+ geoPath: import("d3-geo").GeoPath<unknown, GeoPermissibleObjects>;
33
36
  };
34
37
  };
35
38
  };
@@ -8,7 +8,6 @@ export let lat;
8
8
  export let long;
9
9
  /** Render to canvas */
10
10
  export let render = () => { };
11
- const { width, height } = getContext('LayerCake');
12
11
  const canvas = getContext('canvas');
13
12
  const geo = geoContext();
14
13
  $: [x, y] = $geo([long, lat]) ?? [0, 0];
@@ -1,5 +1,4 @@
1
- <script>import { getContext } from 'svelte';
2
- import { curveNatural } from 'd3-shape';
1
+ <script>import { curveNatural } from 'd3-shape';
3
2
  import { geoOrthographic, geoInterpolate } from 'd3-geo';
4
3
  import { geoContext } from './GeoContext.svelte';
5
4
  import Spline from './Spline.svelte';
@@ -16,7 +15,6 @@ export let loft = 1.0;
16
15
  * @type {CurveFactory | CurveFactoryLineOnly | undefined}
17
16
  */
18
17
  export let curve = curveNatural;
19
- const { width, height } = getContext('LayerCake');
20
18
  const geo = geoContext();
21
19
  $: loftedProjection = geoOrthographic()
22
20
  .translate($geo.translate())
@@ -27,11 +25,4 @@ $: target = $geo(link.target);
27
25
  $: middle = loftedProjection(geoInterpolate(link.source, link.target)(0.5));
28
26
  </script>
29
27
 
30
- <Spline
31
- data={[source, middle, target]}
32
- x={(d) => d[0]}
33
- y={(d) => d[1]}
34
- defined={(d) => $geo.invert(d)}
35
- {curve}
36
- {...$$restProps}
37
- />
28
+ <Spline data={[source, middle, target]} x={(d) => d[0]} y={(d) => d[1]} {curve} {...$$restProps} />
@@ -1,5 +1,7 @@
1
1
  <script>import { getContext } from 'svelte';
2
+ // @ts-expect-error
2
3
  import { tile as d3Tile } from 'd3-tile';
4
+ import { chartContext } from './ChartContext.svelte';
3
5
  import { geoContext } from './GeoContext.svelte';
4
6
  import Group from './Group.svelte';
5
7
  import TileImage from './TileImage.svelte';
@@ -8,7 +10,7 @@ export let zoomDelta = 0;
8
10
  export let tileSize = 256;
9
11
  export let disableCache = false;
10
12
  export let debug = false;
11
- const { containerWidth, containerHeight, padding } = getContext('LayerCake');
13
+ const { containerWidth, containerHeight, padding } = chartContext();
12
14
  const canvas = getContext('canvas');
13
15
  const geo = geoContext();
14
16
  $: center = $geo([0, 0]) ?? [0, 0];
@@ -1,6 +1,7 @@
1
- <script>import { getContext, tick } from 'svelte';
1
+ <script>import { tick } from 'svelte';
2
+ import { chartContext } from './ChartContext.svelte';
2
3
  import { motionStore } from '../stores/motionStore.js';
3
- const { width, height } = getContext('LayerCake');
4
+ const { width, height } = chartContext();
4
5
  /**
5
6
  * Translate x
6
7
  */
@@ -33,6 +34,7 @@ $: if (center || x != null || y != null) {
33
34
  }
34
35
  </script>
35
36
 
37
+ <!-- svelte-ignore a11y-no-static-element-interactions -->
36
38
  <g
37
39
  {transform}
38
40
  {...$$restProps}
@@ -1,13 +1,14 @@
1
- <script>import { getContext } from 'svelte';
1
+ <script>import {} from 'svelte';
2
2
  import { max, min } from 'd3-array';
3
3
  import { cls, notNull } from 'svelte-ux';
4
- import { isScaleBand } from '../utils/scales.js';
4
+ import { chartContext } from './ChartContext.svelte';
5
5
  import Circle from './Circle.svelte';
6
6
  import Line from './Line.svelte';
7
7
  import Bar from './Bar.svelte';
8
8
  import Rect from './Rect.svelte';
9
9
  import { tooltipContext } from './TooltipContext.svelte';
10
- const { flatData, x, xDomain, xScale, xRange, xGet, y, yDomain, yScale, yRange, yGet, rGet, config, } = getContext('LayerCake');
10
+ import { isScaleBand } from '../utils/scales.js';
11
+ const { flatData, x, xDomain, xScale, xRange, xGet, y, yDomain, yScale, yRange, yGet, rGet, config, } = chartContext();
11
12
  const tooltip = tooltipContext();
12
13
  /** Highlight specific data (annotate), espect uses tooltip data */
13
14
  export let data = undefined;
@@ -173,6 +174,7 @@ $: if (highlightData) {
173
174
  {..._area}
174
175
  {...typeof area === 'object' ? area : null}
175
176
  class={cls(
177
+ // @ts-expect-error
176
178
  !area.fill && 'fill-surface-content/5',
177
179
  typeof area === 'object' ? area.class : null
178
180
  )}
@@ -185,14 +187,18 @@ $: if (highlightData) {
185
187
  <slot name="bar" {bar}>
186
188
  <Bar
187
189
  spring={motion}
188
- x={typeof bar === 'object' ? bar.x : null}
189
- y={typeof bar === 'object' ? bar.y : null}
190
- inset={typeof bar === 'object' ? bar.inset : null}
191
- stroke={typeof bar === 'object' ? bar.stroke : null}
192
- strokeWidth={typeof bar === 'object' ? bar.strokeWidth : null}
193
- radius={typeof bar === 'object' ? bar.radius : null}
190
+ x={typeof bar === 'object' ? bar.x : undefined}
191
+ y={typeof bar === 'object' ? bar.y : undefined}
192
+ inset={typeof bar === 'object' ? bar.inset : undefined}
193
+ stroke={typeof bar === 'object' ? bar.stroke : undefined}
194
+ strokeWidth={typeof bar === 'object' ? bar.strokeWidth : undefined}
195
+ radius={typeof bar === 'object' ? bar.radius : undefined}
194
196
  bar={highlightData}
195
- class={cls(!bar.fill && 'fill-primary', typeof bar === 'object' ? bar.class : null)}
197
+ class={cls(
198
+ // @ts-expect-error
199
+ !bar.fill && 'fill-primary',
200
+ typeof bar === 'object' ? bar.class : null
201
+ )}
196
202
  on:click
197
203
  />
198
204
  </slot>
@@ -2,6 +2,7 @@ import { SvelteComponentTyped } from "svelte";
2
2
  import { type ComponentProps } from 'svelte';
3
3
  import Circle from './Circle.svelte';
4
4
  import Line from './Line.svelte';
5
+ import Bar from './Bar.svelte';
5
6
  import Rect from './Rect.svelte';
6
7
  declare const __propDef: {
7
8
  props: {
@@ -10,7 +11,7 @@ declare const __propDef: {
10
11
  /** Show points and pass props to Circles */ points?: boolean | Partial<ComponentProps<Circle>>;
11
12
  /** Show lines and pass props to Lines */ lines?: boolean | Partial<ComponentProps<Line>>;
12
13
  /** Show area and pass props to Rect */ area?: boolean | Partial<ComponentProps<Rect>>;
13
- /** Show bar and pass props to Rect */ bar?: boolean | Partial<ComponentProps<Rect>>;
14
+ /** Show bar and pass props to Rect */ bar?: boolean | Partial<ComponentProps<Bar>>;
14
15
  /** Set to false to disable spring transitions */ motion?: boolean;
15
16
  };
16
17
  events: {
@@ -30,20 +31,20 @@ declare const __propDef: {
30
31
  bar: {
31
32
  bar: boolean | Partial<{
32
33
  [x: string]: any;
33
- x?: number;
34
- initialX?: number;
35
- y?: number;
36
- initialY?: number;
37
- width: number;
38
- initialWidth?: number;
39
- height: number;
40
- initialHeight?: number;
41
- spring?: boolean | import("../stores/motionStore").SpringOptions | {
42
- [prop: string]: import("../stores/motionStore").SpringOptions;
43
- };
44
- tweened?: boolean | import("../stores/motionStore").TweenedOptions | {
45
- [prop: string]: import("../stores/motionStore").TweenedOptions;
46
- };
34
+ bar: Object;
35
+ x?: import("../utils/common").Accessor;
36
+ y?: import("../utils/common").Accessor;
37
+ fill?: string | undefined;
38
+ stroke?: string;
39
+ strokeWidth?: number;
40
+ radius?: number;
41
+ rounded?: "all" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
42
+ inset?: number;
43
+ groupBy?: string | undefined;
44
+ groupPaddingInner?: number;
45
+ groupPaddingOuter?: number;
46
+ spring?: ComponentProps<Rect>["spring"];
47
+ tweened?: ComponentProps<Rect>["tweened"];
47
48
  }>;
48
49
  };
49
50
  lines: {
@@ -1,10 +1,12 @@
1
- <script>import { createEventDispatcher, getContext, onMount, setContext } from 'svelte';
1
+ <script>import { createEventDispatcher, onMount, setContext } from 'svelte';
2
2
  import { writable } from 'svelte/store';
3
3
  import { scaleCanvas } from 'layercake';
4
4
  import { cls } from 'svelte-ux';
5
+ import { chartContext } from './ChartContext.svelte';
5
6
  import Canvas from './layout/Canvas.svelte';
6
7
  import { transformContext } from './TransformContext.svelte';
7
- const { width, height } = getContext('LayerCake');
8
+ const { width, height } = chartContext();
9
+ // @ts-expect-error: this will immediately be defined on mount via `bind:context`
8
10
  export let context = undefined;
9
11
  /** Show canvas for debugging */
10
12
  export let debug = false;
@@ -29,6 +31,7 @@ function* rgbColorGenerator(step = 500) {
29
31
  nextColor += step;
30
32
  yield `rgb(${rgb.join(',')})`;
31
33
  }
34
+ return 'rgb(0,0,0)';
32
35
  }
33
36
  $: colorGenerator = rgbColorGenerator();
34
37
  // Reset color generator whenever updated (width/height) so always reusing same colors (and not exhausting)
@@ -19,7 +19,7 @@ declare const __propDef: {
19
19
  };
20
20
  slots: {
21
21
  default: {
22
- nextColor: () => string | void;
22
+ nextColor: () => string;
23
23
  setColorData: (color: string, data: any) => void;
24
24
  };
25
25
  };
@@ -1,13 +1,15 @@
1
- <script>import { createEventDispatcher, getContext } from 'svelte';
1
+ <script>import { createEventDispatcher } from 'svelte';
2
2
  import { cls } from 'svelte-ux';
3
3
  import { min } from 'd3-array';
4
4
  import { Delaunay } from 'd3-delaunay';
5
+ // @ts-expect-error
5
6
  import { geoVoronoi } from 'd3-geo-voronoi';
7
+ import { curveLinearClosed } from 'd3-shape';
8
+ import { chartContext } from './ChartContext.svelte';
6
9
  import GeoPath from './GeoPath.svelte';
7
10
  import { geoContext } from './GeoContext.svelte';
8
11
  import Spline from './Spline.svelte';
9
- import { curveLinearClosed } from 'd3-shape';
10
- const { flatData, x: xContext, y: yContext } = getContext('LayerCake');
12
+ const { flatData, x: xContext, y: yContext } = chartContext();
11
13
  const geo = geoContext();
12
14
  /** Override data instead of using context */
13
15
  export let data = undefined;
@@ -20,6 +22,7 @@ $: points = (data ?? $flatData).map((d) => {
20
22
  const x = Array.isArray(xValue) ? min(xValue) : xValue;
21
23
  const y = Array.isArray(yValue) ? min(yValue) : yValue;
22
24
  const point = [x, y];
25
+ // @ts-expect-error
23
26
  point.data = d;
24
27
  return point;
25
28
  });
@@ -3,24 +3,25 @@
3
3
  * - [ ] Support step curves (center like scaleBand())
4
4
  * - [ ] Support multiple values (threshold, stacks, etc)
5
5
  */
6
- import { getContext } from 'svelte';
6
+ import {} from 'svelte';
7
7
  import { format as formatValue, cls } from 'svelte-ux';
8
8
  import { greatestAbs } from 'svelte-ux/utils/array';
9
+ const { flatData, yScale, x, y, custom } = chartContext();
9
10
  import Text from './Text.svelte';
10
11
  import { isScaleBand } from '../utils/scales.js';
11
12
  import { createDimensionGetter } from '../utils/rect.js';
12
- const { flatData, yScale, x, y, custom } = getContext('LayerCake');
13
+ import { chartContext } from './ChartContext.svelte';
13
14
  // TODO: Support 'auto' to switch `inside` to `outside` if not enough room
14
15
  export let placement = 'outside';
15
16
  export let offset = 4;
16
- export let significantDigits = 3;
17
17
  export let format = undefined;
18
18
  // export let overlap = false;
19
+ // @ts-expect-error
19
20
  $: yBaseline = $custom?.yBaseline ?? 0;
20
21
  export let groupBy = undefined;
21
22
  export let groupPaddingInner = 0.2;
22
23
  export let groupPaddingOuter = 0;
23
- $: getDimensions = createDimensionGetter(getContext('LayerCake'), {
24
+ $: getDimensions = createDimensionGetter(chartContext(), {
24
25
  // x,
25
26
  // y,
26
27
  groupBy,
@@ -5,7 +5,6 @@ declare const __propDef: {
5
5
  [x: string]: any;
6
6
  placement?: "inside" | "outside";
7
7
  offset?: number;
8
- significantDigits?: number;
9
8
  format?: FormatType | undefined;
10
9
  groupBy?: string | undefined;
11
10
  groupPaddingInner?: number;
@@ -1,11 +1,11 @@
1
- <script>import { getContext } from 'svelte';
2
- import { scaleBand, scaleLinear } from 'd3-scale';
1
+ <script>import { scaleBand, scaleLinear } from 'd3-scale';
3
2
  import { quantize, interpolate, interpolateRound } from 'd3-interpolate';
4
3
  import { quantile, range } from 'd3-array';
5
4
  import { format } from 'svelte-ux';
5
+ import { chartContext } from './ChartContext.svelte';
6
6
  import ColorRamp from './ColorRamp.svelte';
7
7
  import { cls } from 'svelte-ux';
8
- const { rScale } = getContext('LayerCake') ?? {};
8
+ const { rScale } = chartContext() ?? {};
9
9
  export let scale = undefined;
10
10
  export let title = '';
11
11
  export let width = 320;
@@ -123,7 +123,7 @@ else {
123
123
  )}
124
124
  >
125
125
  <div class={cls('text-[10px] font-semibold', classes.title)}>{title}</div>
126
- <slot values={tickValues} {scale}>
126
+ <slot values={tickValues ?? []} {scale}>
127
127
  <svg
128
128
  {width}
129
129
  height={height + tickLength + tickFontSize}
@@ -8,7 +8,7 @@ declare const __propDef: {
8
8
  width?: number;
9
9
  height?: number;
10
10
  ticks?: number;
11
- tickFormat?: FormatType;
11
+ tickFormat?: FormatType | undefined;
12
12
  tickValues?: any[] | undefined;
13
13
  tickFontSize?: number;
14
14
  tickLength?: number;
@@ -25,7 +25,7 @@ declare const __propDef: {
25
25
  };
26
26
  slots: {
27
27
  default: {
28
- values: any[] | undefined;
28
+ values: any[];
29
29
  scale: any;
30
30
  };
31
31
  };
@@ -23,6 +23,7 @@ $: tick().then(() => {
23
23
  });
24
24
  </script>
25
25
 
26
+ <!-- svelte-ignore a11y-no-static-element-interactions -->
26
27
  <line
27
28
  x1={$tweened_x1}
28
29
  y1={$tweened_y1}
@@ -15,17 +15,19 @@ export let x = (d) => (sankey ? d[0] : orientation === 'horizontal' ? d.y : d.x)
15
15
  export let y = (d) => (sankey ? d[1] : orientation === 'horizontal' ? d.x : d.y);
16
16
  export let curve = orientation === 'horizontal' ? curveBumpX : curveBumpY;
17
17
  export let tweened = undefined;
18
+ // @ts-expect-error
18
19
  $: tweenedOptions = tweened ? { interpolate: interpolatePath, ...tweened } : false;
19
20
  $: tweened_d = motionStore('', { tweened: tweenedOptions });
20
21
  $: {
21
22
  orientation; // subscribe to orientation changes to update link
22
23
  const link = d3Link(curve).source(source).target(target).x(x).y(y);
23
- const d = link(data);
24
+ const d = link(data) ?? '';
24
25
  tweened_d.set(d);
25
26
  }
26
27
  </script>
27
28
 
28
29
  <!-- svelte-ignore a11y-mouse-events-have-key-events -->
30
+ <!-- svelte-ignore a11y-no-static-element-interactions -->
29
31
  <path
30
32
  class="path-link"
31
33
  d={$tweened_d}
@@ -1,6 +1,6 @@
1
- <script>import { getContext } from 'svelte';
2
- import { pack as d3Pack } from 'd3-hierarchy';
3
- const { data, width, height } = getContext('LayerCake');
1
+ <script>import { pack as d3Pack } from 'd3-hierarchy';
2
+ import { chartContext } from './ChartContext.svelte';
3
+ const { data, width, height } = chartContext();
4
4
  export let size = undefined;
5
5
  /**
6
6
  * see: https://github.com/d3/d3-hierarchy#pack_padding
@@ -13,6 +13,7 @@ $: {
13
13
  pack.padding(padding);
14
14
  }
15
15
  }
16
+ // @ts-expect-error
16
17
  $: packData = pack($data);
17
18
  </script>
18
19
 
@@ -1,6 +1,6 @@
1
- <script>import { getContext } from 'svelte';
2
- import { partition as d3Partition } from 'd3-hierarchy';
3
- const { data, width, height } = getContext('LayerCake');
1
+ <script>import { partition as d3Partition, } from 'd3-hierarchy';
2
+ import { chartContext } from './ChartContext.svelte';
3
+ const { data, width, height } = chartContext();
4
4
  export let orientation = 'horizontal';
5
5
  export let size = undefined;
6
6
  /**
@@ -1,4 +1,5 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import { type HierarchyRectangularNode } from 'd3-hierarchy';
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  orientation?: "vertical" | "horizontal";
@@ -15,7 +16,7 @@ declare const __propDef: {
15
16
  };
16
17
  slots: {
17
18
  default: {
18
- nodes: import("d3-hierarchy").HierarchyRectangularNode<unknown>[];
19
+ nodes: HierarchyRectangularNode<any>[];
19
20
  };
20
21
  };
21
22
  };