layerchart 0.9.2 → 0.10.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.
package/components/Labels.svelte
CHANGED
|
@@ -10,9 +10,11 @@ import Text from './Text.svelte';
|
|
|
10
10
|
import { formatNumberAsStyle } from 'svelte-ux/utils/number';
|
|
11
11
|
import { isScaleBand } from '../utils/scales';
|
|
12
12
|
import { greatestAbs, unique } from 'svelte-ux/utils/array';
|
|
13
|
+
import { format as formatValue } from 'svelte-ux/utils/format';
|
|
13
14
|
const { flatData, xGet, yRange, xScale, yScale, x, y, custom } = getContext('LayerCake');
|
|
14
15
|
export let orientation = 'auto';
|
|
15
16
|
export let significantDigits = 3;
|
|
17
|
+
export let format = undefined;
|
|
16
18
|
export let formatStyle = null;
|
|
17
19
|
export let overlap = false;
|
|
18
20
|
$: yBaseline = $custom?.yBaseline ?? 0;
|
|
@@ -74,21 +76,29 @@ $: getDimensions = (item) => {
|
|
|
74
76
|
};
|
|
75
77
|
$: getValue = (item) => {
|
|
76
78
|
const value = $y(item);
|
|
77
|
-
const labelValue = Array.isArray(value) ? greatestAbs(value) : value;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
const labelValue = (Array.isArray(value) ? greatestAbs(value) : value) + yBaseline;
|
|
80
|
+
let formattedValue = labelValue;
|
|
81
|
+
if (labelValue != null) {
|
|
82
|
+
if (format) {
|
|
83
|
+
// Apply more versatile formatting first
|
|
84
|
+
formattedValue = formatValue(labelValue, format ?? $yScale.tickFormat?.());
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// Deprecated format
|
|
88
|
+
formattedValue = formatNumberAsStyle(labelValue, formatStyle, 0, significantDigits);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return formattedValue ?? '';
|
|
81
92
|
};
|
|
82
93
|
</script>
|
|
83
94
|
|
|
84
95
|
<g class="label-group">
|
|
85
96
|
{#each $flatData as item, index}
|
|
86
97
|
<Text
|
|
87
|
-
class="group-rect"
|
|
88
98
|
textAnchor="middle"
|
|
89
99
|
verticalAnchor="middle"
|
|
90
100
|
value={getValue(item)}
|
|
91
|
-
|
|
101
|
+
class="group-rect text-xs stroke-white [stroke-width: 2px]"
|
|
92
102
|
{...getDimensions(item)}
|
|
93
103
|
{...$$restProps}
|
|
94
104
|
/>
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import { FormatNumberStyle } from 'svelte-ux/utils/number';
|
|
3
|
+
import { FormatType } from 'svelte-ux/utils/format';
|
|
3
4
|
declare const __propDef: {
|
|
4
5
|
props: {
|
|
5
6
|
[x: string]: any;
|
|
6
7
|
orientation?: 'outside' | 'inside' | 'auto';
|
|
7
8
|
significantDigits?: number;
|
|
9
|
+
format?: FormatType;
|
|
8
10
|
formatStyle?: FormatNumberStyle;
|
|
9
11
|
overlap?: boolean;
|
|
10
12
|
groupBy?: string;
|
package/components/Legend.svelte
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
<script>import { getContext } from 'svelte';
|
|
2
2
|
export let formatLabel = (label) => label;
|
|
3
|
-
const { rScale } = getContext('LayerCake');
|
|
4
|
-
|
|
5
|
-
const range = $rScale.range();
|
|
3
|
+
const { rScale, rDomain, rRange } = getContext('LayerCake');
|
|
4
|
+
$: console.log({ $rDomain });
|
|
6
5
|
// zip values together
|
|
7
|
-
export let items =
|
|
6
|
+
export let items = $rDomain.map((d, i) => ({ label: d, color: $rRange[i] }));
|
|
8
7
|
</script>
|
|
9
8
|
|
|
10
9
|
<slot {items} scale={$rScale}>
|
package/package.json
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
"author": "Sean Lynch <techniq35@gmail.com>",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "techniq/layerchart",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.10.0",
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@rollup/plugin-dsv": "^2.0.3",
|
|
9
9
|
"@sveltejs/adapter-vercel": "^1.0.0-next.59",
|
|
10
10
|
"@sveltejs/kit": "^1.0.0-next.354",
|
|
11
|
-
"@tailwindcss/typography": "^0.5.
|
|
11
|
+
"@tailwindcss/typography": "^0.5.7",
|
|
12
12
|
"@types/d3-array": "^3.0.3",
|
|
13
13
|
"@types/d3-delaunay": "^6.0.1",
|
|
14
14
|
"@types/d3-dsv": "^3.0.0",
|
|
@@ -18,39 +18,39 @@
|
|
|
18
18
|
"@types/d3-scale": "^4.0.2",
|
|
19
19
|
"@types/d3-shape": "^3.1.0",
|
|
20
20
|
"@types/lodash-es": "^4.17.6",
|
|
21
|
-
"autoprefixer": "^10.4.
|
|
21
|
+
"autoprefixer": "^10.4.12",
|
|
22
22
|
"mdsvex": "^0.10.6",
|
|
23
23
|
"prettier": "^2.7.1",
|
|
24
|
-
"prettier-plugin-svelte": "^2.7.
|
|
24
|
+
"prettier-plugin-svelte": "^2.7.1",
|
|
25
25
|
"prism-themes": "^1.9.0",
|
|
26
26
|
"rehype-slug": "^5.0.1",
|
|
27
|
-
"svelte": "^3.
|
|
28
|
-
"svelte-check": "^2.
|
|
27
|
+
"svelte": "^3.50.1",
|
|
28
|
+
"svelte-check": "^2.9.1",
|
|
29
29
|
"svelte-preprocess": "^4.10.7",
|
|
30
|
-
"svelte2tsx": "^0.5.
|
|
31
|
-
"tailwindcss": "^3.1.
|
|
30
|
+
"svelte2tsx": "^0.5.19",
|
|
31
|
+
"tailwindcss": "^3.1.8",
|
|
32
32
|
"tslib": "^2.4.0",
|
|
33
|
-
"typescript": "^4.
|
|
34
|
-
"unist-util-visit": "^4.1.
|
|
33
|
+
"typescript": "^4.8.4",
|
|
34
|
+
"unist-util-visit": "^4.1.1",
|
|
35
35
|
"vite-plugin-sveld": "^1.0.3"
|
|
36
36
|
},
|
|
37
37
|
"type": "module",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@mdi/js": "^
|
|
40
|
-
"d3-array": "^3.
|
|
39
|
+
"@mdi/js": "^7.0.96",
|
|
40
|
+
"d3-array": "^3.2.0",
|
|
41
41
|
"d3-delaunay": "^6.0.2",
|
|
42
42
|
"d3-dsv": "^3.0.1",
|
|
43
43
|
"d3-hierarchy": "^3.1.2",
|
|
44
|
-
"d3-interpolate-path": "^2.
|
|
44
|
+
"d3-interpolate-path": "^2.3.0",
|
|
45
45
|
"d3-quadtree": "^3.0.1",
|
|
46
46
|
"d3-sankey": "^0.12.3",
|
|
47
47
|
"d3-scale": "^4.0.2",
|
|
48
48
|
"d3-scale-chromatic": "^3.0.0",
|
|
49
49
|
"d3-shape": "^3.1.0",
|
|
50
|
-
"date-fns": "^2.
|
|
51
|
-
"layercake": "^
|
|
50
|
+
"date-fns": "^2.29.3",
|
|
51
|
+
"layercake": "^7.1.0",
|
|
52
52
|
"lodash-es": "^4.17.21",
|
|
53
|
-
"svelte-ux": "^0.
|
|
53
|
+
"svelte-ux": "^0.9.2"
|
|
54
54
|
},
|
|
55
55
|
"exports": {
|
|
56
56
|
"./package.json": "./package.json",
|