layerchart 0.22.2 → 0.24.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 (32) hide show
  1. package/README.md +2 -0
  2. package/dist/components/Area.svelte.d.ts +43 -0
  3. package/dist/components/Blur.svelte +1 -1
  4. package/dist/components/Blur.svelte.d.ts +1 -0
  5. package/dist/components/Calendar.svelte +75 -0
  6. package/dist/components/Calendar.svelte.d.ts +35 -0
  7. package/dist/components/Chart.svelte +3 -0
  8. package/dist/components/Chart.svelte.d.ts +11 -0
  9. package/dist/components/CircleClipPath.svelte +2 -2
  10. package/dist/components/CircleClipPath.svelte.d.ts +1 -0
  11. package/dist/components/ClipPath.svelte +1 -1
  12. package/dist/components/ClipPath.svelte.d.ts +1 -0
  13. package/dist/components/Highlight.svelte.d.ts +74 -0
  14. package/dist/components/Legend.svelte +7 -6
  15. package/dist/components/LinearGradient.svelte +15 -15
  16. package/dist/components/LinearGradient.svelte.d.ts +2 -3
  17. package/dist/components/MonthPath.svelte +25 -0
  18. package/dist/components/MonthPath.svelte.d.ts +18 -0
  19. package/dist/components/Points.svelte.d.ts +35 -0
  20. package/dist/components/Rect.svelte.d.ts +37 -0
  21. package/dist/components/RectClipPath.svelte +2 -2
  22. package/dist/components/RectClipPath.svelte.d.ts +1 -0
  23. package/dist/components/Tooltip.svelte +24 -12
  24. package/dist/components/Tooltip.svelte.d.ts +2 -0
  25. package/dist/components/index.d.ts +1 -0
  26. package/dist/components/index.js +1 -0
  27. package/dist/docs/ViewSourceButton.svelte +1 -1
  28. package/dist/stores/motionStore.d.ts +1 -0
  29. package/dist/utils/pivot.d.ts +5 -5
  30. package/dist/utils/rect.d.ts +1 -0
  31. package/dist/utils/scales.d.ts +4 -3
  32. package/package.json +32 -26
package/README.md CHANGED
@@ -23,6 +23,8 @@ Others
23
23
 
24
24
  - Legends including ColorRamps
25
25
 
