layerchart 0.9.1 → 0.9.3
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/Bars.svelte
CHANGED
|
@@ -31,9 +31,15 @@ export let spring = undefined;
|
|
|
31
31
|
export let tweened = undefined;
|
|
32
32
|
// See: https://svelte.dev/repl/7000c5ce05b84cd98ccbfb2768b4be3d?version=3.38.3
|
|
33
33
|
export let groupBy = undefined;
|
|
34
|
+
export let groupPaddingInner = 0.2;
|
|
35
|
+
export let groupPaddingOuter = 0;
|
|
34
36
|
// $: console.log({ $data, $flatData, groupBy, stackBy })
|
|
35
37
|
$: groupKeys = unique($flatData.map((d) => d[groupBy]));
|
|
36
|
-
$: x1Scale = scaleBand()
|
|
38
|
+
$: x1Scale = scaleBand()
|
|
39
|
+
.domain(groupKeys)
|
|
40
|
+
.range([0, $xScale.bandwidth()])
|
|
41
|
+
.paddingInner(groupPaddingInner)
|
|
42
|
+
.paddingOuter(groupPaddingOuter);
|
|
37
43
|
$: getDimensions = (item) => {
|
|
38
44
|
// console.log({ item, y: $y(item) });
|
|
39
45
|
const x = $xGet(item) + (groupBy ? x1Scale(item[groupBy]) : 0) - widthOffset / 2;
|
|
@@ -24,6 +24,8 @@ declare const __propDef: {
|
|
|
24
24
|
spring?: boolean | Parameters<typeof springStore>[1];
|
|
25
25
|
tweened?: boolean | Parameters<typeof tweenedStore>[1];
|
|
26
26
|
groupBy?: string;
|
|
27
|
+
groupPaddingInner?: number;
|
|
28
|
+
groupPaddingOuter?: number;
|
|
27
29
|
};
|
|
28
30
|
events: {
|
|
29
31
|
[evt: string]: CustomEvent<any>;
|
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,10 +76,19 @@ $: 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
|
|
|
@@ -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,4 +1,5 @@
|
|
|
1
1
|
<script>import { getContext } from 'svelte';
|
|
2
|
+
export let formatLabel = (label) => label;
|
|
2
3
|
const { rScale } = getContext('LayerCake');
|
|
3
4
|
const domain = $rScale.domain();
|
|
4
5
|
const range = $rScale.range();
|
|
@@ -11,7 +12,7 @@ export let items = domain.map((d, i) => ({ label: d, color: range[i] }));
|
|
|
11
12
|
{#each items as { label, color }}
|
|
12
13
|
<div class="flex items-center gap-1">
|
|
13
14
|
<div class="h-4 w-4 rounded-full" style:background-color={color} />
|
|
14
|
-
{label}
|
|
15
|
+
{formatLabel(label)}
|
|
15
16
|
</div>
|
|
16
17
|
{/each}
|
|
17
18
|
</div>
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Sean Lynch <techniq35@gmail.com>",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "techniq/layerchart",
|
|
6
|
-
"version": "0.9.
|
|
6
|
+
"version": "0.9.3",
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@rollup/plugin-dsv": "^2.0.3",
|
|
9
9
|
"@sveltejs/adapter-vercel": "^1.0.0-next.59",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"prettier": "^2.7.1",
|
|
24
24
|
"prettier-plugin-svelte": "^2.7.0",
|
|
25
25
|
"prism-themes": "^1.9.0",
|
|
26
|
+
"rehype-slug": "^5.0.1",
|
|
26
27
|
"svelte": "^3.48.0",
|
|
27
28
|
"svelte-check": "^2.7.2",
|
|
28
29
|
"svelte-preprocess": "^4.10.7",
|