svelteplot 0.0.1-alpha.9 → 0.1.3-next.12
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/LICENSE.md +5 -0
- package/README.md +3 -35
- package/dist/Mark.svelte +292 -0
- package/dist/Mark.svelte.d.ts +22 -0
- package/dist/Plot.svelte +148 -156
- package/dist/Plot.svelte.d.ts +15 -15
- package/dist/constants.d.ts +15 -0
- package/dist/constants.js +110 -0
- package/dist/core/Facet.svelte +59 -0
- package/dist/core/Facet.svelte.d.ts +18 -0
- package/dist/core/FacetAxes.svelte +66 -0
- package/dist/core/FacetAxes.svelte.d.ts +4 -0
- package/dist/core/FacetGrid.svelte +86 -0
- package/dist/core/FacetGrid.svelte.d.ts +13 -0
- package/dist/core/Plot.svelte +568 -0
- package/dist/core/Plot.svelte.d.ts +14 -0
- package/dist/helpers/arrowPath.d.ts +14 -0
- package/dist/helpers/arrowPath.js +129 -0
- package/dist/helpers/autoProjection.d.ts +19 -0
- package/dist/helpers/autoProjection.js +87 -0
- package/dist/helpers/autoScales.d.ts +23 -0
- package/dist/helpers/autoScales.js +203 -0
- package/dist/helpers/autoTicks.d.ts +3 -0
- package/dist/helpers/autoTicks.js +40 -0
- package/dist/helpers/autoTimeFormat.d.ts +2 -2
- package/dist/helpers/autoTimeFormat.js +34 -5
- package/dist/helpers/callWithProps.d.ts +8 -0
- package/dist/helpers/callWithProps.js +13 -0
- package/dist/helpers/colors.js +17 -2
- package/dist/helpers/curves.d.ts +3 -0
- package/dist/helpers/curves.js +42 -0
- package/dist/helpers/data.d.ts +9 -0
- package/dist/helpers/data.js +16 -0
- package/dist/helpers/facets.d.ts +12 -0
- package/dist/helpers/facets.js +49 -0
- package/dist/helpers/formats.d.ts +3 -0
- package/dist/helpers/formats.js +3 -0
- package/dist/helpers/getBaseStyles.d.ts +7 -2
- package/dist/helpers/getBaseStyles.js +34 -10
- package/dist/helpers/getLogTicks.js +5 -5
- package/dist/helpers/group.d.ts +6 -0
- package/dist/helpers/group.js +53 -0
- package/dist/helpers/index.d.ts +18 -0
- package/dist/helpers/index.js +55 -0
- package/dist/helpers/isRawValue.d.ts +2 -0
- package/dist/helpers/isRawValue.js +5 -0
- package/dist/helpers/isValid.d.ts +6 -0
- package/dist/helpers/isValid.js +6 -0
- package/dist/helpers/math.d.ts +19 -0
- package/dist/helpers/math.js +116 -0
- package/dist/helpers/mergeDeep.d.ts +1 -1
- package/dist/helpers/noise.d.ts +1 -0
- package/dist/helpers/noise.js +72 -0
- package/dist/helpers/projection.d.ts +33 -0
- package/dist/helpers/projection.js +100 -0
- package/dist/helpers/reduce.d.ts +10 -0
- package/dist/helpers/reduce.js +85 -0
- package/dist/helpers/regressionLoess.d.ts +12 -0
- package/dist/helpers/regressionLoess.js +47 -0
- package/dist/helpers/removeIdenticalLines.d.ts +8 -1
- package/dist/helpers/removeIdenticalLines.js +14 -7
- package/dist/helpers/resolve.d.ts +21 -0
- package/dist/helpers/resolve.js +156 -0
- package/dist/helpers/roundedRect.d.ts +9 -0
- package/dist/helpers/roundedRect.js +31 -0
- package/dist/helpers/scales.d.ts +42 -0
- package/dist/helpers/scales.js +311 -0
- package/dist/helpers/time.d.ts +6 -0
- package/dist/helpers/time.js +282 -0
- package/dist/helpers/typeChecks.d.ts +8 -5
- package/dist/helpers/typeChecks.js +27 -6
- package/dist/index.d.ts +49 -1
- package/dist/index.js +53 -2
- package/dist/marks/Area.svelte +146 -0
- package/dist/marks/Area.svelte.d.ts +30 -0
- package/dist/marks/AreaX.svelte +27 -0
- package/dist/marks/AreaX.svelte.d.ts +12 -0
- package/dist/marks/AreaY.svelte +38 -0
- package/dist/marks/AreaY.svelte.d.ts +19 -0
- package/dist/marks/Arrow.svelte +139 -0
- package/dist/marks/Arrow.svelte.d.ts +44 -0
- package/dist/marks/AxisX.svelte +198 -93
- package/dist/marks/AxisX.svelte.d.ts +17 -16
- package/dist/marks/AxisY.svelte +176 -62
- package/dist/marks/AxisY.svelte.d.ts +17 -14
- package/dist/marks/BarX.svelte +93 -0
- package/dist/marks/BarX.svelte.d.ts +4 -0
- package/dist/marks/BarY.svelte +103 -0
- package/dist/marks/BarY.svelte.d.ts +25 -0
- package/dist/marks/BollingerX.svelte +44 -0
- package/dist/marks/BollingerX.svelte.d.ts +18 -0
- package/dist/marks/BollingerY.svelte +39 -0
- package/dist/marks/BollingerY.svelte.d.ts +18 -0
- package/dist/marks/BoxX.svelte +89 -0
- package/dist/marks/BoxX.svelte.d.ts +4 -0
- package/dist/marks/BoxY.svelte +110 -0
- package/dist/marks/BoxY.svelte.d.ts +29 -0
- package/dist/marks/Cell.svelte +110 -0
- package/dist/marks/Cell.svelte.d.ts +16 -0
- package/dist/marks/CellX.svelte +24 -0
- package/dist/marks/CellX.svelte.d.ts +3 -0
- package/dist/marks/CellY.svelte +24 -0
- package/dist/marks/CellY.svelte.d.ts +3 -0
- package/dist/marks/ColorLegend.svelte +148 -27
- package/dist/marks/ColorLegend.svelte.d.ts +12 -13
- package/dist/marks/CustomMark.svelte +43 -0
- package/dist/marks/CustomMark.svelte.d.ts +16 -0
- package/dist/marks/CustomMarkHTML.svelte +103 -0
- package/dist/marks/CustomMarkHTML.svelte.d.ts +17 -0
- package/dist/marks/DifferenceY.svelte +144 -0
- package/dist/marks/DifferenceY.svelte.d.ts +30 -0
- package/dist/marks/Dot.svelte +128 -73
- package/dist/marks/Dot.svelte.d.ts +24 -14
- package/dist/marks/DotX.svelte +15 -3
- package/dist/marks/DotX.svelte.d.ts +8 -16
- package/dist/marks/DotY.svelte +8 -3
- package/dist/marks/DotY.svelte.d.ts +5 -17
- package/dist/marks/Frame.svelte +39 -31
- package/dist/marks/Frame.svelte.d.ts +7 -14
- package/dist/marks/Geo.svelte +102 -0
- package/dist/marks/Geo.svelte.d.ts +10 -0
- package/dist/marks/Graticule.svelte +28 -0
- package/dist/marks/Graticule.svelte.d.ts +9 -0
- package/dist/marks/GridX.svelte +67 -36
- package/dist/marks/GridX.svelte.d.ts +7 -18
- package/dist/marks/GridY.svelte +64 -25
- package/dist/marks/GridY.svelte.d.ts +7 -14
- package/dist/marks/HTMLTooltip.svelte +91 -0
- package/dist/marks/HTMLTooltip.svelte.d.ts +11 -0
- package/dist/marks/Line.svelte +219 -58
- package/dist/marks/Line.svelte.d.ts +30 -14
- package/dist/marks/LineX.svelte +8 -8
- package/dist/marks/LineX.svelte.d.ts +4 -17
- package/dist/marks/LineY.svelte +7 -8
- package/dist/marks/LineY.svelte.d.ts +4 -17
- package/dist/marks/Link.svelte +180 -0
- package/dist/marks/Link.svelte.d.ts +21 -0
- package/dist/marks/Pointer.svelte +126 -0
- package/dist/marks/Pointer.svelte.d.ts +23 -0
- package/dist/marks/Rect.svelte +103 -0
- package/dist/marks/Rect.svelte.d.ts +15 -0
- package/dist/marks/RectX.svelte +33 -0
- package/dist/marks/RectX.svelte.d.ts +15 -0
- package/dist/marks/RectY.svelte +33 -0
- package/dist/marks/RectY.svelte.d.ts +15 -0
- package/dist/marks/RegressionX.svelte +26 -0
- package/dist/marks/RegressionX.svelte.d.ts +4 -0
- package/dist/marks/RegressionY.svelte +26 -0
- package/dist/marks/RegressionY.svelte.d.ts +4 -0
- package/dist/marks/RuleX.svelte +52 -28
- package/dist/marks/RuleX.svelte.d.ts +14 -14
- package/dist/marks/RuleY.svelte +52 -28
- package/dist/marks/RuleY.svelte.d.ts +14 -14
- package/dist/marks/Sphere.svelte +8 -0
- package/dist/marks/Sphere.svelte.d.ts +51 -0
- package/dist/marks/Spike.svelte +15 -0
- package/dist/marks/Spike.svelte.d.ts +4 -0
- package/dist/marks/SymbolLegend.svelte +27 -12
- package/dist/marks/SymbolLegend.svelte.d.ts +8 -14
- package/dist/marks/Text.svelte +189 -0
- package/dist/marks/Text.svelte.d.ts +26 -0
- package/dist/marks/TickX.svelte +89 -0
- package/dist/marks/TickX.svelte.d.ts +22 -0
- package/dist/marks/TickY.svelte +90 -0
- package/dist/marks/TickY.svelte.d.ts +22 -0
- package/dist/marks/Vector.svelte +219 -0
- package/dist/marks/Vector.svelte.d.ts +31 -0
- package/dist/marks/helpers/BaseAxisX.svelte +210 -0
- package/dist/marks/helpers/BaseAxisX.svelte.d.ts +24 -0
- package/dist/marks/helpers/BaseAxisY.svelte +187 -0
- package/dist/marks/helpers/BaseAxisY.svelte.d.ts +23 -0
- package/dist/marks/helpers/CanvasLayer.svelte +38 -0
- package/dist/marks/helpers/CanvasLayer.svelte.d.ts +13 -0
- package/dist/marks/helpers/DotCanvas.svelte +184 -0
- package/dist/marks/helpers/DotCanvas.svelte.d.ts +11 -0
- package/dist/marks/helpers/GeoCanvas.svelte +165 -0
- package/dist/marks/helpers/GeoCanvas.svelte.d.ts +13 -0
- package/dist/marks/helpers/GroupMultiple.svelte +17 -0
- package/dist/marks/helpers/GroupMultiple.svelte.d.ts +9 -0
- package/dist/marks/helpers/Marker.svelte +93 -0
- package/dist/marks/helpers/Marker.svelte.d.ts +10 -0
- package/dist/marks/helpers/MarkerPath.svelte +141 -0
- package/dist/marks/helpers/MarkerPath.svelte.d.ts +44 -0
- package/dist/marks/helpers/Regression.svelte +174 -0
- package/dist/marks/helpers/Regression.svelte.d.ts +26 -0
- package/dist/marks/helpers/events.d.ts +8 -0
- package/dist/marks/helpers/events.js +74 -0
- package/dist/transforms/bin.d.ts +51 -0
- package/dist/transforms/bin.js +171 -0
- package/dist/transforms/bollinger.d.ts +21 -0
- package/dist/transforms/bollinger.js +53 -0
- package/dist/transforms/centroid.d.ts +9 -0
- package/dist/transforms/centroid.js +13 -0
- package/dist/transforms/facet.d.ts +1 -0
- package/dist/transforms/facet.js +1 -0
- package/dist/transforms/filter.d.ts +2 -0
- package/dist/transforms/filter.js +8 -0
- package/dist/transforms/group.d.ts +66 -0
- package/dist/transforms/group.js +109 -0
- package/dist/transforms/interval.d.ts +11 -0
- package/dist/transforms/interval.js +34 -0
- package/dist/transforms/jitter.d.ts +1 -0
- package/dist/transforms/jitter.js +1 -0
- package/dist/transforms/map.d.ts +10 -0
- package/dist/transforms/map.js +89 -0
- package/dist/transforms/normalize.d.ts +9 -0
- package/dist/transforms/normalize.js +86 -0
- package/dist/transforms/recordize.d.ts +15 -0
- package/dist/transforms/recordize.js +78 -0
- package/dist/transforms/rename.d.ts +14 -0
- package/dist/transforms/rename.js +42 -0
- package/dist/transforms/select.d.ts +35 -0
- package/dist/transforms/select.js +55 -0
- package/dist/transforms/shift.d.ts +13 -0
- package/dist/transforms/shift.js +45 -0
- package/dist/transforms/sort.d.ts +28 -0
- package/dist/transforms/sort.js +66 -0
- package/dist/transforms/stack.d.ts +10 -0
- package/dist/transforms/stack.js +110 -0
- package/dist/transforms/window.d.ts +24 -0
- package/dist/transforms/window.js +73 -0
- package/dist/types.d.ts +625 -188
- package/dist/ui/Checkbox.svelte +6 -0
- package/dist/ui/Checkbox.svelte.d.ts +13 -0
- package/dist/ui/RadioInput.svelte +27 -0
- package/dist/ui/RadioInput.svelte.d.ts +9 -0
- package/dist/ui/Select.svelte +27 -0
- package/dist/ui/Select.svelte.d.ts +9 -0
- package/dist/ui/Slider.svelte +47 -0
- package/dist/ui/Slider.svelte.d.ts +11 -0
- package/dist/ui/Spiral.svelte +46 -0
- package/dist/ui/Spiral.svelte.d.ts +15 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +4 -0
- package/package.json +81 -42
- package/LICENSE +0 -11
- package/dist/classes/Channel.svelte.js +0 -74
- package/dist/classes/Mark.svelte.js +0 -17
- package/dist/classes/Plot.svelte.js +0 -98
- package/dist/contants.d.ts +0 -3
- package/dist/contants.js +0 -40
- package/dist/helpers/GroupMultiple.svelte +0 -8
- package/dist/helpers/GroupMultiple.svelte.d.ts +0 -19
- package/dist/helpers/createScale.d.ts +0 -5
- package/dist/helpers/createScale.js +0 -57
- package/dist/helpers/resolveChannel.d.ts +0 -2
- package/dist/helpers/resolveChannel.js +0 -28
- package/dist/helpers/wrapArray.d.ts +0 -2
- package/dist/helpers/wrapArray.js +0 -4
- package/dist/marks/BaseMark.svelte +0 -22
- package/dist/marks/BaseMark.svelte.d.ts +0 -19
package/dist/marks/Line.svelte
CHANGED
|
@@ -1,61 +1,222 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Line mark, useful for line charts
|
|
4
|
+
-->
|
|
5
|
+
<script module lang="ts">
|
|
6
|
+
import type {
|
|
7
|
+
CurveName,
|
|
8
|
+
PlotContext,
|
|
9
|
+
DataRecord,
|
|
10
|
+
BaseMarkProps,
|
|
11
|
+
ConstantAccessor,
|
|
12
|
+
ChannelAccessor,
|
|
13
|
+
MarkerOptions,
|
|
14
|
+
ScaledDataRecord
|
|
15
|
+
} from '../types.js';
|
|
16
|
+
|
|
17
|
+
export type BaseLineMarkProps = {
|
|
18
|
+
data: DataRecord[];
|
|
19
|
+
z?: ChannelAccessor;
|
|
20
|
+
stroke?: ChannelAccessor;
|
|
21
|
+
outlineStroke?: ConstantAccessor<string>;
|
|
22
|
+
outlineStrokeWidth?: ConstantAccessor<number>;
|
|
23
|
+
dx?: ConstantAccessor<number>;
|
|
24
|
+
dy?: ConstantAccessor<number>;
|
|
25
|
+
curve?: CurveName | CurveFactory;
|
|
26
|
+
tension?: number;
|
|
27
|
+
sort?: ConstantAccessor<RawValue> | { channel: 'stroke' | 'fill' };
|
|
28
|
+
text?: ConstantAccessor<string>;
|
|
29
|
+
textFill?: ConstantAccessor<string>;
|
|
30
|
+
textStroke?: ConstantAccessor<string>;
|
|
31
|
+
textStartOffset?: ConstantAccessor<string>;
|
|
32
|
+
textStrokeWidth?: ConstantAccessor<number>;
|
|
33
|
+
lineClass?: ConstantAccessor<string>;
|
|
34
|
+
} & MarkerOptions;
|
|
30
35
|
</script>
|
|
31
36
|
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{
|
|
37
|
-
{
|
|
38
|
-
{
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
37
|
+
<script lang="ts">
|
|
38
|
+
import Mark from '../Mark.svelte';
|
|
39
|
+
import MarkerPath from './helpers/MarkerPath.svelte';
|
|
40
|
+
import { getContext } from 'svelte';
|
|
41
|
+
import { resolveProp, resolveStyles } from '../helpers/resolve.js';
|
|
42
|
+
import { line, type CurveFactory } from 'd3-shape';
|
|
43
|
+
import { geoPath } from 'd3-geo';
|
|
44
|
+
import callWithProps from '../helpers/callWithProps.js';
|
|
45
|
+
import { maybeCurve } from '../helpers/curves.js';
|
|
46
|
+
import { pick } from 'es-toolkit';
|
|
47
|
+
|
|
48
|
+
type LineMarkProps = BaseMarkProps & {
|
|
49
|
+
x?: ChannelAccessor;
|
|
50
|
+
y?: ChannelAccessor;
|
|
51
|
+
} & BaseLineMarkProps;
|
|
52
|
+
|
|
53
|
+
import type { RawValue } from '../types.js';
|
|
54
|
+
import { isValid } from '../helpers/index.js';
|
|
55
|
+
import { sort } from '../transforms/sort.js';
|
|
56
|
+
import { recordizeXY } from '../transforms/recordize.js';
|
|
57
|
+
import GroupMultiple from './helpers/GroupMultiple.svelte';
|
|
58
|
+
|
|
59
|
+
let {
|
|
60
|
+
data = [{}],
|
|
61
|
+
curve = 'auto',
|
|
62
|
+
tension = 0,
|
|
63
|
+
text,
|
|
64
|
+
class: className = null,
|
|
65
|
+
lineClass = null,
|
|
66
|
+
...options
|
|
67
|
+
}: LineMarkProps = $props();
|
|
68
|
+
|
|
69
|
+
const args = $derived(sort(recordizeXY({ data, ...options })));
|
|
70
|
+
|
|
71
|
+
function groupIndex(data: ScaledDataRecord[], groupByKey) {
|
|
72
|
+
if (!groupByKey) return [data];
|
|
73
|
+
let group = [];
|
|
74
|
+
const groups = [group];
|
|
75
|
+
let lastGroupValue;
|
|
76
|
+
for (const d of data) {
|
|
77
|
+
const groupValue = resolveProp(groupByKey, d.datum);
|
|
78
|
+
if (groupValue === lastGroupValue) {
|
|
79
|
+
group.push(d);
|
|
80
|
+
} else {
|
|
81
|
+
if (group.length === 1) {
|
|
82
|
+
// just one point makes a bad line, add this one, too
|
|
83
|
+
group.push(d);
|
|
84
|
+
}
|
|
85
|
+
// new group
|
|
86
|
+
group = [d];
|
|
87
|
+
groups.push(group);
|
|
88
|
+
lastGroupValue = groupValue;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return groups;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const groupByKey = $derived(args.z || args.stroke);
|
|
95
|
+
|
|
96
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
97
|
+
const plot = $derived(getPlotState());
|
|
98
|
+
|
|
99
|
+
type LinePath = (dr: DataRecord[]) => string;
|
|
100
|
+
|
|
101
|
+
const linePath: LinePath = $derived(
|
|
102
|
+
plot.scales.projection && curve === 'auto'
|
|
103
|
+
? sphereLine(plot.scales.projection)
|
|
104
|
+
: callWithProps(line, [], {
|
|
105
|
+
curve: maybeCurve(curve === 'auto' ? 'linear' : curve, tension),
|
|
106
|
+
x: (d) => d.x,
|
|
107
|
+
y: (d) => d.y,
|
|
108
|
+
defined: (d) => isValid(d.x) && isValid(d.y)
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
function sphereLine(projection) {
|
|
113
|
+
const path = geoPath(projection);
|
|
114
|
+
return (lineData: ScaledDataRecord[]) => {
|
|
115
|
+
let line = [];
|
|
116
|
+
const lines = [line];
|
|
117
|
+
for (const { x, y } of lineData) {
|
|
118
|
+
// if x or y is undefined, start a new line segment
|
|
119
|
+
if (!isValid(x) || !isValid(y)) {
|
|
120
|
+
line = [];
|
|
121
|
+
lines.push(line);
|
|
122
|
+
} else {
|
|
123
|
+
line.push([x, y]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return path({ type: 'MultiLineString', coordinates: lines });
|
|
127
|
+
};
|
|
60
128
|
}
|
|
61
|
-
</
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
<Mark
|
|
132
|
+
type="line"
|
|
133
|
+
channels={['x', 'y', 'opacity', 'stroke', 'strokeOpacity']}
|
|
134
|
+
required={['x', 'y']}
|
|
135
|
+
{...args}>
|
|
136
|
+
{#snippet children({ mark, usedScales, scaledData })}
|
|
137
|
+
{#if scaledData.length > 0}
|
|
138
|
+
<g class={['lines', className]}>
|
|
139
|
+
{#each groupIndex(scaledData, groupByKey) as lineData, i}
|
|
140
|
+
{@const pathString = linePath(lineData)}
|
|
141
|
+
{#if pathString}
|
|
142
|
+
<GroupMultiple class={resolveProp(lineClass, lineData[0])}>
|
|
143
|
+
{#if options.outlineStroke}
|
|
144
|
+
{@const [outlineStyle, outlineStyleClass] = resolveStyles(
|
|
145
|
+
plot,
|
|
146
|
+
{ ...lineData[0], stroke: options.outlineStroke },
|
|
147
|
+
{
|
|
148
|
+
strokeLinejoin: 'round',
|
|
149
|
+
...args,
|
|
150
|
+
stroke: options.outlineStroke,
|
|
151
|
+
strokeWidth:
|
|
152
|
+
options.outlineStrokeWidth ||
|
|
153
|
+
(+options.strokeWidth || 1.4) + 2
|
|
154
|
+
},
|
|
155
|
+
'stroke',
|
|
156
|
+
usedScales
|
|
157
|
+
)}
|
|
158
|
+
<path
|
|
159
|
+
d={pathString}
|
|
160
|
+
style={outlineStyle}
|
|
161
|
+
class={['is-outline', outlineStyleClass]} />
|
|
162
|
+
{/if}
|
|
163
|
+
{@const [style, styleClass] = resolveStyles(
|
|
164
|
+
plot,
|
|
165
|
+
lineData[0],
|
|
166
|
+
{
|
|
167
|
+
strokeWidth: 1.4,
|
|
168
|
+
strokeLinejoin: 'round',
|
|
169
|
+
...args,
|
|
170
|
+
stroke: lineData[0].stroke
|
|
171
|
+
},
|
|
172
|
+
'stroke',
|
|
173
|
+
usedScales
|
|
174
|
+
)}
|
|
175
|
+
{@const [textStyle, textStyleClass] = resolveStyles(
|
|
176
|
+
plot,
|
|
177
|
+
lineData[0],
|
|
178
|
+
{
|
|
179
|
+
textAnchor: 'middle',
|
|
180
|
+
...pick(args, [
|
|
181
|
+
'fontSize',
|
|
182
|
+
'fontWeight',
|
|
183
|
+
'fontStyle',
|
|
184
|
+
'textAnchor'
|
|
185
|
+
]),
|
|
186
|
+
strokeWidth: args.textStrokeWidth
|
|
187
|
+
? args.textStrokeWidth
|
|
188
|
+
: args.textStroke
|
|
189
|
+
? 2
|
|
190
|
+
: 0,
|
|
191
|
+
fill: args.textFill || args.stroke,
|
|
192
|
+
stroke: args.textStroke
|
|
193
|
+
},
|
|
194
|
+
'fill',
|
|
195
|
+
usedScales,
|
|
196
|
+
true
|
|
197
|
+
)}
|
|
198
|
+
<MarkerPath
|
|
199
|
+
{mark}
|
|
200
|
+
scales={plot.scales}
|
|
201
|
+
markerStart={args.markerStart}
|
|
202
|
+
markerMid={args.markerMid}
|
|
203
|
+
markerEnd={args.markerEnd}
|
|
204
|
+
marker={args.marker}
|
|
205
|
+
strokeWidth={args.strokeWidth}
|
|
206
|
+
datum={lineData[0]}
|
|
207
|
+
d={pathString}
|
|
208
|
+
dInv={text ? linePath(lineData.toReversed()) : null}
|
|
209
|
+
color={lineData[0].stroke || 'currentColor'}
|
|
210
|
+
{style}
|
|
211
|
+
class={styleClass}
|
|
212
|
+
text={text ? resolveProp(text, lineData[0]) : null}
|
|
213
|
+
startOffset={resolveProp(args.textStartOffset, lineData[0], '50%')}
|
|
214
|
+
{textStyle}
|
|
215
|
+
{textStyleClass} />
|
|
216
|
+
</GroupMultiple>
|
|
217
|
+
{/if}
|
|
218
|
+
{/each}
|
|
219
|
+
</g>
|
|
220
|
+
{/if}
|
|
221
|
+
{/snippet}
|
|
222
|
+
</Mark>
|
|
@@ -1,15 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { CurveName, DataRecord, BaseMarkProps, ConstantAccessor, ChannelAccessor, MarkerOptions } from '../types.js';
|
|
2
|
+
export type BaseLineMarkProps = {
|
|
3
|
+
data: DataRecord[];
|
|
4
|
+
z?: ChannelAccessor;
|
|
5
|
+
stroke?: ChannelAccessor;
|
|
6
|
+
outlineStroke?: ConstantAccessor<string>;
|
|
7
|
+
outlineStrokeWidth?: ConstantAccessor<number>;
|
|
8
|
+
dx?: ConstantAccessor<number>;
|
|
9
|
+
dy?: ConstantAccessor<number>;
|
|
10
|
+
curve?: CurveName | CurveFactory;
|
|
11
|
+
tension?: number;
|
|
12
|
+
sort?: ConstantAccessor<RawValue> | {
|
|
13
|
+
channel: 'stroke' | 'fill';
|
|
7
14
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
15
|
+
text?: ConstantAccessor<string>;
|
|
16
|
+
textFill?: ConstantAccessor<string>;
|
|
17
|
+
textStroke?: ConstantAccessor<string>;
|
|
18
|
+
textStartOffset?: ConstantAccessor<string>;
|
|
19
|
+
textStrokeWidth?: ConstantAccessor<number>;
|
|
20
|
+
lineClass?: ConstantAccessor<string>;
|
|
21
|
+
} & MarkerOptions;
|
|
22
|
+
import { type CurveFactory } from 'd3-shape';
|
|
23
|
+
import type { RawValue } from '../types.js';
|
|
24
|
+
type LineMarkProps = BaseMarkProps & {
|
|
25
|
+
x?: ChannelAccessor;
|
|
26
|
+
y?: ChannelAccessor;
|
|
27
|
+
} & BaseLineMarkProps;
|
|
28
|
+
/** Line mark, useful for line charts */
|
|
29
|
+
declare const Line: import("svelte").Component<LineMarkProps, {}, "">;
|
|
30
|
+
type Line = ReturnType<typeof Line>;
|
|
31
|
+
export default Line;
|
package/dist/marks/LineX.svelte
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Line, { type BaseLineMarkProps } from './Line.svelte';
|
|
3
|
+
import { recordizeX } from '../index.js';
|
|
4
|
+
|
|
5
|
+
let { data = [{}], ...rest }: BaseLineMarkProps = $props();
|
|
6
|
+
|
|
7
|
+
let args = $derived(recordizeX({ data, ...rest }));
|
|
3
8
|
</script>
|
|
4
9
|
|
|
5
|
-
<Line
|
|
6
|
-
data={data.map((value, index) => ({ value, index, ___orig___: value }))}
|
|
7
|
-
x="value"
|
|
8
|
-
y="index"
|
|
9
|
-
{...rest}
|
|
10
|
-
/>
|
|
10
|
+
<Line {...args} />
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
data: RawValue[];
|
|
6
|
-
};
|
|
7
|
-
events: {
|
|
8
|
-
[evt: string]: CustomEvent<any>;
|
|
9
|
-
};
|
|
10
|
-
slots: {};
|
|
11
|
-
};
|
|
12
|
-
export type LineXProps = typeof __propDef.props;
|
|
13
|
-
export type LineXEvents = typeof __propDef.events;
|
|
14
|
-
export type LineXSlots = typeof __propDef.slots;
|
|
15
|
-
export default class LineX extends SvelteComponent<LineXProps, LineXEvents, LineXSlots> {
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
1
|
+
import { type BaseLineMarkProps } from './Line.svelte';
|
|
2
|
+
declare const LineX: import("svelte").Component<BaseLineMarkProps, {}, "">;
|
|
3
|
+
type LineX = ReturnType<typeof LineX>;
|
|
4
|
+
export default LineX;
|
package/dist/marks/LineY.svelte
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Line, { type BaseLineMarkProps } from './Line.svelte';
|
|
3
|
+
import { recordizeY } from '../index.js';
|
|
4
|
+
|
|
5
|
+
let { data = [{}], ...rest }: BaseLineMarkProps = $props();
|
|
6
|
+
let args = $derived(recordizeY({ data, ...rest }));
|
|
3
7
|
</script>
|
|
4
8
|
|
|
5
|
-
<Line
|
|
6
|
-
data={data.map((value, index) => ({ value, index, ___orig___: value }))}
|
|
7
|
-
x="index"
|
|
8
|
-
y="value"
|
|
9
|
-
{...rest}
|
|
10
|
-
/>
|
|
9
|
+
<Line {...args} />
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
data: RawValue[];
|
|
6
|
-
};
|
|
7
|
-
events: {
|
|
8
|
-
[evt: string]: CustomEvent<any>;
|
|
9
|
-
};
|
|
10
|
-
slots: {};
|
|
11
|
-
};
|
|
12
|
-
export type LineYProps = typeof __propDef.props;
|
|
13
|
-
export type LineYEvents = typeof __propDef.events;
|
|
14
|
-
export type LineYSlots = typeof __propDef.slots;
|
|
15
|
-
export default class LineY extends SvelteComponent<LineYProps, LineYEvents, LineYSlots> {
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
1
|
+
import { type BaseLineMarkProps } from './Line.svelte';
|
|
2
|
+
declare const LineY: import("svelte").Component<BaseLineMarkProps, {}, "">;
|
|
3
|
+
type LineY = ReturnType<typeof LineY>;
|
|
4
|
+
export default LineY;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, type Snippet } from 'svelte';
|
|
3
|
+
import type {
|
|
4
|
+
PlotContext,
|
|
5
|
+
DataRecord,
|
|
6
|
+
BaseMarkProps,
|
|
7
|
+
ConstantAccessor,
|
|
8
|
+
ChannelAccessor,
|
|
9
|
+
CurveName,
|
|
10
|
+
MarkerOptions,
|
|
11
|
+
RawValue,
|
|
12
|
+
ScaledDataRecord
|
|
13
|
+
} from '../types.js';
|
|
14
|
+
import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
|
|
15
|
+
import { maybeData } from '../helpers/index.js';
|
|
16
|
+
import Mark from '../Mark.svelte';
|
|
17
|
+
import MarkerPath from './helpers/MarkerPath.svelte';
|
|
18
|
+
import { replaceChannels } from '../transforms/rename.js';
|
|
19
|
+
import { line, type CurveFactory } from 'd3-shape';
|
|
20
|
+
import callWithProps from '../helpers/callWithProps.js';
|
|
21
|
+
import { maybeCurve } from '../helpers/curves.js';
|
|
22
|
+
import { geoPath } from 'd3-geo';
|
|
23
|
+
import { pick } from 'es-toolkit';
|
|
24
|
+
|
|
25
|
+
type LinkMarkProps = BaseMarkProps & {
|
|
26
|
+
data: DataRecord[];
|
|
27
|
+
sort?: ConstantAccessor<RawValue> | { channel: 'stroke' | 'fill' };
|
|
28
|
+
x1: ChannelAccessor;
|
|
29
|
+
y1: ChannelAccessor;
|
|
30
|
+
x2: ChannelAccessor;
|
|
31
|
+
y2: ChannelAccessor;
|
|
32
|
+
stroke?: ChannelAccessor;
|
|
33
|
+
curve?: 'auto' | CurveName | CurveFactory;
|
|
34
|
+
tension?: number;
|
|
35
|
+
text: ConstantAccessor<string>;
|
|
36
|
+
children?: Snippet;
|
|
37
|
+
} & MarkerOptions;
|
|
38
|
+
|
|
39
|
+
let {
|
|
40
|
+
data = [{}],
|
|
41
|
+
curve = 'auto',
|
|
42
|
+
tension = 0,
|
|
43
|
+
text,
|
|
44
|
+
class: className = null,
|
|
45
|
+
...options
|
|
46
|
+
}: LinkMarkProps = $props();
|
|
47
|
+
|
|
48
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
49
|
+
let plot = $derived(getPlotState());
|
|
50
|
+
|
|
51
|
+
function isValid(value: RawValue): value is number | Date | string {
|
|
52
|
+
return value !== null && (typeof value === 'string' || !Number.isNaN(value));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const sorted = $derived(
|
|
56
|
+
options.sort
|
|
57
|
+
? maybeData(data).toSorted((a, b) =>
|
|
58
|
+
resolveChannel('sort', a, options) > resolveChannel('sort', b, options) ? 1 : -1
|
|
59
|
+
)
|
|
60
|
+
: maybeData(data)
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const args = $derived(
|
|
64
|
+
replaceChannels(
|
|
65
|
+
{ data: sorted, stroke: 'currentColor', ...options },
|
|
66
|
+
{ y: ['y1', 'y2'], x: ['x1', 'x2'] }
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const sphericalLine = $derived(plot.scales.projection && curve === 'auto');
|
|
71
|
+
|
|
72
|
+
const linePath: (d: ScaledDataRecord, reversed: boolean) => string = $derived.by(() => {
|
|
73
|
+
const fn = callWithProps(line, [], {
|
|
74
|
+
curve: maybeCurve(curve === 'auto' ? 'linear' : curve, tension),
|
|
75
|
+
x: (d) => d[0],
|
|
76
|
+
y: (d) => d[1]
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return (d: ScaledDataRecord, reversed = false) =>
|
|
80
|
+
fn(
|
|
81
|
+
reversed
|
|
82
|
+
? [
|
|
83
|
+
[d.x2, d.y2],
|
|
84
|
+
[d.x1, d.y1]
|
|
85
|
+
]
|
|
86
|
+
: [
|
|
87
|
+
[d.x1, d.y1],
|
|
88
|
+
[d.x2, d.y2]
|
|
89
|
+
]
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const sphericalLinePath: (d: ScaledDataRecord, reversed: boolean) => string = $derived.by(
|
|
94
|
+
() => {
|
|
95
|
+
const fn = sphereLine(plot.scales.projection);
|
|
96
|
+
return (d: ScaledDataRecord, reversed = false) => {
|
|
97
|
+
const x1 = resolveChannel('x1', d.datum, args);
|
|
98
|
+
const y1 = resolveChannel('y1', d.datum, args);
|
|
99
|
+
const x2 = resolveChannel('x2', d.datum, args);
|
|
100
|
+
const y2 = resolveChannel('y2', d.datum, args);
|
|
101
|
+
return reversed ? fn(x2, y2, x1, y1) : fn(x1, y1, x2, y2);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
// sphericalLine
|
|
106
|
+
// ?
|
|
107
|
+
|
|
108
|
+
// sphereLine(plot.scales.projection)
|
|
109
|
+
// :
|
|
110
|
+
// );
|
|
111
|
+
|
|
112
|
+
function sphereLine(projection) {
|
|
113
|
+
const path = geoPath(projection);
|
|
114
|
+
return (x1: number, y1: number, x2: number, y2: number) => {
|
|
115
|
+
return path({
|
|
116
|
+
type: 'LineString',
|
|
117
|
+
coordinates: [
|
|
118
|
+
[x1, y1],
|
|
119
|
+
[x2, y2]
|
|
120
|
+
]
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
</script>
|
|
125
|
+
|
|
126
|
+
<Mark
|
|
127
|
+
type="link"
|
|
128
|
+
required={['x1', 'x2', 'y1', 'y2']}
|
|
129
|
+
channels={['x1', 'y1', 'x2', 'y2', 'opacity', 'stroke', 'strokeOpacity']}
|
|
130
|
+
{...args}>
|
|
131
|
+
{#snippet children({ mark, scaledData, usedScales })}
|
|
132
|
+
<g class={['link', className]} data-use-x={usedScales.x ? 1 : 0}>
|
|
133
|
+
{#each scaledData as d}
|
|
134
|
+
{#if d.valid || true}
|
|
135
|
+
{@const dx = resolveProp(args.dx, d.datum, 0)}
|
|
136
|
+
{@const dy = resolveProp(args.dx, d.datum, 0)}
|
|
137
|
+
{@const [style, styleClass] = resolveStyles(
|
|
138
|
+
plot,
|
|
139
|
+
d,
|
|
140
|
+
{ strokeWidth: 1.6, ...args },
|
|
141
|
+
'stroke',
|
|
142
|
+
usedScales
|
|
143
|
+
)}
|
|
144
|
+
{@const [textStyle, textStyleClass] = resolveStyles(
|
|
145
|
+
plot,
|
|
146
|
+
d,
|
|
147
|
+
{
|
|
148
|
+
textAnchor: 'middle',
|
|
149
|
+
...pick(args, ['fontSize', 'fontWeight', 'fontStyle', 'textAnchor']),
|
|
150
|
+
fill: args.textFill || args.stroke,
|
|
151
|
+
stroke: args.textStroke,
|
|
152
|
+
strokeWidth: args.textStrokeWidth
|
|
153
|
+
},
|
|
154
|
+
'fill',
|
|
155
|
+
usedScales
|
|
156
|
+
)}
|
|
157
|
+
|
|
158
|
+
<MarkerPath
|
|
159
|
+
mark={{ ...mark, options: args }}
|
|
160
|
+
scales={plot.scales}
|
|
161
|
+
markerStart={args.markerStart}
|
|
162
|
+
markerEnd={args.markerEnd}
|
|
163
|
+
marker={args.marker}
|
|
164
|
+
class={styleClass}
|
|
165
|
+
strokeWidth={args.strokeWidth}
|
|
166
|
+
datum={d.datum}
|
|
167
|
+
color={d.stroke}
|
|
168
|
+
d={sphericalLine ? sphericalLinePath(d) : linePath(d)}
|
|
169
|
+
dInv={sphericalLine ? sphericalLinePath(d, true) : linePath(d, true)}
|
|
170
|
+
{style}
|
|
171
|
+
text={text ? resolveProp(text, d.datum) : null}
|
|
172
|
+
startOffset={resolveProp(args.textStartOffset, d.datum, '50%')}
|
|
173
|
+
{textStyle}
|
|
174
|
+
{textStyleClass}
|
|
175
|
+
transform={dx || dy ? `translate(${dx}, ${dy})` : null} />
|
|
176
|
+
{/if}
|
|
177
|
+
{/each}
|
|
178
|
+
</g>
|
|
179
|
+
{/snippet}
|
|
180
|
+
</Mark>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { DataRecord, BaseMarkProps, ConstantAccessor, ChannelAccessor, CurveName, MarkerOptions, RawValue } from '../types.js';
|
|
3
|
+
import { type CurveFactory } from 'd3-shape';
|
|
4
|
+
type LinkMarkProps = BaseMarkProps & {
|
|
5
|
+
data: DataRecord[];
|
|
6
|
+
sort?: ConstantAccessor<RawValue> | {
|
|
7
|
+
channel: 'stroke' | 'fill';
|
|
8
|
+
};
|
|
9
|
+
x1: ChannelAccessor;
|
|
10
|
+
y1: ChannelAccessor;
|
|
11
|
+
x2: ChannelAccessor;
|
|
12
|
+
y2: ChannelAccessor;
|
|
13
|
+
stroke?: ChannelAccessor;
|
|
14
|
+
curve?: 'auto' | CurveName | CurveFactory;
|
|
15
|
+
tension?: number;
|
|
16
|
+
text: ConstantAccessor<string>;
|
|
17
|
+
children?: Snippet;
|
|
18
|
+
} & MarkerOptions;
|
|
19
|
+
declare const Link: import("svelte").Component<LinkMarkProps, {}, "">;
|
|
20
|
+
type Link = ReturnType<typeof Link>;
|
|
21
|
+
export default Link;
|