26
+ See also [Svelte UX](http://svelte-ux.techniq.dev) for a large collection of components, actions, stores, and utilities to build highly interactive applications.
27
+
26
28
  ## Publishing
27
29
 
28
30
  - `npm run changeset` for each changelog worthy change
@@ -0,0 +1,43 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { tweened as tweenedStore } from 'svelte/motion';
3
+ import { type Area } from 'd3-shape';
4
+ import type { CurveFactory } from 'd3-shape';
5
+ declare const __propDef: {
6
+ props: {
7
+ [x: string]: any;
8
+ data?: any;
9
+ pathData?: string | undefined | null;
10
+ x?: any;
11
+ y0?: any;
12
+ y1?: any;
13
+ tweened?: boolean | Parameters<typeof tweenedStore>[1];
14
+ clipPath?: string | undefined;
15
+ curve?: CurveFactory | undefined;
16
+ defined?: Parameters<Area<any>['defined']>[0] | undefined;
17
+ line?: boolean | {
18
+ [x: string]: any;
19
+ data?: any;
20
+ pathData?: string | null | undefined;
21
+ x?: any;
22
+ y?: any;
23
+ tweened?: boolean | import("svelte/motion").TweenedOptions<unknown> | undefined;
24
+ draw?: boolean | import("svelte/transition").DrawParams | undefined;
25
+ curve?: CurveFactory | import("d3-shape").CurveFactoryLineOnly | undefined;
26
+ defined?: ((d: any, index: number, data: any[]) => boolean) | undefined;
27
+ } | undefined;
28
+ };
29
+ events: {
30
+ click: MouseEvent;
31
+ mousemove: MouseEvent;
32
+ mouseleave: MouseEvent;
33
+ } & {
34
+ [evt: string]: CustomEvent<any>;
35
+ };
36
+ slots: {};
37
+ };
38
+ export type AreaProps = typeof __propDef.props;
39
+ export type AreaEvents = typeof __propDef.events;
40
+ export type AreaSlots = typeof __propDef.slots;
41
+ export default class Area extends SvelteComponentTyped<AreaProps, AreaEvents, AreaSlots> {
42
+ }
43
+ export {};
@@ -11,6 +11,6 @@ export let stdDeviation = 5;
11
11
 
12
12
  {#if $$slots.default}
13
13
  <g filter="url(#{id})">
14
- <slot {id} />
14
+ <slot {id} url="url(#{id})" />
15
15
  </g>
16
16
  {/if}
@@ -10,6 +10,7 @@ declare const __propDef: {
10
10
  slots: {
11
11
  default: {
12
12
  id: string;
13
+ url: string;
13
14
  };
14
15
  };
15
16
  };
@@ -0,0 +1,75 @@
1
+ <script>import { getContext } from 'svelte';
2
+ import { timeDays, timeMonths, timeWeek, timeYear, utcYear } from 'd3-time';
3
+ import { index } from 'd3-array';
4
+ import { format } from 'date-fns';
5
+ import Rect from './Rect.svelte';
6
+ import MonthPath from './MonthPath.svelte';
7
+ import Text from './Text.svelte';
8
+ export let start;
9
+ export let end;
10
+ /**
11
+ * Size of cell. If `number`, sets width/height as same value (square). If array, sets as [width,height]. If undefined, is derived from Chart width/height
12
+ */
13
+ export let cellSize = undefined;
14
+ /** Enable drawing path around each month. If object, pass as props to underlying <path> */
15
+ export let monthPath = false;
16
+ /**
17
+ * Tooltip context to setup mouse events to show tooltip for related data
18
+ */
19
+ export let tooltip = undefined;
20
+ const { width, height, x, rGet, data, config } = getContext('LayerCake');
21
+ $: yearDays = timeDays(start, end);
22
+ $: yearMonths = timeMonths(start, end);
23
+ $: yearWeeks = timeWeek.count(start, end);
24
+ $: chartCellWidth = $width / (yearWeeks + 1);
25
+ $: chartCellHeight = $height / 7;
26
+ $: chartCellSize = Math.min(chartCellWidth, chartCellHeight); // Use smallest to fit, and keep square aspect
27
+ $: [cellWidth, cellHeight] = Array.isArray(cellSize)
28
+ ? cellSize
29
+ : typeof cellSize === 'number'
30
+ ? [cellSize, cellSize]
31
+ : [chartCellSize, chartCellSize];
32
+ $: dataByDate = data && $config.x ? index($data, (d) => $x(d)) : new Map();
33
+ $: cells = yearDays.map((date) => {
34
+ const cellData = dataByDate.get(date) ?? { date };
35
+ return {
36
+ x: timeWeek.count(timeYear(date), date) * cellWidth,
37
+ y: date.getDay() * cellHeight,
38
+ color: $config.r ? $rGet(cellData) : 'transparent',
39
+ data: cellData,
40
+ };
41
+ });
42
+ </script>
43
+
44
+ <slot {cells}>
45
+ {#each cells as cell}
46
+ <Rect
47
+ x={cell.x}
48
+ y={cell.y}
49
+ width={cellWidth}
50
+ height={cellHeight}
51
+ fill={cell.color}
52
+ on:mousemove={(e) => tooltip?.show(e, cell.data)}
53
+ on:mouseleave={(e) => tooltip?.hide()}
54
+ class="stroke-black/5"
55
+ {...$$restProps}
56
+ />
57
+ {/each}
58
+ </slot>
59
+
60
+ {#if monthPath}
61
+ {#each yearMonths as date}
62
+ <MonthPath
63
+ {date}
64
+ cellSize={[cellWidth, cellHeight]}
65
+ {...typeof monthPath === 'object' ? monthPath : null}
66
+ />
67
+
68
+ <Text
69
+ x={timeWeek.count(timeYear.floor(date), timeWeek.ceil(date)) * cellWidth}
70
+ y={-4}
71
+ value={format(date, 'MMM')}
72
+ class="text-xs"
73
+ />
74
+ {/each}
75
+ {/if}
@@ -0,0 +1,35 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { TooltipContextValue } from './TooltipContext.svelte';
3
+ declare const __propDef: {
4
+ props: {
5
+ [x: string]: any;
6
+ start: Date;
7
+ end: Date;
8
+ cellSize?: number | [number, number] | undefined;
9
+ monthPath?: boolean | {
10
+ [x: string]: any;
11
+ date: Date;
12
+ cellSize: number | [number, number];
13
+ } | undefined;
14
+ tooltip?: TooltipContextValue | undefined;
15
+ };
16
+ events: {
17
+ [evt: string]: CustomEvent<any>;
18
+ };
19
+ slots: {
20
+ default: {
21
+ cells: {
22
+ x: number;
23
+ y: number;
24
+ color: any;
25
+ data: any;
26
+ }[];
27
+ };
28
+ };
29
+ };
30
+ export type CalendarProps = typeof __propDef.props;
31
+ export type CalendarEvents = typeof __propDef.events;
32
+ export type CalendarSlots = typeof __propDef.slots;
33
+ export default class Calendar extends SvelteComponentTyped<CalendarProps, CalendarEvents, CalendarSlots> {
34
+ }
35
+ export {};
@@ -82,6 +82,7 @@ export let geo = undefined;
82
82
  let:yScale
83
83
  let:zScale
84
84
  let:rScale
85
+ let:padding
85
86
  >
86
87
  <GeoContext {...geo} let:projection>
87
88
  {#if tooltip}
@@ -99,6 +100,7 @@ export let geo = undefined;
99
100
  {yScale}
100
101
  {zScale}
101
102
  {rScale}
103
+ {padding}
102
104
  />
103
105
  </TooltipContext>
104
106
  {:else}
@@ -114,6 +116,7 @@ export let geo = undefined;
114
116
  {yScale}
115
117
  {zScale}
116
118
  {rScale}
119
+ {padding}
117
120
  />
118
121
  {/if}
119
122
  </GeoContext>
@@ -35,6 +35,17 @@ declare const __propDef: {
35
35
  yScale: any;
36
36
  zScale: any;
37
37
  rScale: any;
38
+ padding: {
39
+ top: number;
40
+ right: number;
41
+ bottom: number;
42
+ left: number;
43
+ } & {
44
+ top?: number | undefined;
45
+ right?: number | undefined;
46
+ bottom?: number | undefined;
47
+ left?: number | undefined;
48
+ };
38
49
  };
39
50
  };
40
51
  };
@@ -10,7 +10,7 @@ export let spring = undefined;
10
10
  export let tweened = undefined;
11
11
  </script>
12
12
 
13
- <ClipPath {id}>
13
+ <ClipPath {id} let:url>
14
14
  <Circle slot="clip" {cx} {cy} {r} {spring} {tweened} {...$$restProps} />
15
- <slot {id} />
15
+ <slot {id} {url} />
16
16
  </ClipPath>
@@ -16,6 +16,7 @@ declare const __propDef: {
16
16
  slots: {
17
17
  default: {
18
18
  id: string;
19
+ url: string;
19
20
  };
20
21
  };
21
22
  };
@@ -17,6 +17,6 @@ export let useId = undefined;
17
17
 
18
18
  {#if $$slots.default}
19
19
  <g style:clip-path="url(#{id})" on:click on:mousemove on:mouseleave on:keydown>
20
- <slot {id} {useId} />
20
+ <slot {id} url="url(#{id})" {useId} />
21
21
  </g>
22
22
  {/if}
@@ -19,6 +19,7 @@ declare const __propDef: {
19
19
  };
20
20
  default: {
21
21
  id: string;
22
+ url: string;
22
23
  useId: string | undefined;
23
24
  };
24
25
  };
@@ -0,0 +1,74 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ axis?: 'x' | 'y' | 'both' | 'none' | undefined;
5
+ /** Show points and pass props to Circles */ points?: boolean | {
6
+ [x: string]: any;
7
+ cx?: number | undefined;
8
+ initialCx?: number | undefined;
9
+ cy?: number | undefined;
10
+ initialCy?: number | undefined;
11
+ r: number;
12
+ initialR?: number | undefined;
13
+ spring?: boolean | import("svelte/motion").SpringOpts | undefined;
14
+ tweened?: boolean | import("svelte/motion").TweenedOptions<unknown> | undefined;
15
+ } | undefined;
16
+ /** Show lines and pass props to Lines */ lines?: boolean | {
17
+ [x: string]: any;
18
+ x1: number;
19
+ initialX1?: number | undefined;
20
+ y1: number;
21
+ initialY1?: number | undefined;
22
+ x2: number;
23
+ initialX2?: number | undefined;
24
+ y2: number;
25
+ initialY2?: number | undefined;
26
+ spring?: boolean | import("svelte/motion").SpringOpts | undefined;
27
+ tweened?: boolean | import("svelte/motion").TweenedOptions<unknown> | undefined;
28
+ } | undefined;
29
+ /** Show area and pass props to Rect */ area?: boolean | {
30
+ [x: string]: any;
31
+ x?: number | undefined;
32
+ initialX?: number | undefined;
33
+ y?: number | undefined;
34
+ initialY?: number | undefined;
35
+ width: number;
36
+ initialWidth?: number | undefined;
37
+ height: number;
38
+ initialHeight?: number | undefined;
39
+ spring?: boolean | import("svelte/motion").SpringOpts | {
40
+ [prop: string]: import("svelte/motion").SpringOpts | undefined;
41
+ } | undefined;
42
+ tweened?: boolean | import("svelte/motion").TweenedOptions<unknown> | {
43
+ [prop: string]: import("svelte/motion").TweenedOptions<unknown> | undefined;
44
+ } | undefined;
45
+ } | undefined;
46
+ };
47
+ events: {
48
+ click: MouseEvent;
49
+ } & {
50
+ [evt: string]: CustomEvent<any>;
51
+ };
52
+ slots: {
53
+ area: {
54
+ area: {
55
+ x: number;
56
+ y: number;
57
+ width: number;
58
+ height: number;
59
+ };
60
+ };
61
+ lines: {
62
+ lines: any[];
63
+ };
64
+ points: {
65
+ points: any[];
66
+ };
67
+ };
68
+ };
69
+ export type HighlightProps = typeof __propDef.props;
70
+ export type HighlightEvents = typeof __propDef.events;
71
+ export type HighlightSlots = typeof __propDef.slots;
72
+ export default class Highlight extends SvelteComponentTyped<HighlightProps, HighlightEvents, HighlightSlots> {
73
+ }
74
+ export {};
@@ -41,7 +41,7 @@ else if (scale.interpolator) {
41
41
  xScale = Object.assign(scale.copy().interpolator(interpolateRound(0, width)), {
42
42
  range() {
43
43
  return [0, width];
44
- }
44
+ },
45
45
  });
46
46
  interpolator = scale.interpolator();
47
47
  // scaleSequentialQuantile doesn’t implement ticks or tickFormat.
@@ -72,7 +72,7 @@ else if (scale.invertExtent) {
72
72
  y: 0,
73
73
  width: xScale(i) - xScale(i - 1),
74
74
  height,
75
- fill: d
75
+ fill: d,
76
76
  };
77
77
  });
