svelteplot 0.3.11-pr-153.1 → 0.3.11-pr-175.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/dist/core/FacetGrid.svelte +0 -3
- package/dist/helpers/group.d.ts +1 -1
- package/dist/marks/GridX.svelte +4 -2
- package/dist/marks/GridY.svelte +4 -2
- package/dist/marks/HTMLTooltip.svelte +12 -38
- package/dist/marks/HTMLTooltip.svelte.d.ts +0 -2
- package/dist/transforms/index.d.ts +1 -1
- package/dist/transforms/index.js +1 -1
- package/dist/transforms/stack.d.ts +1 -26
- package/dist/transforms/stack.js +2 -37
- package/package.json +1 -1
|
@@ -59,9 +59,6 @@
|
|
|
59
59
|
{#each fyValues as facetY, j (j)}
|
|
60
60
|
<g
|
|
61
61
|
class="facet"
|
|
62
|
-
data-facet-x={i}
|
|
63
|
-
data-facet-y={j}
|
|
64
|
-
data-facet={i * fyValues.length + j}
|
|
65
62
|
fill="currentColor"
|
|
66
63
|
style:display={emptyFacets.get(facetX)?.get(facetY) ? 'none' : 'block'}
|
|
67
64
|
transform="translate({useFacetX ? facetXScale(facetX) : 0}, {useFacetY
|
package/dist/helpers/group.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import type { Channels, DataRecord } from '../types/index.js';
|
|
|
3
3
|
* Groups the data by the fx, fy and z channels and calls the reduce function
|
|
4
4
|
* for each group. Returns the new channels to be added in the transform.
|
|
5
5
|
*/
|
|
6
|
-
export declare function groupFacetsAndZ
|
|
6
|
+
export declare function groupFacetsAndZ(items: DataRecord[], channels: Channels, reduce: (items: DataRecord[]) => any): any;
|
package/dist/marks/GridX.svelte
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { getContext } from 'svelte';
|
|
10
10
|
import Mark from '../Mark.svelte';
|
|
11
11
|
import type { PlotContext, BaseMarkProps, RawValue, PlotDefaults } from '../types/index.js';
|
|
12
|
-
import { resolveChannel, resolveStyles } from '../helpers/resolve.js';
|
|
12
|
+
import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
|
|
13
13
|
import { autoTicks } from '../helpers/autoTicks.js';
|
|
14
14
|
import { testFilter } from '../helpers/index.js';
|
|
15
15
|
import { RAW_VALUE } from '../transforms/recordize.js';
|
|
@@ -68,6 +68,8 @@
|
|
|
68
68
|
(plot.scales.x.type === 'band' ? plot.scales.x.fn.bandwidth() * 0.5 : 0)}
|
|
69
69
|
{@const y1_ = resolveChannel('y1', tick, options)}
|
|
70
70
|
{@const y2_ = resolveChannel('y2', tick, options)}
|
|
71
|
+
{@const dx = +resolveProp(options?.dx, tick, 0)}
|
|
72
|
+
{@const dy = +resolveProp(options?.dy, tick, 0)}
|
|
71
73
|
{@const y1 = options.y1 != null ? plot.scales.y.fn(y1_) : 0}
|
|
72
74
|
{@const y2 = options.y2 != null ? plot.scales.y.fn(y2_) : plot.facetHeight}
|
|
73
75
|
{@const [style, styleClass] = resolveStyles(
|
|
@@ -80,7 +82,7 @@
|
|
|
80
82
|
)}
|
|
81
83
|
<line
|
|
82
84
|
class={styleClass}
|
|
83
|
-
transform="translate({x},{plot.options.marginTop})"
|
|
85
|
+
transform="translate({x + dx},{plot.options.marginTop + dy})"
|
|
84
86
|
{style}
|
|
85
87
|
{y1}
|
|
86
88
|
{y2} />
|
package/dist/marks/GridY.svelte
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { getContext } from 'svelte';
|
|
10
10
|
import Mark from '../Mark.svelte';
|
|
11
11
|
import type { PlotContext, BaseMarkProps, RawValue, PlotDefaults } from '../types/index.js';
|
|
12
|
-
import { resolveChannel, resolveStyles } from '../helpers/resolve.js';
|
|
12
|
+
import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
|
|
13
13
|
import { autoTicks } from '../helpers/autoTicks.js';
|
|
14
14
|
import { testFilter } from '../helpers/index.js';
|
|
15
15
|
import { RAW_VALUE } from '../transforms/recordize.js';
|
|
@@ -70,6 +70,8 @@
|
|
|
70
70
|
{@const x2_ = resolveChannel('x2', tick, options)}
|
|
71
71
|
{@const x1 = options.x1 != null ? plot.scales.x.fn(x1_) : 0}
|
|
72
72
|
{@const x2 = options.x2 != null ? plot.scales.x.fn(x2_) : plot.facetWidth}
|
|
73
|
+
{@const dx = +resolveProp(options?.dx, tick, 0)}
|
|
74
|
+
{@const dy = +resolveProp(options?.dy, tick, 0)}
|
|
73
75
|
{@const [style, styleClass] = resolveStyles(
|
|
74
76
|
plot,
|
|
75
77
|
{ datum: { [RAW_VALUE]: tick } },
|
|
@@ -81,7 +83,7 @@
|
|
|
81
83
|
<line
|
|
82
84
|
{style}
|
|
83
85
|
class={styleClass}
|
|
84
|
-
transform="translate({plot.options.marginLeft},{y})"
|
|
86
|
+
transform="translate({plot.options.marginLeft + dx},{y + dy})"
|
|
85
87
|
{x1}
|
|
86
88
|
{x2} />
|
|
87
89
|
{/if}
|
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
x?: ChannelAccessor<Datum>;
|
|
9
9
|
y?: ChannelAccessor<Datum>;
|
|
10
10
|
r?: ChannelAccessor<Datum>;
|
|
11
|
-
fx?: ChannelAccessor<Datum>;
|
|
12
|
-
fy?: ChannelAccessor<Datum>;
|
|
13
11
|
children: Snippet<[{ datum: Datum }]>;
|
|
14
12
|
}
|
|
15
13
|
import { getContext, type Snippet } from 'svelte';
|
|
@@ -21,33 +19,18 @@
|
|
|
21
19
|
import { resolveChannel } from '../helpers/resolve.js';
|
|
22
20
|
import { quadtree } from 'd3-quadtree';
|
|
23
21
|
import { projectX, projectY } from '../helpers/scales.js';
|
|
24
|
-
import { groupFacetsAndZ } from '../helpers/group.js';
|
|
25
22
|
|
|
26
|
-
let { data, x, y, r,
|
|
23
|
+
let { data, x, y, r, children }: HTMLTooltipMarkProps = $props();
|
|
27
24
|
|
|
28
25
|
let datum = $state(false);
|
|
29
26
|
let tooltipX = $state();
|
|
30
27
|
let tooltipY = $state();
|
|
31
28
|
|
|
32
|
-
let facetOffsetX = $state(0);
|
|
33
|
-
let facetOffsetY = $state(0);
|
|
34
|
-
|
|
35
29
|
function onPointerMove(evt: MouseEvent) {
|
|
36
30
|
const plotRect = plot.body.getBoundingClientRect();
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
const facetIndex = +(facetEl.dataset?.facet ?? 0);
|
|
42
|
-
const facetRect = (facetEl?.firstChild ?? plot.body).getBoundingClientRect();
|
|
43
|
-
|
|
44
|
-
facetOffsetX = facetRect.left - plotRect.left - plot.options.marginLeft;
|
|
45
|
-
facetOffsetY = facetRect.top - plotRect.top - plot.options.marginTop;
|
|
46
|
-
|
|
47
|
-
const relativeX = evt.clientX - facetRect.left + (plot.options.marginLeft ?? 0);
|
|
48
|
-
const relativeY = evt.clientY - facetRect.top + (plot.options.marginTop ?? 0);
|
|
49
|
-
|
|
50
|
-
const pt = trees[facetIndex].find(relativeX, relativeY, 25);
|
|
31
|
+
let relativeX = evt.clientX - plotRect.left;
|
|
32
|
+
let relativeY = evt.clientY - plotRect.top;
|
|
33
|
+
const pt = tree.find(relativeX, relativeY, 25);
|
|
51
34
|
if (pt) {
|
|
52
35
|
tooltipX = resolveChannel('x', pt, { x, y, r });
|
|
53
36
|
tooltipY = resolveChannel('y', pt, { x, y, r });
|
|
@@ -71,26 +54,18 @@
|
|
|
71
54
|
};
|
|
72
55
|
});
|
|
73
56
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const trees = $derived(
|
|
81
|
-
groups.map((items) =>
|
|
82
|
-
quadtree()
|
|
83
|
-
.x((d) => projectX('x', plot.scales, resolveChannel('x', d, { x, y, r })))
|
|
84
|
-
.y((d) => projectY('y', plot.scales, resolveChannel('y', d, { x, y, r })))
|
|
85
|
-
.addAll(items)
|
|
86
|
-
)
|
|
57
|
+
let tree = $derived(
|
|
58
|
+
quadtree()
|
|
59
|
+
.x((d) => projectX('x', plot.scales, resolveChannel('x', d, { x, y, r })))
|
|
60
|
+
.y((d) => projectY('y', plot.scales, resolveChannel('y', d, { x, y, r })))
|
|
61
|
+
.addAll(data)
|
|
87
62
|
);
|
|
88
63
|
</script>
|
|
89
64
|
|
|
90
65
|
<div
|
|
91
66
|
class={['tooltip', { hide: !datum }]}
|
|
92
|
-
style:left="{tooltipX ?
|
|
93
|
-
style:top="{tooltipY ?
|
|
67
|
+
style:left="{tooltipX ? projectX('x', plot.scales, tooltipX) : 0}px"
|
|
68
|
+
style:top="{tooltipY ? projectY('y', plot.scales, tooltipY) : 0}px">
|
|
94
69
|
<div class="tooltip-body">
|
|
95
70
|
{@render children({ datum })}
|
|
96
71
|
</div>
|
|
@@ -102,10 +77,9 @@
|
|
|
102
77
|
background: var(--svelteplot-tooltip-bg);
|
|
103
78
|
border: 1px solid #ccc;
|
|
104
79
|
border-color: var(--svelteplot-tooltip-border);
|
|
105
|
-
font-size:
|
|
80
|
+
font-size: 13px;
|
|
106
81
|
padding: 1ex 1em;
|
|
107
82
|
border-radius: 3px;
|
|
108
|
-
line-height: 1.2;
|
|
109
83
|
box-shadow:
|
|
110
84
|
rgba(50, 50, 93, 0.25) 0px 2px 5px -1px,
|
|
111
85
|
rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;
|
|
@@ -12,5 +12,5 @@ export { renameChannels, replaceChannels } from './rename.js';
|
|
|
12
12
|
export { select, selectFirst, selectLast, selectMaxX, selectMaxY, selectMinX, selectMinY } from './select.js';
|
|
13
13
|
export { shiftX, shiftY } from './shift.js';
|
|
14
14
|
export { sort, shuffle, reverse } from './sort.js';
|
|
15
|
-
export { stackX, stackY
|
|
15
|
+
export { stackX, stackY } from './stack.js';
|
|
16
16
|
export { windowX, windowY } from './window.js';
|
package/dist/transforms/index.js
CHANGED
|
@@ -12,5 +12,5 @@ export { renameChannels, replaceChannels } from './rename.js';
|
|
|
12
12
|
export { select, selectFirst, selectLast, selectMaxX, selectMaxY, selectMinX, selectMinY } from './select.js';
|
|
13
13
|
export { shiftX, shiftY } from './shift.js';
|
|
14
14
|
export { sort, shuffle, reverse } from './sort.js';
|
|
15
|
-
export { stackX, stackY
|
|
15
|
+
export { stackX, stackY } from './stack.js';
|
|
16
16
|
export { windowX, windowY } from './window.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TransformArg } from '../types/index.js';
|
|
2
2
|
export type StackOrder = 'none' | 'appearance' | 'inside-out' | 'sum';
|
|
3
3
|
export type StackOffset = 'none' | 'wiggle' | 'center' | 'normalize' | 'diverging';
|
|
4
4
|
export type StackOptions = {
|
|
@@ -8,28 +8,3 @@ export type StackOptions = {
|
|
|
8
8
|
};
|
|
9
9
|
export declare function stackY<T>({ data, ...channels }: T, opts?: Partial<StackOptions>): T;
|
|
10
10
|
export declare function stackX({ data, ...channels }: TransformArg, opts?: Partial<StackOptions>): TransformArg;
|
|
11
|
-
export declare function stackMarimekko<T>({ data, x, y, value, ...rest }: {
|
|
12
|
-
data: T[];
|
|
13
|
-
x: ChannelAccessor<T>;
|
|
14
|
-
y: ChannelAccessor<T>;
|
|
15
|
-
value: ChannelAccessor<T>;
|
|
16
|
-
fx?: ChannelAccessor<T>;
|
|
17
|
-
fy?: ChannelAccessor<T>;
|
|
18
|
-
}, { x: xOpt, y: yOpt }?: {
|
|
19
|
-
x?: {
|
|
20
|
-
percent?: boolean;
|
|
21
|
-
};
|
|
22
|
-
y?: {
|
|
23
|
-
percent?: boolean;
|
|
24
|
-
};
|
|
25
|
-
}): {
|
|
26
|
-
data: T[];
|
|
27
|
-
x: symbol;
|
|
28
|
-
x1: symbol;
|
|
29
|
-
x2: symbol;
|
|
30
|
-
y: symbol;
|
|
31
|
-
y1: symbol;
|
|
32
|
-
y2: symbol;
|
|
33
|
-
fx?: ChannelAccessor<T>;
|
|
34
|
-
fy?: ChannelAccessor<T>;
|
|
35
|
-
};
|
package/dist/transforms/stack.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import isDataRecord from '../helpers/isDataRecord.js';
|
|
2
|
-
import { resolveChannel
|
|
2
|
+
import { resolveChannel } from '../helpers/resolve.js';
|
|
3
3
|
import { stack, stackOffsetExpand, stackOffsetSilhouette, stackOffsetWiggle, stackOrderAppearance, stackOrderAscending, stackOrderInsideOut, stackOrderNone, stackOffsetDiverging } from 'd3-shape';
|
|
4
|
-
import { index, union,
|
|
5
|
-
import { groupFacetsAndZ } from '../helpers/group';
|
|
4
|
+
import { index, union, groups as d3Groups } from 'd3-array';
|
|
6
5
|
const GROUP = Symbol('group');
|
|
7
6
|
const FACET = Symbol('group');
|
|
8
7
|
const DEFAULT_STACK_OPTIONS = {
|
|
@@ -111,37 +110,3 @@ function applyDefaults(opts) {
|
|
|
111
110
|
}
|
|
112
111
|
return { ...DEFAULT_STACK_OPTIONS, ...opts };
|
|
113
112
|
}
|
|
114
|
-
const X = Symbol('x'), X1 = Symbol('x1'), X2 = Symbol('x2');
|
|
115
|
-
const Y = Symbol('y'), Y1 = Symbol('y1'), Y2 = Symbol('y2');
|
|
116
|
-
export function stackMarimekko({ data, x, y, value, ...rest }, { x: xOpt, y: yOpt } = {}) {
|
|
117
|
-
const out = [];
|
|
118
|
-
groupFacetsAndZ(data, { ...rest }, (data) => {
|
|
119
|
-
const total = sum(data, (d) => d[value]);
|
|
120
|
-
let xPos = 0;
|
|
121
|
-
const grouped = d3Groups(data, (d) => resolveProp(d[x], d)).flatMap(([k, items]) => {
|
|
122
|
-
const groupValue = sum(items, (d) => resolveProp(d[value], d));
|
|
123
|
-
const x1 = xPos, x2 = xPos + groupValue;
|
|
124
|
-
xPos = x2;
|
|
125
|
-
let yPos = 0;
|
|
126
|
-
return items.map((d) => {
|
|
127
|
-
const y1 = yPos, y2 = yPos + resolveProp(d[value], d);
|
|
128
|
-
yPos = y2;
|
|
129
|
-
const normX1 = xOpt?.percent ? x1 / total : x1;
|
|
130
|
-
const normX2 = xOpt?.percent ? x2 / total : x2;
|
|
131
|
-
const normY1 = yOpt?.percent ? y1 / groupValue : y1;
|
|
132
|
-
const normY2 = yOpt?.percent ? y2 / groupValue : y2;
|
|
133
|
-
return {
|
|
134
|
-
...d,
|
|
135
|
-
[X1]: normX1,
|
|
136
|
-
[X2]: normX2,
|
|
137
|
-
[Y1]: normY1,
|
|
138
|
-
[Y2]: normY2,
|
|
139
|
-
[X]: (normX1 + normX2) / 2,
|
|
140
|
-
[Y]: (normY1 + normY2) / 2
|
|
141
|
-
};
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
out.push(...grouped);
|
|
145
|
-
});
|
|
146
|
-
return { ...rest, data: out, x: X, x1: X1, x2: X2, y: Y, y1: Y1, y2: Y2 };
|
|
147
|
-
}
|