layerchart 0.42.0 → 0.43.0

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,8 +1,8 @@
1
- <script>import { getContext } from 'svelte';
2
- import * as d3 from 'd3-hierarchy';
1
+ <script>import { treemap as d3treemap, treemapBinary, treemapDice, treemapResquarify, treemapSlice, treemapSliceDice, treemapSquarify, } from 'd3-hierarchy';
2
+ import { chartContext } from './ChartContext.svelte';
3
3
  import { aspectTile } from '../utils/treemap.js';
4
- const { data, width, height } = getContext('LayerCake');
5
- export let tile = d3.treemapSquarify;
4
+ const { data, width, height } = chartContext();
5
+ export let tile = treemapSquarify;
6
6
  export let padding = 0;
7
7
  export let paddingInner = 0;
8
8
  export let paddingOuter = 0;
@@ -13,22 +13,21 @@ export let paddingRight = undefined;
13
13
  export let selected = null;
14
14
  $: tileFunc =
15
15
  tile === 'squarify'
16
- ? d3.treemapSquarify
16
+ ? treemapSquarify
17
17
  : tile === 'resquarify'
18
- ? d3.treemapResquarify
18
+ ? treemapResquarify
19
19
  : tile === 'binary'
20
- ? d3.treemapBinary
20
+ ? treemapBinary
21
21
  : tile === 'dice'
22
- ? d3.treemapDice
22
+ ? treemapDice
23
23
  : tile === 'slice'
24
- ? d3.treemapSlice
24
+ ? treemapSlice
25
25
  : tile === 'sliceDice'
26
- ? d3.treemapSliceDice
26
+ ? treemapSliceDice
27
27
  : tile;
28
28
  let treemap;
