svelteplot 0.0.1-alpha.11 → 0.0.1-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Plot.svelte +6 -6
- package/dist/classes/Mark.svelte.js +4 -0
- package/dist/classes/Plot.svelte.js +47 -20
- package/dist/classes/Scale.svelte.js +95 -0
- package/dist/contants.d.ts +3 -3
- package/dist/contants.js +18 -16
- package/dist/helpers/autoTimeFormat.d.ts +2 -2
- package/dist/helpers/createScale.js +19 -6
- package/dist/helpers/curves.d.ts +3 -0
- package/dist/helpers/curves.js +42 -0
- package/dist/helpers/getBaseStyles.js +2 -2
- package/dist/helpers/getLogTicks.js +5 -5
- package/dist/helpers/isRawValue.d.ts +2 -0
- package/dist/helpers/isRawValue.js +5 -0
- package/dist/helpers/resolveChannel.d.ts +6 -2
- package/dist/helpers/resolveChannel.js +15 -5
- package/dist/helpers/wrapValueArray.d.ts +6 -0
- package/dist/helpers/wrapValueArray.js +5 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +11 -3
- package/dist/marks/Area.svelte +35 -21
- package/dist/marks/Area.svelte.d.ts +14 -1
- package/dist/marks/AreaX.svelte +8 -15
- package/dist/marks/AreaX.svelte.d.ts +17 -4
- package/dist/marks/AreaY.svelte +9 -10
- package/dist/marks/AreaY.svelte.d.ts +17 -4
- package/dist/marks/AxisX.svelte +7 -8
- package/dist/marks/AxisY.svelte +10 -6
- package/dist/marks/BarX.svelte +52 -0
- package/dist/marks/BarX.svelte.d.ts +25 -0
- package/dist/marks/BarY.svelte +52 -0
- package/dist/marks/BarY.svelte.d.ts +25 -0
- package/dist/marks/BaseMark.svelte +9 -2
- package/dist/marks/BaseMark.svelte.d.ts +2 -1
- package/dist/marks/Dot.svelte +26 -40
- package/dist/marks/Dot.svelte.d.ts +9 -1
- package/dist/marks/GridX.svelte +26 -15
- package/dist/marks/GridX.svelte.d.ts +3 -3
- package/dist/marks/GridY.svelte +15 -4
- package/dist/marks/Line.svelte +16 -27
- package/dist/marks/Line.svelte.d.ts +13 -1
- package/dist/marks/LineX.svelte +5 -7
- package/dist/marks/LineX.svelte.d.ts +11 -4
- package/dist/marks/LineY.svelte +4 -6
- package/dist/marks/LineY.svelte.d.ts +11 -3
- package/dist/marks/RuleX.svelte +15 -7
- package/dist/marks/RuleY.svelte +15 -7
- package/dist/marks/TickX.svelte +30 -0
- package/dist/marks/TickX.svelte.d.ts +15 -0
- package/dist/marks/TickY.svelte +30 -0
- package/dist/marks/TickY.svelte.d.ts +15 -0
- package/dist/transforms/normalize.d.ts +18 -0
- package/dist/transforms/normalize.js +25 -0
- package/dist/transforms/recordize.d.ts +3 -0
- package/dist/transforms/recordize.js +28 -0
- package/dist/transforms/rename.d.ts +4 -0
- package/dist/transforms/rename.js +10 -0
- package/dist/transforms/stack.d.ts +11 -0
- package/dist/transforms/stack.js +73 -0
- package/dist/types.d.ts +51 -35
- package/package.json +20 -15
- package/dist/classes/Channel.svelte.js +0 -74
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
-
import type {
|
|
2
|
+
import type { SCALE_TYPES } from './contants.js';
|
|
3
3
|
import type { Plot } from './classes/Plot.svelte';
|
|
4
4
|
import type { MouseEventHandler } from 'svelte/elements';
|
|
5
|
+
export type ScaleName = 'opacity' | 'color' | 'x' | 'y' | 'angle' | 'radius' | 'symbol' | 'width' | 'fontSize';
|
|
5
6
|
export type Datasets = {
|
|
6
7
|
aapl: {
|
|
7
8
|
Date: Date;
|
|
@@ -11,6 +12,10 @@ export type Datasets = {
|
|
|
11
12
|
Close: number;
|
|
12
13
|
'Adj Close': number;
|
|
13
14
|
}[];
|
|
15
|
+
alphabet: {
|
|
16
|
+
letter: string;
|
|
17
|
+
frequency: number;
|
|
18
|
+
}[];
|
|
14
19
|
cars: {
|
|
15
20
|
name: string;
|
|
16
21
|
'economy (mpg)': number;
|
|
@@ -35,10 +40,32 @@ export type Datasets = {
|
|
|
35
40
|
date: Date;
|
|
36
41
|
unemployment: number;
|
|
37
42
|
}[];
|
|
43
|
+
stageage: {
|
|
44
|
+
state: string;
|
|
45
|
+
age: string;
|
|
46
|
+
population: number;
|
|
47
|
+
pop_share: number;
|
|
48
|
+
}[];
|
|
49
|
+
stocks: {
|
|
50
|
+
Symbol: string;
|
|
51
|
+
Date: Date;
|
|
52
|
+
Open: number;
|
|
53
|
+
High: number;
|
|
54
|
+
Low: number;
|
|
55
|
+
Close: number;
|
|
56
|
+
'Adj Close': number;
|
|
57
|
+
Volume: number;
|
|
58
|
+
}[];
|
|
59
|
+
riaa: {
|
|
60
|
+
format: string;
|
|
61
|
+
group: string;
|
|
62
|
+
year: Date;
|
|
63
|
+
revenue: number;
|
|
64
|
+
}[];
|
|
38
65
|
};
|
|
39
66
|
export type AxisXAnchor = 'bottom' | 'top' | 'both';
|
|
40
67
|
export type AxisYAnchor = 'left' | 'right' | 'both';
|
|
41
|
-
export type
|
|
68
|
+
export type PositionScaleOptions = Partial<{
|
|
42
69
|
label?: string | null;
|
|
43
70
|
domain?: [number, number] | null;
|
|
44
71
|
grid?: boolean;
|
|
@@ -47,7 +74,11 @@ export type PositionChannelOptions = Partial<{
|
|
|
47
74
|
log?: boolean;
|
|
48
75
|
reverse?: boolean;
|
|
49
76
|
}>;
|
|
77
|
+
export type ScaleType = 'linear' | 'pow' | 'sqrt' | 'log' | 'symlog' | 'time' | 'point' | 'band';
|
|
78
|
+
export type PositionScaleType = ScaleType | ('point' | 'band');
|
|
79
|
+
export type ColorScaleType = ScaleType | ('categorical' | 'sequential' | 'sequentialSymlog' | 'sequentialLog' | 'sequentialPow' | 'sequentialSqrt' | 'sequentialQuantile' | 'cyclical' | 'threshold' | 'quantile' | 'quantize' | 'diverging' | 'divergingLog' | 'divergingPow' | 'divergingSqrt' | 'divergingSymlog');
|
|
50
80
|
export type PlotProps = {
|
|
81
|
+
testid?: string;
|
|
51
82
|
height?: number | 'auto';
|
|
52
83
|
marginTop?: number;
|
|
53
84
|
marginBottom?: number;
|
|
@@ -68,13 +99,15 @@ export type PlotProps = {
|
|
|
68
99
|
radius?: {
|
|
69
100
|
range?: [number, number];
|
|
70
101
|
};
|
|
71
|
-
x?:
|
|
102
|
+
x?: PositionScaleOptions & {
|
|
103
|
+
type?: PositionScaleType;
|
|
72
104
|
axis?: AxisXAnchor | {
|
|
73
105
|
anchor: AxisXAnchor;
|
|
74
106
|
tickSpacing: number;
|
|
75
107
|
};
|
|
76
108
|
};
|
|
77
|
-
y?:
|
|
109
|
+
y?: PositionScaleOptions & {
|
|
110
|
+
type?: PositionScaleType;
|
|
78
111
|
axis?: AxisYAnchor | {
|
|
79
112
|
anchor: AxisYAnchor;
|
|
80
113
|
tickSpacing: number;
|
|
@@ -85,6 +118,7 @@ export type PlotProps = {
|
|
|
85
118
|
legend?: boolean;
|
|
86
119
|
} | null;
|
|
87
120
|
color?: {
|
|
121
|
+
type?: ColorScaleType;
|
|
88
122
|
range?: string[];
|
|
89
123
|
domain: RawValue[];
|
|
90
124
|
scheme?: ColorScheme;
|
|
@@ -102,13 +136,13 @@ export type GridProps = {
|
|
|
102
136
|
};
|
|
103
137
|
export type DataRecord = Record<string, RawValue>;
|
|
104
138
|
export type DataRow = DataRecord | RawValue | [number, number];
|
|
105
|
-
export type ChannelAccessor = RawValue | ((d: DataRow) => RawValue) | null;
|
|
139
|
+
export type ChannelAccessor = RawValue | ((d: DataRow) => RawValue) | null | undefined;
|
|
106
140
|
export type RawValue = number | Date | boolean | string | null;
|
|
107
|
-
export type ChannelName = 'opacity' | '
|
|
141
|
+
export type ChannelName = 'angle' | 'fill' | 'fillOpacity' | 'fontSize' | 'opacity' | 'r' | 'sort' | 'stroke' | 'strokeDasharray' | 'strokeOpacity' | 'symbol' | 'width' | 'x' | 'x1' | 'x2' | 'y' | 'y1' | 'y2' | 'z';
|
|
108
142
|
export type MarkStyleProps = 'strokeDasharray' | 'opacity' | 'fill' | 'fillOpacity' | 'fontSize' | 'stroke' | 'strokeWidth' | 'strokeOpacity' | 'x' | 'y' | 'angle' | 'radius' | 'symbol' | 'width';
|
|
109
143
|
export type MarkProps2 = 'x' | 'y' | 'r' | 'rotate' | 'symbol';
|
|
110
144
|
export type ValueOf<T> = T[keyof T];
|
|
111
|
-
export type ChannelType = ValueOf<typeof
|
|
145
|
+
export type ChannelType = ValueOf<typeof SCALE_TYPES>;
|
|
112
146
|
export interface MarkProps {
|
|
113
147
|
data: DataRow[];
|
|
114
148
|
}
|
|
@@ -127,34 +161,6 @@ export type BaseMarkStyleProps = {
|
|
|
127
161
|
strokeDasharray?: ChannelAccessor;
|
|
128
162
|
};
|
|
129
163
|
export type FrameProps = BaseMarkStyleProps;
|
|
130
|
-
export type DotMarkProps = MarkProps & BaseMarkStyleProps & {
|
|
131
|
-
data: DataRow[];
|
|
132
|
-
x?: ChannelAccessor;
|
|
133
|
-
y?: ChannelAccessor;
|
|
134
|
-
r?: ChannelAccessor;
|
|
135
|
-
rotate?: ChannelAccessor;
|
|
136
|
-
symbol?: ChannelAccessor;
|
|
137
|
-
};
|
|
138
|
-
export type LineMarkProps = MarkProps & BaseMarkStyleProps & {
|
|
139
|
-
data: DataRow[];
|
|
140
|
-
x?: ChannelAccessor;
|
|
141
|
-
y?: ChannelAccessor;
|
|
142
|
-
z?: ChannelAccessor;
|
|
143
|
-
sort?: ChannelAccessor | {
|
|
144
|
-
channel: 'stroke' | 'fill';
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
export type AreaMarkProps = MarkProps & BaseMarkStyleProps & {
|
|
148
|
-
data: DataRow[];
|
|
149
|
-
x1?: ChannelAccessor;
|
|
150
|
-
x2?: ChannelAccessor;
|
|
151
|
-
y1?: ChannelAccessor;
|
|
152
|
-
y2?: ChannelAccessor;
|
|
153
|
-
z?: ChannelAccessor;
|
|
154
|
-
sort?: ChannelAccessor | {
|
|
155
|
-
channel: 'stroke' | 'fill';
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
164
|
export type GridOptions = {
|
|
159
165
|
ticks?: RawValue[];
|
|
160
166
|
strokeDasharray?: ChannelAccessor;
|
|
@@ -205,5 +211,15 @@ export type RuleYMarkProps = MarkProps & RuleMarkProps & {
|
|
|
205
211
|
x1?: ChannelAccessor;
|
|
206
212
|
x2?: ChannelAccessor;
|
|
207
213
|
};
|
|
214
|
+
export type TickMarkProps = MarkProps & {
|
|
215
|
+
x?: ChannelAccessor;
|
|
216
|
+
y?: ChannelAccessor;
|
|
217
|
+
stroke?: ChannelAccessor;
|
|
218
|
+
};
|
|
208
219
|
export type ColorScheme = 'brbg' | 'prgn' | 'piyg' | 'puor' | 'rdbu' | 'rdgy' | 'rdylbu' | 'rdylgn' | 'spectral' | 'burd' | 'buylrd' | 'blues' | 'greens' | 'greys' | 'oranges' | 'purples' | 'reds' | 'turbo' | 'viridis' | 'magma' | 'inferno' | 'plasma' | 'cividis' | 'cubehelix' | 'warm' | 'cool' | 'bugn' | 'bupu' | 'gnbu' | 'orrd' | 'pubu' | 'pubugn' | 'purd' | 'rdpu' | 'ylgn' | 'ylgnbu' | 'ylorbr' | 'ylorrd' | 'rainbow' | 'sinebow' | 'accent' | 'category10' | 'dark2' | 'paired' | 'pastel1' | 'pastel2' | 'set1' | 'set2' | 'set3' | 'tableau10';
|
|
220
|
+
export type Curve = 'basis' | 'basis-closed' | 'basis-open' | 'bundle' | 'bump-x' | 'bump-y' | 'cardinal' | 'cardinal-closed' | 'cardinal-open' | 'catmull-rom' | 'catmull-rom-closed' | 'catmull-rom-open' | 'linear' | 'linear-closed' | 'monotone-x' | 'monotone-y' | 'natural' | 'step' | 'step-after' | 'step-before';
|
|
221
|
+
type Channels = Partial<Record<ChannelName, ChannelAccessor>>;
|
|
222
|
+
export type TransformArg = Channels & {
|
|
223
|
+
data: DataRow[];
|
|
224
|
+
};
|
|
209
225
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelteplot",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.13",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite dev",
|
|
6
6
|
"build": "vite build",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"format": "prettier --write .",
|
|
13
13
|
"test:integration": "playwright test",
|
|
14
14
|
"test:unit": "vitest",
|
|
15
|
-
"prepack": "npx svelte-package"
|
|
15
|
+
"prepack": "npx svelte-package",
|
|
16
|
+
"release-alpha": "npm run build && npm version prerelease --preid alpha && npm publish"
|
|
16
17
|
},
|
|
17
18
|
"exports": {
|
|
18
19
|
".": {
|
|
@@ -30,39 +31,43 @@
|
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@playwright/test": "^1.40.1",
|
|
33
|
-
"@sveltejs/adapter-auto": "^
|
|
34
|
-
"@sveltejs/kit": "^
|
|
34
|
+
"@sveltejs/adapter-auto": "^3.1.0",
|
|
35
|
+
"@sveltejs/kit": "^2.0.8",
|
|
35
36
|
"@types/chroma-js": "^2.4.3",
|
|
36
37
|
"@types/d3-interpolate": "^3.0.4",
|
|
37
38
|
"@types/d3-random": "^3.0.3",
|
|
38
39
|
"@types/d3-scale-chromatic": "^3.0.3",
|
|
39
40
|
"@types/d3-shape": "^3.1.6",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
41
|
-
"@typescript-eslint/parser": "^6.
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
|
42
|
+
"@typescript-eslint/parser": "^6.18.1",
|
|
42
43
|
"bulma": "^0.9.4",
|
|
43
44
|
"d3-dsv": "^3.0.1",
|
|
44
45
|
"dayjs": "^1.11.10",
|
|
45
|
-
"eslint": "^8.
|
|
46
|
+
"eslint": "^8.56.0",
|
|
46
47
|
"eslint-config-prettier": "^9.1.0",
|
|
47
48
|
"eslint-plugin-svelte": "^2.35.1",
|
|
48
49
|
"highlight.js": "^11.9.0",
|
|
49
50
|
"highlightjs-svelte": "^1.0.6",
|
|
50
|
-
"prettier": "^3.1.
|
|
51
|
+
"prettier": "^3.1.1",
|
|
51
52
|
"prettier-plugin-svelte": "^3.1.2",
|
|
52
|
-
"sass": "^1.69.
|
|
53
|
-
"svelte": "5.0.0-next.
|
|
53
|
+
"sass": "^1.69.7",
|
|
54
|
+
"svelte": "5.0.0-next.30",
|
|
54
55
|
"svelte-check": "^3.6.2",
|
|
55
|
-
"svelte-highlight": "^7.4.
|
|
56
|
+
"svelte-highlight": "^7.4.8",
|
|
56
57
|
"tslib": "^2.6.2",
|
|
57
|
-
"typescript": "^5.3.
|
|
58
|
-
"vite": "^5.0.
|
|
59
|
-
"vitest": "^1.
|
|
58
|
+
"typescript": "^5.3.3",
|
|
59
|
+
"vite": "^5.0.11",
|
|
60
|
+
"vitest": "^1.1.3"
|
|
60
61
|
},
|
|
61
62
|
"svelte": "./dist/index.js",
|
|
62
63
|
"types": "./dist/index.d.ts",
|
|
63
64
|
"type": "module",
|
|
64
65
|
"dependencies": {
|
|
65
|
-
"@
|
|
66
|
+
"@observablehq/plot": "^0.6.13",
|
|
67
|
+
"@sveltejs/package": "^2.2.5",
|
|
68
|
+
"@sveltejs/vite-plugin-svelte": "^3.0.1",
|
|
69
|
+
"@sveltepress/theme-default": "^1.22.3",
|
|
70
|
+
"@sveltepress/vite": "^0.31.3",
|
|
66
71
|
"@types/d3-array": "^3.2.1",
|
|
67
72
|
"@types/d3-scale": "^4.0.8",
|
|
68
73
|
"@types/underscore": "^1.11.15",
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import resolveChannel from '../helpers/resolveChannel.js';
|
|
2
|
-
import { extent } from 'd3-array';
|
|
3
|
-
import { MARK_PROP_CHANNEL } from '../contants.js';
|
|
4
|
-
import { isBooleanOrNull, isColorOrNull, isDateOrNull, isNumberOrNull, isStringOrNull } from '../helpers/typeChecks.js';
|
|
5
|
-
import { uniq } from 'underscore';
|
|
6
|
-
export class Channel {
|
|
7
|
-
name = undefined;
|
|
8
|
-
plot = undefined;
|
|
9
|
-
constructor(name, plot) {
|
|
10
|
-
this.name = name;
|
|
11
|
-
this.plot = plot;
|
|
12
|
-
}
|
|
13
|
-
// readonly type: ChannelType = CHANNEL_TYPES.position;
|
|
14
|
-
// all marks that have this channel
|
|
15
|
-
marks = $derived(this.plot?.marks ?? []);
|
|
16
|
-
forceDomain = $derived(this.plot && (this.name === 'x' || this.name === 'y')
|
|
17
|
-
? this.plot.options[this.name]?.domain || null
|
|
18
|
-
: null);
|
|
19
|
-
possibleProps = $derived(Object.entries(MARK_PROP_CHANNEL)
|
|
20
|
-
.filter(([, channel]) => channel === this.name)
|
|
21
|
-
.map(([prop]) => prop));
|
|
22
|
-
activeMarks = $derived(this.marks.filter((mark) => mark.channels.has(this.name) && this.possibleProps.find((prop) => mark.props[prop])));
|
|
23
|
-
manualActiveMarks = $derived(this.activeMarks.filter((mark) => !mark.automatic));
|
|
24
|
-
autoTitle = $derived(this.manualActiveMarks.length === 1 &&
|
|
25
|
-
typeof this.manualActiveMarks[0].props?.[this.name] === 'string'
|
|
26
|
-
? this.manualActiveMarks[0].props?.[this.name]
|
|
27
|
-
: null);
|
|
28
|
-
uniqueMarkProps = $derived(uniq(this.manualActiveMarks
|
|
29
|
-
.map((mark) => this.possibleProps
|
|
30
|
-
.filter((prop) => mark.props[prop])
|
|
31
|
-
.map((prop) => mark.props[prop]))
|
|
32
|
-
.flat(2)));
|
|
33
|
-
dataValues = $derived([
|
|
34
|
-
...this.activeMarks
|
|
35
|
-
// only check marks with data
|
|
36
|
-
.filter((mark) => mark.props.data.length)
|
|
37
|
-
.map((mark) => this.possibleProps.map((prop) => mark.props.data.map((row) => resolveChannel(this.name, row, mark.props[prop]))))
|
|
38
|
-
.flat(3)
|
|
39
|
-
.filter((d) => d != null),
|
|
40
|
-
...(this.forceDomain || [])
|
|
41
|
-
]);
|
|
42
|
-
valueType = $derived(this.dataValues.every((v) => v == null)
|
|
43
|
-
? 'null'
|
|
44
|
-
: this.dataValues.every(isColorOrNull)
|
|
45
|
-
? 'color'
|
|
46
|
-
: this.dataValues.every(isBooleanOrNull)
|
|
47
|
-
? 'boolean'
|
|
48
|
-
: this.dataValues.every(isStringOrNull)
|
|
49
|
-
? 'text'
|
|
50
|
-
: this.dataValues.every(isNumberOrNull)
|
|
51
|
-
? 'number'
|
|
52
|
-
: this.dataValues.every(isDateOrNull)
|
|
53
|
-
? 'date'
|
|
54
|
-
: 'mixed');
|
|
55
|
-
domain = $derived(!this.dataValues.length
|
|
56
|
-
? [0, 1]
|
|
57
|
-
: this.valueType === 'boolean' ||
|
|
58
|
-
this.valueType === 'text' ||
|
|
59
|
-
this.valueType === 'color'
|
|
60
|
-
? uniq(this.dataValues)
|
|
61
|
-
: extent(this.dataValues));
|
|
62
|
-
scaleType = $derived(this.name === 'radius'
|
|
63
|
-
? 'sqrt'
|
|
64
|
-
: this.valueType === 'date'
|
|
65
|
-
? 'time'
|
|
66
|
-
: this.valueType === 'number'
|
|
67
|
-
? 'linear'
|
|
68
|
-
: this.valueType === 'text'
|
|
69
|
-
? 'band'
|
|
70
|
-
: this.valueType === 'color'
|
|
71
|
-
? 'identity'
|
|
72
|
-
: 'linear');
|
|
73
|
-
}
|
|
74
|
-
// opacity: typeof === 'number' && between [0,1]
|