layerchart 0.32.3 → 0.34.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.
@@ -18,7 +18,7 @@ export let grid = false;
18
18
  /** Control the number of ticks*/
19
19
  export let ticks = placement === 'left' || placement === 'right' ? 4 : undefined;
20
20
  /** Length of the tick line */
21
- export let tickSize = 4;
21
+ export let tickLength = 4;
22
22
  export let format = undefined;
23
23
  export let labelProps = undefined;
24
24
  export let spring = undefined;
@@ -38,9 +38,11 @@ $: [xRangeMin, xRangeMax] = extent($xRange);
38
38
  $: [yRangeMin, yRangeMax] = extent($yRange);
39
39
  $: tickVals = Array.isArray(ticks)
40
40
  ? ticks
41
- : isScaleBand(scale)
42
- ? scale.domain()
43
- : scale.ticks(typeof ticks === 'function' ? ticks(scale) : ticks);
41
+ : typeof ticks === 'function'
42
+ ? ticks(scale)
43
+ : isScaleBand(scale)
44
+ ? scale.domain()
45
+ : scale.ticks(ticks);
44
46
  function getCoords(tick) {
45
47
  switch (placement) {
46
48
  case 'top':
@@ -222,7 +224,7 @@ function getDefaultLabelProps(tick) {
222
224
  x1={tickCoords.x}
223
225
  y1={tickCoords.y}
224
226
  x2={tickCoords.x}
225
- y2={tickCoords.y + (placement === 'top' ? -tickSize : tickSize)}
227
+ y2={tickCoords.y + (placement === 'top' ? -tickLength : tickLength)}
226
228
  {tweened}
227
229
  {spring}
228
230
  class="tick stroke-surface-content/50"
@@ -231,7 +233,7 @@ function getDefaultLabelProps(tick) {
231
233
  <Line
232
234
  x1={tickCoords.x}
233
235
  y1={tickCoords.y}
234
- x2={tickCoords.x + (placement === 'left' ? -tickSize : tickSize)}
236
+ x2={tickCoords.x + (placement === 'left' ? -tickLength : tickLength)}
235
237
  y2={tickCoords.y}
236
238
  {tweened}
237
239
  {spring}
@@ -11,7 +11,7 @@ declare const __propDef: {
11
11
  /** Draw a rule line. Use Rule component for greater rendering order control */ rule?: boolean | SVGAttributes<SVGLineElement> | undefined;
12
12
  /** Draw a grid lines */ grid?: boolean | SVGAttributes<SVGLineElement> | undefined;
13
13
  /** Control the number of ticks*/ ticks?: number | any[] | Function | undefined;
14
- /** Length of the tick line */ tickSize?: number | undefined;
14
+ /** Length of the tick line */ tickLength?: number | undefined;
15
15
  format?: FormatType | undefined;
16
16
  labelProps?: Partial<ComponentProps<Text>> | undefined;
17
17
  spring?: boolean | Parameters<typeof springStore>[1];
@@ -91,32 +91,8 @@ export let geo = undefined;
91
91
  let:flatData
92
92
  >
93
93
  <GeoContext {...geo} let:projection>
94
- {#if tooltip}
95
- {@const tooltipProps = typeof tooltip === 'object' ? tooltip : {}}
96
- <TooltipContext {...tooltipProps} let:tooltip>
97
- <slot
98
- {aspectRatio}
99
- {containerHeight}
100
- {containerWidth}
101
- {height}
102
- {width}
103
- {element}
104
- {projection}
105
- {tooltip}
106
- {xScale}
107
- {xGet}
108
- {yScale}
109
- {yGet}
110
- {zScale}
111
- {zGet}
112
- {rScale}
113
- {rGet}
114
- {padding}
115
- {data}
116
- {flatData}
117
- />
118
- </TooltipContext>
119
- {:else}
94
+ {@const tooltipProps = typeof tooltip === 'object' ? tooltip : {}}
95
+ <TooltipContext {...tooltipProps} let:tooltip>
120
96
  <slot
121
97
  {aspectRatio}
122
98
  {containerHeight}
@@ -125,6 +101,7 @@ export let geo = undefined;
125
101
  {width}
126
102
  {element}
127
103
  {projection}
104
+ {tooltip}
128
105
  {xScale}
129
106
  {xGet}
130
107
  {yScale}
@@ -137,6 +114,6 @@ export let geo = undefined;
137
114
  {data}
138
115
  {flatData}
139
116
  />
140
- {/if}
117
+ </TooltipContext>
141
118
  </GeoContext>
142
119
  </LayerCake>
@@ -31,6 +31,13 @@ declare const __propDef: {
31
31
  width: number;
32
32
  element: Element;
33
33
  projection: import("d3-geo").GeoProjection | import("d3-geo").GeoIdentityTransform;
34
+ tooltip: {
35
+ y: number;
36
+ x: number;
37
+ data: null;
38
+ show: (event: MouseEvent | TouchEvent, tooltipData?: any) => void;
39
+ hide: () => void;
40
+ };
34
41
  xScale: any;
35
42
  xGet: any;
36
43
  yScale: any;
@@ -9,4 +9,4 @@ export let precision = 6;
9
9
  $: geojson = geoCircle().radius(radius).center(center).precision(precision)();
10
10
  </script>
11
11
 
12
- <GeoPath {geojson} {...$$restProps} />
12
+ <GeoPath {geojson} {...$$restProps} on:mousemove on:mouseleave on:click />
@@ -7,6 +7,10 @@ declare const __propDef: {
7
7
  precision?: number | undefined;
8
8
  };
9
9
  events: {
10
+ mousemove: MouseEvent;
11
+ mouseleave: MouseEvent;
12
+ click: CustomEvent<any>;
13
+ } & {
10
14
  [evt: string]: CustomEvent<any>;
11
15
  };
12
16
  slots: {};
@@ -13,7 +13,7 @@ function setGeoContext(geo) {
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
15
  export let projection = undefined;
16
- export let fitGeojson;
16
+ export let fitGeojson = undefined;
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;
19
19
  export let clipAngle = undefined;
@@ -22,6 +22,8 @@ export let rotate = undefined;
22
22
  export let scale = undefined;
23
23
  export let translate = undefined;
24
24
  export let center = undefined;
25
+ export let reflectX = undefined;
26
+ export let reflectY = undefined;
25
27
  const geo = writable(projection?.());
26
28
  setGeoContext(geo);
27
29
  $: fitSizeRange = (fixedAspectRatio ? [100, 100 / fixedAspectRatio] : [$width, $height]);
@@ -42,6 +44,12 @@ $: if (projection) {
42
44
  if (center && 'center' in _projection) {
43
45
  _projection.center(center);
44
46
  }
47
+ if (reflectX) {
48
+ _projection.reflectX(reflectX);
49
+ }
50
+ if (reflectY) {
51
+ _projection.reflectY(reflectY);
52
+ }
45
53
  if (clipAngle && 'clipAngle' in _projection) {
46
54
  _projection.clipAngle(clipAngle);
47
55
  }
@@ -7,7 +7,7 @@ export declare function geoContext(): GeoContext;
7
7
  declare const __propDef: {
8
8
  props: {
9
9
  /** @type {Function} projection - A d3 projection function. Pass this in as an uncalled function, e.g. `projection={geoAlbersUsa}`. */ projection?: (() => GeoProjection | GeoIdentityTransform) | undefined;
10
- fitGeojson: GeoPermissibleObjects;
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;
13
13
  clipExtent?: [[number, number], [number, number]] | undefined;
@@ -22,6 +22,8 @@ declare const __propDef: {
22
22
  scale?: number | undefined;
23
23
  translate?: [number, number] | undefined;
24
24
  center?: [number, number] | undefined;
25
+ reflectX?: boolean | undefined;
26
+ reflectY?: boolean | undefined;
25
27
  };
26
28
  events: {
27
29
  [evt: string]: CustomEvent<any>;
@@ -14,7 +14,7 @@ export let ticks = width / 64;
14
14
  export let tickFormat = undefined;
15
15
  export let tickValues = undefined;
16
16
  export let tickFontSize = 10;
17
- export let tickSize = 4;
17
+ export let tickLength = 4;
18
18
  export let placement = undefined;
19
19
  export let classes = {};
20
20
  $: if (scale == null && rScale) {
@@ -96,7 +96,7 @@ else {
96
96
  tickValues = scale.domain();
97
97
  tickLabelOffset = xScale.bandwidth() / 2;
98
98
  tickLine = false;
99
- tickSize = 0;
99
+ tickLength = 0;
100
100
  }
101
101
  </script>
102
102
 
@@ -126,8 +126,8 @@ else {
126
126
  <slot values={tickValues} {scale}>
127
127
  <svg
128
128
  {width}
129
- height={height + tickSize + tickFontSize}
130
- viewBox="0 0 {width} {height + tickSize + tickFontSize}"
129
+ height={height + tickLength + tickFontSize}
130
+ viewBox="0 0 {width} {height + tickLength + tickFontSize}"
131
131
  class="overflow-visible"
132
132
  >
133
133
  <g>
@@ -145,7 +145,7 @@ else {
145
145
  <text
146
146
  text-anchor="middle"
147
147
  x={xScale(tick) + tickLabelOffset}
148
- y={height + tickSize + tickFontSize}
148
+ y={height + tickLength + tickFontSize}
149
149
  style:font-size={tickFontSize}
150
150
  class={cls('fill-surface-content', classes.label)}
151
151
  >
@@ -157,7 +157,7 @@ else {
157
157
  x1={xScale(tick)}
158
158
  y1={0}
159
159
  x2={xScale(tick)}
160
- y2={height + tickSize}
160
+ y2={height + tickLength}
161
161
  class={cls('stroke-surface-content', classes.tick)}
162
162
  />
163
163
  {/if}
@@ -11,7 +11,7 @@ declare const __propDef: {
11
11
  tickFormat?: FormatType | undefined;
12
12
  tickValues?: any[] | undefined;
13
13
  tickFontSize?: number | undefined;
14
- tickSize?: number | undefined;
14
+ tickLength?: number | undefined;
15
15
  placement?: ("center" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
16
16
  classes?: {
17
17
  root?: string | undefined;
@@ -40,7 +40,7 @@ const { flatData, x, xScale, xGet, xRange, y, yScale, yGet, yRange, width, heigh
40
40
  /**
41
41
  * @type {'bisect-x' | 'bisect-y' | 'band' | 'bisect-band' | 'bounds' | 'voronoi' | 'quadtree' | 'manual'}
42
42
  */
43
- export let mode = 'bisect-x';
43
+ export let mode = 'manual';
44
44
  /**
45
45
  * @type {'closest' | 'left' | 'right'}
46
46
  */
@@ -22,10 +22,10 @@ export function reset() {
22
22
  $translate = initialTranslate;
23
23
  $scale = initialScale;
24
24
  }
25
- export function increase() {
25
+ export function zoomIn() {
26
26
  scaleTo(1.25, { x: $width / 2, y: $height / 2 });
27
27
  }
28
- export function decrease() {
28
+ export function zoomOut() {
29
29
  scaleTo(0.8, { x: $width / 2, y: $height / 2 });
30
30
  }
31
31
  export function translateCenter() {
@@ -47,17 +47,21 @@ export function zoomTo(center, rect) {
47
47
  function onMouseDown(e) {
48
48
  if (disablePointer)
49
49
  return;
50
+ e.preventDefault();
50
51
  dragging = true;
51
52
  moved = false;
52
53
  svgEl = e.currentTarget.ownerSVGElement; // capture for reference in mousemove event
53
54
  startPoint = localPoint(svgEl, e);
54
55
  startTranslate = $translate;
55
- window.addEventListener('mousemove', onMouseMove);
56
+ window.addEventListener('mousemove', onMouseMove, { capture: true });
56
57
  window.addEventListener('mouseup', onMouseUp);
58
+ dispatch('dragstart');
57
59
  }
58
60
  function onMouseMove(e) {
59
61
  if (!dragging)
60
62
  return;
63
+ e.preventDefault(); // Stop text selection
64
+ e.stopPropagation(); // Stop tooltip from trigging (along with `capture: true`)
61
65
  const endPoint = localPoint(svgEl, e);
62
66
  const deltaX = endPoint.x - startPoint.x;
63
67
  const deltaY = endPoint.y - startPoint.y;
@@ -74,6 +78,7 @@ function onMouseUp(e) {
74
78
  dragging = false;
75
79
  window.removeEventListener('mousemove', onMouseMove);
76
80
  window.removeEventListener('mouseup', onMouseUp);
81
+ dispatch('dragend');
77
82
  }
78
83
  function onClick(e) {
79
84
  if (moved) {
@@ -159,7 +164,7 @@ $: if (mode === 'svg') {
159
164
  };
160
165
  transform = `translate(${newTranslate.x},${newTranslate.y}) scale(${$scale})`;
161
166
  }
162
- $: dispatch('zoom', { scale: $scale, translate: $translate });
167
+ $: dispatch('transform', { scale: $scale, translate: $translate });
163
168
  </script>
164
169
 
165
170
  <g
@@ -15,8 +15,8 @@ declare const __propDef: {
15
15
  } | undefined;
16
16
  initialScale?: number | undefined;
17
17
  reset?: (() => void) | undefined;
18
- increase?: (() => void) | undefined;
19
- decrease?: (() => void) | undefined;
18
+ zoomIn?: (() => void) | undefined;
19
+ zoomOut?: (() => void) | undefined;
20
20
  translateCenter?: (() => void) | undefined;
21
21
  zoomTo?: ((center: {
22
22
  x: number;
@@ -31,7 +31,9 @@ declare const __propDef: {
31
31
  keydown: KeyboardEvent;
32
32
  keyup: KeyboardEvent;
33
33
  keypress: KeyboardEvent;
34
- zoom: CustomEvent<{
34
+ dragstart: CustomEvent<null>;
35
+ dragend: CustomEvent<null>;
36
+ transform: CustomEvent<{
35
37
  scale: number;
36
38
  translate: {
37
39
  x: number;
@@ -55,13 +57,13 @@ declare const __propDef: {
55
57
  };
56
58
  };
57
59
  };
58
- export type ZoomProps = typeof __propDef.props;
59
- export type ZoomEvents = typeof __propDef.events;
60
- export type ZoomSlots = typeof __propDef.slots;
61
- export default class Zoom extends SvelteComponentTyped<ZoomProps, ZoomEvents, ZoomSlots> {
60
+ export type TransformProps = typeof __propDef.props;
61
+ export type TransformEvents = typeof __propDef.events;
62
+ export type TransformSlots = typeof __propDef.slots;
63
+ export default class Transform extends SvelteComponentTyped<TransformProps, TransformEvents, TransformSlots> {
62
64
  get reset(): () => void;
63
- get increase(): () => void;
64
- get decrease(): () => void;
65
+ get zoomIn(): () => void;
66
+ get zoomOut(): () => void;
65
67
  get translateCenter(): () => void;
66
68
  get zoomTo(): (center: {
67
69
  x: number;
@@ -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" | "binary" | "dice" | d3.RatioSquarifyTilingFactory | "squarify" | "resquarify" | "sliceDice" | undefined;
5
+ tile?: "slice" | d3.RatioSquarifyTilingFactory | "binary" | "squarify" | "resquarify" | "dice" | "sliceDice" | undefined;
6
6
  padding?: number | undefined;
7
7
  paddingInner?: number | undefined;
8
8
  paddingOuter?: number | undefined;
@@ -50,4 +50,4 @@ export { default as TooltipSeparator } from './TooltipSeparator.svelte';
50
50
  export { default as Tree } from './Tree.svelte';
51
51
  export { default as Treemap } from './Treemap.svelte';
52
52
  export { default as Voronoi } from './Voronoi.svelte';
53
- export { default as Zoom } from './Zoom.svelte';
53
+ export { default as Transform } from './Transform.svelte';
@@ -50,4 +50,4 @@ export { default as TooltipSeparator } from './TooltipSeparator.svelte';
50
50
  export { default as Tree } from './Tree.svelte';
51
51
  export { default as Treemap } from './Treemap.svelte';
52
52
  export { default as Voronoi } from './Voronoi.svelte';
53
- export { default as Zoom } from './Zoom.svelte';
53
+ export { default as Transform } from './Transform.svelte';
@@ -1,6 +1,6 @@
1
1
  <script>import { Button, Tooltip, cls } from 'svelte-ux';
2
2
  import { mdiArrowULeftTop, mdiMagnifyPlusOutline, mdiMagnifyMinusOutline, mdiImageFilterCenterFocus, } from '@mdi/js';
3
- export let zoom;
3
+ export let transform;
4
4
  export let placement = 'top-right';
5
5
  export let orientation = 'vertical';
6
6
  </script>
@@ -25,28 +25,28 @@ export let orientation = 'vertical';
25
25
  <Tooltip title="Zoom in">
26
26
  <Button
27
27
  icon={mdiMagnifyPlusOutline}
28
- on:click={() => zoom.increase()}
28
+ on:click={() => transform.zoomIn()}
29
29
  class="text-surface-content/50 p-2"
30
30
  />
31
31
  </Tooltip>
32
32
  <Tooltip title="Zoom out">
33
33
  <Button
34
34
  icon={mdiMagnifyMinusOutline}
35
- on:click={() => zoom.decrease()}
35
+ on:click={() => transform.zoomOut()}
36
36
  class="text-surface-content/50 p-2"
37
37
  />
38
38
  </Tooltip>
39
39
  <Tooltip title="Center">
40
40
  <Button
41
41
  icon={mdiImageFilterCenterFocus}
42
- on:click={() => zoom.translateCenter()}
42
+ on:click={() => transform.translateCenter()}
43
43
  class="text-surface-content/50 p-2"
44
44
  />
45
45
  </Tooltip>
46
46
  <Tooltip title="Reset">
47
47
  <Button
48
48
  icon={mdiArrowULeftTop}
49
- on:click={() => zoom.reset()}
49
+ on:click={() => transform.reset()}
50
50
  class="text-surface-content/50 p-2"
51
51
  />
52
52
  </Tooltip>
@@ -0,0 +1,19 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type Transform from '../components/Transform.svelte';
3
+ declare const __propDef: {
4
+ props: {
5
+ transform: Transform;
6
+ placement?: ("center" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
7
+ orientation?: "horizontal" | "vertical" | undefined;
8
+ };
9
+ events: {
10
+ [evt: string]: CustomEvent<any>;
11
+ };
12
+ slots: {};
13
+ };
14
+ export type TransformControlsProps = typeof __propDef.props;
15
+ export type TransformControlsEvents = typeof __propDef.events;
16
+ export type TransformControlsSlots = typeof __propDef.slots;
17
+ export default class TransformControls extends SvelteComponentTyped<TransformControlsProps, TransformControlsEvents, TransformControlsSlots> {
18
+ }
19
+ export {};
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "Sean Lynch <techniq35@gmail.com>",
5
5
  "license": "MIT",
6
6
  "repository": "techniq/layerchart",
7
- "version": "0.32.3",
7
+ "version": "0.34.0",
8
8
  "devDependencies": {
9
9
  "@changesets/cli": "^2.27.1",
10
10
  "@mdi/js": "^7.4.47",
@@ -46,17 +46,17 @@
46
46
  "shapefile": "^0.6.6",
47
47
  "solar-calculator": "^0.3.0",
48
48
  "svelte": "^4.2.12",
49
- "svelte-check": "^3.6.6",
49
+ "svelte-check": "^3.6.7",
50
50
  "svelte-json-tree": "^2.2.0",
51
51
  "svelte-preprocess": "^5.1.3",
52
- "svelte2tsx": "^0.7.3",
52
+ "svelte2tsx": "^0.7.4",
53
53
  "tailwindcss": "^3.4.1",
54
54
  "topojson-client": "^3.1.0",
55
55
  "tslib": "^2.6.2",
56
56
  "typescript": "^5.4.2",
57
57
  "unist-util-visit": "^5.0.0",
58
58
  "us-atlas": "^3.0.1",
59
- "vite": "^5.1.5"
59
+ "vite": "^5.1.6"
60
60
  },
61
61
  "type": "module",
62
62
  "dependencies": {
@@ -65,7 +65,7 @@
65
65
  "d3-color": "^3.1.0",
66
66
  "d3-delaunay": "^6.0.4",
67
67
  "d3-dsv": "^3.0.1",
68
- "d3-geo": "^3.1.0",
68
+ "d3-geo": "^3.1.1",
69
69
  "d3-geo-voronoi": "^2.0.1",
70
70
  "d3-hierarchy": "^3.1.2",
71
71
  "d3-interpolate": "^3.0.1",
@@ -74,16 +74,16 @@
74
74
  "d3-random": "^3.0.1",
75
75
  "d3-sankey": "^0.12.3",
76
76
  "d3-scale": "^4.0.2",
77
- "d3-scale-chromatic": "^3.0.0",
77
+ "d3-scale-chromatic": "^3.1.0",
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.4.0",
82
- "layercake": "^8.0.3",
81
+ "date-fns": "^3.6.0",
82
+ "layercake": "^8.1.1",
83
83
  "lodash-es": "^4.17.21",
84
- "posthog-js": "^1.113.0",
84
+ "posthog-js": "^1.116.0",
85
85
  "shapefile": "^0.6.6",
86
- "svelte-ux": "^0.61.5",
86
+ "svelte-ux": "^0.62.0",
87
87
  "topojson-client": "^3.1.0"
88
88
  },
89
89
  "peerDependencies": {
@@ -1,19 +0,0 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- import type Zoom from '../components/Zoom.svelte';
3
- declare const __propDef: {
4
- props: {
5
- zoom: Zoom;
6
- placement?: ("center" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
7
- orientation?: "horizontal" | "vertical" | undefined;
8
- };
9
- events: {
10
- [evt: string]: CustomEvent<any>;
11
- };
12
- slots: {};
13
- };
14
- export type ZoomControlsProps = typeof __propDef.props;
15
- export type ZoomControlsEvents = typeof __propDef.events;
16
- export type ZoomControlsSlots = typeof __propDef.slots;
17
- export default class ZoomControls extends SvelteComponentTyped<ZoomControlsProps, ZoomControlsEvents, ZoomControlsSlots> {
18
- }
19
- export {};