svelteplot 0.0.1-alpha.8 → 0.1.3-next.11
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 -36
- package/dist/Mark.svelte +292 -0
- package/dist/Mark.svelte.d.ts +22 -0
- package/dist/Plot.svelte +148 -153
- 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 +309 -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 +86 -0
- package/dist/marks/BarX.svelte.d.ts +4 -0
- package/dist/marks/BarY.svelte +98 -0
- package/dist/marks/BarY.svelte.d.ts +4 -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 +0 -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 +14 -0
- package/dist/transforms/recordize.js +79 -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 +22 -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/GridX.svelte
CHANGED
|
@@ -1,42 +1,73 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
);
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import Mark from '../Mark.svelte';
|
|
4
|
+
import type { PlotContext, BaseMarkProps, RawValue } from '../types.js';
|
|
5
|
+
import { resolveChannel, resolveScaledStyles } from '../helpers/resolve.js';
|
|
6
|
+
import { autoTicks } from '../helpers/autoTicks.js';
|
|
7
|
+
import { getUsedScales } from '../helpers/scales.js';
|
|
8
|
+
import { testFilter } from '../helpers/index.js';
|
|
9
|
+
|
|
10
|
+
type GrixXMarkProps = BaseMarkProps & {
|
|
11
|
+
data?: RawValue[];
|
|
12
|
+
automatic?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
let { data = [], automatic = false, ...options }: GrixXMarkProps = $props();
|
|
16
|
+
|
|
17
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
18
|
+
let plot = $derived(getPlotState());
|
|
19
|
+
|
|
20
|
+
let autoTickCount = $derived(
|
|
21
|
+
Math.max(3, Math.round(plot.facetWidth / plot.options.x.tickSpacing))
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
let ticks: RawValue[] = $derived(
|
|
25
|
+
data.length > 0
|
|
26
|
+
? // use custom tick values if user passed any as prop
|
|
27
|
+
data
|
|
28
|
+
: // use custom scale tick values if user passed any as plot scale option
|
|
29
|
+
autoTicks(
|
|
30
|
+
plot.scales.x.type,
|
|
31
|
+
plot.options.x.ticks,
|
|
32
|
+
plot.options.x.interval,
|
|
33
|
+
plot.scales.x.domain,
|
|
34
|
+
plot.scales.x.fn,
|
|
35
|
+
autoTickCount
|
|
36
|
+
)
|
|
37
|
+
);
|
|
19
38
|
</script>
|
|
20
39
|
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
<Mark
|
|
41
|
+
type="gridX"
|
|
42
|
+
data={data.length ? data.map((tick) => ({ __x: tick })) : []}
|
|
43
|
+
channels={['y1', 'y2', 'x', 'stroke', 'strokeOpacity']}
|
|
44
|
+
{...{ ...options, x: '__x' }}
|
|
45
|
+
{automatic}>
|
|
46
|
+
{#snippet children({ usedScales })}
|
|
47
|
+
<g class="grid-x">
|
|
48
|
+
{#each ticks as tick}
|
|
49
|
+
{#if testFilter(tick, options)}
|
|
50
|
+
{@const x =
|
|
51
|
+
plot.scales.x.fn(tick) +
|
|
52
|
+
(plot.scales.x.type === 'band' ? plot.scales.x.fn.bandwidth() * 0.5 : 0)}
|
|
53
|
+
{@const y1_ = resolveChannel('y1', tick, options)}
|
|
54
|
+
{@const y2_ = resolveChannel('y2', tick, options)}
|
|
55
|
+
{@const y1 = options.y1 != null ? plot.scales.y.fn(y1_) : 0}
|
|
56
|
+
{@const y2 = options.y2 != null ? plot.scales.y.fn(y2_) : plot.facetHeight}
|
|
57
|
+
<line
|
|
58
|
+
transform="translate({x},{plot.options.marginTop})"
|
|
59
|
+
style={resolveScaledStyles(tick, options, usedScales, plot, 'stroke')}
|
|
60
|
+
{y1}
|
|
61
|
+
{y2} />
|
|
62
|
+
{/if}
|
|
63
|
+
{/each}
|
|
64
|
+
</g>
|
|
65
|
+
{/snippet}
|
|
66
|
+
</Mark>
|
|
37
67
|
|
|
38
68
|
<style>
|
|
39
|
-
|
|
40
|
-
stroke:
|
|
69
|
+
line {
|
|
70
|
+
stroke: currentColor;
|
|
71
|
+
stroke-opacity: 0.2;
|
|
41
72
|
}
|
|
42
73
|
</style>
|
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
y1?: import("../types.js").ChannelAccessor | undefined;
|
|
6
|
-
y2?: import("../types.js").ChannelAccessor | undefined;
|
|
7
|
-
automatic?: boolean | undefined;
|
|
8
|
-
};
|
|
9
|
-
events: {
|
|
10
|
-
[evt: string]: CustomEvent<any>;
|
|
11
|
-
};
|
|
12
|
-
slots: {};
|
|
1
|
+
import type { BaseMarkProps, RawValue } from '../types.js';
|
|
2
|
+
type GrixXMarkProps = BaseMarkProps & {
|
|
3
|
+
data?: RawValue[];
|
|
4
|
+
automatic?: boolean;
|
|
13
5
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export
|
|
17
|
-
export default class GridX extends SvelteComponent<GridXProps, GridXEvents, GridXSlots> {
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
6
|
+
declare const GridX: import("svelte").Component<GrixXMarkProps, {}, "">;
|
|
7
|
+
type GridX = ReturnType<typeof GridX>;
|
|
8
|
+
export default GridX;
|
package/dist/marks/GridY.svelte
CHANGED
|
@@ -1,31 +1,70 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import Mark from '../Mark.svelte';
|
|
4
|
+
import type { PlotContext, BaseMarkProps, RawValue, DataRecord } from '../types.js';
|
|
5
|
+
import { resolveChannel, resolveScaledStyles } from '../helpers/resolve.js';
|
|
6
|
+
import { autoTicks } from '../helpers/autoTicks.js';
|
|
7
|
+
import { getUsedScales } from '../helpers/scales.js';
|
|
8
|
+
import { testFilter } from '../helpers/index.js';
|
|
9
|
+
|
|
10
|
+
type GridYMarkProps = BaseMarkProps & { data?: RawValue[]; automatic?: boolean };
|
|
11
|
+
|
|
12
|
+
let { data = [], automatic = false, ...options }: GridYMarkProps = $props();
|
|
13
|
+
|
|
14
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
15
|
+
let plot = $derived(getPlotState());
|
|
16
|
+
|
|
17
|
+
let autoTickCount = $derived(
|
|
18
|
+
Math.max(2, Math.round(plot.facetHeight / plot.options.y.tickSpacing))
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
let ticks: RawValue[] = $derived(
|
|
22
|
+
data.length > 0
|
|
23
|
+
? // use custom tick values if user passed any as prop
|
|
24
|
+
data
|
|
25
|
+
: // use custom scale tick values if user passed any as plot scale option
|
|
26
|
+
autoTicks(
|
|
27
|
+
plot.scales.y.type,
|
|
28
|
+
plot.options.y.ticks,
|
|
29
|
+
plot.options.y.interval,
|
|
30
|
+
plot.scales.y.domain,
|
|
31
|
+
plot.scales.y.fn,
|
|
32
|
+
autoTickCount
|
|
33
|
+
)
|
|
34
|
+
);
|
|
11
35
|
</script>
|
|
12
36
|
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
37
|
+
<Mark
|
|
38
|
+
type="gridY"
|
|
39
|
+
data={data.length ? data.map((tick) => ({ ___orig___: tick })) : []}
|
|
40
|
+
channels={['x1', 'x2', 'y', 'stroke', 'strokeOpacity']}
|
|
41
|
+
{...{ ...options, y: '___orig___' }}
|
|
42
|
+
{automatic}>
|
|
43
|
+
{#snippet children({ usedScales })}
|
|
44
|
+
<g class="grid-y">
|
|
45
|
+
{#each ticks as tick}
|
|
46
|
+
{#if testFilter(tick, options)}
|
|
47
|
+
{@const y =
|
|
48
|
+
plot.scales.y.fn(tick) +
|
|
49
|
+
(plot.scales.y.type === 'band' ? plot.scales.y.fn.bandwidth() * 0.5 : 0)}
|
|
50
|
+
{@const x1_ = resolveChannel('x1', tick, options)}
|
|
51
|
+
{@const x2_ = resolveChannel('x2', tick, options)}
|
|
52
|
+
{@const x1 = options.x1 != null ? plot.scales.x.fn(x1_) : 0}
|
|
53
|
+
{@const x2 = options.x2 != null ? plot.scales.x.fn(x2_) : plot.facetWidth}
|
|
54
|
+
<line
|
|
55
|
+
transform="translate({plot.options.marginLeft},{y})"
|
|
56
|
+
style={resolveScaledStyles(tick, options, usedScales, plot, 'stroke')}
|
|
57
|
+
{x1}
|
|
58
|
+
{x2} />
|
|
59
|
+
{/if}
|
|
60
|
+
{/each}
|
|
61
|
+
</g>
|
|
62
|
+
{/snippet}
|
|
63
|
+
</Mark>
|
|
26
64
|
|
|
27
65
|
<style>
|
|
28
|
-
|
|
29
|
-
stroke:
|
|
66
|
+
line {
|
|
67
|
+
stroke: currentColor;
|
|
68
|
+
stroke-opacity: 0.2;
|
|
30
69
|
}
|
|
31
70
|
</style>
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
events: {
|
|
6
|
-
[evt: string]: CustomEvent<any>;
|
|
7
|
-
};
|
|
8
|
-
slots: {};
|
|
1
|
+
import type { BaseMarkProps, RawValue } from '../types.js';
|
|
2
|
+
type GridYMarkProps = BaseMarkProps & {
|
|
3
|
+
data?: RawValue[];
|
|
4
|
+
automatic?: boolean;
|
|
9
5
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
export default class GridY extends SvelteComponent<GridYProps, GridYEvents, GridYSlots> {
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
6
|
+
declare const GridY: import("svelte").Component<GridYMarkProps, {}, "">;
|
|
7
|
+
type GridY = ReturnType<typeof GridY>;
|
|
8
|
+
export default GridY;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
For showing custom HTML tooltips positioned at x/y coordinates
|
|
4
|
+
-->
|
|
5
|
+
<script module lang="ts">
|
|
6
|
+
import type { ChannelAccessor, DataRow } from '../types.js';
|
|
7
|
+
|
|
8
|
+
export type HTMLTooltipMarkProps = {
|
|
9
|
+
data: DataRow[];
|
|
10
|
+
x?: ChannelAccessor;
|
|
11
|
+
y?: ChannelAccessor;
|
|
12
|
+
r?: ChannelAccessor;
|
|
13
|
+
};
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script lang="ts">
|
|
17
|
+
import { getContext } from 'svelte';
|
|
18
|
+
import type { PlotContext } from '../types.js';
|
|
19
|
+
|
|
20
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
21
|
+
let plot = $derived(getPlotState());
|
|
22
|
+
|
|
23
|
+
import { resolveChannel } from '../helpers/resolve.js';
|
|
24
|
+
import { quadtree } from 'd3-quadtree';
|
|
25
|
+
import { projectX, projectY } from '../helpers/scales.js';
|
|
26
|
+
|
|
27
|
+
let { data, x, y, r, children }: HTMLTooltipMarkProps = $props();
|
|
28
|
+
|
|
29
|
+
let datum = $state(false);
|
|
30
|
+
let tooltipX = $state();
|
|
31
|
+
let tooltipY = $state();
|
|
32
|
+
|
|
33
|
+
function onMouseMove(evt: MouseEvent) {
|
|
34
|
+
const pt = tree.find(evt.layerX, evt.layerY, 25);
|
|
35
|
+
if (pt) {
|
|
36
|
+
tooltipX = resolveChannel('x', pt, { x, y, r });
|
|
37
|
+
tooltipY = resolveChannel('y', pt, { x, y, r });
|
|
38
|
+
datum = pt;
|
|
39
|
+
} else {
|
|
40
|
+
datum = false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
$effect(() => {
|
|
45
|
+
// plot.body?.addEventListener('mouseenter', onMouseEnter);
|
|
46
|
+
// plot.body?.addEventListener('mouseleave', onMouseLeave);
|
|
47
|
+
plot.body?.addEventListener('mousemove', onMouseMove);
|
|
48
|
+
|
|
49
|
+
return () => {
|
|
50
|
+
// plot.body?.removeEventListener('mouseenter', onMouseEnter);
|
|
51
|
+
// plot.body?.removeEventListener('mouseleave', onMouseLeave);
|
|
52
|
+
plot.body?.removeEventListener('mousemove', onMouseMove);
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
let tree = $derived(
|
|
57
|
+
quadtree()
|
|
58
|
+
.x((d) => projectX('x', plot.scales, resolveChannel('x', d, { x, y, r })))
|
|
59
|
+
.y((d) => projectY('y', plot.scales, resolveChannel('y', d, { x, y, r })))
|
|
60
|
+
.addAll(data)
|
|
61
|
+
);
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<div
|
|
65
|
+
class={['tooltip', { hide: !datum }]}
|
|
66
|
+
style:left="{tooltipX ? projectX('x', plot.scales, tooltipX) : 0}px"
|
|
67
|
+
style:top="{tooltipY ? projectY('y', plot.scales, tooltipY) : 0}px">
|
|
68
|
+
<div class="tooltip-body">
|
|
69
|
+
{@render children({ datum })}
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
<style>
|
|
74
|
+
div.tooltip {
|
|
75
|
+
background: white;
|
|
76
|
+
background: var(--svelteplot-tooltip-bg);
|
|
77
|
+
border: 1px solid #ccc;
|
|
78
|
+
border-color: var(--svelteplot-tooltip-border);
|
|
79
|
+
font-size: 13px;
|
|
80
|
+
padding: 1ex 1em;
|
|
81
|
+
border-radius: 3px;
|
|
82
|
+
box-shadow:
|
|
83
|
+
rgba(50, 50, 93, 0.25) 0px 2px 5px -1px,
|
|
84
|
+
rgba(0, 0, 0, 0.3) 0px 1px 3px -1px;
|
|
85
|
+
position: absolute;
|
|
86
|
+
pointer-events: none;
|
|
87
|
+
}
|
|
88
|
+
.tooltip.hide {
|
|
89
|
+
display: none;
|
|
90
|
+
}
|
|
91
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ChannelAccessor, DataRow } from '../types.js';
|
|
2
|
+
export type HTMLTooltipMarkProps = {
|
|
3
|
+
data: DataRow[];
|
|
4
|
+
x?: ChannelAccessor;
|
|
5
|
+
y?: ChannelAccessor;
|
|
6
|
+
r?: ChannelAccessor;
|
|
7
|
+
};
|
|
8
|
+
/** For showing custom HTML tooltips positioned at x/y coordinates */
|
|
9
|
+
declare const HtmlTooltip: import("svelte").Component<HTMLTooltipMarkProps, {}, "">;
|
|
10
|
+
type HtmlTooltip = ReturnType<typeof HtmlTooltip>;
|
|
11
|
+
export default HtmlTooltip;
|
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>
|