svelteplot 0.4.5-pr-208.0 → 0.4.5-pr-209.0

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 (37) hide show
  1. package/dist/Mark.svelte +73 -87
  2. package/dist/Mark.svelte.d.ts +34 -37
  3. package/dist/marks/Area.svelte.d.ts +34 -37
  4. package/dist/marks/AreaX.svelte.d.ts +34 -36
  5. package/dist/marks/AreaY.svelte.d.ts +34 -36
  6. package/dist/marks/Arrow.svelte.d.ts +34 -37
  7. package/dist/marks/AxisX.svelte +2 -2
  8. package/dist/marks/AxisX.svelte.d.ts +35 -38
  9. package/dist/marks/AxisY.svelte.d.ts +34 -37
  10. package/dist/marks/BarX.svelte.d.ts +34 -37
  11. package/dist/marks/BarY.svelte.d.ts +34 -37
  12. package/dist/marks/Cell.svelte.d.ts +34 -37
  13. package/dist/marks/Dot.svelte +1 -1
  14. package/dist/marks/Dot.svelte.d.ts +34 -37
  15. package/dist/marks/DotX.svelte.d.ts +34 -37
  16. package/dist/marks/DotY.svelte.d.ts +34 -37
  17. package/dist/marks/Geo.svelte.d.ts +34 -37
  18. package/dist/marks/GridX.svelte.d.ts +34 -37
  19. package/dist/marks/GridY.svelte.d.ts +34 -37
  20. package/dist/marks/Line.svelte.d.ts +34 -37
  21. package/dist/marks/LineX.svelte.d.ts +34 -36
  22. package/dist/marks/LineY.svelte.d.ts +34 -36
  23. package/dist/marks/Link.svelte.d.ts +34 -37
  24. package/dist/marks/Rect.svelte.d.ts +34 -37
  25. package/dist/marks/RuleX.svelte.d.ts +34 -37
  26. package/dist/marks/RuleY.svelte.d.ts +34 -37
  27. package/dist/marks/Spike.svelte.d.ts +34 -36
  28. package/dist/marks/Text.svelte.d.ts +34 -37
  29. package/dist/marks/TickX.svelte.d.ts +34 -37
  30. package/dist/marks/TickY.svelte.d.ts +34 -37
  31. package/dist/marks/Vector.svelte.d.ts +34 -37
  32. package/dist/marks/helpers/BaseAxisX.svelte +12 -0
  33. package/dist/marks/helpers/BaseAxisX.svelte.d.ts +1 -0
  34. package/dist/types/mark.d.ts +34 -37
  35. package/package.json +2 -3
  36. package/dist/transforms/dodge.d.ts +0 -17
  37. package/dist/transforms/dodge.js +0 -128
@@ -12,19 +12,16 @@ import type { MouseEventHandler } from 'svelte/elements';
12
12
  import type { ChannelAccessor, ConstantAccessor, DataRecord, RawValue } from './index.js';
13
13
  import type * as CSS from 'csstype';
14
14
  import type { ScaledChannelName, ScaleName } from './scale.js';
