layerchart 0.44.0 → 0.51.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 (116) hide show
  1. package/dist/components/Arc.svelte +18 -1
  2. package/dist/components/Arc.svelte.d.ts +3 -0
  3. package/dist/components/Area.svelte +49 -18
  4. package/dist/components/Area.svelte.d.ts +0 -1
  5. package/dist/components/Axis.svelte +2 -1
  6. package/dist/components/Axis.svelte.d.ts +2 -1
  7. package/dist/components/Bar.svelte +18 -8
  8. package/dist/components/Bar.svelte.d.ts +6 -3
  9. package/dist/components/Bars.svelte +18 -11
  10. package/dist/components/Bars.svelte.d.ts +3 -3
  11. package/dist/components/Blur.svelte +1 -1
  12. package/dist/components/Brush.svelte +2 -1
  13. package/dist/components/Calendar.svelte +2 -2
  14. package/dist/components/Calendar.svelte.d.ts +1 -1
  15. package/dist/components/Chart.svelte +85 -25
  16. package/dist/components/Chart.svelte.d.ts +77 -37
  17. package/dist/components/ChartContext.svelte +124 -6
  18. package/dist/components/ChartContext.svelte.d.ts +50 -2
  19. package/dist/components/Circle.svelte +1 -1
  20. package/dist/components/CircleClipPath.svelte +1 -1
  21. package/dist/components/ClipPath.svelte +1 -1
  22. package/dist/components/GeoPath.svelte +1 -1
  23. package/dist/components/GeoPath.svelte.d.ts +1 -1
  24. package/dist/components/Highlight.svelte +45 -19
  25. package/dist/components/Highlight.svelte.d.ts +2 -3
  26. package/dist/components/HitCanvas.svelte +1 -1
  27. package/dist/components/Hull.svelte +1 -1
  28. package/dist/components/Labels.svelte +39 -73
  29. package/dist/components/Labels.svelte.d.ts +2 -5
  30. package/dist/components/Legend.svelte +5 -5
  31. package/dist/components/Legend.svelte.d.ts +2 -2
  32. package/dist/components/Line.svelte +1 -1
  33. package/dist/components/LinearGradient.svelte +1 -1
  34. package/dist/components/MotionPath.svelte +1 -1
  35. package/dist/components/Pie.svelte +18 -41
  36. package/dist/components/Pie.svelte.d.ts +2 -3
  37. package/dist/components/Points.svelte +110 -56
  38. package/dist/components/Points.svelte.d.ts +20 -2
  39. package/dist/components/RadialGradient.svelte +1 -1
  40. package/dist/components/Rect.svelte +2 -1
  41. package/dist/components/Rect.svelte.d.ts +1 -0
  42. package/dist/components/RectClipPath.svelte +1 -1
  43. package/dist/components/Rule.svelte +1 -1
  44. package/dist/components/Spline.svelte +26 -18
  45. package/dist/components/Spline.svelte.d.ts +1 -1
  46. package/dist/components/Text.svelte +1 -1
  47. package/dist/components/Threshold.svelte +19 -81
  48. package/dist/components/Threshold.svelte.d.ts +13 -20
  49. package/dist/components/TransformContext.svelte.d.ts +2 -2
  50. package/dist/components/TransformControls.svelte +2 -1
  51. package/dist/components/TransformControls.svelte.d.ts +2 -2
  52. package/dist/components/Voronoi.svelte +15 -5
  53. package/dist/components/Voronoi.svelte.d.ts +6 -1
  54. package/dist/components/charts/AreaChart.svelte +182 -0
  55. package/dist/components/charts/AreaChart.svelte.d.ts +261 -0
  56. package/dist/components/charts/BarChart.svelte +207 -0
  57. package/dist/components/charts/BarChart.svelte.d.ts +241 -0
  58. package/dist/components/charts/LineChart.svelte +138 -0
  59. package/dist/components/charts/LineChart.svelte.d.ts +260 -0
  60. package/dist/components/charts/PieChart.svelte +146 -0
  61. package/dist/components/charts/PieChart.svelte.d.ts +220 -0
  62. package/dist/components/charts/ScatterChart.svelte +133 -0
  63. package/dist/components/charts/ScatterChart.svelte.d.ts +236 -0
  64. package/dist/components/charts/index.d.ts +5 -0
  65. package/dist/components/charts/index.js +5 -0
  66. package/dist/components/index.d.ts +2 -6
  67. package/dist/components/index.js +3 -6
  68. package/dist/components/layout/Canvas.svelte +1 -1
  69. package/dist/components/layout/Html.svelte +1 -1
  70. package/dist/components/layout/Svg.svelte +14 -4
  71. package/dist/components/layout/Svg.svelte.d.ts +1 -0
  72. package/dist/components/{Tooltip.svelte → tooltip/Tooltip.svelte} +5 -28
  73. package/dist/components/{Tooltip.svelte.d.ts → tooltip/Tooltip.svelte.d.ts} +1 -5
  74. package/dist/components/{TooltipContext.svelte → tooltip/TooltipContext.svelte} +20 -12
  75. package/dist/components/tooltip/TooltipHeader.svelte +21 -0
  76. package/dist/components/tooltip/TooltipHeader.svelte.d.ts +23 -0
  77. package/dist/components/tooltip/TooltipItem.svelte +37 -0
  78. package/dist/components/{TooltipItem.svelte.d.ts → tooltip/TooltipItem.svelte.d.ts} +4 -1
  79. package/dist/components/tooltip/TooltipList.svelte +12 -0
  80. package/dist/components/tooltip/TooltipList.svelte.d.ts +18 -0
  81. package/dist/components/tooltip/TooltipSeparator.svelte +4 -0
  82. package/dist/components/tooltip/index.d.ts +6 -0
  83. package/dist/components/tooltip/index.js +6 -0
  84. package/dist/docs/Blockquote.svelte +2 -1
  85. package/dist/docs/Code.svelte +2 -1
  86. package/dist/docs/CurveMenuField.svelte +2 -1
  87. package/dist/docs/GeoDebug.svelte +3 -1
  88. package/dist/docs/Json.svelte +1 -1
  89. package/dist/docs/Preview.svelte +2 -1
  90. package/dist/docs/TransformDebug.svelte +2 -1
  91. package/dist/utils/common.d.ts +1 -1
  92. package/dist/utils/common.js +2 -2
  93. package/dist/utils/common.test.d.ts +8 -0
  94. package/dist/utils/common.test.js +38 -0
  95. package/dist/utils/event.js +1 -1
  96. package/dist/utils/genData.d.ts +2 -2
  97. package/dist/utils/genData.js +20 -20
  98. package/dist/utils/math.d.ts +2 -2
  99. package/dist/utils/math.js +8 -2
  100. package/dist/utils/rect.d.ts +4 -10
  101. package/dist/utils/rect.js +15 -19
  102. package/dist/utils/scales.d.ts +8 -2
  103. package/dist/utils/scales.js +15 -1
  104. package/dist/utils/stack.d.ts +2 -2
  105. package/dist/utils/stack.js +37 -20
  106. package/dist/utils/stack.test.d.ts +6 -0
  107. package/dist/utils/stack.test.js +136 -0
  108. package/dist/utils/string.js +41 -0
  109. package/dist/utils/ticks.js +1 -2
  110. package/package.json +9 -3
  111. package/dist/components/AreaStack.svelte +0 -47
  112. package/dist/components/AreaStack.svelte.d.ts +0 -28
  113. package/dist/components/TooltipItem.svelte +0 -26
  114. package/dist/components/TooltipSeparator.svelte +0 -4
  115. /package/dist/components/{TooltipContext.svelte.d.ts → tooltip/TooltipContext.svelte.d.ts} +0 -0
  116. /package/dist/components/{TooltipSeparator.svelte.d.ts → tooltip/TooltipSeparator.svelte.d.ts} +0 -0
