layerchart 0.7.0 → 0.7.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/Arc.svelte +5 -6
- package/components/Baseline.svelte +8 -1
- package/components/Chart.svelte +1 -3
- package/components/Tooltip.svelte +10 -4
- package/docs/Layout.svelte +11 -4
- package/docs/Preview.svelte +38 -7
- package/docs/Preview.svelte.d.ts +2 -1
- package/package.json +2 -2
- package/utils/scales.d.ts +2 -0
- package/utils/scales.js +2 -0
package/components/Arc.svelte
CHANGED
|
@@ -37,15 +37,14 @@ export let startAngle = undefined;
|
|
|
37
37
|
*/
|
|
38
38
|
export let endAngle = undefined;
|
|
39
39
|
/**
|
|
40
|
-
* Define innerRadius.
|
|
41
|
-
* value >= 1: discrete value
|
|
42
|
-
* value
|
|
43
|
-
* value <
|
|
44
|
-
* default: yRange min
|
|
40
|
+
* Define innerRadius. Defaults to yRange min
|
|
41
|
+
* • value >= 1: discrete value
|
|
42
|
+
* • value < 1: percent of `outerRadius`
|
|
43
|
+
* • value < 0: offset of `outerRadius`
|
|
45
44
|
*/
|
|
46
45
|
export let innerRadius = undefined;
|
|
47
46
|
/**
|
|
48
|
-
* Define outerRadius. Defaults to yRange max/2 (ie. chart height / 2)
|
|
47
|
+
* Define outerRadius. Defaults to yRange max / 2 (ie. chart height / 2)
|
|
49
48
|
*/
|
|
50
49
|
export let outerRadius = undefined;
|
|
51
50
|
export let cornerRadius = 0;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script>import { getContext } from 'svelte';
|
|
2
2
|
import { min, max } from 'd3-array';
|
|
3
|
+
import { isScaleBand } from '../utils/scales';
|
|
3
4
|
const { xRange, yScale, yRange } = getContext('LayerCake');
|
|
4
5
|
export let x = false;
|
|
5
6
|
export let y = false;
|
|
@@ -7,7 +8,13 @@ export let y = false;
|
|
|
7
8
|
|
|
8
9
|
<g class="baseline">
|
|
9
10
|
{#if x}
|
|
10
|
-
<line
|
|
11
|
+
<line
|
|
12
|
+
x1={0}
|
|
13
|
+
x2={max($xRange) || 0}
|
|
14
|
+
y1={isScaleBand($yScale) ? max($yRange) : $yScale(0) || 0}
|
|
15
|
+
y2={isScaleBand($yScale) ? max($yRange) : $yScale(0) || 0}
|
|
16
|
+
class="baseline"
|
|
17
|
+
/>
|
|
11
18
|
{/if}
|
|
12
19
|
|
|
13
20
|
{#if y}
|
package/components/Chart.svelte
CHANGED
|
@@ -9,7 +9,6 @@ import { isScaleBand } from '../utils/scales';
|
|
|
9
9
|
* Resolve a value from data based on the accessor type
|
|
10
10
|
*/
|
|
11
11
|
function getValue(accessor, d) {
|
|
12
|
-
console.log({ accessor });
|
|
13
12
|
if (Array.isArray(accessor)) {
|
|
14
13
|
return accessor.map((a) => getValue(a, d));
|
|
15
14
|
}
|
|
@@ -49,8 +48,7 @@ $: if (yBaseline != null) {
|
|
|
49
48
|
* Reverse the default y range ([0, height] becomes [height, 0]). By default this is `true` unless using scaleBand y scale.
|
|
50
49
|
* see: https://layercake.graphics/guide#yreverse
|
|
51
50
|
* see: https://github.com/mhkeller/layercake/issues/83
|
|
52
|
-
|
|
53
|
-
*/
|
|
51
|
+
*/
|
|
54
52
|
$: yReverse = yScale ? !isScaleBand(yScale) : true;
|
|
55
53
|
</script>
|
|
56
54
|
|
|
@@ -107,9 +107,10 @@ function findData(previousValue, currentValue, valueAtPoint, accessor) {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
function handleTooltip(event, tooltipData) {
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const
|
|
110
|
+
const referenceNode = event.target.closest('.layercake-container');
|
|
111
|
+
const point = localPoint(referenceNode, event);
|
|
112
|
+
const localX = point?.x - $padding.left ?? 0;
|
|
113
|
+
const localY = point?.y - $padding.top ?? 0;
|
|
113
114
|
// If tooltipData not provided already (voronoi, etc), attempt to find it
|
|
114
115
|
// TODO: When using bisect-x/y/band, values should be sorted. Tyipcally are for `x`, but not `y` (and band depends on if x or y scale)
|
|
115
116
|
if (tooltipData == null) {
|
|
@@ -150,7 +151,6 @@ function handleTooltip(event, tooltipData) {
|
|
|
150
151
|
const index = bisectX($flatData, xValueAtPoint, 1);
|
|
151
152
|
const previousValue = $flatData[index - 1];
|
|
152
153
|
const currentValue = $flatData[index];
|
|
153
|
-
console.log({ index, previousValue, currentValue });
|
|
154
154
|
tooltipData = findData(previousValue, currentValue, xValueAtPoint, $x);
|
|
155
155
|
}
|
|
156
156
|
else if (mode === 'bisect-y') {
|
|
@@ -319,6 +319,9 @@ $: if (mode === 'bounds' || mode === 'band') {
|
|
|
319
319
|
style:stroke={debug ? 'red' : 'transparent'}
|
|
320
320
|
on:mousemove={(e) => handleTooltip(e, point.data)}
|
|
321
321
|
on:mouseleave={hideTooltip}
|
|
322
|
+
on:click={(e) => {
|
|
323
|
+
dispatch('click', { data: point.data });
|
|
324
|
+
}}
|
|
322
325
|
/>
|
|
323
326
|
</g>
|
|
324
327
|
{/each}
|
|
@@ -337,6 +340,9 @@ $: if (mode === 'bounds' || mode === 'band') {
|
|
|
337
340
|
style:stroke={debug ? 'red' : 'transparent'}
|
|
338
341
|
on:mousemove={(e) => handleTooltip(e, rect.data)}
|
|
339
342
|
on:mouseleave={hideTooltip}
|
|
343
|
+
on:click={(e) => {
|
|
344
|
+
dispatch('click', { data: rect.data });
|
|
345
|
+
}}
|
|
340
346
|
/>
|
|
341
347
|
{/each}
|
|
342
348
|
</g>
|
package/docs/Layout.svelte
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
<Button
|
|
27
27
|
class="text-black/50"
|
|
28
28
|
icon={mdiCodeTags}
|
|
29
|
-
href="https://github.com/techniq/
|
|
29
|
+
href="https://github.com/techniq/layerchart/blob/master/src/lib/components/{component}.svelte"
|
|
30
30
|
target="_blank"
|
|
31
31
|
/>
|
|
32
32
|
</Tooltip>
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
<Button
|
|
38
38
|
class="text-black/50"
|
|
39
39
|
icon={mdiFileDocumentEditOutline}
|
|
40
|
-
href="https://github.com/techniq/
|
|
40
|
+
href="https://github.com/techniq/layerchart/blob/master/{filename}"
|
|
41
41
|
target="_blank"
|
|
42
42
|
/>
|
|
43
43
|
</Tooltip>
|
|
@@ -46,9 +46,16 @@
|
|
|
46
46
|
{/if}
|
|
47
47
|
|
|
48
48
|
{#if description}
|
|
49
|
-
|
|
49
|
+
<div class="text-sm text-black/50">
|
|
50
|
+
{description}
|
|
51
|
+
</div>
|
|
50
52
|
{/if}
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
{#if $$slots.toc}
|
|
55
|
+
<div class="text-xs uppercase text-black/50 leading-8 tracking-widest mt-4">Contents</div>
|
|
56
|
+
<div class="border border-black/20 rounded bg-white">
|
|
57
|
+
<slot name="toc" />
|
|
58
|
+
</div>
|
|
59
|
+
{/if}
|
|
53
60
|
|
|
54
61
|
<slot />
|
package/docs/Preview.svelte
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
<script
|
|
1
|
+
<script>// TODO: No longer copy from svelte-ux after prismjs is migrated to ESM (commonjs causes issue with Vite from another library)
|
|
2
|
+
import Prism from 'prismjs';
|
|
2
3
|
import 'prism-svelte';
|
|
4
|
+
import { mdiCodeTags, mdiContentCopy } from '@mdi/js';
|
|
5
|
+
import { slide } from 'svelte/transition';
|
|
6
|
+
import { Button } from 'svelte-ux';
|
|
3
7
|
export let code = null;
|
|
4
8
|
export let language = 'svelte';
|
|
5
|
-
export let
|
|
6
|
-
|
|
9
|
+
export let highlightedCode = Prism.highlight(code, Prism.languages.svelte, language);
|
|
10
|
+
export let showCode = false;
|
|
7
11
|
</script>
|
|
8
12
|
|
|
9
13
|
<div class="border border-black/20 rounded bg-white">
|
|
@@ -11,9 +15,36 @@ $: displayCode = highlight ? Prism.highlight(code, Prism.languages.svelte, 'svel
|
|
|
11
15
|
<slot />
|
|
12
16
|
</div>
|
|
13
17
|
|
|
14
|
-
{#if
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
+
{#if code && showCode}
|
|
19
|
+
<div class="relative">
|
|
20
|
+
<pre
|
|
21
|
+
class="language-{language} rounded"
|
|
22
|
+
style="margin: 0; white-space: normal;"
|
|
23
|
+
transition:slide|local>
|
|
24
|
+
<code class="language-{language}">{@html highlightedCode}</code>
|
|
25
|
+
</pre>
|
|
26
|
+
|
|
27
|
+
<div class="absolute top-0 right-0 p-2">
|
|
28
|
+
<Button
|
|
29
|
+
icon={mdiContentCopy}
|
|
30
|
+
small
|
|
31
|
+
class=" text-white/70 hover:bg-white/20 py-1"
|
|
32
|
+
on:click={() => navigator.clipboard.writeText(code)}
|
|
33
|
+
>
|
|
34
|
+
Copy
|
|
35
|
+
</Button>
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
18
38
|
{/if}
|
|
19
39
|
</div>
|
|
40
|
+
|
|
41
|
+
{#if code}
|
|
42
|
+
<Button
|
|
43
|
+
icon={mdiCodeTags}
|
|
44
|
+
small
|
|
45
|
+
class=" text-black/70 py-1"
|
|
46
|
+
on:click={() => (showCode = !showCode)}
|
|
47
|
+
>
|
|
48
|
+
{showCode ? 'Hide' : 'Show'} Code
|
|
49
|
+
</Button>
|
|
50
|
+
{/if}
|
package/docs/Preview.svelte.d.ts
CHANGED
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.7.
|
|
6
|
+
"version": "0.7.3",
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@rollup/plugin-dsv": "^2.0.3",
|
|
9
9
|
"@sveltejs/adapter-vercel": "^1.0.0-next.59",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"date-fns": "^2.28.0",
|
|
50
50
|
"layercake": "^6.1.0",
|
|
51
51
|
"lodash-es": "^4.17.21",
|
|
52
|
-
"svelte-ux": "^0.6.
|
|
52
|
+
"svelte-ux": "^0.6.10"
|
|
53
53
|
},
|
|
54
54
|
"exports": {
|
|
55
55
|
"./package.json": "./package.json",
|
package/utils/scales.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { MotionOptions } from '../stores/motionStore';
|
|
|
7
7
|
* https://github.com/d3/d3-scale/pull/64
|
|
8
8
|
* https://github.com/vega/vega-scale/blob/master/src/scaleBand.js#L118
|
|
9
9
|
* https://observablehq.com/@d3/ordinal-brushing
|
|
10
|
+
* https://github.com/d3/d3-scale/blob/11777dac7d4b0b3e229d658aee3257ea67bd5ffa/src/band.js#L32
|
|
11
|
+
* https://gist.github.com/LuisSevillano/d53a1dc529eef518780c6df99613e2fd
|
|
10
12
|
*/
|
|
11
13
|
export declare function scaleBandInvert(scale: any): (value: any) => any;
|
|
12
14
|
export declare function isScaleBand(scale: any): boolean;
|
package/utils/scales.js
CHANGED
|
@@ -9,6 +9,8 @@ import { motionStore } from '../stores/motionStore';
|
|
|
9
9
|
* https://github.com/d3/d3-scale/pull/64
|
|
10
10
|
* https://github.com/vega/vega-scale/blob/master/src/scaleBand.js#L118
|
|
11
11
|
* https://observablehq.com/@d3/ordinal-brushing
|
|
12
|
+
* https://github.com/d3/d3-scale/blob/11777dac7d4b0b3e229d658aee3257ea67bd5ffa/src/band.js#L32
|
|
13
|
+
* https://gist.github.com/LuisSevillano/d53a1dc529eef518780c6df99613e2fd
|
|
12
14
|
*/
|
|
13
15
|
export function scaleBandInvert(scale) {
|
|
14
16
|
const domain = scale.domain();
|