78
78
  tickValues = range(thresholds.length);
@@ -90,7 +90,7 @@ else {
90
90
  y: 0,
91
91
  width: Math.max(0, xScale.bandwidth() - 1),
92
92
  height,
93
- fill: scale(d)
93
+ fill: scale(d),
94
94
  };
95
95
  });
96
96
  tickValues = scale.domain();
@@ -101,6 +101,7 @@ else {
101
101
  </script>
102
102
 
103
103
  <div
104
+ {...$$restProps}
104
105
  class={cls(
105
106
  'inline-block',
106
107
  placement && [
@@ -114,12 +115,12 @@ else {
114
115
  right: 'top-1/2 right-0 -translate-y-1/2',
115
116
  'bottom-left': 'bottom-0 left-0',
116
117
  bottom: 'bottom-0 left-1/2 -translate-x-1/2',
117
- 'bottom-right': 'bottom-0 right-0'
118
- }[placement]
118
+ 'bottom-right': 'bottom-0 right-0',
119
+ }[placement],
119
120
  ],
121
+ $$restProps.class,
120
122
  classes.root
121
123
  )}
122
- {...$$restProps}
123
124
  >
124
125
  <div class={cls('text-[10px] font-semibold', classes.title)}>{title}</div>
125
126
  <slot values={tickValues} {scale}>
