svelteplot 0.0.1-alpha.11 → 0.0.1-alpha.13
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/Plot.svelte +6 -6
- package/dist/classes/Mark.svelte.js +4 -0
- package/dist/classes/Plot.svelte.js +47 -20
- package/dist/classes/Scale.svelte.js +95 -0
- package/dist/contants.d.ts +3 -3
- package/dist/contants.js +18 -16
- package/dist/helpers/autoTimeFormat.d.ts +2 -2
- package/dist/helpers/createScale.js +19 -6
- package/dist/helpers/curves.d.ts +3 -0
- package/dist/helpers/curves.js +42 -0
- package/dist/helpers/getBaseStyles.js +2 -2
- package/dist/helpers/getLogTicks.js +5 -5
- package/dist/helpers/isRawValue.d.ts +2 -0
- package/dist/helpers/isRawValue.js +5 -0
- package/dist/helpers/resolveChannel.d.ts +6 -2
- package/dist/helpers/resolveChannel.js +15 -5
- package/dist/helpers/wrapValueArray.d.ts +6 -0
- package/dist/helpers/wrapValueArray.js +5 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +11 -3
- package/dist/marks/Area.svelte +35 -21
- package/dist/marks/Area.svelte.d.ts +14 -1
- package/dist/marks/AreaX.svelte +8 -15
- package/dist/marks/AreaX.svelte.d.ts +17 -4
- package/dist/marks/AreaY.svelte +9 -10
- package/dist/marks/AreaY.svelte.d.ts +17 -4
- package/dist/marks/AxisX.svelte +7 -8
- package/dist/marks/AxisY.svelte +10 -6
- package/dist/marks/BarX.svelte +52 -0
- package/dist/marks/BarX.svelte.d.ts +25 -0
- package/dist/marks/BarY.svelte +52 -0
- package/dist/marks/BarY.svelte.d.ts +25 -0
- package/dist/marks/BaseMark.svelte +9 -2
- package/dist/marks/BaseMark.svelte.d.ts +2 -1
- package/dist/marks/Dot.svelte +26 -40
- package/dist/marks/Dot.svelte.d.ts +9 -1
- package/dist/marks/GridX.svelte +26 -15
- package/dist/marks/GridX.svelte.d.ts +3 -3
- package/dist/marks/GridY.svelte +15 -4
- package/dist/marks/Line.svelte +16 -27
- package/dist/marks/Line.svelte.d.ts +13 -1
- package/dist/marks/LineX.svelte +5 -7
- package/dist/marks/LineX.svelte.d.ts +11 -4
- package/dist/marks/LineY.svelte +4 -6
- package/dist/marks/LineY.svelte.d.ts +11 -3
- package/dist/marks/RuleX.svelte +15 -7
- package/dist/marks/RuleY.svelte +15 -7
- package/dist/marks/TickX.svelte +30 -0
- package/dist/marks/TickX.svelte.d.ts +15 -0
- package/dist/marks/TickY.svelte +30 -0
- package/dist/marks/TickY.svelte.d.ts +15 -0
- package/dist/transforms/normalize.d.ts +18 -0
- package/dist/transforms/normalize.js +25 -0
- package/dist/transforms/recordize.d.ts +3 -0
- package/dist/transforms/recordize.js +28 -0
- package/dist/transforms/rename.d.ts +4 -0
- package/dist/transforms/rename.js +10 -0
- package/dist/transforms/stack.d.ts +11 -0
- package/dist/transforms/stack.js +73 -0
- package/dist/types.d.ts +51 -35
- package/package.json +20 -15
- package/dist/classes/Channel.svelte.js +0 -74
package/dist/marks/Area.svelte
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
1
3
|
<script>import resolveChannel from "../helpers/resolveChannel.js";
|
|
2
4
|
import { getContext } from "svelte";
|
|
3
5
|
import BaseMark from "./BaseMark.svelte";
|
|
@@ -5,51 +7,63 @@ import getBaseStyles from "../helpers/getBaseStyles.js";
|
|
|
5
7
|
import { area } from "d3-shape";
|
|
6
8
|
import { groupBy } from "underscore";
|
|
7
9
|
import callWithProps from "../helpers/callWithProps.js";
|
|
10
|
+
import { maybeCurve } from "../helpers/curves.js";
|
|
8
11
|
const BaseMark_Area = BaseMark;
|
|
9
12
|
const plot = getContext("svelteplot");
|
|
10
13
|
let {
|
|
11
14
|
data,
|
|
15
|
+
curve,
|
|
16
|
+
tension,
|
|
12
17
|
x1 = null,
|
|
13
18
|
x2 = null,
|
|
14
19
|
y1 = null,
|
|
15
20
|
y2 = null,
|
|
16
21
|
z = null,
|
|
17
|
-
fill,
|
|
18
|
-
stroke,
|
|
19
|
-
sort,
|
|
22
|
+
fill = null,
|
|
23
|
+
stroke = null,
|
|
24
|
+
sort = null,
|
|
20
25
|
...styleProps
|
|
21
26
|
} = $props();
|
|
27
|
+
let channels = $derived({
|
|
28
|
+
x1,
|
|
29
|
+
x2,
|
|
30
|
+
y1,
|
|
31
|
+
y2,
|
|
32
|
+
fill,
|
|
33
|
+
stroke,
|
|
34
|
+
z,
|
|
35
|
+
sort
|
|
36
|
+
});
|
|
22
37
|
let groups = $derived(
|
|
23
|
-
z || fill || stroke ? Object.values(groupBy(data, (d) => resolveChannel("z", d,
|
|
38
|
+
z || fill || stroke ? Object.values(groupBy(data, (d) => resolveChannel("z", d, channels))) : [data]
|
|
24
39
|
);
|
|
25
40
|
let sortedGroups = $derived(
|
|
26
41
|
sort ? groups.sort(
|
|
27
|
-
(a, b) => resolveChannel("sort", a[0],
|
|
42
|
+
(a, b) => resolveChannel("sort", a[0], channels) > resolveChannel("sort", b[0], channels) ? 1 : -1
|
|
28
43
|
) : groups
|
|
29
44
|
);
|
|
30
45
|
let areaPath = $derived(
|
|
31
|
-
callWithProps(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
y: (d) => plot.yScale(resolveChannel("y", d, y1))
|
|
46
|
+
callWithProps(area, [], {
|
|
47
|
+
curve: maybeCurve(curve, tension),
|
|
48
|
+
...x1 != null && x2 != null ? {
|
|
49
|
+
// "vertical" area
|
|
50
|
+
x0: (d) => plot.xScale(resolveChannel("x1", d, channels)),
|
|
51
|
+
x1: (d) => plot.xScale(resolveChannel("x2", d, channels)),
|
|
52
|
+
y: (d) => plot.yScale(resolveChannel("y1", d, channels))
|
|
39
53
|
} : {
|
|
40
|
-
// horizontal area
|
|
41
|
-
x: (d) => plot.xScale(resolveChannel("
|
|
42
|
-
y0: (d) => plot.yScale(resolveChannel("
|
|
43
|
-
y1: (d) => plot.yScale(resolveChannel("
|
|
54
|
+
// "horizontal" area
|
|
55
|
+
x: (d) => plot.xScale(resolveChannel("x1", d, channels)),
|
|
56
|
+
y0: (d) => plot.yScale(resolveChannel("y1", d, channels)),
|
|
57
|
+
y1: (d) => plot.yScale(resolveChannel("y2", d, channels))
|
|
44
58
|
}
|
|
45
|
-
)
|
|
59
|
+
})
|
|
46
60
|
);
|
|
47
61
|
</script>
|
|
48
62
|
|
|
49
63
|
<BaseMark_Area
|
|
50
64
|
type="area"
|
|
51
65
|
{data}
|
|
52
|
-
channels={['
|
|
66
|
+
channels={['x1', 'x2', 'y1', 'y2', 'fill', 'stroke']}
|
|
53
67
|
{x1}
|
|
54
68
|
{x2}
|
|
55
69
|
{y1}
|
|
@@ -63,10 +77,10 @@ let areaPath = $derived(
|
|
|
63
77
|
<path
|
|
64
78
|
d={areaPath(areaData)}
|
|
65
79
|
style:stroke={stroke
|
|
66
|
-
? plot.colorScale(resolveChannel('
|
|
80
|
+
? plot.colorScale(resolveChannel('stroke', areaData[0], channels))
|
|
67
81
|
: 'none'}
|
|
68
82
|
style:fill={fill
|
|
69
|
-
? plot.colorScale(resolveChannel('
|
|
83
|
+
? plot.colorScale(resolveChannel('fill', areaData[0], channels))
|
|
70
84
|
: 'currentColor'}
|
|
71
85
|
style={getBaseStyles(areaData[0], styleProps)}
|
|
72
86
|
/>
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, Curve } from '../types.js';
|
|
3
|
+
export type AreaMarkProps = MarkProps & BaseMarkStyleProps & {
|
|
4
|
+
x1?: ChannelAccessor;
|
|
5
|
+
x2?: ChannelAccessor;
|
|
6
|
+
y1?: ChannelAccessor;
|
|
7
|
+
y2?: ChannelAccessor;
|
|
8
|
+
z?: ChannelAccessor;
|
|
9
|
+
sort?: ChannelAccessor | {
|
|
10
|
+
channel: 'stroke' | 'fill';
|
|
11
|
+
};
|
|
12
|
+
curve: Curve | CurveFactory;
|
|
13
|
+
tension: number;
|
|
14
|
+
};
|
|
15
|
+
import { type CurveFactory } from 'd3-shape';
|
|
3
16
|
declare const __propDef: {
|
|
4
17
|
props: AreaMarkProps;
|
|
5
18
|
events: {
|
package/dist/marks/AreaX.svelte
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let
|
|
6
|
-
$
|
|
7
|
-
y1: dataIsRawValueArray ? "index" : y,
|
|
8
|
-
x1: dataIsRawValueArray ? 0 : x ? 0 : x1,
|
|
9
|
-
x2: dataIsRawValueArray ? "value" : x ? x : x2
|
|
10
|
-
});
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
3
|
+
<script>import Area from "./Area.svelte";
|
|
4
|
+
import { stackX, recordizeX, renameChannels } from "..";
|
|
5
|
+
let { data: rawData, stack, ...rawChannels } = $props();
|
|
6
|
+
let { data, ...channels } = $derived(renameChannels(stackX(recordizeX({ data: rawData, ...rawChannels }), stack), { y: "y1" }));
|
|
11
7
|
</script>
|
|
12
8
|
|
|
13
9
|
<Area
|
|
14
|
-
data
|
|
15
|
-
|
|
16
|
-
x1={dataIsRawValueArray ? 0 : x ? 0 : x1}
|
|
17
|
-
x2={dataIsRawValueArray ? 'value' : x ? x : x2}
|
|
18
|
-
{...rest}
|
|
10
|
+
{data}
|
|
11
|
+
{...channels}
|
|
19
12
|
/>
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, Curve } from '../types.js';
|
|
3
|
+
import type { CurveFactory } from 'd3-shape';
|
|
4
|
+
import type { StackOptions } from '../transforms/stack.js';
|
|
5
|
+
export type AreaXMarkProps = MarkProps & BaseMarkStyleProps & {
|
|
6
|
+
x?: ChannelAccessor;
|
|
7
|
+
x1?: ChannelAccessor;
|
|
8
|
+
x2?: ChannelAccessor;
|
|
9
|
+
y?: ChannelAccessor;
|
|
10
|
+
z?: ChannelAccessor;
|
|
11
|
+
sort?: ChannelAccessor | {
|
|
12
|
+
channel: 'stroke' | 'fill';
|
|
6
13
|
};
|
|
14
|
+
curve: Curve | CurveFactory;
|
|
15
|
+
tension: number;
|
|
16
|
+
stack?: StackOptions;
|
|
17
|
+
};
|
|
18
|
+
declare const __propDef: {
|
|
19
|
+
props: AreaXMarkProps;
|
|
7
20
|
events: {
|
|
8
21
|
[evt: string]: CustomEvent<any>;
|
|
9
22
|
};
|
package/dist/marks/AreaY.svelte
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
3
|
+
<script>import Area from "./Area.svelte";
|
|
4
|
+
import { stackY, recordizeY, renameChannels } from "..";
|
|
5
|
+
let { data: rawData, stack, ...rawChannels } = $props();
|
|
6
|
+
let { data, ...channels } = $derived(renameChannels(stackY(recordizeY({ data: rawData, ...rawChannels }), stack), { x: "x1" }));
|
|
7
|
+
$inspect({ data, channels });
|
|
6
8
|
</script>
|
|
7
9
|
|
|
8
10
|
<Area
|
|
9
|
-
data
|
|
10
|
-
|
|
11
|
-
y1={dataIsRawValueArray ? 0 : y ? 0 : y1}
|
|
12
|
-
y2={dataIsRawValueArray ? 'value' : y ? y : y2}
|
|
13
|
-
{...rest}
|
|
11
|
+
{data}
|
|
12
|
+
{...channels}
|
|
14
13
|
/>
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, Curve } from '../types.js';
|
|
3
|
+
import type { CurveFactory } from 'd3-shape';
|
|
4
|
+
import type { StackOptions } from '../transforms/stack.js';
|
|
5
|
+
export type AreaYMarkProps = MarkProps & BaseMarkStyleProps & {
|
|
6
|
+
x?: ChannelAccessor;
|
|
7
|
+
y?: ChannelAccessor;
|
|
8
|
+
y1?: ChannelAccessor;
|
|
9
|
+
y2?: ChannelAccessor;
|
|
10
|
+
z?: ChannelAccessor;
|
|
11
|
+
sort?: ChannelAccessor | {
|
|
12
|
+
channel: 'stroke' | 'fill';
|
|
6
13
|
};
|
|
14
|
+
curve: Curve | CurveFactory;
|
|
15
|
+
tension: number;
|
|
16
|
+
stack?: StackOptions;
|
|
17
|
+
};
|
|
18
|
+
declare const __propDef: {
|
|
19
|
+
props: AreaYMarkProps;
|
|
7
20
|
events: {
|
|
8
21
|
[evt: string]: CustomEvent<any>;
|
|
9
22
|
};
|
package/dist/marks/AxisX.svelte
CHANGED
|
@@ -26,7 +26,7 @@ let autoTicks = $derived(
|
|
|
26
26
|
ticks.length > 0 ? ticks : plot.options?.x?.ticks ?? plot.xScale.ticks(autoTickCount)
|
|
27
27
|
);
|
|
28
28
|
let useTickFormat = $derived(
|
|
29
|
-
typeof tickFormat === "function" ? tickFormat : plot.x.scaleType === "time" ? typeof tickFormat === "string" ? (d) => dayjs(d).format(tickFormat).split("\n") : autoTimeFormat(plot.x, plot.plotWidth) : (d) => String(d)
|
|
29
|
+
typeof tickFormat === "function" ? tickFormat : plot.x.scaleType === "time" ? typeof tickFormat === "string" ? (d) => dayjs(d).format(tickFormat).split("\n") : autoTimeFormat(plot.x, plot.plotWidth) : (d) => String(plot.x.scaleOptions.percent ? +(d * 100).toFixed(5) : d)
|
|
30
30
|
);
|
|
31
31
|
let tickTexts = $derived(
|
|
32
32
|
removeIdenticalLines(
|
|
@@ -35,7 +35,7 @@ let tickTexts = $derived(
|
|
|
35
35
|
);
|
|
36
36
|
let optionsLabel = $derived(plot.options?.x?.label);
|
|
37
37
|
let useTitle = $derived(
|
|
38
|
-
title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : plot.x.autoTitle ? plot.options.x?.reverse ? `\u2190 ${plot.x.autoTitle}` : `${plot.x.autoTitle} \u2192` : "")
|
|
38
|
+
title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : plot.x.autoTitle ? plot.options.x?.reverse ? `\u2190 ${plot.x.autoTitle}${plot.x.scaleOptions.percent ? " (%)" : ""}` : `${plot.x.autoTitle}${plot.x.scaleOptions.percent ? " (%)" : ""} \u2192` : "")
|
|
39
39
|
);
|
|
40
40
|
</script>
|
|
41
41
|
|
|
@@ -54,7 +54,9 @@ let useTitle = $derived(
|
|
|
54
54
|
{@const prevTextLines = t && tickTexts[t - 1]}
|
|
55
55
|
<g
|
|
56
56
|
class="x-tick"
|
|
57
|
-
transform="translate({plot.xScale(tick)
|
|
57
|
+
transform="translate({plot.xScale(tick) +
|
|
58
|
+
(plot.xScale.bandwidth ? plot.xScale.bandwidth() * 0.5 : 0)},{anchor ===
|
|
59
|
+
'bottom'
|
|
58
60
|
? plot.margins.top + plot.plotHeight
|
|
59
61
|
: plot.margins.top})"
|
|
60
62
|
>
|
|
@@ -86,8 +88,8 @@ let useTitle = $derived(
|
|
|
86
88
|
text {
|
|
87
89
|
text-anchor: middle;
|
|
88
90
|
font-size: 11px;
|
|
89
|
-
|
|
90
|
-
fill:
|
|
91
|
+
opacity: 0.8;
|
|
92
|
+
fill: currentColor;
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
text.axis-title {
|
|
@@ -96,7 +98,4 @@ let useTitle = $derived(
|
|
|
96
98
|
.x-tick line {
|
|
97
99
|
stroke: currentColor;
|
|
98
100
|
}
|
|
99
|
-
.x-tick line.grid {
|
|
100
|
-
stroke: #d9d9d9;
|
|
101
|
-
}
|
|
102
101
|
</style>
|
package/dist/marks/AxisY.svelte
CHANGED
|
@@ -17,17 +17,18 @@ let {
|
|
|
17
17
|
fill = null,
|
|
18
18
|
...styleProps
|
|
19
19
|
} = $props();
|
|
20
|
-
let autoTickCount = $derived(plot.plotHeight /
|
|
20
|
+
let autoTickCount = $derived(plot.plotHeight / (plot.options.y?.tickSpacing || 80));
|
|
21
21
|
let autoTicks = $derived(
|
|
22
22
|
ticks.length > 0 ? ticks : plot.options.y?.ticks || plot.yScale.ticks(autoTickCount)
|
|
23
23
|
);
|
|
24
24
|
let useTickFormat = $derived(
|
|
25
|
-
typeof tickFormat === "function" ? tickFormat : plot.y.scaleType === "time" ? typeof tickFormat === "string" ? (d) => dayjs(d).format(tickFormat).split("\n") : autoTimeFormat(plot.y, plot.plotHeight) : (d) => String(d)
|
|
25
|
+
typeof tickFormat === "function" ? tickFormat : plot.y.scaleType === "time" ? typeof tickFormat === "string" ? (d) => dayjs(d).format(tickFormat).split("\n") : autoTimeFormat(plot.y, plot.plotHeight) : (d) => String(plot.y.scaleOptions.percent ? +(d * 100).toFixed(5) : d)
|
|
26
26
|
);
|
|
27
27
|
let optionsLabel = $derived(plot.options.y?.label);
|
|
28
28
|
let useTitle = $derived(
|
|
29
|
-
title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : plot.y.autoTitle ? `\u2191 ${plot.y.autoTitle}` : "")
|
|
29
|
+
title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : plot.y.autoTitle ? `\u2191 ${plot.y.autoTitle}${plot.y.scaleOptions.percent ? " (%)" : ""}` : "")
|
|
30
30
|
);
|
|
31
|
+
$inspect(plot.y.propNames);
|
|
31
32
|
</script>
|
|
32
33
|
|
|
33
34
|
<BaseMark_AxisX type="axis-y" data={ticks} channels={['y']} {automatic}>
|
|
@@ -46,13 +47,15 @@ let useTitle = $derived(
|
|
|
46
47
|
<g
|
|
47
48
|
class="y-tick"
|
|
48
49
|
transform="translate({plot.margins.left +
|
|
49
|
-
(anchor === 'left' ? 0 : plot.plotWidth)},{plot.yScale(tick)
|
|
50
|
+
(anchor === 'left' ? 0 : plot.plotWidth)},{plot.yScale(tick) +
|
|
51
|
+
(plot.yScale.bandwidth ? plot.yScale.bandwidth() * 0.5 : 0)})"
|
|
50
52
|
>
|
|
51
53
|
<text
|
|
52
54
|
class:is-left={anchor === 'left'}
|
|
53
55
|
style={getBaseStyles(tick, { fill, fontSize: tickFontSize })}
|
|
54
56
|
x={(tickSize + tickPadding) * (anchor === 'left' ? -1 : 1)}
|
|
55
|
-
dominant-baseline="middle"
|
|
57
|
+
dominant-baseline="middle"
|
|
58
|
+
>{Array.isArray(tickText) ? tickText.join(' ') : tickText}</text
|
|
56
59
|
>
|
|
57
60
|
<line
|
|
58
61
|
style={getBaseStyles(tick, styleProps)}
|
|
@@ -66,7 +69,8 @@ let useTitle = $derived(
|
|
|
66
69
|
<style>
|
|
67
70
|
text {
|
|
68
71
|
font-size: 11px;
|
|
69
|
-
|
|
72
|
+
opacity: 0.8;
|
|
73
|
+
fill: currentColor;
|
|
70
74
|
}
|
|
71
75
|
text.is-left {
|
|
72
76
|
text-anchor: end;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
3
|
+
<script>import { getContext } from "svelte";
|
|
4
|
+
import BaseMark from "./BaseMark.svelte";
|
|
5
|
+
import getBaseStyles from "../helpers/getBaseStyles.js";
|
|
6
|
+
import resolveChannel from "../helpers/resolveChannel.js";
|
|
7
|
+
import { stackX } from "../transforms/stack.js";
|
|
8
|
+
import { recordizeX } from "../transforms/recordize.js";
|
|
9
|
+
const BaseMark_BarX = BaseMark;
|
|
10
|
+
const plot = getContext("svelteplot");
|
|
11
|
+
let { data: rawData, inset = 0, ...rawChannels } = $props();
|
|
12
|
+
let { data, ...channels } = $derived(stackX(recordizeX({ data: rawData, ...rawChannels })));
|
|
13
|
+
function isValid(value) {
|
|
14
|
+
return value !== null && !Number.isNaN(value);
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<BaseMark_BarX type="bar-x" {data} channels={['y', 'x1', 'x2', 'fill', 'stroke']} {...channels}>
|
|
19
|
+
<g class="bars-x">
|
|
20
|
+
{#each data as datum}
|
|
21
|
+
{@const cy = resolveChannel('y', datum, channels)}
|
|
22
|
+
{@const cx1 = resolveChannel('x1', datum, channels)}
|
|
23
|
+
{@const cx2 = resolveChannel('x2', datum, channels)}
|
|
24
|
+
{@const minx = Math.min(plot.xScale(cx1), plot.xScale(cx2))}
|
|
25
|
+
{@const maxx = Math.max(plot.xScale(cx1), plot.xScale(cx2))}
|
|
26
|
+
{@const maybeFillColor = resolveChannel('fill', datum, channels)}
|
|
27
|
+
{@const maybeStrokeColor = resolveChannel('stroke', datum, channels)}
|
|
28
|
+
{#if isValid(cy) && isValid(cx1) && isValid(cx2)}
|
|
29
|
+
<rect
|
|
30
|
+
style={getBaseStyles(datum, channels)}
|
|
31
|
+
style:fill={maybeFillColor
|
|
32
|
+
? plot.colorScale(maybeFillColor)
|
|
33
|
+
: maybeStrokeColor
|
|
34
|
+
? null
|
|
35
|
+
: 'currentColor'}
|
|
36
|
+
style:stroke={maybeStrokeColor ? plot.colorScale(maybeStrokeColor) : null}
|
|
37
|
+
transform="translate({[minx, plot.yScale(cy)+inset]})"
|
|
38
|
+
width={maxx - minx}
|
|
39
|
+
height={plot.yScale.bandwidth()- inset*2}
|
|
40
|
+
/>
|
|
41
|
+
{/if}
|
|
42
|
+
{/each}
|
|
43
|
+
</g>
|
|
44
|
+
</BaseMark_BarX>
|
|
45
|
+
|
|
46
|
+
<style>
|
|
47
|
+
rect {
|
|
48
|
+
fill: none;
|
|
49
|
+
stroke: none;
|
|
50
|
+
stroke-width: 1.6px;
|
|
51
|
+
}
|
|
52
|
+
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, DataRow } from '../types.js';
|
|
3
|
+
import type { StackOptions } from '../transforms/stack.js';
|
|
4
|
+
export type BarXMarkProps = MarkProps & BaseMarkStyleProps & {
|
|
5
|
+
data: DataRow[];
|
|
6
|
+
x?: ChannelAccessor;
|
|
7
|
+
x1?: ChannelAccessor;
|
|
8
|
+
x2?: ChannelAccessor;
|
|
9
|
+
y?: ChannelAccessor;
|
|
10
|
+
inset: number;
|
|
11
|
+
stack: StackOptions;
|
|
12
|
+
};
|
|
13
|
+
declare const __propDef: {
|
|
14
|
+
props: BarXMarkProps;
|
|
15
|
+
events: {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
};
|
|
18
|
+
slots: {};
|
|
19
|
+
};
|
|
20
|
+
export type BarXProps = typeof __propDef.props;
|
|
21
|
+
export type BarXEvents = typeof __propDef.events;
|
|
22
|
+
export type BarXSlots = typeof __propDef.slots;
|
|
23
|
+
export default class BarX extends SvelteComponent<BarXProps, BarXEvents, BarXSlots> {
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
3
|
+
<script>import { getContext } from "svelte";
|
|
4
|
+
import BaseMark from "./BaseMark.svelte";
|
|
5
|
+
import getBaseStyles from "../helpers/getBaseStyles.js";
|
|
6
|
+
import resolveChannel from "../helpers/resolveChannel.js";
|
|
7
|
+
import { stackY } from "../transforms/stack.js";
|
|
8
|
+
import { recordizeY } from "../transforms/recordize.js";
|
|
9
|
+
const BaseMark_BarY = BaseMark;
|
|
10
|
+
const plot = getContext("svelteplot");
|
|
11
|
+
let { data: rawData, insetLeft, insetRight, ...rawChannels } = $props();
|
|
12
|
+
let { data, ...channels } = $derived(stackY(recordizeY({ data: rawData, ...rawChannels })));
|
|
13
|
+
function isValid(value) {
|
|
14
|
+
return value !== null && !Number.isNaN(value);
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<BaseMark_BarY type="bar-y" {data} channels={['x', 'y1', 'y2', 'fill', 'stroke']} {...channels}>
|
|
19
|
+
<g class="bars-y">
|
|
20
|
+
{#each data as datum}
|
|
21
|
+
{@const cx = resolveChannel('x', datum, channels)}
|
|
22
|
+
{@const cy1 = resolveChannel('y1', datum, channels)}
|
|
23
|
+
{@const cy2 = resolveChannel('y2', datum, channels)}
|
|
24
|
+
{@const miny = Math.min(plot.yScale(cy1), plot.yScale(cy2))}
|
|
25
|
+
{@const maxy = Math.max(plot.yScale(cy1), plot.yScale(cy2))}
|
|
26
|
+
{@const maybeFillColor = resolveChannel('fill', datum, channels)}
|
|
27
|
+
{@const maybeStrokeColor = resolveChannel('stroke', datum, channels)}
|
|
28
|
+
{#if isValid(cx) && isValid(cy1) && isValid(cy2)}
|
|
29
|
+
<rect
|
|
30
|
+
style={getBaseStyles(datum, channels)}
|
|
31
|
+
style:fill={maybeFillColor
|
|
32
|
+
? plot.colorScale(maybeFillColor)
|
|
33
|
+
: maybeStrokeColor
|
|
34
|
+
? null
|
|
35
|
+
: 'currentColor'}
|
|
36
|
+
style:stroke={maybeStrokeColor ? plot.colorScale(maybeStrokeColor) : null}
|
|
37
|
+
transform="translate({[plot.xScale(cx), miny]})"
|
|
38
|
+
height={maxy - miny}
|
|
39
|
+
width={plot.xScale.bandwidth()}
|
|
40
|
+
/>
|
|
41
|
+
{/if}
|
|
42
|
+
{/each}
|
|
43
|
+
</g>
|
|
44
|
+
</BaseMark_BarY>
|
|
45
|
+
|
|
46
|
+
<style>
|
|
47
|
+
rect {
|
|
48
|
+
fill: none;
|
|
49
|
+
stroke: none;
|
|
50
|
+
stroke-width: 1.6px;
|
|
51
|
+
}
|
|
52
|
+
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, DataRow } from '../types.js';
|
|
3
|
+
import type { StackOptions } from '../transforms/stack.js';
|
|
4
|
+
export type BarYMarkProps = MarkProps & BaseMarkStyleProps & {
|
|
5
|
+
data: DataRow[];
|
|
6
|
+
x?: ChannelAccessor;
|
|
7
|
+
y?: ChannelAccessor;
|
|
8
|
+
y1?: ChannelAccessor;
|
|
9
|
+
y2?: ChannelAccessor;
|
|
10
|
+
stack: StackOptions;
|
|
11
|
+
inset: number;
|
|
12
|
+
};
|
|
13
|
+
declare const __propDef: {
|
|
14
|
+
props: BarYMarkProps;
|
|
15
|
+
events: {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
};
|
|
18
|
+
slots: {};
|
|
19
|
+
};
|
|
20
|
+
export type BarYProps = typeof __propDef.props;
|
|
21
|
+
export type BarYEvents = typeof __propDef.events;
|
|
22
|
+
export type BarYSlots = typeof __propDef.slots;
|
|
23
|
+
export default class BarY extends SvelteComponent<BarYProps, BarYEvents, BarYSlots> {
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -3,8 +3,15 @@
|
|
|
3
3
|
<script generics="T extends BaseMarkProps">import { Mark } from "../classes/Mark.svelte";
|
|
4
4
|
import { getContext } from "svelte";
|
|
5
5
|
const plot = getContext("svelteplot");
|
|
6
|
-
let {
|
|
7
|
-
|
|
6
|
+
let {
|
|
7
|
+
type,
|
|
8
|
+
data = [],
|
|
9
|
+
channels = [],
|
|
10
|
+
children,
|
|
11
|
+
automatic,
|
|
12
|
+
...rest
|
|
13
|
+
} = $props();
|
|
14
|
+
const mark = new Mark(type, channels, !!automatic, { data, ...rest });
|
|
8
15
|
plot.addMark(mark);
|
|
9
16
|
$effect(() => {
|
|
10
17
|
mark.channels = new Set(channels);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
import type { BaseMarkProps } from '../types.js';
|
|
3
|
+
import { type Snippet } from 'svelte';
|
|
3
4
|
declare class __sveltets_Render<T extends BaseMarkProps> {
|
|
4
5
|
props(): T & {
|
|
5
|
-
children?:
|
|
6
|
+
children?: Snippet<void> | undefined;
|
|
6
7
|
};
|
|
7
8
|
events(): {} & {
|
|
8
9
|
[evt: string]: CustomEvent<any>;
|
package/dist/marks/Dot.svelte
CHANGED
|
@@ -1,65 +1,51 @@
|
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
1
3
|
<script>import { getContext } from "svelte";
|
|
2
|
-
import { symbol as d3Symbol } from "d3-shape";
|
|
3
4
|
import BaseMark from "./BaseMark.svelte";
|
|
4
|
-
import resolveChannel from "../helpers/resolveChannel.js";
|
|
5
5
|
import getBaseStyles from "../helpers/getBaseStyles.js";
|
|
6
|
+
import resolveChannel from "../helpers/resolveChannel.js";
|
|
6
7
|
import { isSymbol, maybeSymbol } from "../helpers/symbols.js";
|
|
8
|
+
import { symbol as d3Symbol } from "d3-shape";
|
|
7
9
|
const BaseMark_Dot = BaseMark;
|
|
8
10
|
const plot = getContext("svelteplot");
|
|
9
|
-
let {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
r = 3,
|
|
14
|
-
symbol = "circle",
|
|
15
|
-
stroke = null,
|
|
16
|
-
fill = null,
|
|
17
|
-
...styleProps
|
|
18
|
-
} = $props();
|
|
19
|
-
let styleProps2 = $derived({
|
|
20
|
-
...styleProps,
|
|
21
|
-
...!styleProps.fill && !styleProps.stroke ? { stroke: "currentColor" } : {}
|
|
22
|
-
});
|
|
11
|
+
let { data, ...channels } = $props();
|
|
12
|
+
let { r = 3, symbol = "circle" } = $derived(channels);
|
|
13
|
+
let channelsWithDefaults = $derived({ ...channels, r, symbol });
|
|
14
|
+
$inspect(channelsWithDefaults);
|
|
23
15
|
function isValid(value) {
|
|
24
16
|
return value !== null && !Number.isNaN(value);
|
|
25
17
|
}
|
|
18
|
+
function getSymbolPath(symbolT, size) {
|
|
19
|
+
const symbolType = isSymbol(symbolT) ? maybeSymbol(symbolT) : maybeSymbol(plot.symbolScale(symbolT));
|
|
20
|
+
return d3Symbol(symbolType, size)();
|
|
21
|
+
}
|
|
26
22
|
</script>
|
|
27
23
|
|
|
28
24
|
<BaseMark_Dot
|
|
29
25
|
type="dot"
|
|
30
26
|
{data}
|
|
31
|
-
channels={[
|
|
32
|
-
|
|
33
|
-
...(y ? ['y'] : []),
|
|
34
|
-
...(r ? ['radius'] : []),
|
|
35
|
-
...(symbol ? ['symbol'] : []),
|
|
36
|
-
...(fill || stroke ? ['color'] : [])
|
|
37
|
-
]}
|
|
38
|
-
{x}
|
|
39
|
-
{y}
|
|
40
|
-
{r}
|
|
41
|
-
{fill}
|
|
42
|
-
{stroke}
|
|
43
|
-
{symbol}
|
|
44
|
-
{...styleProps}
|
|
27
|
+
channels={['x', 'y', 'r', 'symbol', 'fill', 'stroke']}
|
|
28
|
+
{...channels}
|
|
45
29
|
>
|
|
46
30
|
<g class="dots">
|
|
47
31
|
{#each data as datum, i}
|
|
48
|
-
{@const cx = resolveChannel('x', datum,
|
|
49
|
-
{@const cy = resolveChannel('y', datum,
|
|
50
|
-
{@const
|
|
32
|
+
{@const cx = resolveChannel('x', datum, channelsWithDefaults)}
|
|
33
|
+
{@const cy = resolveChannel('y', datum, channelsWithDefaults)}
|
|
34
|
+
{@const maybeFillColor = resolveChannel('fill', datum, channelsWithDefaults)}
|
|
35
|
+
{@const maybeStrokeColor = resolveChannel('stroke', datum, channelsWithDefaults)}
|
|
36
|
+
{@const radius =
|
|
37
|
+
typeof r === 'number'
|
|
38
|
+
? r
|
|
39
|
+
: plot.radiusScale(resolveChannel('r', datum, channelsWithDefaults))}
|
|
40
|
+
{@const size = radius * radius * Math.PI}
|
|
41
|
+
{@const symbolT = resolveChannel('symbol', datum, channelsWithDefaults)}
|
|
51
42
|
{@const symbolType = isSymbol(symbolT)
|
|
52
43
|
? maybeSymbol(symbolT)
|
|
53
44
|
: maybeSymbol(plot.symbolScale(symbolT))}
|
|
54
|
-
{@const radius =
|
|
55
|
-
typeof r === 'number' ? r : plot.radiusScale(resolveChannel('radius', datum, r))}
|
|
56
|
-
{@const size = radius * radius * Math.PI}
|
|
57
|
-
{@const maybeFillColor = resolveChannel('color', datum, fill)}
|
|
58
|
-
{@const maybeStrokeColor = resolveChannel('color', datum, stroke)}
|
|
59
45
|
{#if isValid(cx) && isValid(cy)}
|
|
60
46
|
<path
|
|
61
|
-
d={
|
|
62
|
-
style={getBaseStyles(datum,
|
|
47
|
+
d={getSymbolPath(symbolType, size)}
|
|
48
|
+
style={getBaseStyles(datum, channels)}
|
|
63
49
|
style:fill={maybeFillColor ? plot.colorScale(maybeFillColor) : null}
|
|
64
50
|
style:stroke={maybeStrokeColor
|
|
65
51
|
? plot.colorScale(maybeStrokeColor)
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
import type {
|
|
2
|
+
import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, DataRow } from '../types.js';
|
|
3
|
+
export type DotMarkProps = MarkProps & BaseMarkStyleProps & {
|
|
4
|
+
data: DataRow[];
|
|
5
|
+
x?: ChannelAccessor;
|
|
6
|
+
y?: ChannelAccessor;
|
|
7
|
+
r?: ChannelAccessor;
|
|
8
|
+
rotate?: ChannelAccessor;
|
|
9
|
+
symbol?: ChannelAccessor;
|
|
10
|
+
};
|
|
3
11
|
declare const __propDef: {
|
|
4
12
|
props: DotMarkProps;
|
|
5
13
|
events: {
|