@@ -1,15 +1,17 @@
1
1
  <script>import {} from 'svelte';
2
2
  import { max, min } from 'd3-array';
3
- import { cls, notNull } from 'svelte-ux';
3
+ import { pointRadial } from 'd3-shape';
4
+ import { notNull } from '@layerstack/utils/typeGuards';
5
+ import { cls } from '@layerstack/tailwind';
4
6
  import { chartContext } from './ChartContext.svelte';
5
7
  import Circle from './Circle.svelte';
6
8
  import Line from './Line.svelte';
7
9
  import Bar from './Bar.svelte';
8
10
  import Rect from './Rect.svelte';
9
- import { tooltipContext } from './TooltipContext.svelte';
11
+ import { tooltipContext } from './tooltip/TooltipContext.svelte';
10
12
  import { isScaleBand } from '../utils/scales.js';
11
13
  import { accessor } from '../utils/common.js';
12
- const { data: contextData, flatData, x: xContext, xDomain, xScale, xRange, y: yContext, yDomain, yScale, yRange, rGet, config, } = chartContext();
14
+ const { data: contextData, flatData, x: xContext, xDomain, xScale, xRange, y: yContext, yDomain, yScale, yRange, cGet, config, radial, } = chartContext();
13
15
  const tooltip = tooltipContext();
