svelteplot 0.0.1-alpha.2 → 0.0.1-alpha.20
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 +47 -41
- package/dist/Plot.svelte.d.ts +3 -3
- package/dist/classes/Mark.svelte.js +4 -0
- package/dist/classes/Plot.svelte.js +50 -24
- package/dist/classes/Scale.svelte.js +94 -0
- package/dist/contants.d.ts +3 -3
- package/dist/contants.js +18 -16
- package/dist/helpers/GroupMultiple.svelte.d.ts +3 -3
- package/dist/helpers/autoTimeFormat.d.ts +2 -2
- package/dist/helpers/autoTimeFormat.js +1 -1
- package/dist/helpers/callWithProps.d.ts +4 -0
- package/dist/helpers/callWithProps.js +9 -0
- package/dist/helpers/colors.d.ts +1 -1
- package/dist/helpers/createScale.d.ts +2 -1
- package/dist/helpers/createScale.js +37 -16
- package/dist/helpers/curves.d.ts +3 -0
- package/dist/helpers/curves.js +42 -0
- package/dist/helpers/getBaseStyles.d.ts +1 -1
- package/dist/helpers/getBaseStyles.js +2 -3
- package/dist/helpers/getLogTicks.js +5 -5
- package/dist/helpers/isDataRecord.d.ts +1 -1
- 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 +16 -6
- package/dist/helpers/typeChecks.d.ts +1 -1
- package/dist/helpers/typeChecks.js +1 -1
- package/dist/helpers/wrapArray.d.ts +2 -2
- package/dist/helpers/wrapValueArray.d.ts +6 -0
- package/dist/helpers/wrapValueArray.js +5 -0
- package/dist/index.d.ts +15 -1
- package/dist/index.js +17 -1
- package/dist/marks/Area.svelte +95 -0
- package/dist/marks/Area.svelte.d.ts +28 -0
- package/dist/marks/AreaX.svelte +11 -0
- package/dist/marks/AreaX.svelte.d.ts +30 -0
- package/dist/marks/AreaY.svelte +12 -0
- package/dist/marks/AreaY.svelte.d.ts +30 -0
- package/dist/marks/AxisX.svelte +17 -17
- package/dist/marks/AxisX.svelte.d.ts +3 -3
- package/dist/marks/AxisY.svelte +25 -11
- package/dist/marks/AxisY.svelte.d.ts +3 -3
- 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 +10 -3
- package/dist/marks/BaseMark.svelte.d.ts +5 -4
- package/dist/marks/ColorLegend.svelte +26 -24
- package/dist/marks/ColorLegend.svelte.d.ts +2 -2
- package/dist/marks/Dot.svelte +28 -43
- package/dist/marks/Dot.svelte.d.ts +11 -3
- package/dist/marks/DotX.svelte.d.ts +3 -3
- package/dist/marks/DotY.svelte.d.ts +3 -3
- package/dist/marks/Frame.svelte +1 -1
- package/dist/marks/Frame.svelte.d.ts +4 -4
- package/dist/marks/GridX.svelte +29 -18
- package/dist/marks/GridX.svelte.d.ts +6 -6
- package/dist/marks/GridY.svelte +17 -7
- package/dist/marks/GridY.svelte.d.ts +3 -3
- package/dist/marks/Line.svelte +28 -29
- package/dist/marks/Line.svelte.d.ts +15 -3
- package/dist/marks/LineX.svelte +5 -7
- package/dist/marks/LineX.svelte.d.ts +13 -6
- package/dist/marks/LineY.svelte +4 -6
- package/dist/marks/LineY.svelte.d.ts +14 -6
- package/dist/marks/RuleX.svelte +17 -9
- package/dist/marks/RuleX.svelte.d.ts +3 -3
- package/dist/marks/RuleY.svelte +17 -10
- package/dist/marks/RuleY.svelte.d.ts +3 -3
- package/dist/marks/SymbolLegend.svelte +17 -17
- package/dist/marks/SymbolLegend.svelte.d.ts +2 -2
- 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 +36 -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 +80 -0
- package/dist/types.d.ts +60 -23
- package/package.json +28 -23
- package/dist/classes/Channel.svelte.js +0 -72
|
@@ -10,7 +10,7 @@ export function getLogTicks(domain, count = 6) {
|
|
|
10
10
|
return [];
|
|
11
11
|
if (domain[0] === 0)
|
|
12
12
|
return ticksArray(domain[0], domain[1], count - 2);
|
|
13
|
-
let mult = Math.pow(10, Math.floor(Math.log10(Math.abs(domain[1] - domain[0]))) - 1);
|
|
13
|
+
let mult = 1; //Math.pow(10, Math.floor(Math.log10(Math.abs(domain[1] - domain[0]))) - 1);
|
|
14
14
|
count += 2;
|
|
15
15
|
let candidates = getTickCandidates(domain, mult);
|
|
16
16
|
if (candidates[0].num > count) {
|
|
@@ -46,12 +46,12 @@ function getTickCandidates(domain, mult = 1) {
|
|
|
46
46
|
return logSeries.map((factors) => {
|
|
47
47
|
let i = Math.pow(10, Math.floor(Math.log10(domain[0])));
|
|
48
48
|
let f = 0;
|
|
49
|
-
const
|
|
50
|
-
while (i < domain[1] &&
|
|
49
|
+
const ticks = [i];
|
|
50
|
+
while (i < domain[1] && ticks.length < 50) {
|
|
51
51
|
i *= factors[f] * mult;
|
|
52
|
-
|
|
52
|
+
ticks.push(i);
|
|
53
53
|
f = (f + 1) % factors.length;
|
|
54
54
|
}
|
|
55
|
-
return { ticks
|
|
55
|
+
return { ticks, num: ticks.length };
|
|
56
56
|
});
|
|
57
57
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { DataRecord } from '../types';
|
|
1
|
+
import type { DataRecord } from '../types.js';
|
|
2
2
|
export default function (value: any): value is DataRecord;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import type { ChannelName, ChannelAccessor, DataRow, RawValue } from '../types';
|
|
2
|
-
|
|
1
|
+
import type { ChannelName, ChannelAccessor, DataRow, RawValue } from '../types.js';
|
|
2
|
+
type ChannelAlias = {
|
|
3
|
+
channel: ChannelName;
|
|
4
|
+
};
|
|
5
|
+
export default function (channel: ChannelName, datum: DataRow, channels: Partial<Record<ChannelName, ChannelAccessor | ChannelAlias>>): RawValue;
|
|
6
|
+
export {};
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { CHANNEL_SCALE } from '../contants.js';
|
|
2
|
+
import isDataRecord from './isDataRecord.js';
|
|
3
|
+
import isRawValue from './isRawValue.js';
|
|
4
|
+
export default function (channel, datum, channels) {
|
|
5
|
+
const scale = CHANNEL_SCALE[channel];
|
|
6
|
+
const maybeAccessor = channel === 'z' ? channels.z || channels.fill || channels.stroke : channels[channel];
|
|
7
|
+
const accessor = isDataRecord(maybeAccessor) && maybeAccessor?.channel
|
|
8
|
+
? channels[maybeAccessor?.channel]
|
|
9
|
+
: maybeAccessor;
|
|
10
|
+
if (isDataRecord(accessor) && accessor.channel)
|
|
11
|
+
throw new Error('multiple channel aliases are not allowed');
|
|
3
12
|
if ((channel === 'x' || channel === 'y') && Array.isArray(datum) && accessor === null) {
|
|
4
13
|
// special case for [[x0,y0], [x1,y1], ...] format
|
|
5
14
|
return datum[channel === 'x' ? 0 : 1];
|
|
@@ -14,15 +23,16 @@ export default function (channel, datum, accessor = null) {
|
|
|
14
23
|
// fallback to channel name as accessor
|
|
15
24
|
if (accessor === null && datum[channel] !== undefined)
|
|
16
25
|
return datum[channel];
|
|
17
|
-
|
|
18
|
-
return accessor;
|
|
26
|
+
return isRawValue(accessor) ? accessor : null;
|
|
19
27
|
}
|
|
20
28
|
else {
|
|
21
29
|
// return single value or accessor
|
|
22
30
|
return typeof accessor === 'function'
|
|
23
31
|
? accessor(datum)
|
|
24
|
-
: accessor !== null
|
|
32
|
+
: accessor !== null && isRawValue(accessor)
|
|
25
33
|
? accessor
|
|
26
|
-
: datum
|
|
34
|
+
: !Array.isArray(datum) && (scale === 'x' || scale === 'y')
|
|
35
|
+
? datum
|
|
36
|
+
: null;
|
|
27
37
|
}
|
|
28
38
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RawValue } from '../types';
|
|
1
|
+
import type { RawValue } from '../types.js';
|
|
2
2
|
export declare function isBooleanOrNull(v: RawValue): boolean;
|
|
3
3
|
export declare function isDateOrNull(v: RawValue): boolean;
|
|
4
4
|
export declare function isNumberOrNull(v: RawValue): boolean;
|
|
@@ -14,7 +14,7 @@ export function isStringOrNull(v) {
|
|
|
14
14
|
}
|
|
15
15
|
export function isColorOrNull(v) {
|
|
16
16
|
// todo: maybe not use chroma.js here to save kb
|
|
17
|
-
return v == null || (typeof v === 'string' && chroma.valid(v));
|
|
17
|
+
return v == null || (typeof v === 'string' && (chroma.valid(v) || v === 'currentColor'));
|
|
18
18
|
}
|
|
19
19
|
export function isOpacityOrNull(v) {
|
|
20
20
|
return v == null || (typeof v === 'number' && isFinite(v) && v >= 0 && v <= 1);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { DataRow } from '../types';
|
|
2
|
-
export default function (data: DataRow[]): (Date | [number, number] | import("../types").DataRecord)[];
|
|
1
|
+
import type { DataRow } from '../types.js';
|
|
2
|
+
export default function (data: DataRow[]): (Date | [number, number] | import("../types.js").DataRecord)[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
export { default as Plot } from './Plot.svelte';
|
|
2
|
+
export { default as Area } from './marks/Area.svelte';
|
|
3
|
+
export { default as AreaX } from './marks/AreaX.svelte';
|
|
4
|
+
export { default as AreaY } from './marks/AreaY.svelte';
|
|
5
|
+
export { default as AxisX } from './marks/AxisX.svelte';
|
|
6
|
+
export { default as AxisY } from './marks/AxisY.svelte';
|
|
7
|
+
export { default as BarX } from './marks/BarX.svelte';
|
|
8
|
+
export { default as BarY } from './marks/BarY.svelte';
|
|
9
|
+
export { default as ColorLegend } from './marks/ColorLegend.svelte';
|
|
1
10
|
export { default as Dot } from './marks/Dot.svelte';
|
|
2
11
|
export { default as DotX } from './marks/DotX.svelte';
|
|
3
12
|
export { default as DotY } from './marks/DotY.svelte';
|
|
4
|
-
export { default as Plot } from './Plot.svelte';
|
|
5
13
|
export { default as Frame } from './marks/Frame.svelte';
|
|
6
14
|
export { default as GridX } from './marks/GridX.svelte';
|
|
7
15
|
export { default as GridY } from './marks/GridY.svelte';
|
|
@@ -10,3 +18,9 @@ export { default as LineX } from './marks/LineX.svelte';
|
|
|
10
18
|
export { default as LineY } from './marks/LineY.svelte';
|
|
11
19
|
export { default as RuleX } from './marks/RuleX.svelte';
|
|
12
20
|
export { default as RuleY } from './marks/RuleY.svelte';
|
|
21
|
+
export { default as SymbolLegend } from './marks/SymbolLegend.svelte';
|
|
22
|
+
export { default as TickX } from './marks/TickX.svelte';
|
|
23
|
+
export { default as TickY } from './marks/TickY.svelte';
|
|
24
|
+
export { stackX, stackY } from './transforms/stack.js';
|
|
25
|
+
export { recordizeX, recordizeY } from './transforms/recordize.js';
|
|
26
|
+
export { renameChannels } from './transforms/rename.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
// Reexport your entry components here
|
|
2
|
+
export { default as Plot } from './Plot.svelte';
|
|
3
|
+
// marks
|
|
4
|
+
export { default as Area } from './marks/Area.svelte';
|
|
5
|
+
export { default as AreaX } from './marks/AreaX.svelte';
|
|
6
|
+
export { default as AreaY } from './marks/AreaY.svelte';
|
|
7
|
+
export { default as AxisX } from './marks/AxisX.svelte';
|
|
8
|
+
export { default as AxisY } from './marks/AxisY.svelte';
|
|
9
|
+
export { default as BarX } from './marks/BarX.svelte';
|
|
10
|
+
export { default as BarY } from './marks/BarY.svelte';
|
|
11
|
+
export { default as ColorLegend } from './marks/ColorLegend.svelte';
|
|
2
12
|
export { default as Dot } from './marks/Dot.svelte';
|
|
3
13
|
export { default as DotX } from './marks/DotX.svelte';
|
|
4
14
|
export { default as DotY } from './marks/DotY.svelte';
|
|
5
|
-
export { default as Plot } from './Plot.svelte';
|
|
6
15
|
export { default as Frame } from './marks/Frame.svelte';
|
|
7
16
|
export { default as GridX } from './marks/GridX.svelte';
|
|
8
17
|
export { default as GridY } from './marks/GridY.svelte';
|
|
@@ -11,3 +20,10 @@ export { default as LineX } from './marks/LineX.svelte';
|
|
|
11
20
|
export { default as LineY } from './marks/LineY.svelte';
|
|
12
21
|
export { default as RuleX } from './marks/RuleX.svelte';
|
|
13
22
|
export { default as RuleY } from './marks/RuleY.svelte';
|
|
23
|
+
export { default as SymbolLegend } from './marks/SymbolLegend.svelte';
|
|
24
|
+
export { default as TickX } from './marks/TickX.svelte';
|
|
25
|
+
export { default as TickY } from './marks/TickY.svelte';
|
|
26
|
+
// transforms
|
|
27
|
+
export { stackX, stackY } from './transforms/stack.js';
|
|
28
|
+
export { recordizeX, recordizeY } from './transforms/recordize.js';
|
|
29
|
+
export { renameChannels } from './transforms/rename.js';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
3
|
+
<script>import resolveChannel from "../helpers/resolveChannel.js";
|
|
4
|
+
import { getContext } from "svelte";
|
|
5
|
+
import BaseMark from "./BaseMark.svelte";
|
|
6
|
+
import getBaseStyles from "../helpers/getBaseStyles.js";
|
|
7
|
+
import { area } from "d3-shape";
|
|
8
|
+
import { groupBy } from "underscore";
|
|
9
|
+
import callWithProps from "../helpers/callWithProps.js";
|
|
10
|
+
import { maybeCurve } from "../helpers/curves.js";
|
|
11
|
+
const BaseMark_Area = BaseMark;
|
|
12
|
+
const plot = getContext("svelteplot");
|
|
13
|
+
let {
|
|
14
|
+
data,
|
|
15
|
+
curve,
|
|
16
|
+
tension,
|
|
17
|
+
x1 = null,
|
|
18
|
+
x2 = null,
|
|
19
|
+
y1 = null,
|
|
20
|
+
y2 = null,
|
|
21
|
+
z = null,
|
|
22
|
+
fill = null,
|
|
23
|
+
stroke = null,
|
|
24
|
+
sort = null,
|
|
25
|
+
...styleProps
|
|
26
|
+
} = $props();
|
|
27
|
+
let channels = $derived({
|
|
28
|
+
x1,
|
|
29
|
+
x2,
|
|
30
|
+
y1,
|
|
31
|
+
y2,
|
|
32
|
+
fill,
|
|
33
|
+
stroke,
|
|
34
|
+
z,
|
|
35
|
+
sort
|
|
36
|
+
});
|
|
37
|
+
let groups = $derived(
|
|
38
|
+
z || fill || stroke ? Object.values(groupBy(data, (d) => resolveChannel("z", d, channels))) : [data]
|
|
39
|
+
);
|
|
40
|
+
let sortedGroups = $derived(
|
|
41
|
+
sort ? groups.sort(
|
|
42
|
+
(a, b) => resolveChannel("sort", a[0], channels) > resolveChannel("sort", b[0], channels) ? 1 : -1
|
|
43
|
+
) : groups
|
|
44
|
+
);
|
|
45
|
+
let areaPath = $derived(
|
|
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))
|
|
53
|
+
} : {
|
|
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))
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<BaseMark_Area
|
|
64
|
+
type="area"
|
|
65
|
+
{data}
|
|
66
|
+
channels={['x1', 'x2', 'y1', 'y2', 'fill', 'stroke']}
|
|
67
|
+
{x1}
|
|
68
|
+
{x2}
|
|
69
|
+
{y1}
|
|
70
|
+
{y2}
|
|
71
|
+
{fill}
|
|
72
|
+
{stroke}
|
|
73
|
+
{...styleProps}
|
|
74
|
+
>
|
|
75
|
+
<g class="areas">
|
|
76
|
+
{#each sortedGroups as areaData}
|
|
77
|
+
<path
|
|
78
|
+
d={areaPath(areaData)}
|
|
79
|
+
style:stroke={stroke
|
|
80
|
+
? plot.colorScale(resolveChannel('stroke', areaData[0], channels))
|
|
81
|
+
: 'none'}
|
|
82
|
+
style:fill={fill
|
|
83
|
+
? plot.colorScale(resolveChannel('fill', areaData[0], channels))
|
|
84
|
+
: 'currentColor'}
|
|
85
|
+
style={getBaseStyles(areaData[0], styleProps)}
|
|
86
|
+
/>
|
|
87
|
+
{/each}
|
|
88
|
+
</g>
|
|
89
|
+
</BaseMark_Area>
|
|
90
|
+
|
|
91
|
+
<style>
|
|
92
|
+
.lines path {
|
|
93
|
+
stroke-width: 1.4px;
|
|
94
|
+
}
|
|
95
|
+
</style>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
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';
|
|
16
|
+
declare const __propDef: {
|
|
17
|
+
props: AreaMarkProps;
|
|
18
|
+
events: {
|
|
19
|
+
[evt: string]: CustomEvent<any>;
|
|
20
|
+
};
|
|
21
|
+
slots: {};
|
|
22
|
+
};
|
|
23
|
+
export type AreaProps = typeof __propDef.props;
|
|
24
|
+
export type AreaEvents = typeof __propDef.events;
|
|
25
|
+
export type AreaSlots = typeof __propDef.slots;
|
|
26
|
+
export default class Area extends SvelteComponentTyped<AreaProps, AreaEvents, AreaSlots> {
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
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(
|
|
7
|
+
renameChannels(stackX(recordizeX({ data: rawData, ...rawChannels }), stack), { y: "y1" })
|
|
8
|
+
);
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<Area {data} {...channels} />
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
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';
|
|
13
|
+
};
|
|
14
|
+
curve: Curve | CurveFactory;
|
|
15
|
+
tension: number;
|
|
16
|
+
stack?: StackOptions;
|
|
17
|
+
};
|
|
18
|
+
declare const __propDef: {
|
|
19
|
+
props: AreaXMarkProps;
|
|
20
|
+
events: {
|
|
21
|
+
[evt: string]: CustomEvent<any>;
|
|
22
|
+
};
|
|
23
|
+
slots: {};
|
|
24
|
+
};
|
|
25
|
+
export type AreaXProps = typeof __propDef.props;
|
|
26
|
+
export type AreaXEvents = typeof __propDef.events;
|
|
27
|
+
export type AreaXSlots = typeof __propDef.slots;
|
|
28
|
+
export default class AreaX extends SvelteComponentTyped<AreaXProps, AreaXEvents, AreaXSlots> {
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
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(
|
|
7
|
+
renameChannels(stackY(recordizeY({ data: rawData, ...rawChannels }), stack), { x: "x1" })
|
|
8
|
+
);
|
|
9
|
+
$inspect({ data, channels });
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<Area {data} {...channels} />
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
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';
|
|
13
|
+
};
|
|
14
|
+
curve: Curve | CurveFactory;
|
|
15
|
+
tension: number;
|
|
16
|
+
stack?: StackOptions;
|
|
17
|
+
};
|
|
18
|
+
declare const __propDef: {
|
|
19
|
+
props: AreaYMarkProps;
|
|
20
|
+
events: {
|
|
21
|
+
[evt: string]: CustomEvent<any>;
|
|
22
|
+
};
|
|
23
|
+
slots: {};
|
|
24
|
+
};
|
|
25
|
+
export type AreaYProps = typeof __propDef.props;
|
|
26
|
+
export type AreaYEvents = typeof __propDef.events;
|
|
27
|
+
export type AreaYSlots = typeof __propDef.slots;
|
|
28
|
+
export default class AreaY extends SvelteComponentTyped<AreaYProps, AreaYEvents, AreaYSlots> {
|
|
29
|
+
}
|
|
30
|
+
export {};
|
package/dist/marks/AxisX.svelte
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
<script>import { getContext } from "svelte";
|
|
2
|
-
import BaseMark from "./BaseMark.svelte";
|
|
3
|
-
import resolveChannel from "../helpers/resolveChannel";
|
|
4
|
-
import getBaseStyles from "../helpers/getBaseStyles";
|
|
5
|
-
import removeIdenticalLines from "../helpers/removeIdenticalLines";
|
|
6
|
-
import autoTimeFormat from "../helpers/autoTimeFormat";
|
|
7
2
|
import dayjs from "dayjs";
|
|
8
|
-
import
|
|
3
|
+
import BaseMark from "./BaseMark.svelte";
|
|
4
|
+
import getBaseStyles from "../helpers/getBaseStyles.js";
|
|
5
|
+
import removeIdenticalLines from "../helpers/removeIdenticalLines.js";
|
|
6
|
+
import autoTimeFormat from "../helpers/autoTimeFormat.js";
|
|
9
7
|
const BaseMark_AxisX = BaseMark;
|
|
10
8
|
const plot = getContext("svelteplot");
|
|
11
9
|
let {
|
|
@@ -20,12 +18,15 @@ let {
|
|
|
20
18
|
fill = null,
|
|
21
19
|
...styleProps
|
|
22
20
|
} = $props();
|
|
23
|
-
let autoTickCount = $derived(
|
|
21
|
+
let autoTickCount = $derived(
|
|
22
|
+
Math.max(2, Math.round(plot.plotWidth / (plot.options?.x?.tickSpacing || 80)))
|
|
23
|
+
);
|
|
24
|
+
$inspect(autoTickCount);
|
|
24
25
|
let autoTicks = $derived(
|
|
25
|
-
ticks.length > 0 ? ticks :
|
|
26
|
+
ticks.length > 0 ? ticks : plot.options?.x?.ticks ?? plot.xScale.ticks(autoTickCount)
|
|
26
27
|
);
|
|
27
28
|
let useTickFormat = $derived(
|
|
28
|
-
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)
|
|
29
30
|
);
|
|
30
31
|
let tickTexts = $derived(
|
|
31
32
|
removeIdenticalLines(
|
|
@@ -34,7 +35,7 @@ let tickTexts = $derived(
|
|
|
34
35
|
);
|
|
35
36
|
let optionsLabel = $derived(plot.options?.x?.label);
|
|
36
37
|
let useTitle = $derived(
|
|
37
|
-
title || (optionsLabel === null ? null : optionsLabel
|
|
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` : "")
|
|
38
39
|
);
|
|
39
40
|
</script>
|
|
40
41
|
|
|
@@ -45,7 +46,7 @@ let useTitle = $derived(
|
|
|
45
46
|
x={plot.plotWidth + plot.margins.left}
|
|
46
47
|
y={plot.height - 10}
|
|
47
48
|
class="axis-title"
|
|
48
|
-
dominant-baseline="hanging">{useTitle}
|
|
49
|
+
dominant-baseline="hanging">{useTitle}</text
|
|
49
50
|
>
|
|
50
51
|
{/if}
|
|
51
52
|
{#each autoTicks as tick, t}
|
|
@@ -53,7 +54,9 @@ let useTitle = $derived(
|
|
|
53
54
|
{@const prevTextLines = t && tickTexts[t - 1]}
|
|
54
55
|
<g
|
|
55
56
|
class="x-tick"
|
|
56
|
-
transform="translate({plot.xScale(tick)
|
|
57
|
+
transform="translate({plot.xScale(tick) +
|
|
58
|
+
(plot.xScale.bandwidth ? plot.xScale.bandwidth() * 0.5 : 0)},{anchor ===
|
|
59
|
+
'bottom'
|
|
57
60
|
? plot.margins.top + plot.plotHeight
|
|
58
61
|
: plot.margins.top})"
|
|
59
62
|
>
|
|
@@ -85,8 +88,8 @@ let useTitle = $derived(
|
|
|
85
88
|
text {
|
|
86
89
|
text-anchor: middle;
|
|
87
90
|
font-size: 11px;
|
|
88
|
-
|
|
89
|
-
fill:
|
|
91
|
+
opacity: 0.8;
|
|
92
|
+
fill: currentColor;
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
text.axis-title {
|
|
@@ -95,7 +98,4 @@ let useTitle = $derived(
|
|
|
95
98
|
.x-tick line {
|
|
96
99
|
stroke: currentColor;
|
|
97
100
|
}
|
|
98
|
-
.x-tick line.grid {
|
|
99
|
-
stroke: #d9d9d9;
|
|
100
|
-
}
|
|
101
101
|
</style>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { AxisMarkOptions } from '../types';
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { AxisMarkOptions } from '../types.js';
|
|
3
3
|
declare const __propDef: {
|
|
4
4
|
props: AxisMarkOptions & {
|
|
5
5
|
anchor?: "bottom" | "top" | undefined;
|
|
@@ -12,6 +12,6 @@ declare const __propDef: {
|
|
|
12
12
|
export type AxisXProps = typeof __propDef.props;
|
|
13
13
|
export type AxisXEvents = typeof __propDef.events;
|
|
14
14
|
export type AxisXSlots = typeof __propDef.slots;
|
|
15
|
-
export default class AxisX extends
|
|
15
|
+
export default class AxisX extends SvelteComponentTyped<AxisXProps, AxisXEvents, AxisXSlots> {
|
|
16
16
|
}
|
|
17
17
|
export {};
|
package/dist/marks/AxisY.svelte
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>import { getContext } from "svelte";
|
|
2
2
|
import BaseMark from "./BaseMark.svelte";
|
|
3
|
-
import getBaseStyles from "../helpers/getBaseStyles";
|
|
4
|
-
import
|
|
3
|
+
import getBaseStyles from "../helpers/getBaseStyles.js";
|
|
4
|
+
import autoTimeFormat from "../helpers/autoTimeFormat.js";
|
|
5
5
|
const BaseMark_AxisX = BaseMark;
|
|
6
6
|
const plot = getContext("svelteplot");
|
|
7
7
|
let {
|
|
@@ -11,37 +11,50 @@ let {
|
|
|
11
11
|
tickSize = 6,
|
|
12
12
|
tickPadding = 3,
|
|
13
13
|
title = null,
|
|
14
|
-
tickFormat
|
|
14
|
+
tickFormat,
|
|
15
15
|
tickFontSize = null,
|
|
16
16
|
fill = null,
|
|
17
17
|
...styleProps
|
|
18
18
|
} = $props();
|
|
19
|
-
let autoTickCount = $derived(plot.plotHeight /
|
|
19
|
+
let autoTickCount = $derived(plot.plotHeight / (plot.options.y?.tickSpacing || 80));
|
|
20
20
|
let autoTicks = $derived(
|
|
21
|
-
ticks.length > 0 ? ticks :
|
|
21
|
+
ticks.length > 0 ? ticks : plot.options.y?.ticks || plot.yScale.ticks(autoTickCount)
|
|
22
22
|
);
|
|
23
|
-
let
|
|
23
|
+
let useTickFormat = $derived(
|
|
24
|
+
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)
|
|
25
|
+
);
|
|
26
|
+
let optionsLabel = $derived(plot.options.y?.label);
|
|
24
27
|
let useTitle = $derived(
|
|
25
|
-
title || (optionsLabel === null ? null : optionsLabel
|
|
28
|
+
title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : plot.y.autoTitle ? `\u2191 ${plot.y.autoTitle}${plot.y.scaleOptions.percent ? " (%)" : ""}` : "")
|
|
26
29
|
);
|
|
30
|
+
$inspect(plot.y.propNames);
|
|
27
31
|
</script>
|
|
28
32
|
|
|
29
33
|
<BaseMark_AxisX type="axis-y" data={ticks} channels={['y']} {automatic}>
|
|
30
34
|
<g class="axis-y">
|
|
31
35
|
{#if useTitle}
|
|
32
|
-
<text
|
|
36
|
+
<text
|
|
37
|
+
style:text-anchor={anchor === 'left' ? 'start' : 'end'}
|
|
38
|
+
x={anchor === 'left' ? 0 : plot.width}
|
|
39
|
+
y={5}
|
|
40
|
+
class="axis-title"
|
|
41
|
+
dominant-baseline="hanging">{useTitle}</text
|
|
42
|
+
>
|
|
33
43
|
{/if}
|
|
34
44
|
{#each autoTicks as tick}
|
|
45
|
+
{@const tickText = useTickFormat(tick)}
|
|
35
46
|
<g
|
|
36
47
|
class="y-tick"
|
|
37
48
|
transform="translate({plot.margins.left +
|
|
38
|
-
(anchor === 'left' ? 0 : plot.plotWidth)},{plot.yScale(tick)
|
|
49
|
+
(anchor === 'left' ? 0 : plot.plotWidth)},{plot.yScale(tick) +
|
|
50
|
+
(plot.yScale.bandwidth ? plot.yScale.bandwidth() * 0.5 : 0)})"
|
|
39
51
|
>
|
|
40
52
|
<text
|
|
41
53
|
class:is-left={anchor === 'left'}
|
|
42
54
|
style={getBaseStyles(tick, { fill, fontSize: tickFontSize })}
|
|
43
55
|
x={(tickSize + tickPadding) * (anchor === 'left' ? -1 : 1)}
|
|
44
|
-
dominant-baseline="middle"
|
|
56
|
+
dominant-baseline="middle"
|
|
57
|
+
>{Array.isArray(tickText) ? tickText.join(' ') : tickText}</text
|
|
45
58
|
>
|
|
46
59
|
<line
|
|
47
60
|
style={getBaseStyles(tick, styleProps)}
|
|
@@ -55,7 +68,8 @@ let useTitle = $derived(
|
|
|
55
68
|
<style>
|
|
56
69
|
text {
|
|
57
70
|
font-size: 11px;
|
|
58
|
-
|
|
71
|
+
opacity: 0.8;
|
|
72
|
+
fill: currentColor;
|
|
59
73
|
}
|
|
60
74
|
text.is-left {
|
|
61
75
|
text-anchor: end;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { AxisYMarkProps } from '../types';
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { AxisYMarkProps } from '../types.js';
|
|
3
3
|
declare const __propDef: {
|
|
4
4
|
props: AxisYMarkProps;
|
|
5
5
|
events: {
|
|
@@ -10,6 +10,6 @@ declare const __propDef: {
|
|
|
10
10
|
export type AxisYProps = typeof __propDef.props;
|
|
11
11
|
export type AxisYEvents = typeof __propDef.events;
|
|
12
12
|
export type AxisYSlots = typeof __propDef.slots;
|
|
13
|
-
export default class AxisY extends
|
|
13
|
+
export default class AxisY extends SvelteComponentTyped<AxisYProps, AxisYEvents, AxisYSlots> {
|
|
14
14
|
}
|
|
15
15
|
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 { 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>
|