svelteplot 0.0.1-alpha.11 → 0.0.1-alpha.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.
Files changed (62) hide show
  1. package/dist/Plot.svelte +6 -6
  2. package/dist/classes/Mark.svelte.js +4 -0
  3. package/dist/classes/Plot.svelte.js +47 -20
  4. package/dist/classes/Scale.svelte.js +95 -0
  5. package/dist/contants.d.ts +3 -3
  6. package/dist/contants.js +18 -16
  7. package/dist/helpers/autoTimeFormat.d.ts +2 -2
  8. package/dist/helpers/createScale.js +19 -6
  9. package/dist/helpers/curves.d.ts +3 -0
  10. package/dist/helpers/curves.js +42 -0
  11. package/dist/helpers/getBaseStyles.js +2 -2
  12. package/dist/helpers/getLogTicks.js +5 -5
  13. package/dist/helpers/isRawValue.d.ts +2 -0
  14. package/dist/helpers/isRawValue.js +5 -0
  15. package/dist/helpers/resolveChannel.d.ts +6 -2
  16. package/dist/helpers/resolveChannel.js +15 -5
  17. package/dist/helpers/wrapValueArray.d.ts +6 -0
  18. package/dist/helpers/wrapValueArray.js +5 -0
  19. package/dist/index.d.ts +10 -3
  20. package/dist/index.js +11 -3
  21. package/dist/marks/Area.svelte +35 -21
  22. package/dist/marks/Area.svelte.d.ts +14 -1
  23. package/dist/marks/AreaX.svelte +8 -15
  24. package/dist/marks/AreaX.svelte.d.ts +17 -4
  25. package/dist/marks/AreaY.svelte +9 -10
  26. package/dist/marks/AreaY.svelte.d.ts +17 -4
  27. package/dist/marks/AxisX.svelte +7 -8
  28. package/dist/marks/AxisY.svelte +10 -6
  29. package/dist/marks/BarX.svelte +52 -0
  30. package/dist/marks/BarX.svelte.d.ts +25 -0
  31. package/dist/marks/BarY.svelte +52 -0
  32. package/dist/marks/BarY.svelte.d.ts +25 -0
  33. package/dist/marks/BaseMark.svelte +9 -2
  34. package/dist/marks/BaseMark.svelte.d.ts +2 -1
  35. package/dist/marks/Dot.svelte +26 -40
  36. package/dist/marks/Dot.svelte.d.ts +9 -1
  37. package/dist/marks/GridX.svelte +26 -15
  38. package/dist/marks/GridX.svelte.d.ts +3 -3
  39. package/dist/marks/GridY.svelte +15 -4
  40. package/dist/marks/Line.svelte +16 -27
  41. package/dist/marks/Line.svelte.d.ts +13 -1
  42. package/dist/marks/LineX.svelte +5 -7
  43. package/dist/marks/LineX.svelte.d.ts +11 -4
  44. package/dist/marks/LineY.svelte +4 -6
  45. package/dist/marks/LineY.svelte.d.ts +11 -3
  46. package/dist/marks/RuleX.svelte +15 -7
  47. package/dist/marks/RuleY.svelte +15 -7
  48. package/dist/marks/TickX.svelte +30 -0
  49. package/dist/marks/TickX.svelte.d.ts +15 -0
  50. package/dist/marks/TickY.svelte +30 -0
  51. package/dist/marks/TickY.svelte.d.ts +15 -0
  52. package/dist/transforms/normalize.d.ts +18 -0
  53. package/dist/transforms/normalize.js +25 -0
  54. package/dist/transforms/recordize.d.ts +3 -0
  55. package/dist/transforms/recordize.js +28 -0
  56. package/dist/transforms/rename.d.ts +4 -0
  57. package/dist/transforms/rename.js +10 -0
  58. package/dist/transforms/stack.d.ts +11 -0
  59. package/dist/transforms/stack.js +73 -0
  60. package/dist/types.d.ts +51 -35
  61. package/package.json +18 -14
  62. 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 { CHANNEL_TYPES } from './contants.js';
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 PositionChannelOptions = Partial<{
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?: PositionChannelOptions & {
102
+ x?: PositionScaleOptions & {
103
+ type?: PositionScaleType;
72
104
  axis?: AxisXAnchor | {
73
105
  anchor: AxisXAnchor;
74
106
  tickSpacing: number;
75
107
  };
76
108
  };
77
- y?: PositionChannelOptions & {
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' | 'color' | 'x' | 'y' | 'angle' | 'radius' | 'symbol' | 'width';
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 CHANNEL_TYPES>;
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.11",
3
+ "version": "0.0.1-alpha.12",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build",
@@ -30,39 +30,43 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@playwright/test": "^1.40.1",
33
- "@sveltejs/adapter-auto": "^2.1.1",
34
- "@sveltejs/kit": "^1.27.6",
33
+ "@sveltejs/adapter-auto": "^3.1.0",
34
+ "@sveltejs/kit": "^2.0.8",
35
35
  "@types/chroma-js": "^2.4.3",
36
36
  "@types/d3-interpolate": "^3.0.4",
37
37
  "@types/d3-random": "^3.0.3",
38
38
  "@types/d3-scale-chromatic": "^3.0.3",
39
39
  "@types/d3-shape": "^3.1.6",
40
- "@typescript-eslint/eslint-plugin": "^6.13.2",
41
- "@typescript-eslint/parser": "^6.13.2",
40
+ "@typescript-eslint/eslint-plugin": "^6.18.1",
41
+ "@typescript-eslint/parser": "^6.18.1",
42
42
  "bulma": "^0.9.4",
43
43
  "d3-dsv": "^3.0.1",
44
44
  "dayjs": "^1.11.10",
45
- "eslint": "^8.55.0",
45
+ "eslint": "^8.56.0",
46
46
  "eslint-config-prettier": "^9.1.0",
47
47
  "eslint-plugin-svelte": "^2.35.1",
48
48
  "highlight.js": "^11.9.0",
49
49
  "highlightjs-svelte": "^1.0.6",
50
- "prettier": "^3.1.0",
50
+ "prettier": "^3.1.1",
51
51
  "prettier-plugin-svelte": "^3.1.2",
52
- "sass": "^1.69.5",
53
- "svelte": "5.0.0-next.22",
52
+ "sass": "^1.69.7",
53
+ "svelte": "5.0.0-next.30",
54
54
  "svelte-check": "^3.6.2",
55
- "svelte-highlight": "^7.4.2",
55
+ "svelte-highlight": "^7.4.8",
56
56
  "tslib": "^2.6.2",
57
- "typescript": "^5.3.2",
58
- "vite": "^5.0.5",
59
- "vitest": "^1.0.1"
57
+ "typescript": "^5.3.3",
58
+ "vite": "^5.0.11",
59
+ "vitest": "^1.1.3"
60
60
  },
61
61
  "svelte": "./dist/index.js",
62
62
  "types": "./dist/index.d.ts",
63
63
  "type": "module",
64
64
  "dependencies": {
65
- "@sveltejs/package": "^2.2.3",
65
+ "@observablehq/plot": "^0.6.13",
66
+ "@sveltejs/package": "^2.2.5",
67
+ "@sveltejs/vite-plugin-svelte": "^3.0.1",
68
+ "@sveltepress/theme-default": "^1.22.3",
69
+ "@sveltepress/vite": "^0.31.3",
66
70
  "@types/d3-array": "^3.2.1",
67
71
  "@types/d3-scale": "^4.0.8",
68
72
  "@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]