14
16
  /** Highlight specific data (annotate), espect uses tooltip data */
15
17
  export let data = undefined;
@@ -32,7 +34,6 @@ export let area = false;
32
34
  export let bar = false;
33
35
  /** Set to false to disable spring transitions */
34
36
  export let motion = true;
35
- // TODO: Fix circle points being backwards for stack (see AreaStack)
36
37
  const _x = accessor(x);
37
38
  const _y = accessor(y);
38
39
  let _points = [];
@@ -47,10 +48,10 @@ $: highlightData = data ?? $tooltip.data;
47
48
  $: if (highlightData) {
48
49
  const xValue = _x(highlightData);
49
50
  const xCoord = Array.isArray(xValue) ? xValue.map((v) => $xScale(v)) : $xScale(xValue);
50
- const xOffset = isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0;
51
+ const xOffset = isScaleBand($xScale) && !$radial ? $xScale.bandwidth() / 2 : 0;
51
52
  const yValue = _y(highlightData);
52
53
  const yCoord = Array.isArray(yValue) ? yValue.map((v) => $yScale(v)) : $yScale(yValue);
53
- const yOffset = isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0;
54
+ const yOffset = isScaleBand($yScale) && !$radial ? $yScale.bandwidth() / 2 : 0;
54
55
  // Reset lines
55
56
  _lines = [];
56
57
  const defaultAxis = isScaleBand($yScale) ? 'y' : 'x';
@@ -65,18 +66,18 @@ $: if (highlightData) {
65
66
  ..._lines,
66
67
  ...xCoord.filter(notNull).map((xItem, i) => ({
67
68
  x1: xItem + xOffset,
68
- y1: 0,
69
+ y1: min($yRange),
69
70
  x2: xItem + xOffset,
70
71
  y2: max($yRange),
71
72
  })),
72
73
  ];
73
74
  }