29
29
  $: {
30
- treemap = d3
31
- .treemap()
30
+ treemap = d3treemap()
32
31
  .size([$width, $height])
33
32
  .tile(aspectTile(tileFunc, $width, $height));
34
33
  if (padding) {
@@ -1,23 +1,23 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import * as d3 from 'd3-hierarchy';
2
+ import { treemapSquarify, type HierarchyRectangularNode } from 'd3-hierarchy';
3
3
  declare const __propDef: {
4
4
  props: {
5
- tile?: typeof d3.treemapSquarify | "binary" | "squarify" | "resquarify" | "dice" | "slice" | "sliceDice";
5
+ tile?: typeof treemapSquarify | "binary" | "squarify" | "resquarify" | "dice" | "slice" | "sliceDice";
6
6
  padding?: number;
7
7
  paddingInner?: number;
8
8
  paddingOuter?: number;
9
9
  paddingTop?: number;
10
10
  paddingBottom?: number;
11
- paddingLeft?: undefined;
12
- paddingRight?: undefined;
13
- selected?: any;
11
+ paddingLeft?: number | undefined;
12
+ paddingRight?: number | undefined;
13
+ selected?: HierarchyRectangularNode<any> | null | undefined;
14
14
  };
15
15
  events: {
16
16
  [evt: string]: CustomEvent<any>;
17
17
  };
18
18
  slots: {
19
19
  default: {
20
- nodes: any;
20
+ nodes: HierarchyRectangularNode<any>[];
21
21
  };
22
22
  };
23
23
  };
@@ -1,11 +1,13 @@
1
- <script>import { createEventDispatcher, getContext } from 'svelte';
2
- import { cls } from 'svelte-ux';
1
+ <script>import { createEventDispatcher } from 'svelte';
3
2
  import { min } from 'd3-array';
4
3
  import { Delaunay } from 'd3-delaunay';
4
+ // @ts-expect-error
5
5
  import { geoVoronoi } from 'd3-geo-voronoi';
6
+ import { cls } from 'svelte-ux';
7
+ import { chartContext } from './ChartContext.svelte';
6
8
  import GeoPath from './GeoPath.svelte';
7
9
  import { geoContext } from './GeoContext.svelte';
8
- const { flatData, xGet, yGet, x: xContext, y: yContext, width, height } = getContext('LayerCake');
10
+ const { flatData, xGet, yGet, x: xContext, y: yContext, width, height } = chartContext();
9
11
  const geo = geoContext();
10
12
  /** Override data instead of using context */
11
13
  export let data = undefined;
@@ -18,6 +20,7 @@ $: points = (data ?? $flatData).map((d) => {
18
20
  const x = Array.isArray(xValue) ? min(xValue) : xValue;
19
21
  const y = Array.isArray(yValue) ? min(yValue) : yValue;
20
22
  const point = [x, y];
23
+ // @ts-expect-error
21
24
  point.data = d;
22
25
  return point;
23
26
  });
@@ -48,6 +51,8 @@ $: boundHeight = Math.max($height, 0);
48
51
  {:else}
49
52
  {@const voronoi = Delaunay.from(points).voronoi([0, 0, boundWidth, boundHeight])}
50
53
  {#each points as point, i}
54
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
55
+ <!-- svelte-ignore a11y-no-static-element-interactions -->
51
56
  <path
52
57
  d={voronoi.renderCell(i)}
53
58
  class={cls('fill-transparent', classes.path)}
@@ -1,12 +1,14 @@
1
- <script>import { getContext, onMount, setContext } from 'svelte';
1
+ <script>import { 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 { transformContext } from '../TransformContext.svelte';
6
- const { width, height, containerWidth, containerHeight, padding } = getContext('LayerCake');
7
+ const { width, height, containerWidth, containerHeight, padding } = chartContext();
7
8
  /** The `<canvas>` tag. Useful for bindings. */
8
9
  export let element = undefined;
9
10
  /** The `<canvas>`'s 2d context. Useful for bindings. */
11
+ // @ts-expect-error: set during onMount()
10
12
  export let context = undefined;
11
13
  /** Force the use of a software (instead of hardware accelerated) 2D canvas and can save memory when calling getImageData() frequently.
12
14
  * see: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#willreadfrequently */
@@ -31,7 +33,7 @@ const { mode, scale, translate } = transformContext();
31
33
  $: if (context) {
32
34
  scaleCanvas(context, $containerWidth, $containerHeight);
33
35
  context.clearRect(0, 0, $containerWidth, $containerHeight);
34
- context.translate($padding.left, $padding.top);
36
+ context.translate($padding.left ?? 0, $padding.top ?? 0);
35
37
  if (mode === 'canvas') {
36
38
  const center = { x: $width / 2, y: $height / 2 };
37
39
  const newTranslate = {
@@ -1,5 +1,5 @@
1
- <script>import { getContext } from 'svelte';
2
- import { cls } from 'svelte-ux';
1
+ <script>import { cls } from 'svelte-ux';
2
+ import { chartContext } from '../ChartContext.svelte';
3
3
  /** The layer's outermost `<div>` tag. Useful for bindings. */
4
4
  export let element = undefined;
5
5
  /** The layer's z-index. */
@@ -14,7 +14,7 @@ export let label = undefined;
14
14
  export let labelledBy = undefined;
15
15
  /** A string passed to the `aria-describedby` property on the `<div>` tag. */
16
16
  export let describedBy = undefined;
17
- const { padding } = getContext('LayerCake');
17
+ const { padding } = chartContext();
18
18
  $: roleVal = role || (label || labelledBy || describedBy ? 'figure' : undefined);
19
19
  </script>
20
20
 
@@ -1,5 +1,5 @@
1
- <script>import { getContext } from 'svelte';
2
- import { cls } from 'svelte-ux';
1
+ <script>import { cls } from 'svelte-ux';
2
+ import { chartContext } from '../ChartContext.svelte';
3
3
  import { transformContext } from '../TransformContext.svelte';
4
4
  /** The layer's `<svg>` tag. Useful for bindings. */
5
5
  export let element = undefined;
@@ -19,7 +19,7 @@ export let labelledBy = undefined;
19
19
  export let describedBy = undefined;
20
20
  /** Shorthand to set the contents of `<title></title>` for accessibility. You can also set arbitrary HTML via the "title" slot but this is a convenient shorthand. If you use the "title" slot, this prop is ignored. */
21
21
  export let title = undefined;
22
- const { containerWidth, containerHeight, width, height, padding } = getContext('LayerCake');
22
+ const { containerWidth, containerHeight, width, height, padding } = chartContext();
23
23
  const { mode, scale, translate } = transformContext();
24
24
  let transform = '';
25
25
  $: if (mode === 'canvas') {
@@ -32,6 +32,8 @@ $: if (mode === 'canvas') {
32
32
  }
33
33
  </script>
34
34
 
35
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
36
+ <!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
35
37
  <svg
36
38
  bind:this={element}
37
39
  {viewBox}
@@ -48,6 +50,7 @@ $: if (mode === 'canvas') {
48
50
  aria-labelledby={labelledBy}
49
51
  aria-describedby={describedBy}
50
52
  on:click
53
+ role="figure"
51
54
  >
52
55
  <slot name="title">
53
56
  {#if title}<title>{title}</title>{/if}
@@ -1,16 +1,15 @@
1
1
  <script>import Prism from 'prismjs';
2
2
  import 'prism-svelte';
3
- import { CopyButton, cls, getComponentClasses } from 'svelte-ux';
3
+ import { CopyButton, cls } from 'svelte-ux';
4
4
  export let source = null;
5
5
  export let language = 'svelte';
6
6
  export let highlightedSource = source
7
7
  ? Prism.highlight(source, Prism.languages[language] ?? Prism.languages.text, language)
8
8
  : '';
9
9
  export let classes = {};
10
- const settingsClasses = getComponentClasses('Code');
11
10
  </script>
12
11
 
13
- <div class={cls('Code', 'rounded', settingsClasses.root, classes.root, $$props.class)}>
12
+ <div class={cls('Code', 'rounded', classes.root, $$props.class)}>
14
13
  {#if source}
15
14
  <div class="relative">
16
15
  <pre
@@ -1,7 +1,7 @@
1
- <script>import { getContext } from 'svelte';
2
- import { format, Checkbox, cls } from 'svelte-ux';
1
+ <script>import { format, Checkbox, cls } from 'svelte-ux';
2
+ import { chartContext } from '../components/ChartContext.svelte';
3
3
  import { geoContext } from '../components/GeoContext.svelte';
4
- const { width, height } = getContext('LayerCake');
4
+ const { width, height } = chartContext();
5
5
  const geo = geoContext();
6
6
  let showCenter = false;
7
7
  </script>
@@ -33,7 +33,7 @@ let showCenter = false;
33
33
 
34
34
  <div>
35
35
  <span class="opacity-50">long/lat: <Checkbox bind:checked={showCenter} size="xs" /></span>
36
- {#each $geo.invert?.([$width / 2, $height / 2]) as coord}
36
+ {#each $geo.invert?.([$width / 2, $height / 2]) ?? [] as coord}
37
37
  <div class="text-right">{format(coord, 'decimal')}</div>
38
38
  {/each}
39
39
  </div>
@@ -1,7 +1,5 @@
1
- <script>"use strict";
2
- // console.log($$props, $$slots);
3
- </script>
4
-
1
+ <!-- href provided by markdown/mdsvex -->
2
+ <!-- svelte-ignore a11y-missing-attribute -->
5
3
  <a class="text-primary font-medium" {...$$restProps}>
6
4
  <slot />
7
5
  </a>
@@ -1,3 +1,17 @@
1
+ /** @typedef {typeof __propDef.props} LinkProps */
2
+ /** @typedef {typeof __propDef.events} LinkEvents */
3
+ /** @typedef {typeof __propDef.slots} LinkSlots */
4
+ export default class Link extends SvelteComponentTyped<{
5
+ [x: string]: any;
6
+ }, {
7
+ [evt: string]: CustomEvent<any>;
8
+ }, {
9
+ default: {};
10
+ }> {
11
+ }
12
+ export type LinkProps = typeof __propDef.props;
13
+ export type LinkEvents = typeof __propDef.events;
14
+ export type LinkSlots = typeof __propDef.slots;
1
15
  import { SvelteComponentTyped } from "svelte";
2
16
  declare const __propDef: {
3
17
  props: {
@@ -10,9 +24,4 @@ declare const __propDef: {
10
24
  default: {};
11
25
  };
12
26
  };
13
- export type LinkProps = typeof __propDef.props;
14
- export type LinkEvents = typeof __propDef.events;
15
- export type LinkSlots = typeof __propDef.slots;
16
- export default class Link extends SvelteComponentTyped<LinkProps, LinkEvents, LinkSlots> {
17
- }
18
27
  export {};
@@ -9,7 +9,7 @@ import Json from './Json.svelte';
9
9
  export let code = undefined;
10
10
  export let data = undefined;
11
11
  export let language = 'svelte';
12
- export let highlightedCode = Prism.highlight(code, Prism.languages.svelte, language);
12
+ export let highlightedCode = code ? Prism.highlight(code, Prism.languages.svelte, language) : '';
13
13
  export let showCode = false;
14
14
  let copyValue = null;
15
15
  try {
@@ -89,7 +89,7 @@ $: serviceUrl = getServiceUrl(selected);
89
89
  toggleIcon={null}
90
90
  stepper
91
91
  >
92
- <div slot="append" on:click|stopPropagation>
92
+ <div slot="append" on:click|stopPropagation role="none">
93
93
  <div class="text-[10px] text-surface-content/50 text-center">2x</div>
94
94
  <Switch bind:checked={doubleScale} size="md" />
95
95
  </div>
@@ -2,7 +2,7 @@ import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
4
  doubleScale?: boolean;
5
- serviceUrl?: (x: number, y: number, z: number) => string;
5
+ serviceUrl?: Function;
6
6
  };
7
7
  events: {
8
8
  click: MouseEvent;
@@ -1,9 +1,9 @@
1
- <script>import { mdiGithub } from '@mdi/js';
2
- import { Button, Dialog, Toggle, Tooltip } from 'svelte-ux';
1
+ <script>import { Button, Dialog, Toggle, Tooltip } from 'svelte-ux';
2
+ import { mdiGithub } from '@mdi/js';
3
3
  import Code from './Code.svelte';
4
4
  export let label;
5
- export let source;
6
- export let href;
5
+ export let source = undefined;
6
+ export let href = undefined;
7
7
  export let icon;
8
8
  </script>
9
9
 
@@ -1,10 +1,12 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { ComponentProps } from 'svelte';
3
+ import { Button } from 'svelte-ux';
2
4
  declare const __propDef: {
3
5
  props: {
4
6
  label: string;
5
- source: string;
6
- href: string;
7
- icon: string;
7
+ source?: string | undefined;
8
+ href?: string | undefined;
9
+ icon: ComponentProps<Button>["icon"];
8
10
  };
9
11
  events: {
10
12
  [evt: string]: CustomEvent<any>;
@@ -1,6 +1,6 @@
1
1
  import { spring, tweened } from 'svelte/motion';
2
- export type SpringOptions = Parameters<typeof spring>[1];
3
- export type TweenedOptions = Parameters<typeof tweened>[1];
2
+ export type SpringOptions = Parameters<typeof spring<any>>[1];
3
+ export type TweenedOptions = Parameters<typeof tweened<any>>[1];
4
4
  export type MotionOptions = {
5
5
  spring?: boolean | SpringOptions;
6
6
  tweened?: boolean | TweenedOptions;
@@ -22,14 +22,16 @@ export function resolveOptions(prop, options) {
22
22
  spring: typeof options.spring === 'boolean' || options.spring == null
23
23
  ? options.spring
24
24
  : prop in options.spring
25
- ? options.spring[prop]
25
+ ? //@ts-expect-error
26
+ options.spring[prop]
26
27
  : Object.keys(options.spring).some((key) => ['precision', 'damping', 'stiffness'].includes(key))
27
28
  ? options.tweened
28
29
  : false,
29
30
  tweened: typeof options.tweened === 'boolean' || options.tweened == null
30
31
  ? options.tweened
31
32
  : prop in options.tweened
32
- ? options.tweened[prop]
33
+ ? //@ts-expect-error
34
+ options.tweened[prop]
33
35
  : Object.keys(options.tweened).some((key) => ['delay', 'duration', 'easing'].includes(key))
34
36
  ? options.tweened
35
37
  : false,
@@ -0,0 +1,5 @@
1
+ import { extent as d3extent, type Numeric } from 'd3-array';
2
+ /**
3
+ * Wrapper around d3-array's `extent()` but remove [undefined, undefined] return type
4
+ */
5
+ export declare function extent<T extends Numeric>(iterable: Parameters<typeof d3extent<T>>[0]): [T, T];
@@ -0,0 +1,7 @@
1
+ import { extent as d3extent } from 'd3-array';
2
+ /**
3
+ * Wrapper around d3-array's `extent()` but remove [undefined, undefined] return type
4
+ */
5
+ export function extent(iterable) {
6
+ return d3extent(iterable);
7
+ }
@@ -0,0 +1,2 @@
1
+ export type Accessor<TData = any> = number | string | ((d: TData) => any) | undefined | Accessor<TData>[];
2
+ export declare function accessor<TData = any>(prop: Accessor<TData>): (d: TData) => any;
@@ -0,0 +1,18 @@
1
+ import { get } from 'lodash-es';
2
+ export function accessor(prop) {
3
+ if (Array.isArray(prop)) {
4
+ return (d) => prop.map((p) => accessor(p)(d));
5
+ }
6
+ else if (typeof prop === 'function') {
7
+ // function
8
+ return prop;
9
+ }
10
+ else if (typeof prop === 'string') {
11
+ // path
12
+ return (d) => get(d, prop);
13
+ }
14
+ else {
15
+ // return full object
16
+ return (d) => d;
17
+ }
18
+ }
@@ -14,35 +14,35 @@ export declare function getRandomInteger(min: number, max: number, includeMax?:
14
14
  export declare function randomWalk(options?: {
15
15
  count?: number;
16
16
  }): number[];
17
- export declare function createSeries(options: {
17
+ export declare function createSeries<TKey extends string>(options: {
18
18
  count?: number;
19
19
  min: number;
20
20
  max: number;
21
- keys?: Array<string>;
21
+ keys?: TKey[];
22
22
  value?: 'number' | 'integer';
23
- }): {
23
+ }): ({
24
24
  x: number;
25
- }[];
26
- export declare function createDateSeries(options: {
25
+ } & { [K in TKey]: number; })[];
26
+ export declare function createDateSeries<TKey extends string>(options: {
27
27
  count?: number;
28
28
  min: number;
29
29
  max: number;
30
- keys?: Array<string>;
30
+ keys?: TKey[];
31
31
  value?: 'number' | 'integer';
32
- }): {
32
+ }): ({
33
33
  date: Date;
34
- }[];
35
- export declare function createTimeSeries(options: {
34
+ } & { [K in TKey]: number; })[];
35
+ export declare function createTimeSeries<TKey extends string>(options: {
36
36
  count?: number;
37
37
  min: number;
38
38
  max: number;
39
- keys: Array<string>;
39
+ keys: TKey[];
40
40
  value: 'number' | 'integer';
41
- }): {
41
+ }): ({
42
42
  name: string;
43
43
  startDate: Date;
44
44
  endDate: Date;
45
- }[];
45
+ } & { [K in TKey]: number; })[];
46
46
  export declare const wideData: {
47
47
  year: string;
48
48
  apples: number;
@@ -56,21 +56,21 @@ export declare const longData: {
56
56
  fruit: string;
57
57
  value: number;
58
58
  }[];
59
- export declare function getPhyllotaxis({ radius, count, width, height }: {
60
- radius: any;
61
- count: any;
62
- width: any;
63
- height: any;
59
+ export declare function getPhyllotaxis({ radius, count, width, height, }: {
60
+ radius: number;
61
+ count: number;
62
+ width: number;
63
+ height: number;
64
64
  }): {
65
65
  x: number;
66
66
  y: number;
67
67
  }[];
68
- export declare function getSpiral({ angle, radius, count, width, height }: {
69
- angle: any;
70
- radius: any;
71
- count: any;
72
- width: any;
73
- height: any;
68
+ export declare function getSpiral({ angle, radius, count, width, height, }: {
69
+ angle: number;
70
+ radius: number;
71
+ count: number;
72
+ width: number;
73
+ height: number;
74
74
  }): {
75
75
  x: number;
76
76
  y: number;
@@ -23,6 +23,7 @@ export function getRandomInteger(min, max, includeMax = true) {
23
23
  */
24
24
  export function randomWalk(options) {
25
25
  const random = randomNormal();
26
+ // @ts-expect-error
26
27
  return Array.from(cumsum({ length: options?.count ?? 100 }, random));
27
28
  }
28
29
  export function createSeries(options) {
@@ -108,12 +109,12 @@ export const longData = [
108
109
  { year: '2016', basket: 2, fruit: 'cherries', value: 720 },
109
110
  { year: '2016', basket: 2, fruit: 'dates', value: 400 },
110
111
  ];
111
- export function getPhyllotaxis({ radius, count, width, height }) {
112
+ export function getPhyllotaxis({ radius, count, width, height, }) {
112
113
  // Phyllotaxis: https://www.youtube.com/watch?v=KWoJgHFYWxY
113
114
  const rads = Math.PI * (3 - Math.sqrt(5)); // ~2.4 rads or ~137.5 degrees
114
115
  return getSpiral({ angle: radiansToDegrees(rads), radius, count, width, height });
115
116
  }
116
- export function getSpiral({ angle, radius, count, width, height }) {
117
+ export function getSpiral({ angle, radius, count, width, height, }) {
117
118
  return Array.from({ length: count }, (_, i) => {
118
119
  const r = radius * Math.sqrt(i);
119
120
  const a = degreesToRadians(angle * i);
@@ -1,11 +1,11 @@
1
- import { type GeoPermissibleObjects, type GeoProjection, type GeoStreamWrapper } from 'd3-geo';
1
+ import { geoPath as d3geoPath, type GeoProjection, type GeoStreamWrapper } from 'd3-geo';
2
2
  import { type Path } from 'd3-path';
3
3
  import { type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
4
4
  /**
5
5
  * Render a geoPath() using curve factory
6
6
  * @see {@link https://observablehq.com/@d3/context-to-curve}
7
7
  */
8
- export declare function geoCurvePath(projection: GeoProjection | GeoStreamWrapper | null, curve: CurveFactory | CurveFactoryLineOnly, context?: CanvasRenderingContext2D | Path): (object: GeoPermissibleObjects) => string | undefined;
8
+ export declare function geoCurvePath(projection: GeoProjection | GeoStreamWrapper | null, curve: CurveFactory | CurveFactoryLineOnly, context?: CanvasRenderingContext2D | Path): ReturnType<typeof d3geoPath>;
9
9
  /**
10
10
  * Return the point on Earth's surface that is diametrically opposite to another point
11
11
  * @see: https://en.wikipedia.org/wiki/Antipodes
@@ -15,7 +15,7 @@ export declare function antipode([longitude, latitude]: [number, number]): [numb
15
15
  * Check if point ([x, y]) is visible on projection
16
16
  * @see: https://observablehq.com/@d3/testing-projection-visibility
17
17
  */
18
- export declare function isVisible(projection: GeoProjection | GeoStreamWrapper): ([x, y]: [any, any]) => boolean;
18
+ export declare function isVisible(projection: GeoProjection | GeoStreamWrapper): ([x, y]: [number, number]) => boolean;
19
19
  export declare function geoFitObjectTransform(projection: GeoProjection, size: [number, number], object: Parameters<typeof projection.fitSize>[1]): {
20
20
  translate: {
21
21
  x: number;
package/dist/utils/geo.js CHANGED
@@ -14,6 +14,7 @@ export function geoCurvePath(projection, curve, context) {
14
14
  };
15
15
  // Expose geoPath properties such as `.centroid()`
16
16
  Object.setPrototypeOf(fn, geoPath);
17
+ // @ts-expect-error
17
18
  return fn;
18
19
  }
19
20
  /**
@@ -52,6 +53,7 @@ export function antipode([longitude, latitude]) {
52
53
  */
53
54
  export function isVisible(projection) {
54
55
  let visible;
56
+ // @ts-expect-error
55
57
  const stream = projection.stream({
56
58
  point() {
57
59
  visible = true;
@@ -19,7 +19,7 @@ export declare function graphFromHierarchy(hierarchy: ReturnType<typeof d3Hierar
19
19
  * Create graph from node (and target node/links downward)
20
20
  */
21
21
  export declare function graphFromNode(node: SankeyNodeMinimal<any, any>): {
22
- nodes: SankeyNodeMinimal<any, any>[];
22
+ nodes: any[];
23
23
  links: any[];
24
24
  };
25
25
  /**
@@ -7,8 +7,8 @@ export function graphFromCsv(csv) {
7
7
  ? {
8
8
  source,
9
9
  target,
10
- // @ts-ignore
11
- value: !value || isNaN((value = +value)) ? 1 : value,
10
+ // @ts-expect-error
11
+ value: !value || isNaN((value = +value)) ? 1 : +value,
12
12
  // color: linkColor,
13
13
  }
14
14
  : null);
@@ -29,7 +29,7 @@ export function graphFromHierarchy(hierarchy) {
29
29
  export function graphFromNode(node) {
30
30
  const nodes = [node];
31
31
  const links = [];
32
- node.sourceLinks.forEach((link) => {
32
+ node.sourceLinks?.forEach((link) => {
33
33
  nodes.push(link.target);
34
34
  links.push(link);
35
35
  if (link.target.sourceLinks.length) {
@@ -3,4 +3,4 @@ import type { HierarchyNode } from 'd3-hierarchy';
3
3
  * Find first ancestor matching filter, including node.
4
4
  * Similar to `node.find()` (https://github.com/d3/d3-hierarchy#node_find) but checks ancestors instead of descendants
5
5
  */
6
- export declare function findAncestor<T = any>(node: HierarchyNode<T>, filter: (node: any) => boolean): HierarchyNode<T> | null;
6
+ export declare function findAncestor<T = any>(node: HierarchyNode<T>, filter: (node: HierarchyNode<T>) => boolean): HierarchyNode<T> | null;
@@ -7,6 +7,7 @@ export function findAncestor(node, filter) {
7
7
  if (filter(node)) {
8
8
  return node;
9
9
  }
10
+ // @ts-expect-error
10
11
  node = node.parent;
11
12
  }
12
13
  return null;
@@ -1,8 +1,10 @@
1
+ import type { ChartContext } from '../components/ChartContext.svelte';
2
+ import { type Accessor } from './common.js';
1
3
  type DimensionGetterOptions = {
2
4
  /** Override `x` accessor from context */
3
- x?: (item: any) => any;
5
+ x?: Accessor;
4
6
  /** Override `y` accessor from context */
5
- y?: (item: any) => any;
7
+ y?: Accessor;
6
8
  groupBy?: string;
7
9
  inset?: number;
8
10
  groupPadding?: {
@@ -10,7 +12,7 @@ type DimensionGetterOptions = {
10
12
  outer?: number;
11
13
  };
12
14
  };
13
- export declare function createDimensionGetter(context: any, options?: DimensionGetterOptions): import("svelte/store").Readable<(item: any) => {
15
+ export declare function createDimensionGetter<TData>(context: ChartContext<TData>, options?: DimensionGetterOptions): import("svelte/store").Readable<(item: any) => {
14
16
  x: any;
15
17
  y: number;
16
18
  width: number;