layerchart 0.32.1 → 0.32.3

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.
@@ -3,7 +3,7 @@ import { type ComponentProps } from 'svelte';
3
3
  import { fade } from 'svelte/transition';
4
4
  import type { SVGAttributes } from 'svelte/elements';
5
5
  import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
6
- import { type TransitionParams } from 'svelte-ux';
6
+ import { type FormatType, type TransitionParams } from 'svelte-ux';
7
7
  import Text from './Text.svelte';
8
8
  declare const __propDef: {
9
9
  props: {
@@ -12,7 +12,7 @@ declare const __propDef: {
12
12
  /** Draw a grid lines */ grid?: boolean | SVGAttributes<SVGLineElement> | undefined;
13
13
  /** Control the number of ticks*/ ticks?: number | any[] | Function | undefined;
14
14
  /** Length of the tick line */ tickSize?: number | undefined;
15
- format?: any;
15
+ format?: FormatType | undefined;
16
16
  labelProps?: Partial<ComponentProps<Text>> | undefined;
17
17
  spring?: boolean | Parameters<typeof springStore>[1];
18
18
  tweened?: boolean | Parameters<typeof tweenedStore>[1];
@@ -1,6 +1,6 @@
1
1
  <script context="module">import { getContext, setContext } from 'svelte';
2
2
  import { writable } from 'svelte/store';
3
- import { geoMercator, } from 'd3-geo';
3
+ import {} from 'd3-geo';
4
4
  export const geoContextKey = Symbol();
5
5
  export function geoContext() {
6
6
  return getContext(geoContextKey);
@@ -12,7 +12,7 @@ function setGeoContext(geo) {
12
12
 
13
13
  <script>const { width, height } = getContext('LayerCake');
14
14
  /** @type {Function} projection - A d3 projection function. Pass this in as an uncalled function, e.g. `projection={geoAlbersUsa}`. */
15
- export let projection = geoMercator;
15
+ export let projection = undefined;
16
16
  export let fitGeojson;
17
17
  /** 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. */
18
18
  export let fixedAspectRatio = undefined;
@@ -22,10 +22,10 @@ export let rotate = undefined;
22
22
  export let scale = undefined;
23
23
  export let translate = undefined;
24
24
  export let center = undefined;
25
- const geo = writable(projection());
25
+ const geo = writable(projection?.());
26
26
  setGeoContext(geo);
27
27
  $: fitSizeRange = (fixedAspectRatio ? [100, 100 / fixedAspectRatio] : [$width, $height]);
28
- $: {
28
+ $: if (projection) {
29
29
  const _projection = projection();
30
30
  if (fitGeojson && 'fitSize' in _projection) {
31
31
  _projection.fitSize(fitSizeRange, fitGeojson);
@@ -1,10 +1,10 @@
1
1
  <script>import { createEventDispatcher, getContext } from 'svelte';
2
2
  import { geoPath as d3geoPath } from 'd3-geo';
3
- import { geoContext } from './GeoContext.svelte';
4
3
  import { scaleCanvas } from 'layercake';
4
+ import { cls } from 'svelte-ux';
5
+ import { geoContext } from './GeoContext.svelte';
5
6
  export let geojson;
6
7
  export let fill = undefined;
7
- export let fillScale = undefined;
8
8
  export let stroke = undefined;
9
9
  export let strokeWidth = undefined;
10
10
  /** Render to canvas */
@@ -32,7 +32,7 @@ $: if (renderContext === 'canvas' && $ctx) {
32
32
  // Set the context here since setting it in `$: geoPath` is a circular reference
33
33
  geoPath.context($ctx);
34
34
  geoPath(geojson);
35
- $ctx.fillStyle = fill || (fillScale && $rGet(fillScale)) || 'transparent';
35
+ $ctx.fillStyle = fill || 'transparent';
36
36
  $ctx.fill();
37
37
  $ctx.lineWidth = strokeWidth;
38
38
  $ctx.strokeStyle = stroke;
@@ -44,13 +44,17 @@ $: if (renderContext === 'canvas' && $ctx) {
44
44
  {#if renderContext === 'svg'}
45
45
  <slot {geoPath}>
46
46
  <path
47
+ {...$$restProps}
47
48
  d={geoPath(geojson)}
48
- fill={fill || (fillScale && $rGet(fillScale)) || 'transparent'}
49
- stroke={stroke || 'black'}
49
+ {fill}
50
+ {stroke}
50
51
  on:mousemove={(e) => tooltip?.show(e, geojson)}
52
+ on:mousemove
51
53
  on:mouseleave={(e) => tooltip?.hide()}
54
+ on:mouseleave
52
55
  on:click={(event) => dispatch('click', { geoPath, event })}
53
- {...$$restProps}
56
+ on:click
57
+ class={cls($$props.fill == null && 'fill-transparent', $$props.class)}
54
58
  />
55
59
  </slot>
56
60
  {/if}
@@ -6,7 +6,6 @@ declare const __propDef: {
6
6
  [x: string]: any;
7
7
  geojson: GeoPermissibleObjects;
8
8
  fill?: string | undefined;
9
- fillScale?: Object | undefined;
10
9
  stroke?: string | undefined;
11
10
  strokeWidth?: number | string | undefined;
12
11
  render?: ((ctx: CanvasRenderingContext2D, { geoPath: GeoPath }: {
@@ -15,10 +14,9 @@ declare const __propDef: {
15
14
  tooltip?: TooltipContextValue | undefined;
16
15
  };
17
16
  events: {
18
- click: CustomEvent<{
19
- geoPath: GeoPath;
20
- event: MouseEvent;
21
- }>;
17
+ mousemove: MouseEvent;
18
+ mouseleave: MouseEvent;
19
+ click: CustomEvent<any>;
22
20
  } & {
23
21
  [evt: string]: CustomEvent<any>;
24
22
  };
@@ -1,6 +1,6 @@
1
1
  <script>import { getContext } from 'svelte';
2
- import { geoOrthographic, geoInterpolate } from 'd3-geo';
3
2
  import { curveNatural } from 'd3-shape';
3
+ import { geoOrthographic, geoInterpolate } from 'd3-geo';
4
4
  import { geoContext } from './GeoContext.svelte';
5
5
  import Spline from './Spline.svelte';
6
6
  export let link;
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { CurveFactory, CurveFactoryLineOnly } from 'd3-shape';
2
+ import { type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  [x: string]: any;
@@ -20,16 +20,13 @@ export let tweened = undefined;
20
20
  let tweened_x = motionStore(initialX, { spring, tweened });
21
21
  let tweened_y = motionStore(initialY, { spring, tweened });
22
22
  $: tick().then(() => {
23
- tweened_x.set(x);
24
- tweened_y.set(y);
23
+ tweened_x.set(x ?? (center === 'x' || center === true ? $width / 2 : 0));
24
+ tweened_y.set(y ?? (center === 'y' || center === true ? $height / 2 : 0));
25
25
  });
26
26
  let transform = undefined;
27
- $: if (x != null || y != null) {
27
+ $: if (center || x != null || y != null) {
28
28
  transform = `translate(${$tweened_x ?? 0}, ${$tweened_y ?? 0})`;
29
29
  }
30
- $: if (center) {
31
- transform = `translate(${$width / 2}, ${$height / 2})`;
32
- }
33
30
  </script>
34
31
 
35
32
  <g {transform} {...$$restProps} on:click on:mousemove on:mouseleave>
@@ -7,7 +7,7 @@ declare const __propDef: {
7
7
  initialX?: number | undefined;
8
8
  y?: number | undefined;
9
9
  initialY?: number | undefined;
10
- center?: boolean | undefined;
10
+ center?: boolean | "x" | "y" | undefined;
11
11
  spring?: boolean | Parameters<typeof springStore>[1];
12
12
  tweened?: boolean | Parameters<typeof tweenedStore>[1];
13
13
  };
@@ -1,4 +1,5 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import { type FormatType } from 'svelte-ux';
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  [x: string]: any;
@@ -7,7 +8,7 @@ declare const __propDef: {
7
8
  width?: number | undefined;
8
9
  height?: number | undefined;
9
10
  ticks?: number | undefined;
10
- tickFormat?: any;
11
+ tickFormat?: FormatType | undefined;
11
12
  tickValues?: any[] | undefined;
12
13
  tickFontSize?: number | undefined;
13
14
  tickSize?: number | undefined;
@@ -40,6 +40,7 @@ export let outerRadius = undefined;
40
40
  export let cornerRadius = 0;
41
41
  export let padAngle = 0;
42
42
  // export let padRadius = 0;
43
+ export let placement = 'center';
43
44
  export let spring = undefined;
44
45
  export let tweened = undefined;
45
46
  /**
@@ -50,7 +51,7 @@ export let offset = 0;
50
51
  * Tooltip context to setup mouse events to show tooltip for related data
51
52
  */
52
53
  export let tooltip = undefined;
53
- const { data: contextData, x, y, xRange, rGet, config } = getContext('LayerCake');
54
+ const { data: contextData, x, y, xRange, rGet, config, width, height } = getContext('LayerCake');
54
55
  $: resolved_endAngle = endAngle ?? degreesToRadians($config.xRange ? max($xRange) : max(range));
55
56
  let tweened_endAngle = motionStore(0, { spring, tweened });
56
57
  $: tweened_endAngle.set(resolved_endAngle);
@@ -61,9 +62,20 @@ $: pie = d3pie()
61
62
  .value($x);
62
63
  $: arcs = pie(data ?? $contextData);
63
64
  // $: console.log({ arcs, $yRange });
65
+ $: radius = Math.min($width / 2, $height / 2);
66
+ $: coords = {
67
+ x: placement === 'left'
68
+ ? radius
69
+ : placement === 'center'
70
+ ? $width / 2
71
+ : placement === 'right'
72
+ ? $width - radius
73
+ : 0,
74
+ y: placement === 'none' ? 0 : $height / 2,
75
+ };
64
76
  </script>
65
77
 
66
- <Group center>
78
+ <Group x={coords.x} y={coords.y}>
67
79
  <slot {arcs}>
68
80
  {#each arcs as arc, index}
69
81
  <Arc
@@ -25,6 +25,7 @@ declare const __propDef: {
25
25
  */ outerRadius?: number | undefined;
26
26
  cornerRadius?: number | undefined;
27
27
  padAngle?: number | undefined;
28
+ placement?: "center" | "left" | "right" | "none" | undefined;
28
29
  spring?: boolean | Parameters<typeof springStore>[1];
29
30
  tweened?: boolean | Parameters<typeof tweenedStore>[1];
30
31
  /**
@@ -288,10 +288,10 @@ $: if (mode === 'bounds' || mode === 'band') {
288
288
  {:else if mode === 'voronoi'}
289
289
  <Svg>
290
290
  <Voronoi
291
- on:mousemove={(e) => showTooltip(e.detail.event, e.detail.point.data)}
291
+ on:mousemove={(e) => showTooltip(e.detail.event, e.detail.data)}
292
292
  on:mouseleave={hideTooltip}
293
293
  on:click={(e) => {
294
- onClick({ data: e.detail.point.data });
294
+ onClick({ data: e.detail.data });
295
295
  }}
296
296
  classes={{ path: cls(debug && 'fill-danger/10 stroke-danger') }}
297
297
  />
@@ -1,10 +1,11 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import { type FormatType } from 'svelte-ux';
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  [x: string]: any;
5
6
  label: any;
6
7
  value?: any;
7
- format?: any;
8
+ format?: FormatType | undefined;
8
9
  valueAlign?: "center" | "left" | "right" | undefined;
9
10
  classes?: {
10
11
  label?: string | undefined;
@@ -2,7 +2,7 @@ import { SvelteComponentTyped } from "svelte";
2
2
  import * as d3 from 'd3-hierarchy';
3
3
  declare const __propDef: {
4
4
  props: {
5
- tile?: "slice" | d3.RatioSquarifyTilingFactory | "binary" | "squarify" | "resquarify" | "dice" | "sliceDice" | undefined;
5
+ tile?: "slice" | "binary" | "dice" | d3.RatioSquarifyTilingFactory | "squarify" | "resquarify" | "sliceDice" | undefined;
6
6
  padding?: number | undefined;
7
7
  paddingInner?: number | undefined;
8
8
  paddingOuter?: number | undefined;
@@ -1,33 +1,55 @@
1
1
  <script>import { createEventDispatcher, getContext } from 'svelte';
2
2
  import { draw as _drawTransition } from 'svelte/transition';
3
- import { Delaunay } from 'd3-delaunay';
4
- import { min } from 'd3-array';
5
3
  import { cls } from 'svelte-ux';
6
- const { flatData, xGet, yGet, width, height } = getContext('LayerCake');
4
+ import { min } from 'd3-array';
5
+ import { Delaunay } from 'd3-delaunay';
6
+ import { geoVoronoi } from 'd3-geo-voronoi';
7
+ import GeoPath from './GeoPath.svelte';
8
+ import { geoContext } from './GeoContext.svelte';
9
+ const { flatData, xGet, yGet, x: xContext, y: yContext, width, height } = getContext('LayerCake');
10
+ const geo = geoContext();
7
11
  /** Override data instead of using context */
8
12
  export let data = undefined;
9
13
  export let classes = {};
10
14
  const dispatch = createEventDispatcher();
11
15
  $: points = (data ?? $flatData).map((d) => {
12
- const xValue = $xGet(d);
13
- const yValue = $yGet(d);
16
+ // geo voronoi needs raw latitude/longtude, not mapped to range (chart dimensions)
17
+ const xValue = $geo ? $xContext(d) : $xGet(d);
18
+ const yValue = $geo ? $yContext(d) : $yGet(d);
14
19
  const x = Array.isArray(xValue) ? min(xValue) : xValue;
15
20
  const y = Array.isArray(yValue) ? min(yValue) : yValue;
16
21
  const point = [x, y];
17
22
  point.data = d;
18
23
  return point;
19
24
  });
20
- $: voronoi = Delaunay.from(points).voronoi([0, 0, Math.max($width, 0), Math.max($height, 0)]); // width and/or height can sometimes be negative (when loading data remotely and updately)
25
+ // Width and/or height can sometimes be negative (when loading data remotely and updately)
26
+ $: boundWidth = Math.max($width, 0);
27
+ $: boundHeight = Math.max($height, 0);
21
28
  </script>
22
29
 
23
30
  <g {...$$restProps} class={cls(classes.root, $$props.class)}>
24
- {#each points as point, i}
25
- <path
26
- d={voronoi.renderCell(i)}
27
- class={cls('fill-transparent', classes.path)}
28
- on:mousemove={(e) => dispatch('mousemove', { point, event: e })}
29
- on:mouseleave
30
- on:click={(e) => dispatch('click', { point })}
31
- />
32
- {/each}
31
+ {#if $geo}
32
+ {@const polygons = geoVoronoi().polygons(points)}
33
+ {#each polygons.features as feature}
34
+ <GeoPath
35
+ geojson={feature}
36
+ class={cls('fill-transparent', classes.path)}
37
+ on:mousemove={(e) =>
38
+ dispatch('mousemove', { event: e, data: feature.properties.site.data, feature })}
39
+ on:mouseleave
40
+ on:click={(e) => dispatch('click', { data: feature.properties.site.data, feature })}
41
+ />
42
+ {/each}
43
+ {:else}
44
+ {@const voronoi = Delaunay.from(points).voronoi([0, 0, boundWidth, boundHeight])}
45
+ {#each points as point, i}
46
+ <path
47
+ d={voronoi.renderCell(i)}
48
+ class={cls('fill-transparent', classes.path)}
49
+ on:mousemove={(e) => dispatch('mousemove', { event: e, data: point.data, point })}
50
+ on:mouseleave
51
+ on:click={(e) => dispatch('click', { data: point.data, point })}
52
+ />
53
+ {/each}
54
+ {/if}
33
55
  </g>
@@ -1,4 +1,5 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
+ import type { GeoPermissibleObjects } from 'd3-geo';
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  [x: string]: any;
@@ -11,15 +12,15 @@ declare const __propDef: {
11
12
  events: {
12
13
  mouseleave: MouseEvent;
13
14
  click: CustomEvent<{
14
- point: {
15
- data: any;
16
- };
15
+ data: any;
16
+ point?: [number, number] | undefined;
17
+ feature?: GeoPermissibleObjects | undefined;
17
18
  }>;
18
19
  mousemove: CustomEvent<{
19
- point: {
20
- data: any;
21
- };
22
20
  event: MouseEvent;
21
+ data: any;
22
+ point?: [number, number] | undefined;
23
+ feature?: GeoPermissibleObjects | undefined;
23
24
  }>;
24
25
  } & {
25
26
  [evt: string]: CustomEvent<any>;
@@ -7,7 +7,7 @@ declare const __propDef: {
7
7
  spring?: boolean | Parameters<typeof motionStore>[1]['spring'];
8
8
  tweened?: boolean | Parameters<typeof motionStore>[1]['tweened'];
9
9
  disablePointer?: boolean | undefined;
10
- scroll?: "scale" | "translate" | "none" | undefined;
10
+ scroll?: "none" | "scale" | "translate" | undefined;
11
11
  clickDistance?: number | undefined;
12
12
  initialTranslate?: {
13
13
  x: number;
package/package.json CHANGED
@@ -4,14 +4,14 @@
4
4
  "author": "Sean Lynch <techniq35@gmail.com>",
5
5
  "license": "MIT",
6
6
  "repository": "techniq/layerchart",
7
- "version": "0.32.1",
7
+ "version": "0.32.3",
8
8
  "devDependencies": {
9
9
  "@changesets/cli": "^2.27.1",
10
10
  "@mdi/js": "^7.4.47",
11
11
  "@rollup/plugin-dsv": "^3.0.4",
12
12
  "@sveltejs/adapter-auto": "^3.1.1",
13
- "@sveltejs/kit": "^2.5.1",
14
- "@sveltejs/package": "^2.2.7",
13
+ "@sveltejs/kit": "^2.5.3",
14
+ "@sveltejs/package": "^2.3.0",
15
15
  "@svitejs/changesets-changelog-github-compact": "^1.1.0",
16
16
  "@tailwindcss/typography": "^0.5.10",
17
17
  "@types/d3-array": "^3.2.1",
@@ -32,14 +32,13 @@
32
32
  "@types/prismjs": "^1.26.3",
33
33
  "@types/shapefile": "^0.6.4",
34
34
  "@types/topojson-client": "^3.1.4",
35
- "autoprefixer": "^10.4.17",
36
- "d3-color": "^3.1.0",
35
+ "autoprefixer": "^10.4.18",
37
36
  "execa": "^8.0.1",
38
- "marked": "^12.0.0",
37
+ "marked": "^12.0.1",
39
38
  "mdsvex": "^0.11.0",
40
39
  "posthog-js": "^1.95.1",
41
40
  "prettier": "^3.2.5",
42
- "prettier-plugin-svelte": "^3.2.1",
41
+ "prettier-plugin-svelte": "^3.2.2",
43
42
  "prism-svelte": "^0.5.0",
44
43
  "prism-themes": "^1.9.0",
45
44
  "prismjs": "^1.29.0",
@@ -47,17 +46,17 @@
47
46
  "shapefile": "^0.6.6",
48
47
  "solar-calculator": "^0.3.0",
49
48
  "svelte": "^4.2.12",
50
- "svelte-check": "^3.6.4",
49
+ "svelte-check": "^3.6.6",
51
50
  "svelte-json-tree": "^2.2.0",
52
51
  "svelte-preprocess": "^5.1.3",
53
- "svelte2tsx": "^0.7.1",
52
+ "svelte2tsx": "^0.7.3",
54
53
  "tailwindcss": "^3.4.1",
55
54
  "topojson-client": "^3.1.0",
56
55
  "tslib": "^2.6.2",
57
- "typescript": "^5.3.3",
56
+ "typescript": "^5.4.2",
58
57
  "unist-util-visit": "^5.0.0",
59
58
  "us-atlas": "^3.0.1",
60
- "vite": "^5.1.4"
59
+ "vite": "^5.1.5"
61
60
  },
62
61
  "type": "module",
63
62
  "dependencies": {
@@ -67,6 +66,7 @@
67
66
  "d3-delaunay": "^6.0.4",
68
67
  "d3-dsv": "^3.0.1",
69
68
  "d3-geo": "^3.1.0",
69
+ "d3-geo-voronoi": "^2.0.1",
70
70
  "d3-hierarchy": "^3.1.2",
71
71
  "d3-interpolate": "^3.0.1",
72
72
  "d3-interpolate-path": "^2.3.0",
@@ -78,12 +78,12 @@
78
78
  "d3-shape": "^3.2.0",
79
79
  "d3-tile": "^1.0.0",
80
80
  "d3-time": "^3.1.0",
81
- "date-fns": "^3.3.1",
82
- "layercake": "^8.0.2",
81
+ "date-fns": "^3.4.0",
82
+ "layercake": "^8.0.3",
83
83
  "lodash-es": "^4.17.21",
84
- "posthog-js": "^1.108.3",
84
+ "posthog-js": "^1.113.0",
85
85
  "shapefile": "^0.6.6",
86
- "svelte-ux": "^0.61.2",
86
+ "svelte-ux": "^0.61.5",
87
87
  "topojson-client": "^3.1.0"
88
88
  },
89
89
  "peerDependencies": {