74
- else {
75
+ else if (xCoord) {
75
76
  _lines = [
76
77
  ..._lines,
77
78
  {
78
79
  x1: xCoord + xOffset,
79
- y1: 0,
80
+ y1: min($yRange),
80
81
  x2: xCoord + xOffset,
81
82
  y2: max($yRange),
82
83
  },
@@ -112,18 +113,18 @@ $: if (highlightData) {
112
113
  _lines = [
113
114
  ..._lines,
114
115
  ...yCoord.filter(notNull).map((yItem, i) => ({
115
- x1: 0,
116
+ x1: min($xRange),
116
117
  y1: yItem + yOffset,
117
118
  x2: max($xRange),
118
119
  y2: yItem + yOffset,
119
120
  })),
120
121
  ];
121
122
  }
122
- else {
123
+ else if (yCoord) {
123
124
  _lines = [
124
125
  ..._lines,
125
126
  {
126
- x1: 0,
127
+ x1: min($xRange),
127
128
  y1: yCoord + yOffset,
128
129
  x2: max($xRange),
129
130
  y2: yCoord + yOffset,
@@ -172,11 +173,10 @@ $: if (highlightData) {
172
173
  })
173
174
  .filter((d) => d.point); // remove if no point found (ex. Histogram);
174
175
  _points = seriesPointsData.map((seriesPoint, i) => {
175
- console.log({ seriesPoint });
176
176
  return {
177
177
  x: $xScale(seriesPoint.point[1]) + xOffset,
178
178
  y: yCoord + yOffset,
179
- fill: $config.r ? $rGet(seriesPoint.series) : null,
179
+ fill: $config.c ? $cGet(seriesPoint.series) : null,
180
180
  };
181
181
  });
182
182
  }
@@ -189,7 +189,7 @@ $: if (highlightData) {
189
189
  x: xItem + xOffset,
190
190
  y: yCoord + yOffset,
191
191
  // TODO: is there a better way to expose the series key/value?
192
- fill: $config.r ? $rGet({ ...highlightData, $key }) : null,
192
+ fill: $config.c ? $cGet({ ...highlightData, $key }) : null,
193
193
  };
194
194
  });
195
195
  }
@@ -214,7 +214,7 @@ $: if (highlightData) {
214
214
  _points = seriesPointsData.map((seriesPoint, i) => ({
215
215
  x: xCoord + xOffset,
216
216
  y: $yScale(seriesPoint.point[1]) + yOffset,
217
- fill: $config.r ? $rGet(seriesPoint.series) : null,
217
+ fill: $config.c ? $cGet(seriesPoint.series) : null,
218
218
  }));
219
219
  }
220
220
  }
@@ -226,20 +226,46 @@ $: if (highlightData) {
226
226
  x: xCoord + xOffset,
227
227
  y: yItem + yOffset,
228
228
  // TODO: is there a better way to expose the series key/value?
229
- fill: $config.r ? $rGet({ ...highlightData, $key }) : null,
229
+ fill: $config.c ? $cGet({ ...highlightData, $key }) : null,
230
230
  };
231
231
  });
232
232
  }
233
233
  }
234
- else {
234
+ else if (xCoord != null && yCoord != null) {
235
235
  _points = [
236
236
  {
237
237
  x: xCoord + xOffset,
238
238
  y: yCoord + yOffset,
239
- fill: $config.r ? $rGet(highlightData) : null,
239
+ fill: $config.c ? $cGet(highlightData) : null,
240
240
  },
241
241
  ];
242
242
  }
243
+ else {
244
+ _points = [];
245
+ }
246
+ if ($radial) {
247
+ // Translate x/y to angle/radius
248
+ _points = _points.map((p) => {
249
+ const [x, y] = pointRadial(p.x, p.y);
250
+ return {
251
+ ...p,
252
+ x,
253
+ y,
254
+ };
255
+ });
256
+ _lines = _lines.map((l) => {
257
+ const [x1, y1] = pointRadial(l.x1, l.y1);
258
+ const [x2, y2] = pointRadial(l.x2, l.y2);
259
+ return {
260
+ ...l,
261
+ x1,
262
+ y1,
263
+ x2,
264
+ y2,
265
+ };
266
+ });
267
+ // TODO: How to handle _areas
268
+ }
243
269
  }
244
270
  </script>
245
271
 