@@ -1,9 +1,12 @@
1
1
  <script>import { uniqueId } from 'svelte-ux';
2
2
  /** Unique id for linearGradient */
3
3
  export let id = uniqueId('linearGradient-');
4
- export let from;
5
- export let via = undefined; // TODO: Currently --tw-gradient-via is not the color but the full stops
6
- export let to;
4
+ /** Array array of strings (colors), will equally distributed from 0-100%. If array of tuples, will use first value as the offset, and second as color */
5
+ export let stops = [
6
+ 'var(--tw-gradient-from)',
7
+ 'var(--tw-gradient-to)',
8
+ ];
9
+ /** Apply color stops top-to-bottom (true) or left-to-right (false) */
7
10
  export let vertical = false;
8
11
  export let x1 = '0%';
9
12
  export let y1 = '0%';
@@ -26,20 +29,17 @@ export let units = 'objectBoundingBox';
26
29
  {...$$restProps}
27
30
  >
28
31
  <slot name="stops">
29
- {#if from}
30
- <stop offset="0%" stop-color={from === true ? 'var(--tw-gradient-from)' : from} />
31
- {/if}
32
-
33
- {#if via}
34
- <!-- <stop offset="50%" stop-color={via === true ? 'var(--tw-gradient-via)' : via} /> -->
35
- <stop offset="50%" stop-color={via} />
36
- {/if}
37
-
38
- {#if to}
39
- <stop offset="100%" stop-color={to === true ? 'var(--tw-gradient-to)' : to} />
32
+ {#if stops}
33
+ {#each stops as stop, i}
34
+ {#if Array.isArray(stop)}
35
+ <stop offset={stop[0]} stop-color={stop[1]} />
36
+ {:else}
37
+ <stop offset="{i * (100 / (stops.length - 1))}%" stop-color={stop} />
38
+ {/if}
39
+ {/each}
40
40
  {/if}
41
41
  </slot>
42
42
  </linearGradient>
43
43
  </defs>
44
44
 
45
- <slot {id} />
45
+ <slot {id} url="url(#{id})" />
@@ -3,9 +3,7 @@ declare const __propDef: {
3
3
  props: {
4
4
  [x: string]: any;
5
5
  id?: string | undefined;
6
- from: string | boolean;
7
- via?: string | boolean | undefined;
8
- to: string | boolean;
6
+ stops?: string[] | [string | number, string][] | undefined;
9
7
  vertical?: boolean | undefined;
10
8
  x1?: string | undefined;
11
9
  y1?: string | undefined;
@@ -21,6 +19,7 @@ declare const __propDef: {
21
19
  stops: {};
22
20
  default: {
23
21
  id: string;
22
+ url: string;
24
23
  };
25
24
  };
26
25
  };
@@ -0,0 +1,25 @@
1
+ <script>import { timeWeek, timeYear } from 'd3-time';
2
+ import { endOfMonth } from 'date-fns';
3
+ export let date;
4
+ /**
5
+ * Size of cell. If `number`, sets width/height as same. If array, sets [width,height]. If undefined, is based on Chart width/height
6
+ */
7
+ export let cellSize;
8
+ $: [cellWidth, cellHeight] = Array.isArray(cellSize) ? cellSize : [cellSize, cellSize];
9
+ // start of month
10
+ $: startDayOfWeek = date.getDay();
11
+ $: startWeek = timeWeek.count(timeYear(date), date);
12
+ // end of month
13
+ $: monthEnd = endOfMonth(date);
14
+ $: endDayOfWeek = monthEnd.getDay();
15
+ $: endWeek = timeWeek.count(timeYear(monthEnd), monthEnd);
16
+ $: pathData = `
17
+ M${(startWeek + 1) * cellWidth},${startDayOfWeek * cellHeight}
18
+ H${startWeek * cellWidth} V${cellHeight * 7}
19
+ H${endWeek * cellWidth} V${(endDayOfWeek + 1) * cellHeight}
20
+ H${(endWeek + 1) * cellWidth} V0
21
+ H${(startWeek + 1) * cellWidth}Z
22
+ `;
23
+ </script>
24
+
25
+ <path d={pathData} fill="none" stroke="black" {...$$restProps} />
@@ -0,0 +1,18 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ [x: string]: any;
5
+ date: Date;
6
+ cellSize: number | [number, number];
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {};
12
+ };
13
+ export type MonthPathProps = typeof __propDef.props;
14
+ export type MonthPathEvents = typeof __propDef.events;
15
+ export type MonthPathSlots = typeof __propDef.slots;
16
+ export default class MonthPath extends SvelteComponentTyped<MonthPathProps, MonthPathEvents, MonthPathSlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,35 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ [x: string]: any;
5
+ r?: number | undefined;
6
+ offsetX?: number | ((value: number, context: any) => number) | undefined;
7
+ offsetY?: number | ((value: number, context: any) => number) | undefined;
8
+ links?: boolean | {
9
+ [x: string]: any;
10
+ data?: any;
11
+ sankey?: boolean | undefined;
12
+ source?: ((d: any) => any) | undefined;
13
+ target?: ((d: any) => any) | undefined;
14
+ orientation?: "horizontal" | "vertical" | undefined;
15
+ x?: ((d: any) => any) | undefined;
16
+ y?: ((d: any) => any) | undefined;
17
+ curve?: import("d3-shape").CurveFactory | undefined;
18
+ tweened?: boolean | import("svelte/motion").TweenedOptions<unknown> | undefined;
19
+ } | undefined;
20
+ };
21
+ events: {
22
+ [evt: string]: CustomEvent<any>;
23
+ };
24
+ slots: {
25
+ default: {
26
+ points: any;
27
+ };
28
+ };
29
+ };
30
+ export type PointsProps = typeof __propDef.props;
31
+ export type PointsEvents = typeof __propDef.events;
32
+ export type PointsSlots = typeof __propDef.slots;
33
+ export default class Points extends SvelteComponentTyped<PointsProps, PointsEvents, PointsSlots> {
34
+ }
35
+ export {};
@@ -0,0 +1,37 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import { type SpringOptions, type TweenedOptions } from '../stores/motionStore';
3
+ declare const __propDef: {
4
+ props: {
5
+ [x: string]: any;
6
+ x?: number | undefined;
7
+ initialX?: number | undefined;
8
+ y?: number | undefined;
9
+ initialY?: number | undefined;
10
+ width: number;
11
+ initialWidth?: number | undefined;
12
+ height: number;
13
+ initialHeight?: number | undefined;
14
+ spring?: boolean | import("svelte/motion").SpringOpts | {
15
+ [prop: string]: import("svelte/motion").SpringOpts | undefined;
16
+ } | undefined;
17
+ tweened?: boolean | import("svelte/motion").TweenedOptions<unknown> | {
18
+ [prop: string]: import("svelte/motion").TweenedOptions<unknown> | undefined;
19
+ } | undefined;
20
+ };
21
+ events: {
22
+ click: MouseEvent;
23
+ mouseover: MouseEvent;
24
+ mousemove: MouseEvent;
25
+ mouseout: MouseEvent;
26
+ mouseleave: MouseEvent;
27
+ } & {
28
+ [evt: string]: CustomEvent<any>;
29
+ };
30
+ slots: {};
31
+ };
32
+ export type RectProps = typeof __propDef.props;
33
+ export type RectEvents = typeof __propDef.events;
34
+ export type RectSlots = typeof __propDef.slots;
35
+ export default class Rect extends SvelteComponentTyped<RectProps, RectEvents, RectSlots> {
36
+ }
37
+ export {};
@@ -11,7 +11,7 @@ export let spring = undefined;
11
11
  export let tweened = undefined;
12
12
  </script>
13
13
 
14
- <ClipPath {id}>
14
+ <ClipPath {id} let:url>
15
15
  <Rect slot="clip" {x} {y} {width} {height} {spring} {tweened} {...$$restProps} />
16
- <slot {id} />
16
+ <slot {id} {url} />
17
17
  </ClipPath>
@@ -17,6 +17,7 @@ declare const __propDef: {
17
17
  slots: {
18
18
  default: {
19
19
  id: string;
20
+ url: string;
20
21
  };
21
22
  };
22
23
  };
@@ -4,8 +4,12 @@ import { fade } from 'svelte/transition';
4
4
  import { writable } from 'svelte/store';
5
5
  import { cls } from 'svelte-ux';
6
6
  import { tooltipContext } from './TooltipContext.svelte';
7
- export let topOffset = 10;
8
- export let leftOffset = 10;
7
+ /** Use fixed `top` position instead of calculating based on data and mouse position */
8
+ export let top = undefined;
9
+ /** Use fixed `left` position instead of calculating based on data and mouse position */
10
+ export let left = undefined;
11
+ export let topOffset = top ? 0 : 10;
12
+ export let leftOffset = left ? 0 : 10;
9
13
  export let contained = 'container'; // TODO: Support 'window' using getBoundingClientRect()
10
14
  export let animate = true;
11
15
  export let header = undefined;
@@ -14,24 +18,32 @@ const { containerWidth, containerHeight } = getContext('LayerCake');
14
18
  const tooltip = tooltipContext();
15
19
  let tooltipWidth = 0;
16
20
  let tooltipHeight = 0;
17
- let top = animate ? spring($tooltip.top) : writable($tooltip.top);
21
+ let topPos = animate ? spring($tooltip.top) : writable($tooltip.top);
18
22
  $: if ($tooltip) {
19
- if (contained === 'container' && $tooltip.top + topOffset + tooltipHeight > $containerHeight) {
23
+ if (top != null) {
24
+ $topPos = top;
25
+ }
26
+ else if (contained === 'container' &&
27
+ $tooltip.top + topOffset + tooltipHeight > $containerHeight) {
20
28
  // Change side. Do not allow tooltip to go above the top
21
- $top = Math.max($tooltip.top - (topOffset + tooltipHeight), 0);
29
+ $topPos = Math.max($tooltip.top - (topOffset + tooltipHeight), 0);
22
30
  }
23
31
  else {
24
- $top = $tooltip.top + topOffset;
32
+ $topPos = $tooltip.top + topOffset;
25
33
  }
26
34
  }
27
- let left = animate ? spring($tooltip.left) : writable($tooltip.left);
35
+ let leftPos = animate ? spring($tooltip.left) : writable($tooltip.left);
28
36
  $: if ($tooltip) {
29
- if (contained === 'container' && $tooltip.left + leftOffset + tooltipWidth > $containerWidth) {
37
+ if (left != null) {
38
+ $leftPos = left;
39
+ }
40
+ else if (contained === 'container' &&
41
+ $tooltip.left + leftOffset + tooltipWidth > $containerWidth) {
30
42
  // Change side
31
- $left = Math.max($tooltip.left - (leftOffset + tooltipWidth), 0);
43
+ $leftPos = Math.max($tooltip.left - (leftOffset + tooltipWidth), 0);
32
44
  }
33
45
  else {
34
- $left = $tooltip.left + leftOffset;
46
+ $leftPos = $tooltip.left + leftOffset;
35
47
  }
36
48
  }
37
49
  </script>
@@ -39,8 +51,8 @@ $: if ($tooltip) {
39
51
  {#if $tooltip.data}
40
52
  <div
41
53
  class={cls('absolute pointer-events-none z-50', classes.root)}
42
- style:top="{$top}px"
43
- style:left="{$left}px"
54
+ style:top="{$topPos}px"
55
+ style:left="{$leftPos}px"
44
56
  transition:fade={{ duration: 100 }}
45
57
  bind:clientWidth={tooltipWidth}
46
58
  bind:clientHeight={tooltipHeight}
@@ -2,6 +2,8 @@ import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
4
  [x: string]: any;
5
+ top?: number | undefined;
6
+ left?: number | undefined;
5
7
  topOffset?: number | undefined;
6
8
  leftOffset?: number | undefined;
7
9
  contained?: false | "container" | undefined;
@@ -5,6 +5,7 @@ export { default as Axis } from './Axis.svelte';
5
5
  export { default as Bars } from './Bars.svelte';
6
6
  export { default as Blur } from './Blur.svelte';
7
7
  export { default as Bounds } from './Bounds.svelte';
8
+ export { default as Calendar } from './Calendar.svelte';
8
9
  export { default as Chart } from './Chart.svelte';
9
10
  export { default as ChartClipPath } from './ChartClipPath.svelte';
10
11
  export { default as Circle } from './Circle.svelte';
@@ -5,6 +5,7 @@ export { default as Axis } from './Axis.svelte';
5
5
  export { default as Bars } from './Bars.svelte';
6
6
  export { default as Blur } from './Blur.svelte';
7
7
  export { default as Bounds } from './Bounds.svelte';
8
+ export { default as Calendar } from './Calendar.svelte';
8
9
  export { default as Chart } from './Chart.svelte';
9
10
  export { default as ChartClipPath } from './ChartClipPath.svelte';
10
11
  export { default as Circle } from './Circle.svelte';
@@ -13,7 +13,7 @@ export let icon;
13
13
  <Dialog
14
14
  {open}
15
15
  on:close={toggle}
16
- class="max-h-[98vh] md:max-h-[90vh] max-w-[98vw] md:max-w-[90vw] grid grid-rows-[auto,1fr,auto]"
16
+ class="max-h-[98dvh] md:max-h-[90dvh] max-w-[98vw] md:max-w-[90vw] grid grid-rows-[auto,1fr,auto]"
17
17
  >
18
18
  <div class="grid grid-cols-[1fr,auto] gap-3 items-center p-4">
19
19
  <div class="overflow-auto">
@@ -1,3 +1,4 @@
1
+ /// <reference types="svelte" />
1
2
  import { spring, tweened } from 'svelte/motion';
2
3
  export type SpringOptions = Parameters<typeof spring>[1];
3
4
  export type TweenedOptions = Parameters<typeof tweened>[1];
@@ -1,14 +1,14 @@
1
- export declare function getAccessor(key: any): any;
1
+ export declare function getAccessor(key: string): (d: any) => any;
2
2
  /**
3
3
  * Pivot longer (columns to rows)
4
4
  * - see: https://observablehq.com/d/3ea8d446f5ba96fe
5
5
  * - see also: https://observablehq.com/d/ac2a320cf2b0adc4 as generator
6
6
  */
7
- export declare function pivotLonger(data: any, columns: any, name: any, value: any): any;
7
+ export declare function pivotLonger(data: any[], columns: string[], name: string, value: string): any[];
8
8
  /**
9
9
  * Pivot wider (rows to columns)
10
10
  * - see: https://github.com/d3/d3-array/issues/142#issuecomment-761861983
11
11
  */
12
- export declare function pivotWider(data: any, column: any, name: any, value: any): any[];
13
- export declare function first(items: any): any;
14
- export declare function last(items: any): any;
12
+ export declare function pivotWider(data: any[], column: string, name: string, value: string): any[];
13
+ export declare function first(items: any[]): any;
14
+ export declare function last(items: any[]): any;
@@ -1,3 +1,4 @@
1
+ /// <reference types="svelte" />
1
2
  type DimensionGetterOptions = {
2
3
  /** Override `x` accessor from context */
3
4
  x?: (item: any) => any;
@@ -1,3 +1,4 @@
1
+ /// <reference types="svelte" />
1
2
  import { tweened, spring } from 'svelte/motion';
2
3
  import { type MotionOptions } from '../stores/motionStore';
3
4
  import { type ScaleBand } from 'd3-scale';
@@ -29,7 +30,7 @@ export declare function groupScaleBand<Domain extends {
29
30
  * Animate d3-scale as domain and/or range are updated using tweened store
30
31
  */
31
32
  export declare function tweenedScale(scale: any, tweenedOptions?: Parameters<typeof tweened>[1]): {
32
- subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: ((value?: any) => void) | undefined) => import("svelte/store").Unsubscriber;
33
+ subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: import("svelte/store").Invalidator<any> | undefined) => import("svelte/store").Unsubscriber;
33
34
  domain: (values: any) => Promise<void>;
34
35
  range: (values: any) => Promise<void>;
35
36
  };
@@ -37,7 +38,7 @@ export declare function tweenedScale(scale: any, tweenedOptions?: Parameters<typ
37
38
  * Animate d3-scale as domain and/or range are updated using spring store
38
39
  */
39
40
  export declare function springScale(scale: any, springOptions?: Parameters<typeof spring>[1]): {
40
- subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: ((value?: any) => void) | undefined) => import("svelte/store").Unsubscriber;
41
+ subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: import("svelte/store").Invalidator<any> | undefined) => import("svelte/store").Unsubscriber;
41
42
  domain: (values: any) => Promise<void>;
42
43
  range: (values: any) => Promise<void>;
43
44
  };
@@ -45,7 +46,7 @@ export declare function springScale(scale: any, springOptions?: Parameters<typeo
45
46
  * Create a store wrapper around a d3-scale which interpolates the domain and/or range using `tweened()` or `spring()` stores. Fallbacks to `writable()` store if not interpolating
46
47
  */
47
48
  export declare function motionScale(scale: any, options: MotionOptions): {
48
- subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: ((value?: any) => void) | undefined) => import("svelte/store").Unsubscriber;
49
+ subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: import("svelte/store").Invalidator<any> | undefined) => import("svelte/store").Unsubscriber;
49
50
  domain: (values: any) => void | Promise<void>;
50
51
  range: (values: any) => void | Promise<void>;
51
52
  };
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "layerchart",
3
+ "description": "Composable Svelte chart components to build a wide range of visualizations",
3
4
  "author": "Sean Lynch <techniq35@gmail.com>",
4
5
  "license": "MIT",
5
6
  "repository": "techniq/layerchart",
6
- "version": "0.22.2",
7
+ "version": "0.24.0",
7
8
  "scripts": {
8
9
  "dev": "vite dev",
9
10
  "build": "vite build",
@@ -22,50 +23,52 @@
22
23
  "devDependencies": {
23
24
  "@rollup/plugin-dsv": "^3.0.2",
24
25
  "@sveltejs/adapter-vercel": "^3.0.3",
25
- "@sveltejs/kit": "^1.22.4",
26
- "@sveltejs/package": "^2.2.0",
26
+ "@sveltejs/kit": "^1.25.0",
27
+ "@sveltejs/package": "^2.2.2",
27
28
  "@svitejs/changesets-changelog-github-compact": "^1.1.0",
28
- "@tailwindcss/typography": "^0.5.9",
29
- "@types/d3-array": "^3.0.5",
29
+ "@tailwindcss/typography": "^0.5.10",
30
+ "@types/d3-array": "^3.0.7",
30
31
  "@types/d3-delaunay": "^6.0.1",
31
- "@types/d3-dsv": "^3.0.1",
32
- "@types/d3-geo": "^3.0.3",
33
- "@types/d3-hierarchy": "^3.1.2",
32
+ "@types/d3-dsv": "^3.0.2",
33
+ "@types/d3-geo": "^3.0.4",
34
+ "@types/d3-hierarchy": "^3.1.3",
34
35
  "@types/d3-interpolate": "^3.0.1",
35
36
  "@types/d3-interpolate-path": "^2.0.0",
36
37
  "@types/d3-quadtree": "^3.0.2",
37
38
  "@types/d3-random": "^3.0.1",
38
39
  "@types/d3-sankey": "^0.12.1",
39
- "@types/d3-scale": "^4.0.3",
40
- "@types/d3-shape": "^3.1.1",
41
- "@types/lodash-es": "^4.17.8",
40
+ "@types/d3-scale": "^4.0.4",
41
+ "@types/d3-scale-chromatic": "^3.0.0",
42
+ "@types/d3-shape": "^3.1.2",
43
+ "@types/lodash-es": "^4.17.9",
42
44
  "@types/marked": "^5.0.1",
43
45
  "@types/shapefile": "^0.6.1",
44
- "@types/topojson-client": "^3.1.1",
45
- "autoprefixer": "^10.4.14",
46
- "execa": "^7.2.0",
47
- "marked": "^5.1.2",
46
+ "@types/topojson-client": "^3.1.2",
47
+ "autoprefixer": "^10.4.15",
48
+ "execa": "^8.0.1",
49
+ "marked": "^9.0.0",
48
50
  "mdsvex": "^0.11.0",
49
- "prettier": "^3.0.1",
51
+ "prettier": "^3.0.3",
50
52
  "prettier-plugin-svelte": "^3.0.3",
51
53
  "prism-themes": "^1.9.0",
52
- "rehype-slug": "^5.1.0",
53
- "svelte-check": "^3.4.6",
54
+ "rehype-slug": "^6.0.0",
55
+ "svelte": "^4.2.0",
56
+ "svelte-check": "^3.5.1",
54
57
  "svelte-preprocess": "^5.0.4",
55
- "svelte2tsx": "^0.6.19",
58
+ "svelte2tsx": "^0.6.21",
56
59
  "tailwindcss": "^3.3.3",
57
- "tslib": "^2.6.1",
58
- "typescript": "^5.1.6",
60
+ "tslib": "^2.6.2",
61
+ "typescript": "^5.2.2",
59
62
  "unist-util-visit": "^5.0.0",
60
63
  "us-atlas": "^3.0.1",
61
- "vite": "^4.4.9",
62
- "vite-plugin-sveld": "^1.1.0"
64
+ "vite": "^4.4.9"
63
65
  },
64
66
  "type": "module",
65
67
  "dependencies": {
66
68
  "@changesets/cli": "^2.26.2",
67
69
  "@mdi/js": "^7.2.96",
68
- "@vercel/analytics": "^1.0.1",
70
+ "@types/d3-time": "^3.0.0",
71
+ "@vercel/analytics": "^1.0.2",
69
72
  "d3-array": "^3.2.4",
70
73
  "d3-delaunay": "^6.0.4",
71
74
  "d3-dsv": "^3.0.1",
@@ -80,14 +83,17 @@
80
83
  "d3-scale-chromatic": "^3.0.0",
81
84
  "d3-shape": "^3.2.0",
82
85
  "d3-tile": "^1.0.0",
86
+ "d3-time": "^3.1.0",
83
87
  "date-fns": "^2.30.0",
84
88
  "layercake": "^7.6.1",
85
89
  "lodash-es": "^4.17.21",
86
90
  "shapefile": "^0.6.6",
87
- "svelte": "^3.59.1",
88
- "svelte-ux": "^0.47.4",
91
+ "svelte-ux": "^0.49.1",
89
92
  "topojson-client": "^3.1.0"
90
93
  },
94
+ "peerDependencies": {
95
+ "svelte": "^3.56.0 || ^4.0.0"
96
+ },
91
97
  "main": "./dist/index.js",
92
98
  "exports": {
93
99
  ".": {