svelteplot 0.0.1-alpha.9 → 0.1.3-next.4
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 +290 -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 +14 -0
- package/dist/constants.js +109 -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 +567 -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 +53 -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 +17 -0
- package/dist/helpers/resolve.js +152 -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 +81 -0
- package/dist/marks/BarX.svelte.d.ts +4 -0
- package/dist/marks/BarY.svelte +95 -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 +32 -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 +173 -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 +185 -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 +213 -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 +164 -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 +64 -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 +13 -0
- package/dist/transforms/recordize.js +75 -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 +61 -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 +79 -40
- 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/Plot.svelte.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import Plot from './core/Plot.svelte';
|
|
2
|
+
import type { PlotOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The Plot component is the container for plots. It collects the marks with
|
|
5
|
+
* their data and channels and computes the shared scales.
|
|
6
|
+
*
|
|
7
|
+
* The Plot component is split into two parts. This is the outer Plot which
|
|
8
|
+
* provides convenient defaults and automatically adds axes etc to the grapihcs.
|
|
9
|
+
* The downside is that it adds a bunch of imports that you may not be using.
|
|
10
|
+
* To help with this you can use the core/Plot component directly for a more
|
|
11
|
+
* low-level Plot wrapper.
|
|
12
|
+
*/
|
|
13
|
+
declare const Plot: import("svelte").Component<Partial<PlotOptions>, {}, "">;
|
|
14
|
+
type Plot = ReturnType<typeof Plot>;
|
|
15
|
+
export default Plot;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ScaleName, ScaleType, ScaledChannelName } from './types.js';
|
|
2
|
+
export declare const SCALE_TYPES: Record<ScaleName, symbol>;
|
|
3
|
+
export declare const SCALES: ScaleName[];
|
|
4
|
+
export declare const VALID_SCALE_TYPES: Record<ScaleName, Set<ScaleType>>;
|
|
5
|
+
/**
|
|
6
|
+
* Map of all scaled channels
|
|
7
|
+
*/
|
|
8
|
+
export declare const CHANNEL_SCALE: Record<ScaledChannelName, ScaleName>;
|
|
9
|
+
export declare const CSS_VAR: RegExp;
|
|
10
|
+
export declare const CSS_COLOR: RegExp;
|
|
11
|
+
export declare const CSS_COLOR_MIX: RegExp;
|
|
12
|
+
export declare const CSS_COLOR_CONTRAST: RegExp;
|
|
13
|
+
export declare const CSS_RGBA: RegExp;
|
|
14
|
+
export declare const CSS_URL: RegExp;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export const SCALE_TYPES = {
|
|
2
|
+
opacity: Symbol('opacity'),
|
|
3
|
+
color: Symbol('color'),
|
|
4
|
+
x: Symbol('position'),
|
|
5
|
+
y: Symbol('position'),
|
|
6
|
+
symbol: Symbol('symbol'),
|
|
7
|
+
r: Symbol('radius'),
|
|
8
|
+
length: Symbol('length'),
|
|
9
|
+
fx: Symbol('fx'),
|
|
10
|
+
fy: Symbol('fy'),
|
|
11
|
+
projection: Symbol('projection')
|
|
12
|
+
};
|
|
13
|
+
export const SCALES = [
|
|
14
|
+
'x',
|
|
15
|
+
'y',
|
|
16
|
+
'color',
|
|
17
|
+
'opacity',
|
|
18
|
+
'symbol',
|
|
19
|
+
'r',
|
|
20
|
+
'length',
|
|
21
|
+
'fx',
|
|
22
|
+
'fy',
|
|
23
|
+
'projection'
|
|
24
|
+
];
|
|
25
|
+
export const VALID_SCALE_TYPES = {
|
|
26
|
+
color: new Set([
|
|
27
|
+
'linear',
|
|
28
|
+
'categorical',
|
|
29
|
+
'ordinal',
|
|
30
|
+
'diverging',
|
|
31
|
+
'quantile',
|
|
32
|
+
'quantize',
|
|
33
|
+
'quantile-cont',
|
|
34
|
+
'threshold',
|
|
35
|
+
'log',
|
|
36
|
+
'symlog',
|
|
37
|
+
'pow',
|
|
38
|
+
'sqrt',
|
|
39
|
+
'diverging-log',
|
|
40
|
+
'diverging-pow',
|
|
41
|
+
'diverging-sqrt',
|
|
42
|
+
'diverging-symlog'
|
|
43
|
+
]),
|
|
44
|
+
x: new Set([
|
|
45
|
+
'linear',
|
|
46
|
+
'log',
|
|
47
|
+
'symlog',
|
|
48
|
+
'time',
|
|
49
|
+
'ordinal',
|
|
50
|
+
'band',
|
|
51
|
+
'point',
|
|
52
|
+
'quantile',
|
|
53
|
+
'quantize',
|
|
54
|
+
'threshold'
|
|
55
|
+
]),
|
|
56
|
+
y: new Set([
|
|
57
|
+
'linear',
|
|
58
|
+
'log',
|
|
59
|
+
'symlog',
|
|
60
|
+
'time',
|
|
61
|
+
'ordinal',
|
|
62
|
+
'band',
|
|
63
|
+
'point',
|
|
64
|
+
'quantile',
|
|
65
|
+
'quantize',
|
|
66
|
+
'threshold'
|
|
67
|
+
])
|
|
68
|
+
// ...
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Map of all scaled channels
|
|
72
|
+
*/
|
|
73
|
+
export const CHANNEL_SCALE = {
|
|
74
|
+
x: 'x',
|
|
75
|
+
x1: 'x',
|
|
76
|
+
x2: 'x',
|
|
77
|
+
y: 'y',
|
|
78
|
+
y1: 'y',
|
|
79
|
+
y2: 'y',
|
|
80
|
+
r: 'r',
|
|
81
|
+
length: 'length',
|
|
82
|
+
fx: 'fx',
|
|
83
|
+
fy: 'fy',
|
|
84
|
+
symbol: 'symbol',
|
|
85
|
+
fill: 'color',
|
|
86
|
+
stroke: 'color',
|
|
87
|
+
opacity: 'opacity',
|
|
88
|
+
fillOpacity: 'opacity',
|
|
89
|
+
strokeOpacity: 'opacity'
|
|
90
|
+
};
|
|
91
|
+
export const CSS_VAR = /^var\(--([a-z-0-9,\s]+)\)$/;
|
|
92
|
+
export const CSS_COLOR = /^color\(/;
|
|
93
|
+
export const CSS_COLOR_MIX = /^color-mix\(/; // just check for prefix
|
|
94
|
+
export const CSS_COLOR_CONTRAST = /^color-contrast\(/; // just check for prefix
|
|
95
|
+
export const CSS_RGBA = /^rgba\(/; // just check for prefix
|
|
96
|
+
export const CSS_URL = /^url\(#/; // just check for prefix
|
|
97
|
+
// export const CHANNEL_MAP: Record<ScaleName, ValueOf<typeof SCALE_TYPES>> = {
|
|
98
|
+
// x: SCALE_TYPES.x,
|
|
99
|
+
// y: SCALE_TYPES.y,
|
|
100
|
+
// opacity: SCALE_TYPES.opacity,
|
|
101
|
+
// strokeOpacity: SCALE_TYPES.opacity,
|
|
102
|
+
// strokeWidth: SCALE_TYPES.width,
|
|
103
|
+
// fillOpacity: SCALE_TYPES.opacity,
|
|
104
|
+
// stroke: SCALE_TYPES.color,
|
|
105
|
+
// fill: SCALE_TYPES.color,
|
|
106
|
+
// r: SCALE_TYPES.radius,
|
|
107
|
+
// rotate: SCALE_TYPES.angle,
|
|
108
|
+
// symbol: SCALE_TYPES.symbol
|
|
109
|
+
// };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { setContext, type Snippet } from 'svelte';
|
|
3
|
+
import { resolveChannel } from '../helpers/resolve.js';
|
|
4
|
+
import type { BaseMarkProps, DataRecord, PlotScale, RawValue } from '../types.js';
|
|
5
|
+
import { identity } from '../helpers';
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
fx,
|
|
9
|
+
fy,
|
|
10
|
+
left,
|
|
11
|
+
top,
|
|
12
|
+
right,
|
|
13
|
+
bottom,
|
|
14
|
+
topEmpty,
|
|
15
|
+
bottomEmpty,
|
|
16
|
+
leftEmpty,
|
|
17
|
+
rightEmpty,
|
|
18
|
+
children
|
|
19
|
+
}: {
|
|
20
|
+
fx: RawValue;
|
|
21
|
+
fy: RawValue;
|
|
22
|
+
left: boolean;
|
|
23
|
+
top: boolean;
|
|
24
|
+
right: boolean;
|
|
25
|
+
bottom: boolean;
|
|
26
|
+
topEmpty: boolean;
|
|
27
|
+
bottomEmpty: boolean;
|
|
28
|
+
leftEmpty: boolean;
|
|
29
|
+
rightEmpty: boolean;
|
|
30
|
+
children?: Snippet;
|
|
31
|
+
} = $props();
|
|
32
|
+
|
|
33
|
+
setContext('svelteplot/facet', {
|
|
34
|
+
getTestFacet() {
|
|
35
|
+
return (datum: DataRecord, options: Partial<BaseMarkProps>) => {
|
|
36
|
+
return (
|
|
37
|
+
(options.fx == null || resolveChannel('fx', datum, options) === fx) &&
|
|
38
|
+
(options.fy == null || resolveChannel('fy', datum, options) === fy)
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
getFacetState() {
|
|
43
|
+
return {
|
|
44
|
+
fx,
|
|
45
|
+
fy,
|
|
46
|
+
left,
|
|
47
|
+
top,
|
|
48
|
+
right,
|
|
49
|
+
bottom,
|
|
50
|
+
topEmpty,
|
|
51
|
+
bottomEmpty,
|
|
52
|
+
leftEmpty,
|
|
53
|
+
rightEmpty
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
{@render children?.()}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { RawValue } from '../types.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
fx: RawValue;
|
|
5
|
+
fy: RawValue;
|
|
6
|
+
left: boolean;
|
|
7
|
+
top: boolean;
|
|
8
|
+
right: boolean;
|
|
9
|
+
bottom: boolean;
|
|
10
|
+
topEmpty: boolean;
|
|
11
|
+
bottomEmpty: boolean;
|
|
12
|
+
leftEmpty: boolean;
|
|
13
|
+
rightEmpty: boolean;
|
|
14
|
+
children?: Snippet;
|
|
15
|
+
};
|
|
16
|
+
declare const Facet: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
17
|
+
type Facet = ReturnType<typeof Facet>;
|
|
18
|
+
export default Facet;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
The FacetAxes component renders the facet axes
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { getContext } from 'svelte';
|
|
7
|
+
import type { PlotContext } from '../types.js';
|
|
8
|
+
import { scaleBand } from 'd3-scale';
|
|
9
|
+
import BaseAxisX from '../marks/helpers/BaseAxisX.svelte';
|
|
10
|
+
import BaseAxisY from '../marks/helpers/BaseAxisY.svelte';
|
|
11
|
+
|
|
12
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
13
|
+
// we need the plot context for the overall width & height
|
|
14
|
+
const plot = $derived(getPlotState());
|
|
15
|
+
|
|
16
|
+
const useFacetX = $derived(plot.scales.fx.domain.length > 0);
|
|
17
|
+
const useFacetY = $derived(plot.scales.fy.domain.length > 0);
|
|
18
|
+
|
|
19
|
+
const fxValues = $derived(useFacetX ? plot.scales.fx.domain : [true]);
|
|
20
|
+
const fyValues = $derived(useFacetY ? plot.scales.fy.domain : [true]);
|
|
21
|
+
|
|
22
|
+
// create band scales for fx and fy
|
|
23
|
+
const facetXScale = $derived(
|
|
24
|
+
scaleBand().paddingInner(0.1).domain(fxValues).rangeRound([0, plot.plotWidth])
|
|
25
|
+
);
|
|
26
|
+
const facetYScale = $derived(
|
|
27
|
+
scaleBand().paddingInner(0.1).domain(fyValues).rangeRound([0, plot.plotHeight])
|
|
28
|
+
);
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<!-- facet grid -->
|
|
32
|
+
{#if fxValues.length > 1 && plot.options.fx.axis}
|
|
33
|
+
<g transform="translate({plot.options.marginLeft}, 0)">
|
|
34
|
+
<BaseAxisX
|
|
35
|
+
scaleFn={facetXScale}
|
|
36
|
+
scaleType="band"
|
|
37
|
+
ticks={fxValues}
|
|
38
|
+
tickFormat={(d) => d}
|
|
39
|
+
tickSize={0}
|
|
40
|
+
tickPadding={5}
|
|
41
|
+
anchor={plot.options.fx.axis}
|
|
42
|
+
options={plot.options.fx.axisOptions || {}}
|
|
43
|
+
{...plot.options.fx.axisProps || {}}
|
|
44
|
+
height={plot.plotHeight}
|
|
45
|
+
marginTop={plot.options.marginTop}
|
|
46
|
+
{plot} />
|
|
47
|
+
</g>
|
|
48
|
+
{/if}
|
|
49
|
+
{#if fyValues.length > 1 && plot.options.fy.axis}
|
|
50
|
+
<g transform="translate(0, {plot.options.marginTop})">
|
|
51
|
+
<BaseAxisY
|
|
52
|
+
scaleFn={facetYScale}
|
|
53
|
+
scaleType="band"
|
|
54
|
+
ticks={fyValues}
|
|
55
|
+
tickFormat={(d) => d}
|
|
56
|
+
tickSize={0}
|
|
57
|
+
tickPadding={5}
|
|
58
|
+
anchor={plot.options.fy.axis}
|
|
59
|
+
lineAnchor="center"
|
|
60
|
+
options={plot.options.fy.axisOptions || {}}
|
|
61
|
+
{...plot.options.fy.axisProps || {}}
|
|
62
|
+
width={plot.plotWidth}
|
|
63
|
+
marginLeft={plot.options.marginLeft}
|
|
64
|
+
{plot} />
|
|
65
|
+
</g>
|
|
66
|
+
{/if}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
The FacetGrid component repeats the
|
|
4
|
+
marks for each facet domain value
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import { getContext, setContext, type Snippet } from 'svelte';
|
|
8
|
+
import type { PlotContext, GenericMarkOptions, Mark } from '../types.js';
|
|
9
|
+
import { scaleBand } from 'd3-scale';
|
|
10
|
+
import Facet from './Facet.svelte';
|
|
11
|
+
import { getEmptyFacets } from '../helpers/facets.js';
|
|
12
|
+
|
|
13
|
+
const { getPlotState, updateDimensions } = getContext<PlotContext>('svelteplot');
|
|
14
|
+
// we need the plot context for the overall width & height
|
|
15
|
+
const plot = $derived(getPlotState());
|
|
16
|
+
|
|
17
|
+
let {
|
|
18
|
+
children,
|
|
19
|
+
marks
|
|
20
|
+
}: {
|
|
21
|
+
children: Snippet;
|
|
22
|
+
marks: Mark<GenericMarkOptions>[];
|
|
23
|
+
} = $props();
|
|
24
|
+
|
|
25
|
+
const useFacetX = $derived(plot.scales.fx.domain.length > 0);
|
|
26
|
+
const useFacetY = $derived(plot.scales.fy.domain.length > 0);
|
|
27
|
+
|
|
28
|
+
const fxValues = $derived(useFacetX ? plot.scales.fx.domain : [true]);
|
|
29
|
+
const fyValues = $derived(useFacetY ? plot.scales.fy.domain : [true]);
|
|
30
|
+
|
|
31
|
+
// we need to track which facets are "empty", meaning that they don't contain
|
|
32
|
+
// any "faceted" data points. this can happen when fx and fy are combined and
|
|
33
|
+
// certain combinations don't yield results
|
|
34
|
+
const emptyFacets = $derived(getEmptyFacets(marks, fxValues, fyValues));
|
|
35
|
+
|
|
36
|
+
// create band scales for fx and fy
|
|
37
|
+
const facetXScale = $derived(
|
|
38
|
+
scaleBand()
|
|
39
|
+
.paddingInner(fxValues.length > 1 ? 0.1 : 0)
|
|
40
|
+
.domain(fxValues)
|
|
41
|
+
.rangeRound([0, plot.plotWidth])
|
|
42
|
+
);
|
|
43
|
+
const facetYScale = $derived(
|
|
44
|
+
scaleBand()
|
|
45
|
+
.paddingInner(fyValues.length > 1 ? 0.1 : 0)
|
|
46
|
+
.domain(fyValues)
|
|
47
|
+
.rangeRound([0, plot.plotHeight])
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const facetWidth = $derived(useFacetX ? facetXScale.bandwidth() : plot.plotWidth);
|
|
51
|
+
const facetHeight = $derived(useFacetY ? facetYScale.bandwidth() : plot.plotHeight);
|
|
52
|
+
|
|
53
|
+
$effect.pre(() => {
|
|
54
|
+
updateDimensions(facetWidth, facetHeight);
|
|
55
|
+
});
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
{#each fxValues as facetX, i}
|
|
59
|
+
{#each fyValues as facetY, j}
|
|
60
|
+
<g
|
|
61
|
+
class="facet"
|
|
62
|
+
fill="currentColor"
|
|
63
|
+
style:display={emptyFacets.get(facetX)?.get(facetY) ? 'none' : 'block'}
|
|
64
|
+
transform="translate({useFacetX ? facetXScale(facetX) : 0}, {useFacetY
|
|
65
|
+
? facetYScale(facetY)
|
|
66
|
+
: 0})">
|
|
67
|
+
<Facet
|
|
68
|
+
fx={facetX}
|
|
69
|
+
fy={facetY}
|
|
70
|
+
left={i === 0}
|
|
71
|
+
right={i === fxValues.length - 1}
|
|
72
|
+
top={j === 0}
|
|
73
|
+
bottom={j === fyValues.length - 1}
|
|
74
|
+
leftEmpty={!!(i === 0 || emptyFacets.get(fxValues[i - 1])?.get(facetY))}
|
|
75
|
+
topEmpty={!!(j === 0 || emptyFacets.get(facetX)?.get(fyValues[j - 1]))}
|
|
76
|
+
rightEmpty={!!(
|
|
77
|
+
i === fxValues.length - 1 || emptyFacets.get(fxValues[i + 1])?.get(facetY)
|
|
78
|
+
)}
|
|
79
|
+
bottomEmpty={!!(
|
|
80
|
+
j === fyValues.length - 1 || emptyFacets.get(facetX)?.get(fyValues[j + 1])
|
|
81
|
+
)}>
|
|
82
|
+
{@render children()}
|
|
83
|
+
</Facet>
|
|
84
|
+
</g>
|
|
85
|
+
{/each}
|
|
86
|
+
{/each}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { GenericMarkOptions, Mark } from '../types.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
children: Snippet;
|
|
5
|
+
marks: Mark<GenericMarkOptions>[];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* The FacetGrid component repeats the
|
|
9
|
+
* marks for each facet domain value
|
|
10
|
+
*/
|
|
11
|
+
declare const FacetGrid: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
12
|
+
type FacetGrid = ReturnType<typeof FacetGrid>;
|
|
13
|
+
export default FacetGrid;
|