@@ -41,15 +41,14 @@ declare const __propDef: {
41
41
  bar: Object;
42
42
  x?: Accessor;
43
43
  y?: Accessor;
44
+ x1?: Accessor;
45
+ y1?: Accessor;
44
46
  fill?: string | undefined;
45
47
  stroke?: string | undefined;
46
48
  strokeWidth?: number | undefined;
47
49
  radius?: number | undefined;
48
50
  rounded?: ("all" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
49
51
  inset?: number | undefined;
50
- groupBy?: string | undefined;
51
- groupPaddingInner?: number | undefined;
52
- groupPaddingOuter?: number | undefined;
53
52
  spring?: ComponentProps<Rect>["spring"];
54
53
  tweened?: ComponentProps<Rect>["tweened"];
55
54
  }>;
@@ -1,7 +1,7 @@
1
1
  <script>import { createEventDispatcher, onMount, setContext } from 'svelte';
2
2
  import { writable } from 'svelte/store';
3
3
  import { scaleCanvas } from 'layercake';
4
- import { cls } from 'svelte-ux';
4
+ import { cls } from '@layerstack/tailwind';
5
5
  import { chartContext } from './ChartContext.svelte';
6
6
  import Canvas from './layout/Canvas.svelte';
7
7
  import { transformContext } from './TransformContext.svelte';
@@ -1,10 +1,10 @@
1
1
  <script>import { createEventDispatcher } from 'svelte';
2
- import { cls } from 'svelte-ux';
3
2
  import { min } from 'd3-array';
4
3
  import { Delaunay } from 'd3-delaunay';
5
4
  // @ts-expect-error
6
5
  import { geoVoronoi } from 'd3-geo-voronoi';
7
6
  import { curveLinearClosed } from 'd3-shape';
7
+ import { cls } from '@layerstack/tailwind';
8
8
  import { chartContext } from './ChartContext.svelte';
9
9
  import GeoPath from './GeoPath.svelte';
10
10
  import { geoContext } from './GeoContext.svelte';
@@ -1,62 +1,25 @@
1
- <script>/*
2
- * TODO
3
- * - [ ] Support step curves (center like scaleBand())
4
- * - [ ] Support multiple values (threshold, stacks, etc)
5
- */
6
- import {} from 'svelte';
7
- import { format as formatValue, cls } from 'svelte-ux';
8
- import { greatestAbs } from 'svelte-ux/utils/array';
9
- const { flatData, yScale, x, y, custom } = chartContext();
1
+ <script>import { SvelteComponent } from 'svelte';
2
+ import { format as formatValue } from '@layerstack/utils';
3
+ import { cls } from '@layerstack/tailwind';
10
4
  import Text from './Text.svelte';
11
5
  import { isScaleBand } from '../utils/scales.js';
12
- import { createDimensionGetter } from '../utils/rect.js';
13
6
  import { chartContext } from './ChartContext.svelte';
14
- // TODO: Support 'auto' to switch `inside` to `outside` if not enough room
7
+ import Points from './Points.svelte';
15
8
  export let placement = 'outside';
16
- export let offset = 4;
9
+ export let offset = placement === 'center' ? 0 : 4;
17
10
  export let format = undefined;
18
- // export let overlap = false;
19
- // @ts-expect-error
20
- $: yBaseline = $custom?.yBaseline ?? 0;
21
- export let groupBy = undefined;
22
- export let groupPaddingInner = 0.2;
23
- export let groupPaddingOuter = 0;
24
- $: getDimensions = createDimensionGetter(chartContext(), {
25
- // x,
26
- // y,
27
- groupBy,
28
- // padding,
29
- groupPadding: {
30
- inner: groupPaddingInner,
31
- outer: groupPaddingOuter,
32
- },
33
- });
34
- $: getValue = (item) => (isScaleBand($yScale) ? $x(item) : $y(item));
35
- $: getLabelValue = (item) => {
36
- const value = getValue(item);
37
- return (Array.isArray(value) ? greatestAbs(value) : value) + yBaseline;
38
- };
39
- $: getFormattedValue = (item) => {
40
- const labelValue = getLabelValue(item);
41
- let formattedValue = labelValue;
42
- if (labelValue != null) {
43
- if (format) {
44
- // Apply more versatile formatting first
45
- formattedValue = formatValue(labelValue, format ?? $yScale.tickFormat?.());
46
- }
47
- }
48
- return formattedValue ?? '';
49
- };
50
- $: getTextProps = (item) => {
51
- const labelValue = getLabelValue(item);
52
- const dimensions = $getDimensions(item);
11
+ const { yScale } = chartContext();
12
+ $: getTextProps = (point) => {
13
+ const value = isScaleBand($yScale) ? point.xValue : point.yValue;
14
+ const formattedValue = formatValue(value, format ?? $yScale.tickFormat?.());
53
15
  if (isScaleBand($yScale)) {
54
16
  // Position label left/right on horizontal bars
55
- if (labelValue < 0) {
17
+ if (value < 0) {
56
18
  // left
57
19
  return {
58
- x: dimensions?.x + (placement === 'outside' ? -offset : offset),
59
- y: dimensions?.y + (dimensions?.height ?? 0) / 2,
20
+ value: formattedValue,
21
+ x: point.x + (placement === 'outside' ? -offset : offset),
22
+ y: point.y,
60
23
  textAnchor: placement === 'outside' ? 'end' : 'start',
61
24
  verticalAnchor: 'middle',
62
25
  capHeight: '.6rem',
@@ -65,8 +28,9 @@ $: getTextProps = (item) => {
65
28
  else {
66
29
  // right
67
30
  return {
68
- x: dimensions?.x + dimensions?.width + (placement === 'outside' ? offset : -offset),
69
- y: dimensions?.y + (dimensions?.height ?? 0) / 2,
31
+ value: formattedValue,
32
+ x: point.x + (placement === 'outside' ? offset : -offset),
33
+ y: point.y,
70
34
  textAnchor: placement === 'outside' ? 'start' : 'end',
71
35
  verticalAnchor: 'middle',
72
36
  capHeight: '.6rem',
@@ -75,24 +39,26 @@ $: getTextProps = (item) => {
75
39
  }
76
40
  else {
77
41
  // Position label top/bottom on vertical bars
78
- if (labelValue < 0) {
42
+ if (value < 0) {
79
43
  // bottom
80
44
  return {
81
- x: dimensions?.x + (dimensions?.width ?? 0) / 2,
82
- y: dimensions?.y + dimensions?.height + (placement === 'outside' ? offset : -offset),
45
+ value: formattedValue,
46
+ x: point.x,
47
+ y: point.y + (placement === 'outside' ? offset : -offset),
83
48
  capHeight: '.6rem',
84
49
  textAnchor: 'middle',
85
- verticalAnchor: placement === 'outside' ? 'start' : 'end',
50
+ verticalAnchor: placement === 'center' ? 'middle' : placement === 'outside' ? 'start' : 'end',
86
51
  };
87
52
  }
88
53
  else {
89
54
  // top
90
55
  return {
91
- x: dimensions?.x + (dimensions?.width ?? 0) / 2,
92
- y: dimensions?.y + (placement === 'outside' ? -offset : offset),
56
+ value: formattedValue,
57
+ x: point.x,
58
+ y: point.y + (placement === 'outside' ? -offset : offset),
93
59
  capHeight: '.6rem',
94
60
  textAnchor: 'middle',
95
- verticalAnchor: placement === 'outside' ? 'end' : 'start',
61
+ verticalAnchor: placement === 'center' ? 'middle' : placement === 'outside' ? 'end' : 'start',
96
62
  };
97
63
  }
98
64
  }
@@ -100,18 +66,18 @@ $: getTextProps = (item) => {
100
66
  </script>
101
67
 
102
68
  <g class="Labels">
103
- {#each $flatData as item, index}
104
- <!-- TODO: Add labels for each item when array/stack? Use `getValue(item)` instead and iterate -->
105
- <Text
106
- value={getFormattedValue(item)}
107
- class={cls(
108
- 'text-xs',
109
- placement === 'inside'
110
- ? 'fill-surface-300 stroke-surface-content'
111
- : 'fill-surface-content stroke-surface-100'
112
- )}
113
- {...getTextProps(item)}
114
- {...$$restProps}
115
- />
116
- {/each}
69
+ <Points let:points>
70
+ {#each points as point}
71
+ <Text
72
+ class={cls(
73
+ 'text-xs',
74
+ placement === 'inside'
75
+ ? 'fill-surface-300 stroke-surface-content'
76
+ : 'fill-surface-content stroke-surface-100'
77
+ )}
78
+ {...getTextProps(point)}
79
+ {...$$restProps}
80
+ />
81
+ {/each}
82
+ </Points>
117
83
  </g>
@@ -1,14 +1,11 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import { type FormatType } from 'svelte-ux';
2
+ import { type FormatType } from '@layerstack/utils';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  [x: string]: any;
6
- placement?: ("inside" | "outside") | undefined;
6
+ placement?: ("inside" | "outside" | "center") | undefined;
7
7
  offset?: number | undefined;
8
8
  format?: FormatType | undefined;
9
- groupBy?: string | undefined;
10
- groupPaddingInner?: number | undefined;
11
- groupPaddingOuter?: number | undefined;
12
9
  };
13
10
  events: {
14
11
  [evt: string]: CustomEvent<any>;
@@ -1,11 +1,11 @@
1
1
  <script>import { scaleBand, scaleLinear } from 'd3-scale';
2
2
  import { quantize, interpolate, interpolateRound } from 'd3-interpolate';
3
3
  import { quantile, range } from 'd3-array';
4
- import { format } from 'svelte-ux';
4
+ import { format } from '@layerstack/utils';
5
5
  import { chartContext } from './ChartContext.svelte';
6
6
  import ColorRamp from './ColorRamp.svelte';
7
- import { cls } from 'svelte-ux';
8
- const { rScale } = chartContext() ?? {};
7
+ import { cls } from '@layerstack/tailwind';
8
+ const { cScale } = chartContext() ?? {};
9
9
  export let scale = undefined;
10
10
  export let title = '';
11
11
  export let width = 320;
@@ -17,9 +17,9 @@ export let tickFontSize = 10;
17
17
  export let tickLength = 4;
18
18
  export let placement = undefined;
19
19
  export let classes = {};
20
- $: if (scale == null && rScale) {
20
+ $: if (scale == null && cScale) {
21
21
  // Read scale from chart context
22
- scale = $rScale;
22
+ scale = $cScale;
23
23
  }
24
24
  let xScale;
25
25
  let interpolator;
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import { type FormatType } from 'svelte-ux';
2
+ import { type FormatType } from '@layerstack/utils';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  [x: string]: any;
@@ -12,7 +12,7 @@ declare const __propDef: {
12
12
  tickValues?: any[] | undefined;
13
13
  tickFontSize?: number | undefined;
14
14
  tickLength?: number | undefined;
15
- placement?: ("center" | "left" | "right" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
15
+ placement?: ("left" | "right" | "center" | "bottom" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
16
16
  classes?: {
17
17
  root?: string;
18
18
  title?: string;
@@ -1,5 +1,5 @@
1
1
  <script>import { tick } from 'svelte';
2
- import { cls } from 'svelte-ux';
2
+ import { cls } from '@layerstack/tailwind';
3
3
  import { motionStore } from '../stores/motionStore.js';
4
4
  export let x1;
5
5
  export let initialX1 = x1;
@@ -1,4 +1,4 @@
1
- <script>import { uniqueId } from 'svelte-ux';
1
+ <script>import { uniqueId } from '@layerstack/utils';
2
2
  /** Unique id for linearGradient */
3
3
  export let id = uniqueId('linearGradient-');
4
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 */
@@ -1,5 +1,5 @@
1
1
  <script>import { onMount } from 'svelte';
2
- import { uniqueId } from 'svelte-ux';
2
+ import { uniqueId } from '@layerstack/utils';
3
3
  /** Id of path to move object along */
4
4
  export let pathId = uniqueId('motionPathId-');
5
5
  /** Id of object to move along path */
@@ -2,7 +2,6 @@
2
2
  import { min, max } from 'd3-array';
3
3
  import Arc from './Arc.svelte';
4
4
  import { chartContext } from './ChartContext.svelte';
5
- import Group from './Group.svelte';
6
5
  import { degreesToRadians } from '../utils/math.js';
7
6
  import { motionStore } from '../stores/motionStore.js';
8
7
  /*
@@ -39,8 +38,6 @@ export let innerRadius = undefined;
39
38
  export let outerRadius = undefined;
40
39
  export let cornerRadius = 0;
41
40
  export let padAngle = 0;
42
- // export let padRadius = 0;
43
- export let placement = 'center';
44
41
  export let spring = undefined;
45
42
  export let tweened = undefined;
46
43
  /**
@@ -48,10 +45,10 @@ export let tweened = undefined;
48
45
  */
49
46
  export let offset = 0;
50
47
  /**
51
- * Tooltip context to setup mouse events to show tooltip for related data
48
+ * Tooltip context to setup pointer events to show tooltip for related data
52
49
  */
53
50
  export let tooltip = undefined;
54
- const { data: contextData, x, y, xRange, rGet, config, width, height } = chartContext();
51
+ const { data: contextData, x, y, xRange, c, cScale, config, width, height } = chartContext();
55
52
  // @ts-expect-error
56
53
  $: resolved_endAngle = endAngle ?? degreesToRadians($config.xRange ? max($xRange) : max(range));
57
54
  let tweened_endAngle = motionStore(0, { spring, tweened });
@@ -63,41 +60,21 @@ $: pie = d3pie()
63
60
  .padAngle(padAngle)
64
61
  .value($x);
65
62
  $: arcs = pie(data ?? (Array.isArray($contextData) ? $contextData : []));
66
- $: radius = Math.min($width / 2, $height / 2);
67
- $: coords = {
68
- x: placement === 'left'
69
- ? radius
70
- : placement === 'center'
71
- ? $width / 2
72
- : placement === 'right'
73
- ? $width - radius
74
- : 0,
75
- y: placement === 'none' ? 0 : $height / 2,
76
- };
77
63
  </script>
78
64
 
79
- <Group x={coords.x} y={coords.y}>
80
- <slot {arcs}>
81
- {#each arcs as arc}
82
- <Arc
83
- startAngle={arc.startAngle}
84
- endAngle={arc.endAngle}
85
- padAngle={arc.padAngle}
86
- {innerRadius}
87
- {outerRadius}
88
- {cornerRadius}
89
- {offset}
90
- fill={$config.r ? $rGet(arc.data) : null}
91
- on:pointerenter={(e) => tooltip?.show(e, arc.data)}
92
- on:pointermove={(e) => tooltip?.show(e, arc.data)}
93
- on:pointerleave={(e) => tooltip?.hide()}
94
- on:touchmove={(e) => {
95
- if (tooltip) {
96
- // Prevent touch to not interfer with pointer when using tooltip
97
- e.preventDefault();
98
- }
99
- }}
100
- />
101
- {/each}
102
- </slot>
103
- </Group>
65
+ <slot {arcs}>
66
+ {#each arcs as arc}
67
+ <Arc
68
+ startAngle={arc.startAngle}
69
+ endAngle={arc.endAngle}
70
+ padAngle={arc.padAngle}
71
+ {innerRadius}
72
+ {outerRadius}
73
+ {cornerRadius}
74
+ {offset}
75
+ fill={$config.c ? $cScale?.($c(arc.data)) : null}
76
+ data={arc.data}
77
+ {tooltip}
78
+ />
79
+ {/each}
80
+ </slot>
@@ -1,6 +1,6 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { spring as springStore, tweened as tweenedStore } from 'svelte/motion';
3
- import type { TooltipContextValue } from './TooltipContext.svelte';
3
+ import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
4
4
  declare const __propDef: {
5
5
  props: {
6
6
  data?: any[] | undefined;
@@ -25,14 +25,13 @@ declare const __propDef: {
25
25
  */ outerRadius?: number | undefined;
26
26
  cornerRadius?: number;
27
27
  padAngle?: number;
28
- placement?: "left" | "center" | "right" | "none";
29
28
  spring?: boolean | Parameters<typeof springStore>[1];
30
29
  tweened?: boolean | Parameters<typeof tweenedStore>[1];
31
30
  /**
32
31
  * Offset all arcs from center
33
32
  */ offset?: number;
34
33
  /**
35
- * Tooltip context to setup mouse events to show tooltip for related data
34
+ * Tooltip context to setup pointer events to show tooltip for related data
36
35
  */ tooltip?: TooltipContextValue | undefined;
37
36
  };
38
37
  events: {