layerchart 0.15.6 → 0.17.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 (88) hide show
  1. package/README.md +22 -1
  2. package/dist/components/Arc.svelte +10 -10
  3. package/dist/components/Arc.svelte.d.ts +2 -1
  4. package/dist/components/Area.svelte +10 -10
  5. package/dist/components/AreaStack.svelte +25 -25
  6. package/dist/components/Axis.svelte +131 -0
  7. package/dist/components/Axis.svelte.d.ts +25 -0
  8. package/dist/components/Bars.svelte +30 -71
  9. package/dist/components/Bars.svelte.d.ts +1 -1
  10. package/dist/components/Baseline.svelte +20 -20
  11. package/dist/components/Blur.svelte +7 -7
  12. package/dist/components/Chart.svelte +46 -40
  13. package/dist/components/Chart.svelte.d.ts +2 -0
  14. package/dist/components/ChartClipPath.svelte +7 -7
  15. package/dist/components/Circle.svelte +7 -7
  16. package/dist/components/CircleClipPath.svelte +5 -5
  17. package/dist/components/ClipPath.svelte +4 -4
  18. package/dist/components/ClipPathUse.svelte +5 -5
  19. package/dist/components/ConnectedPoints.svelte +16 -16
  20. package/dist/components/GeoPath.svelte +11 -11
  21. package/dist/components/GeoPoint.svelte +3 -3
  22. package/dist/components/GeoTile.svelte +5 -5
  23. package/dist/components/Graticule.svelte +12 -12
  24. package/dist/components/Group.svelte +1 -1
  25. package/dist/components/HighlightLine.svelte +25 -25
  26. package/dist/components/HighlightRect.svelte +1 -1
  27. package/dist/components/Labels.svelte +83 -74
  28. package/dist/components/Labels.svelte.d.ts +4 -3
  29. package/dist/components/Legend.svelte +59 -59
  30. package/dist/components/Legend.svelte.d.ts +3 -2
  31. package/dist/components/Line.svelte +8 -8
  32. package/dist/components/LinearGradient.svelte +22 -22
  33. package/dist/components/Link.svelte +10 -10
  34. package/dist/components/Link.svelte.d.ts +1 -1
  35. package/dist/components/Pack.svelte.d.ts +2 -2
  36. package/dist/components/Partition.svelte.d.ts +5 -5
  37. package/dist/components/Path.svelte +16 -16
  38. package/dist/components/Pattern.svelte +3 -3
  39. package/dist/components/Pie.svelte +21 -21
  40. package/dist/components/Pie.svelte.d.ts +18 -18
  41. package/dist/components/Points.svelte +14 -14
  42. package/dist/components/Rect.svelte +8 -8
  43. package/dist/components/RectClipPath.svelte +5 -5
  44. package/dist/components/Sankey.svelte.d.ts +2 -2
  45. package/dist/components/Text.svelte +32 -32
  46. package/dist/components/Threshold.svelte +25 -25
  47. package/dist/components/TileImage.svelte +21 -21
  48. package/dist/components/Tooltip.svelte +25 -25
  49. package/dist/components/TooltipContext.svelte +80 -78
  50. package/dist/components/TooltipContext.svelte.d.ts +1 -1
  51. package/dist/components/TooltipItem.svelte +11 -12
  52. package/dist/components/TooltipItem.svelte.d.ts +2 -1
  53. package/dist/components/Tree.svelte.d.ts +9 -9
  54. package/dist/components/Zoom.svelte +18 -18
  55. package/dist/components/Zoom.svelte.d.ts +1 -1
  56. package/dist/components/index.d.ts +1 -2
  57. package/dist/components/index.js +1 -2
  58. package/dist/docs/Blockquote.svelte +2 -2
  59. package/dist/docs/Blockquote.svelte.d.ts +6 -17
  60. package/dist/docs/Code.svelte +25 -27
  61. package/dist/docs/Code.svelte.d.ts +8 -17
  62. package/dist/docs/GeoDebug.svelte +26 -27
  63. package/dist/docs/Header1.svelte +2 -3
  64. package/dist/docs/Header1.svelte.d.ts +5 -14
  65. package/dist/docs/Layout.svelte +11 -11
  66. package/dist/docs/Layout.svelte.d.ts +9 -20
  67. package/dist/docs/Link.svelte +2 -2
  68. package/dist/docs/Link.svelte.d.ts +5 -14
  69. package/dist/docs/Preview.svelte +25 -25
  70. package/dist/docs/Preview.svelte.d.ts +1 -1
  71. package/dist/docs/RangeField.svelte +18 -18
  72. package/dist/docs/TilesetField.svelte +13 -13
  73. package/dist/docs/ViewSourceButton.svelte +42 -0
  74. package/dist/docs/ViewSourceButton.svelte.d.ts +19 -0
  75. package/dist/docs/ZoomControls.svelte +40 -41
  76. package/dist/docs/ZoomControls.svelte.d.ts +2 -2
  77. package/dist/utils/genData.d.ts +2 -2
  78. package/dist/utils/quadtree.d.ts +10 -2
  79. package/dist/utils/quadtree.js +1 -1
  80. package/dist/utils/rect.d.ts +19 -0
  81. package/dist/utils/rect.js +97 -0
  82. package/dist/utils/scales.d.ts +8 -0
  83. package/dist/utils/scales.js +17 -0
  84. package/package.json +90 -88
  85. package/dist/components/AxisX.svelte +0 -43
  86. package/dist/components/AxisX.svelte.d.ts +0 -37
  87. package/dist/components/AxisY.svelte +0 -55
  88. package/dist/components/AxisY.svelte.d.ts +0 -37