15
- import type { DodgeXOptions, DodgeYOptions } from '../transforms/dodge.js';
16
15
  export type BaseMarkProps<T> = Partial<{
17
16
  /**
18
17
  * Filter the data without modifying the inferred scales
19
18
  */
20
- filter: ConstantAccessor<boolean, T>;
21
- facet: 'auto' | 'include' | 'exclude';
19
+ filter?: ConstantAccessor<boolean, T>;
20
+ facet?: 'auto' | 'include' | 'exclude';
22
21
  fx: ChannelAccessor<T>;
23
22
  fy: ChannelAccessor<T>;
24
23
  dx: ConstantAccessor<number, T>;
25
24
  dy: ConstantAccessor<number, T>;
26
- dodgeX: DodgeXOptions;
27
- dodgeY: DodgeYOptions;
28
25
  fill: ChannelAccessor<T>;
29
26
  fillOpacity: ConstantAccessor<number, T>;
30
27
  sort: string | ConstantAccessor<RawValue, T> | ((a: RawValue, b: RawValue) => number) | {
@@ -47,44 +44,44 @@ export type BaseMarkProps<T> = Partial<{
47
44
  imageFilter: ConstantAccessor<string, T>;
48
45
  shapeRendering: ConstantAccessor<CSS.Property.ShapeRendering, T>;
49
46
  paintOrder: ConstantAccessor<string, T>;
50
- onclick: MouseEventHandler<SVGPathElement>;
51
- ondblclick: MouseEventHandler<SVGPathElement>;
52
- onmouseup: MouseEventHandler<SVGPathElement>;
53
- onmousedown: MouseEventHandler<SVGPathElement>;
54
- onmouseenter: MouseEventHandler<SVGPathElement>;
55
- onmousemove: MouseEventHandler<SVGPathElement>;
56
- onmouseleave: MouseEventHandler<SVGPathElement>;
57
- onmouseout: MouseEventHandler<SVGPathElement>;
58
- onmouseover: MouseEventHandler<SVGPathElement>;
59
- onpointercancel: MouseEventHandler<SVGPathElement>;
60
- onpointerdown: MouseEventHandler<SVGPathElement>;
61
- onpointerup: MouseEventHandler<SVGPathElement>;
62
- onpointerenter: MouseEventHandler<SVGPathElement>;
63
- onpointerleave: MouseEventHandler<SVGPathElement>;
64
- onpointermove: MouseEventHandler<SVGPathElement>;
65
- onpointerover: MouseEventHandler<SVGPathElement>;
66
- onpointerout: MouseEventHandler<SVGPathElement>;
67
- ondrag: MouseEventHandler<SVGPathElement>;
68
- ondrop: MouseEventHandler<SVGPathElement>;
69
- ondragstart: MouseEventHandler<SVGPathElement>;
70
- ondragenter: MouseEventHandler<SVGPathElement>;
71
- ondragleave: MouseEventHandler<SVGPathElement>;
72
- ondragover: MouseEventHandler<SVGPathElement>;
73
- ondragend: MouseEventHandler<SVGPathElement>;
74
- ontouchstart: MouseEventHandler<SVGPathElement>;
75
- ontouchmove: MouseEventHandler<SVGPathElement>;
76
- ontouchend: MouseEventHandler<SVGPathElement>;
77
- ontouchcancel: MouseEventHandler<SVGPathElement>;
78
- oncontextmenu: MouseEventHandler<SVGPathElement>;
79
- onwheel: MouseEventHandler<SVGPathElement>;
47
+ onclick?: MouseEventHandler<SVGPathElement>;
48
+ ondblclick?: MouseEventHandler<SVGPathElement>;
49
+ onmouseup?: MouseEventHandler<SVGPathElement>;
50
+ onmousedown?: MouseEventHandler<SVGPathElement>;
51
+ onmouseenter?: MouseEventHandler<SVGPathElement>;
52
+ onmousemove?: MouseEventHandler<SVGPathElement>;
53
+ onmouseleave?: MouseEventHandler<SVGPathElement>;
54
+ onmouseout?: MouseEventHandler<SVGPathElement>;
55
+ onmouseover?: MouseEventHandler<SVGPathElement>;
56
+ onpointercancel?: MouseEventHandler<SVGPathElement>;
57
+ onpointerdown?: MouseEventHandler<SVGPathElement>;
58
+ onpointerup?: MouseEventHandler<SVGPathElement>;
59
+ onpointerenter?: MouseEventHandler<SVGPathElement>;
60
+ onpointerleave?: MouseEventHandler<SVGPathElement>;
61
+ onpointermove?: MouseEventHandler<SVGPathElement>;
62
+ onpointerover?: MouseEventHandler<SVGPathElement>;
63
+ onpointerout?: MouseEventHandler<SVGPathElement>;
64
+ ondrag?: MouseEventHandler<SVGPathElement>;
65
+ ondrop?: MouseEventHandler<SVGPathElement>;
66
+ ondragstart?: MouseEventHandler<SVGPathElement>;
67
+ ondragenter?: MouseEventHandler<SVGPathElement>;
68
+ ondragleave?: MouseEventHandler<SVGPathElement>;
69
+ ondragover?: MouseEventHandler<SVGPathElement>;
70
+ ondragend?: MouseEventHandler<SVGPathElement>;
71
+ ontouchstart?: MouseEventHandler<SVGPathElement>;
72
+ ontouchmove?: MouseEventHandler<SVGPathElement>;
73
+ ontouchend?: MouseEventHandler<SVGPathElement>;
74
+ ontouchcancel?: MouseEventHandler<SVGPathElement>;
75
+ oncontextmenu?: MouseEventHandler<SVGPathElement>;
76
+ onwheel?: MouseEventHandler<SVGPathElement>;
80
77
  /**
81
78
  * if you want to give your mark element an extra CSS class
82
79
  */
83
- class: string;
80
+ class?: string;
84
81
  /**
85
82
  * if you want to give your mark element an extra inline style
86
83
  */
87
- style: string;
84
+ style?: string;
88
85
  cursor: ConstantAccessor<CSS.Property.Cursor, T>;
89
86
  }>;
90
87
  export type LinkableMarkProps<T> = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.4.5-pr-208.0",
3
+ "version": "0.4.5-pr-209.0",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",
@@ -114,7 +114,6 @@
114
114
  "types": "./dist/index.d.ts",
115
115
  "type": "module",
116
116
  "dependencies": {
117
- "@gka/d3-regression": "^1.3.10-pr48",
118
117
  "d3-array": "^3.2.4",
119
118
  "d3-color": "^3.1.0",
120
119
  "d3-format": "^3.1.0",
@@ -123,13 +122,13 @@
123
122
  "d3-path": "^3.1.0",
124
123
  "d3-quadtree": "^3.0.1",
125
124
  "d3-random": "^3.0.1",
125
+ "@gka/d3-regression": "^1.3.10-pr48",
126
126
  "d3-scale": "^4.0.2",
127
127
  "d3-scale-chromatic": "^3.1.0",
128
128
  "d3-shape": "^3.2.0",
129
129
  "d3-time": "^3.1.0",
130
130
  "es-toolkit": "^1.39.10",
131
131
  "fast-equals": "^5.2.2",
132
- "interval-tree-1d": "^1.0.4",
133
132
  "merge-deep": "^3.0.3",
134
133
  "svelte": "5.38.7"
135
134
  }
@@ -1,17 +0,0 @@
1
- import type { ScaledDataRecord, TransformArg, PlotState } from '../types';
2
- type BaseDodgeOptions = {
3
- anchor?: string;
4
- padding?: number;
5
- r?: number;
6
- };
7
- type AnchorX = 'left' | 'right' | 'middle';
8
- type AnchorY = 'top' | 'bottom' | 'middle';
9
- export type DodgeXOptions = AnchorX | (BaseDodgeOptions & {
10
- anchor?: 'left' | 'right' | 'middle';
11
- });
12
- export type DodgeYOptions = AnchorY | (BaseDodgeOptions & {
13
- anchor?: 'top' | 'bottom' | 'middle';
14
- });
15
- export declare function dodgeX(args: TransformArg<ScaledDataRecord>, plotState: PlotState): ScaledDataRecord[];
16
- export declare function dodgeY(args: TransformArg<ScaledDataRecord>, plotState: PlotState): ScaledDataRecord[];
17
- export {};
@@ -1,128 +0,0 @@
1
- import IntervalTree from 'interval-tree-1d';
2
- import { groupFacetsAndZ } from '../helpers/group';
3
- export function dodgeX(args, plotState) {
4
- if (!args.dodgeX)
5
- return args.data;
6
- let { anchor = 'left', padding = 1, r = args.dodgeX.r } = maybeAnchor(args.dodgeX);
7
- let anchorFunction;
8
- switch (`${anchor}`.toLowerCase()) {
9
- case 'left':
10
- anchorFunction = anchorXLeft;
11
- break;
12
- case 'right':
13
- anchorFunction = anchorXRight;
14
- break;
15
- case 'middle':
16
- anchorFunction = anchorXMiddle;
17
- break;
18
- default:
19
- throw new Error(`unknown dodge anchor: ${anchor}`);
20
- }
21
- return dodge('x', 'y', anchorFunction, Number(padding), r, args, plotState);
22
- }
23
- export function dodgeY(args, plotState) {
24
- if (!args.dodgeY)
25
- return args.data;
26
- let { anchor = 'bottom', padding = 1, r = args.dodgeY.r } = maybeAnchor(args.dodgeY);
27
- let anchorFunction;
28
- switch (`${anchor}`.toLowerCase()) {
29
- case 'top':
30
- anchorFunction = anchorYTop;
31
- break;
32
- case 'bottom':
33
- anchorFunction = anchorYBottom;
34
- break;
35
- case 'middle':
36
- anchorFunction = anchorYMiddle;
37
- break;
38
- default:
39
- throw new Error(`unknown dodge anchor: ${anchor}`);
40
- }
41
- return dodge('y', 'x', anchorFunction, Number(padding), r, args, plotState);
42
- }
43
- function dodge(y, x, anchor, padding, r, { data, ...channels }, plotState) {
44
- if (r != null && typeof r !== 'number') {
45
- // use the r channel
46
- // let { channels, sort, reverse } = options;
47
- // channels = maybeNamed(channels);
48
- // if (channels?.r === undefined)
49
- // options = { ...options, channels: { ...channels, r: { value: r, scale: 'r' } } };
50
- // if (sort === undefined && reverse === undefined) options.sort = { channel: '-r' };
51
- }
52
- const { fx, fy } = channels;
53
- let [ky, ty] = anchor(plotState);
54
- const compare = ky ? compareAscending : compareSymmetric;
55
- const cr = r !== undefined ? r : 3; // default radius if no r channel
56
- // group data by facets
57
- groupFacetsAndZ(data, { fx, fy }, (items) => {
58
- // apply dodge within each facet
59
- const tree = IntervalTree();
60
- const data = items.filter((d) => (typeof d.r !== 'number' || d.r >= 0) && isFinite(d[x]) && isFinite(d[y]));
61
- const intervals = new Float64Array(2 * data.length + 2);
62
- data.forEach((d, i) => {
63
- const ri = d.r ?? r ?? 3;
64
- const y0 = ky ? ri + padding : 0; // offset baseline for varying radius
65
- const l = d[x] - ri;
66
- const h = d[x] + ri;
67
- // The first two positions are 0 to test placing the dot on the baseline.
68
- let k = 2;
69
- // For any previously placed circles that may overlap this circle, compute
70
- // the y-positions that place this circle tangent to these other circles.
71
- // https://observablehq.com/@mbostock/circle-offset-along-line
72
- tree.queryInterval(l - padding, h + padding, ([, , j]) => {
73
- const yj = data[j][y] - y0;
74
- const dx = d[x] - data[j][x];
75
- const dr = padding + (channels.r ? d.r + data[j].r : 2 * cr);
76
- const dy = Math.sqrt(dr * dr - dx * dx);
77
- intervals[k++] = yj - dy;
78
- intervals[k++] = yj + dy;
79
- });
80
- // Find the best y-value where this circle can fit.
81
- let candidates = intervals.slice(0, k);
82
- if (ky)
83
- candidates = candidates.filter((y) => y >= 0);
84
- out: for (const diff of candidates.sort(compare)) {
85
- for (let j = 0; j < k; j += 2) {
86
- if (intervals[j] + 1e-6 < diff && diff < intervals[j + 1] - 1e-6) {
87
- continue out;
88
- }
89
- }
90
- d[y] = diff + y0;
91
- break;
92
- }
93
- // Insert the placed circle into the interval tree.
94
- tree.insert([l, h, i]);
95
- });
96
- if (!ky)
97
- ky = 1;
98
- data.forEach((d) => (d[y] = d[y] * ky + ty));
99
- });
100
- return data;
101
- }
102
- function maybeAnchor(anchor) {
103
- return typeof anchor === 'string' ? { anchor } : anchor;
104
- }
105
- function anchorXLeft({ options: { marginLeft } }) {
106
- return [1, marginLeft];
107
- }
108
- function anchorXRight({ facetWidth: width, options: { marginLeft } }) {
109
- return [-1, marginLeft + width];
110
- }
111
- function anchorXMiddle({ facetWidth: width, options: { marginLeft } }) {
112
- return [0, marginLeft + width / 2];
113
- }
114
- function anchorYTop({ options: { marginTop } }) {
115
- return [1, marginTop];
116
- }
117
- function anchorYBottom({ facetHeight: height }) {
118
- return [-1, height];
119
- }
120
- function anchorYMiddle({ facetHeight: height, options: { marginTop, marginBottom } }) {
121
- return [0, (marginTop + height) / 2];
122
- }
123
- function compareSymmetric(a, b) {
124
- return Math.abs(a) - Math.abs(b);
125
- }
126
- function compareAscending(a, b) {
127
- return a - b;
128
- }