@@ -13,11 +13,11 @@ $: tweened_r.set(r);
13
13
  </script>
14
14
 
15
15
  <circle
16
- cx={$tweened_cx}
17
- cy={$tweened_cy}
18
- r={$tweened_r}
19
- {...$$restProps}
20
- on:click
21
- on:mousemove
22
- on:mouseleave
16
+ cx={$tweened_cx}
17
+ cy={$tweened_cy}
18
+ r={$tweened_r}
19
+ {...$$restProps}
20
+ on:click
21
+ on:mousemove
22
+ on:mouseleave
23
23
  />
@@ -1,4 +1,4 @@
1
- <script>import { uniqueId } from 'svelte-ux/utils/string';
1
+ <script>import { uniqueId } from 'svelte-ux';
2
2
  import ClipPath from './ClipPath.svelte';
3
3
  import Circle from './Circle.svelte';
4
4
  /** Unique id for clipPath */
@@ -11,11 +11,11 @@ export let tweened = undefined;
11
11
  </script>
12
12
 
13
13
  <ClipPath {id}>
14
- <Circle {cx} {cy} {r} {spring} {tweened} />
14
+ <Circle {cx} {cy} {r} {spring} {tweened} />
15
15
  </ClipPath>
16
16
 
17
17
  {#if $$slots.default}
18
- <g style="clip-path: url(#{id})" on:click on:mousemove on:mouseleave>
19
- <slot {id} />
20
- </g>
18
+ <g style="clip-path: url(#{id})" on:click on:mousemove on:mouseleave>
19
+ <slot {id} />
20
+ </g>
21
21
  {/if}
@@ -1,10 +1,10 @@
1
- <script>import { uniqueId } from 'svelte-ux/utils/string';
1
+ <script>import { uniqueId } from 'svelte-ux';
2
2
  /** Unique id for clipPath */
3
3
  export let id = uniqueId('clipPath-');
4
4
  </script>
5
5
 
6
6
  <defs>
7
- <clipPath {id} {...$$restProps}>
8
- <slot {id} />
9
- </clipPath>
7
+ <clipPath {id} {...$$restProps}>
8
+ <slot {id} />
9
+ </clipPath>
10
10
  </defs>
@@ -1,4 +1,4 @@
1
- <script>import { uniqueId } from 'svelte-ux/utils/string';
1
+ <script>import { uniqueId } from 'svelte-ux';
2
2
  import ClipPath from './ClipPath.svelte';
3
3
  /** Id of path or shape */
4
4
  export let refId;
@@ -7,11 +7,11 @@ export let clipPathId = uniqueId('clipPath-');
7
7
  </script>
8
8
 
9
9
  <ClipPath id={clipPathId}>
10
- <use href="#{refId}" />
10
+ <use href="#{refId}" />
11
11
  </ClipPath>
12
12
 
13
13
  {#if $$slots.default}
14
- <g style="clip-path: url(#{clipPathId})" on:click on:mousemove on:mouseleave on:keydown>
15
- <slot {refId} {clipPathId} />
16
- </g>
14
+ <g style="clip-path: url(#{clipPathId})" on:click on:mousemove on:mouseleave on:keydown>
15
+ <slot {refId} {clipPathId} />
16
+ </g>
17
17
  {/if}
@@ -1,8 +1,8 @@
1
1
  <script>/*
2
- TODO:
3
- - [ ] Consider becoming LinkLine using d3-path buider https://github.com/d3/d3-path
4
- - https://github.com/airbnb/visx/blob/master/packages/visx-shape/src/shapes/link/line/LinkHorizontalLine.tsx
5
- */
2
+ TODO:
3
+ - [ ] Consider becoming LinkLine using d3-path buider https://github.com/d3/d3-path
4
+ - https://github.com/airbnb/visx/blob/master/packages/visx-shape/src/shapes/link/line/LinkHorizontalLine.tsx
5
+ */
6
6
  import { getContext } from 'svelte';
7
7
  import { extent } from 'd3-array';
8
8
  import Line from './Line.svelte';
@@ -28,9 +28,9 @@ function getOffset(value, offset, scale) {
28
28
  $: points = $data.flatMap((d) => {
29
29
  if (Array.isArray($config.x)) {
30
30
  /*
31
- x={["prop1" ,"prop2"]}
32
- y="prop3"
33
- */
31
+ x={["prop1" ,"prop2"]}
32
+ y="prop3"
33
+ */
34
34
  const [xMin, xMax] = extent($xGet(d));
35
35
  return {
36
36
  x1: xMin + getOffset(xMin, offsetX, $xScale),
@@ -41,9 +41,9 @@ $: points = $data.flatMap((d) => {
41
41
  }
42
42
  else if (Array.isArray($config.y)) {
43
43
  /*
44
- x="prop1"
45
- y={["prop2" ,"prop3"]}
46
- */
44
+ x="prop1"
45
+ y={["prop2" ,"prop3"]}
46
+ */
47
47
  const [yMin, yMax] = extent($yGet(d));
48
48
  return {
49
49
  x1: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
@@ -54,9 +54,9 @@ $: points = $data.flatMap((d) => {
54
54
  }
55
55
  else {
56
56
  /*
57
- x="prop1"
58
- y="prop2"
59
- */
57
+ x="prop1"
58
+ y="prop2"
59
+ */
60
60
  // Not really supported (nothing to connect...)
61
61
  return {
62
62
  x1: $xGet(d) + getOffset($xGet(d), offsetX, $xScale),
@@ -69,7 +69,7 @@ $: points = $data.flatMap((d) => {
69
69
  </script>
70
70
 
71
71
  <g class="connected-points">
72
- {#each points as p}
73
- <Line x1={p.x1} y1={p.y1} x2={p.x2} y2={p.y2} {...$$restProps} />
74
- {/each}
72
+ {#each points as p}
73
+ <Line x1={p.x1} y1={p.y1} x2={p.x2} y2={p.y2} {...$$restProps} />
74
+ {/each}
75
75
  </g>
@@ -42,15 +42,15 @@ $: if (renderContext === 'canvas' && $ctx) {
42
42
  </script>
43
43
 
44
44
  {#if renderContext === 'svg'}
45
- <slot {geoPath}>
46
- <path
47
- d={geoPath(geojson)}
48
- fill={fill || (fillScale && $rGet(fillScale)) || 'transparent'}
49
- stroke={stroke || 'black'}
50
- on:mousemove={(e) => tooltip?.show(e, geojson)}
51
- on:mouseleave={(e) => tooltip?.hide()}
52
- on:click={(event) => dispatch('click', { geoPath, event })}
53
- {...$$restProps}
54
- />
55
- </slot>
45
+ <slot {geoPath}>
46
+ <path
47
+ d={geoPath(geojson)}
48
+ fill={fill || (fillScale && $rGet(fillScale)) || 'transparent'}
49
+ stroke={stroke || 'black'}
50
+ on:mousemove={(e) => tooltip?.show(e, geojson)}
51
+ on:mouseleave={(e) => tooltip?.hide()}
52
+ on:click={(event) => dispatch('click', { geoPath, event })}
53
+ {...$$restProps}
54
+ />
55
+ </slot>
56
56
  {/if}
@@ -22,7 +22,7 @@ $: if (renderContext === 'canvas' && $ctx) {
22
22
  </script>
23
23
 
24
24
  {#if renderContext === 'svg'}
25
- <g transform="translate({x},{y})">
26
- <slot />
27
- </g>
25
+ <g transform="translate({x},{y})">
26
+ <slot />
27
+ </g>
28
28
  {/if}
@@ -39,9 +39,9 @@ $: if (renderContext === 'canvas' && $ctx && url) {
39
39
  </script>
40
40
 
41
41
  {#if renderContext === 'svg' && url}
42
- <slot {tiles}>
43
- {#each tiles as [x, y, z] (url(x, y, z))}
44
- <TileImage {url} {x} {y} {z} {tx} {ty} {k} {disableCache} {debug} />
45
- {/each}
46
- </slot>
42
+ <slot {tiles}>
43
+ {#each tiles as [x, y, z] (url(x, y, z))}
44
+ <TileImage {url} {x} {y} {z} {tx} {ty} {k} {disableCache} {debug} />
45
+ {/each}
46
+ </slot>
47
47
  {/if}
@@ -9,18 +9,18 @@ $: graticule.step(step);
9
9
  </script>
10
10
 
11
11
  <g class="graticule">
12
- <!-- TODO: Any reason to still render the single `MultiLineString` path if using `lines` and/or `outline` -->
13
- {#if !lines && !outline}
14
- <GeoPath geojson={graticule()} {...$$restProps} />
15
- {/if}
12
+ <!-- TODO: Any reason to still render the single `MultiLineString` path if using `lines` and/or `outline` -->
13
+ {#if !lines && !outline}
14
+ <GeoPath geojson={graticule()} {...$$restProps} />
15
+ {/if}
16
16
 
17
- {#if lines}
18
- {#each graticule.lines() as line}
19
- <GeoPath geojson={line} {...lines} />
20
- {/each}
21
- {/if}
17
+ {#if lines}
18
+ {#each graticule.lines() as line}
19
+ <GeoPath geojson={line} {...lines} />
20
+ {/each}
21
+ {/if}
22
22
 
23
- {#if outline}
24
- <GeoPath geojson={graticule.outline()} {...outline} />
25
- {/if}
23
+ {#if outline}
24
+ <GeoPath geojson={graticule.outline()} {...outline} />
25
+ {/if}
26
26
  </g>
@@ -29,5 +29,5 @@ $: if (center) {
29
29
  </script>
30
30
 
31
31
  <g {transform} {...$$restProps} on:click on:mousemove on:mouseleave>
32
- <slot />
32
+ <slot />
33
33
  </g>
@@ -115,30 +115,30 @@ $: if ($tooltip.data) {
115
115
  </script>
116
116
 
117
117
  {#if $tooltip.data}
118
- {#each lines as line}
119
- <Line
120
- spring
121
- x1={line.x1}
122
- y1={line.y1}
123
- x2={line.x2}
124
- y2={line.y2}
125
- stroke="rgba(0,0,0,.5)"
126
- stroke-width={2}
127
- style="pointerEvents: none"
128
- stroke-dasharray="2,2"
129
- />
130
- {/each}
118
+ {#each lines as line}
119
+ <Line
120
+ spring
121
+ x1={line.x1}
122
+ y1={line.y1}
123
+ x2={line.x2}
124
+ y2={line.y2}
125
+ stroke="rgba(0,0,0,.5)"
126
+ stroke-width={2}
127
+ style="pointerEvents: none"
128
+ stroke-dasharray="2,2"
129
+ />
130
+ {/each}
131
131
 
132
- {#each points as point}
133
- <Circle
134
- spring
135
- cx={point.x}
136
- cy={point.y}
137
- r={7}
138
- fill="rgba(255,255,255,.9)"
139
- stroke={point.color}
140
- stroke-width={2}
141
- />
142
- <Circle spring cx={point.x} cy={point.y} r={3} fill={point.color} />
143
- {/each}
132
+ {#each points as point}
133
+ <Circle
134
+ spring
135
+ cx={point.x}
136
+ cy={point.y}
137
+ r={7}
138
+ fill="rgba(255,255,255,.9)"
139
+ stroke={point.color}
140
+ stroke-width={2}
141
+ />
142
+ <Circle spring cx={point.x} cy={point.y} r={3} fill={point.color} />
143
+ {/each}
144
144
  {/if}
@@ -67,5 +67,5 @@ $: {
67
67
  </script>
68
68
 
69
69
  {#if $tooltip.data}
70
- <Rect spring {...dimensions} fill="rgba(0,0,0,.1)" on:click />
70
+ <Rect spring {...dimensions} fill="rgba(0,0,0,.1)" on:click />
71
71
  {/if}
@@ -4,79 +4,39 @@
4
4
  * - [ ] Support multiple values (threshold, stacks, etc)
5
5
  */
6
6
  import { getContext } from 'svelte';
7
- import { scaleBand } from 'd3-scale';
8
- import { max, min } from 'd3-array';
9
7
  import Text from './Text.svelte';
8
+ import { format as formatValue } from 'svelte-ux';
10
9
  import { formatNumberAsStyle } from 'svelte-ux/utils/number';
10
+ import { greatestAbs } from 'svelte-ux/utils/array';
11
11
  import { isScaleBand } from '../utils/scales';
12
- import { greatestAbs, unique } from 'svelte-ux/utils/array';
13
- import { format as formatValue } from 'svelte-ux/utils/format';
14
- const { flatData, xGet, yRange, xScale, yScale, x, y, custom } = getContext('LayerCake');
15
- export let orientation = 'auto';
12
+ import { createDimensionGetter } from '../utils/rect';
13
+ const { flatData, yScale, x, y, custom } = getContext('LayerCake');
14
+ // export let orientation: 'outside' | 'inside' | 'auto' = 'auto';
16
15
  export let significantDigits = 3;
17
16
  export let format = undefined;
18
17
  export let formatStyle = null;
19
- export let overlap = false;
18
+ // export let overlap = false;
20
19
  $: yBaseline = $custom?.yBaseline ?? 0;
21
20
  export let groupBy = undefined;
22
- const x1Scale = scaleBand();
23
- $: if (isScaleBand($xScale) && groupBy) {
24
- const groupKeys = unique($flatData.map((d) => d[groupBy]));
25
- x1Scale.domain(groupKeys).range([0, $xScale.bandwidth()]).paddingInner(0.2);
26
- }
27
- $: getDimensions = (item) => {
28
- // console.log({ item, y: $y(item) });
29
- let x = $xGet(item);
30
- let width = 0;
31
- if (isScaleBand($xScale)) {
32
- width = groupBy ? x1Scale.bandwidth() : $xScale.bandwidth();
33
- x += (groupBy ? x1Scale(item[groupBy]) : 0) + width / 2;
34
- }
35
- const yValue = $y(item);
36
- let yTop = 0;
37
- let yBottom = 0;
38
- if (Array.isArray(yValue)) {
39
- // Array contains both top and bottom values;
40
- yTop = max(yValue);
41
- yBottom = min(yValue);
42
- }
43
- else if (yValue == null) {
44
- // null/undefined value
45
- yTop = 0;
46
- yBottom = 0;
47
- }
48
- else if (yValue > 0) {
49
- // Positive value
50
- yTop = yValue;
51
- yBottom = min($yRange); // or `0`?
52
- }
53
- else {
54
- // Negative value
55
- yTop = min($yRange); // or `0`?
56
- yBottom = yValue;
57
- }
58
- if (yBottom < 0) {
59
- // Show label below
60
- return {
61
- x,
62
- y: $yScale(yBottom),
63
- dy: '0.5em',
64
- width
65
- };
66
- }
67
- else {
68
- // Show label above
69
- return {
70
- x,
71
- y: $yScale(yTop),
72
- dy: '-0.6em',
73
- width
74
- };
21
+ export let groupPaddingInner = 0.2;
22
+ export let groupPaddingOuter = 0;
23
+ $: getDimensions = createDimensionGetter(getContext('LayerCake'), {
24
+ // x,
25
+ // y,
26
+ groupBy,
27
+ // padding,
28
+ groupPadding: {
29
+ inner: groupPaddingInner,
30
+ outer: groupPaddingOuter
75
31
  }
32
+ });
33
+ $: getValue = (item) => (isScaleBand($yScale) ? $x(item) : $y(item));
34
+ $: getLabelValue = (item) => {
35
+ const value = getValue(item);
36
+ return (Array.isArray(value) ? greatestAbs(value) : value) + yBaseline;
76
37
  };
77
- $: getValue = (item) => {
78
- const value = $y(item);
79
- const labelValue = (Array.isArray(value) ? greatestAbs(value) : value) + yBaseline;
38
+ $: getFormattedValue = (item) => {
39
+ const labelValue = getLabelValue(item);
80
40
  let formattedValue = labelValue;
81
41
  if (labelValue != null) {
82
42
  if (format) {
@@ -90,17 +50,66 @@ $: getValue = (item) => {
90
50
  }
91
51
  return formattedValue ?? '';
92
52
  };
53
+ $: getTextProps = (item) => {
54
+ const labelValue = getLabelValue(item);
55
+ const dimensions = $getDimensions(item);
56
+ if (isScaleBand($yScale)) {
57
+ // Position label left/right on horizontal bars
58
+ if (labelValue < 0) {
59
+ // left
60
+ return {
61
+ x: dimensions?.x - 4,
62
+ y: dimensions?.y + (dimensions?.height ?? 0) / 2,
63
+ textAnchor: 'end',
64
+ verticalAnchor: 'middle',
65
+ capHeight: '.6rem'
66
+ };
67
+ }
68
+ else {
69
+ // right
70
+ return {
71
+ x: dimensions?.x + dimensions?.width + 4,
72
+ y: dimensions?.y + (dimensions?.height ?? 0) / 2,
73
+ textAnchor: 'start',
74
+ verticalAnchor: 'middle',
75
+ capHeight: '.6rem'
76
+ };
77
+ }
78
+ }
79
+ else {
80
+ // Position label top/bottom on vertical bars
81
+ if (labelValue < 0) {
82
+ // bottom
83
+ return {
84
+ x: dimensions?.x + (dimensions?.width ?? 0) / 2,
85
+ y: dimensions?.y + dimensions?.height,
86
+ dy: '0.5em',
87
+ textAnchor: 'middle',
88
+ verticalAnchor: 'middle'
89
+ };
90
+ }
91
+ else {
92
+ // top
93
+ return {
94
+ x: dimensions?.x + (dimensions?.width ?? 0) / 2,
95
+ y: dimensions?.y,
96
+ dy: '-0.6em',
97
+ textAnchor: 'middle',
98
+ verticalAnchor: 'middle'
99
+ };
100
+ }
101
+ }
102
+ };
93
103
  </script>
94
104
 
95
- <g class="label-group">
96
- {#each $flatData as item, index}
97
- <Text
98
- textAnchor="middle"
99
- verticalAnchor="middle"
100
- value={getValue(item)}
101
- class="group-rect text-xs stroke-white [stroke-width:2px]"
102
- {...getDimensions(item)}
103
- {...$$restProps}
104
- />
105
- {/each}
105
+ <g class="Labels">
106
+ {#each $flatData as item, index}
107
+ <!-- TODO: Add labels for each item when array/stack? Use `getValue(item)` instead and iterate -->
108
+ <Text
109
+ value={getFormattedValue(item)}
110
+ class="text-xs stroke-white [stroke-width:2px]"
111
+ {...getTextProps(item)}
112
+ {...$$restProps}
113
+ />
114
+ {/each}
106
115
  </g>
@@ -1,13 +1,14 @@
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
- orientation?: "auto" | "outside" | "inside" | undefined;
6
6
  significantDigits?: number | undefined;
7
- format?: any;
7
+ format?: FormatType;
8
8
  formatStyle?: any;
9
- overlap?: boolean | undefined;
10
9
  groupBy?: string | undefined;
10
+ groupPaddingInner?: number | undefined;
11
+ groupPaddingOuter?: number | undefined;
11
12
  };
12
13
  events: {
13
14
  [evt: string]: CustomEvent<any>;
@@ -2,9 +2,9 @@
2
2
  import { scaleBand, scaleLinear } from 'd3-scale';
3
3
  import { quantize, interpolate, interpolateRound } from 'd3-interpolate';
4
4
  import { quantile, range } from 'd3-array';
5
- import { format } from 'svelte-ux/utils/format';
5
+ import { format } from 'svelte-ux';
6
6
  import ColorRamp from './ColorRamp.svelte';
7
- import { cls } from 'svelte-ux/utils/styles';
7
+ import { cls } from 'svelte-ux';
8
8
  const { rScale } = getContext('LayerCake') ?? {};
9
9
  export let scale = undefined;
10
10
  export let title = '';
@@ -101,64 +101,64 @@ else {
101
101
  </script>
102
102
 
103
103
  <div
104
- class={cls(
105
- 'inline-block',
106
- {
107
- 'top-left': 'absolute top-0 left-0',
108
- top: 'absolute top-0 left-1/2 -translate-x-1/2',
109
- 'top-right': 'absolute top-0 right-0',
110
- left: 'absolute top-1/2 left-0 -translate-y-1/2',
111
- center: 'absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2',
112
- right: 'absolute top-1/2 right-0 -translate-y-1/2',
113
- 'bottom-left': 'absolute bottom-0 left-0',
114
- bottom: 'absolute bottom-0 left-1/2 -translate-x-1/2',
115
- 'bottom-right': 'absolute bottom-0 right-0'
116
- }[placement],
117
- classes.root
118
- )}
119
- {...$$restProps}
104
+ class={cls(
105
+ 'inline-block',
106
+ {
107
+ 'top-left': 'absolute top-0 left-0',
108
+ top: 'absolute top-0 left-1/2 -translate-x-1/2',
109
+ 'top-right': 'absolute top-0 right-0',
110
+ left: 'absolute top-1/2 left-0 -translate-y-1/2',
111
+ center: 'absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2',
112
+ right: 'absolute top-1/2 right-0 -translate-y-1/2',
113
+ 'bottom-left': 'absolute bottom-0 left-0',
114
+ bottom: 'absolute bottom-0 left-1/2 -translate-x-1/2',
115
+ 'bottom-right': 'absolute bottom-0 right-0'
116
+ }[placement],
117
+ classes.root
118
+ )}
119
+ {...$$restProps}
120
120
  >
121
- <div class={cls('text-[10px] font-semibold', classes.title)}>{title}</div>
122
- <slot values={tickValues} {scale}>
123
- <svg
124
- {width}
125
- height={height + tickSize + tickFontSize}
126
- viewBox="0 0 {width} {height + tickSize + tickFontSize}"
127
- class="overflow-visible"
128
- >
129
- <g>
130
- {#if interpolator}
131
- <ColorRamp {width} {height} {interpolator} />
132
- {:else if swatches}
133
- {#each swatches as swatch, i}
134
- <rect {...swatch} />
135
- {/each}
136
- {/if}
137
- </g>
121
+ <div class={cls('text-[10px] font-semibold', classes.title)}>{title}</div>
122
+ <slot values={tickValues} {scale}>
123
+ <svg
124
+ {width}
125
+ height={height + tickSize + tickFontSize}
126
+ viewBox="0 0 {width} {height + tickSize + tickFontSize}"
127
+ class="overflow-visible"
128
+ >
129
+ <g>
130
+ {#if interpolator}
131
+ <ColorRamp {width} {height} {interpolator} />
132
+ {:else if swatches}
133
+ {#each swatches as swatch, i}
134
+ <rect {...swatch} />
135
+ {/each}
136
+ {/if}
137
+ </g>
138
138
 
139
- <g>
140
- {#each tickValues ?? xScale?.ticks?.(ticks) ?? [] as tick, i}
141
- <text
142
- text-anchor="middle"
143
- x={xScale(tick) + tickLabelOffset}
144
- y={height + tickSize + tickFontSize}
145
- style:font-size={tickFontSize}
146
- class={classes.label}
147
- >
148
- {tickFormat ? format(tick, tickFormat) : tick}
149
- </text>
139
+ <g>
140
+ {#each tickValues ?? xScale?.ticks?.(ticks) ?? [] as tick, i}
141
+ <text
142
+ text-anchor="middle"
143
+ x={xScale(tick) + tickLabelOffset}
144
+ y={height + tickSize + tickFontSize}
145
+ style:font-size={tickFontSize}
146
+ class={classes.label}
147
+ >
148
+ {tickFormat ? format(tick, tickFormat) : tick}
149
+ </text>
150
150
 
151
- {#if tickLine}
152
- <line
153
- x1={xScale(tick)}
154
- y1={0}
155
- x2={xScale(tick)}
156
- y2={height + tickSize}
157
- class={cls('stroke-black', classes.tick)}
158
- />
159
- {/if}
160
- {/each}
161
- </g>
162
- </svg>
163
- </slot>
151
+ {#if tickLine}
152
+ <line
153
+ x1={xScale(tick)}
154
+ y1={0}
155
+ x2={xScale(tick)}
156
+ y2={height + tickSize}
157
+ class={cls('stroke-black', classes.tick)}
158
+ />
159
+ {/if}
160
+ {/each}
161
+ </g>
162
+ </svg>
163
+ </slot>
164
164
  </div>
@@ -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,11 +8,11 @@ declare const __propDef: {
7
8
  width?: number | undefined;
8
9
  height?: number | undefined;
9
10
  ticks?: number | undefined;
10
- tickFormat?: any;
11
+ tickFormat?: FormatType;
11
12
  tickValues?: any[] | undefined;
12
13
  tickFontSize?: number | undefined;
13
14
  tickSize?: number | undefined;
14
- placement?: ("left" | "right" | "top" | "center" | "top-left" | "top-right" | "bottom-left" | "bottom" | "bottom-right") | undefined;
15
+ placement?: ("top" | "bottom" | "left" | "right" | "center" | "top-left" | "top-right" | "bottom-left" | "bottom-right") | undefined;
15
16
  classes?: {
16
17
  root?: string | undefined;
17
18
  title?: string | undefined;