svelteplot 0.4.2-pr-192.0 → 0.4.2-pr-194.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.
- package/dist/Mark.svelte +4 -2
- package/dist/helpers/resolve.js +4 -4
- package/dist/marks/Area.svelte +3 -3
- package/dist/marks/Arrow.svelte +4 -4
- package/dist/marks/Dot.svelte +3 -3
- package/dist/marks/Geo.svelte +3 -3
- package/dist/marks/RuleX.svelte +1 -1
- package/dist/marks/RuleX.svelte.d.ts +1 -1
- package/dist/marks/Vector.svelte +3 -3
- package/dist/marks/helpers/MarkerPath.svelte +10 -2
- package/dist/marks/helpers/RectPath.svelte +5 -4
- package/dist/marks/helpers/events.d.ts +5 -6
- package/dist/marks/helpers/events.js +41 -41
- package/dist/transforms/recordize.d.ts +9 -7
- package/dist/transforms/recordize.js +23 -24
- package/dist/types/channel.d.ts +1 -1
- package/dist/types/data.d.ts +2 -0
- package/dist/types/index.d.ts +6 -6
- package/package.json +1 -1
package/dist/Mark.svelte
CHANGED
|
@@ -135,11 +135,12 @@
|
|
|
135
135
|
const resolvedData: ResolvedDataRecord<Datum>[] = $derived(
|
|
136
136
|
data
|
|
137
137
|
.map((d, i) => ({ ...d, [INDEX]: i }))
|
|
138
|
-
.flatMap((row) => {
|
|
138
|
+
.flatMap((row, index) => {
|
|
139
139
|
const channels = options as Record<ChannelName, ChannelAccessor<Datum>>;
|
|
140
140
|
if (!testFacet(row, channels) || !testFilter(row, channels)) return [];
|
|
141
141
|
const out: ResolvedDataRecord<Datum> = {
|
|
142
|
-
datum: row
|
|
142
|
+
datum: row,
|
|
143
|
+
index
|
|
143
144
|
};
|
|
144
145
|
for (const [channel] of Object.entries(CHANNEL_SCALE) as [
|
|
145
146
|
ScaledChannelName,
|
|
@@ -208,6 +209,7 @@
|
|
|
208
209
|
resolvedData.flatMap((row) => {
|
|
209
210
|
const out: ScaledDataRecord<Datum> = {
|
|
210
211
|
datum: row.datum,
|
|
212
|
+
index: row[INDEX],
|
|
211
213
|
valid: true
|
|
212
214
|
};
|
|
213
215
|
// compute dx/dy
|
package/dist/helpers/resolve.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CHANNEL_SCALE } from '../constants.js';
|
|
1
|
+
import { CHANNEL_SCALE, INDEX } from '../constants.js';
|
|
2
2
|
import isDataRecord from './isDataRecord.js';
|
|
3
3
|
import isRawValue from './isRawValue.js';
|
|
4
4
|
import { isValid } from './index.js';
|
|
@@ -11,7 +11,7 @@ export function resolveProp(accessor, datum, _defaultValue = null) {
|
|
|
11
11
|
// so we're passing the original value to accessor functions instead of our wrapped record
|
|
12
12
|
return datum == null
|
|
13
13
|
? accessor()
|
|
14
|
-
: accessor(datum[RAW_VALUE] != null ? datum[RAW_VALUE] : datum);
|
|
14
|
+
: accessor(datum[RAW_VALUE] != null ? datum[RAW_VALUE] : datum, datum[INDEX]);
|
|
15
15
|
}
|
|
16
16
|
else if ((typeof accessor === 'string' || typeof accessor === 'symbol') &&
|
|
17
17
|
datum &&
|
|
@@ -51,7 +51,7 @@ function resolve(datum, accessor, channel, scale) {
|
|
|
51
51
|
// datum[RAW_VALUE] exists if an array of raw values was used as dataset and got
|
|
52
52
|
// "recordized" by the recordize transform. We want to hide this wrapping to the user
|
|
53
53
|
// so we're passing the original value to accessor functions instead of our wrapped record
|
|
54
|
-
return accessor(datum[RAW_VALUE] != null ? datum[RAW_VALUE] : datum);
|
|
54
|
+
return accessor(datum[RAW_VALUE] != null ? datum[RAW_VALUE] : datum, datum?.[INDEX]);
|
|
55
55
|
// use accessor string
|
|
56
56
|
if ((typeof accessor === 'string' || typeof accessor === 'symbol') &&
|
|
57
57
|
datum[accessor] !== undefined)
|
|
@@ -69,7 +69,7 @@ function resolve(datum, accessor, channel, scale) {
|
|
|
69
69
|
else {
|
|
70
70
|
// return single value or accessor
|
|
71
71
|
return typeof accessor === 'function'
|
|
72
|
-
? accessor(datum)
|
|
72
|
+
? accessor(datum, datum?.[INDEX])
|
|
73
73
|
: accessor !== null && isRawValue(accessor)
|
|
74
74
|
? accessor
|
|
75
75
|
: !Array.isArray(datum) && (scale === 'x' || scale === 'y')
|
package/dist/marks/Area.svelte
CHANGED
|
@@ -136,11 +136,11 @@
|
|
|
136
136
|
class={['svelteplot-area', className, styleClass]}
|
|
137
137
|
clip-path={options.clipPath}
|
|
138
138
|
d={areaPath(areaData)}
|
|
139
|
-
|
|
139
|
+
{@attach addEventHandlers({
|
|
140
140
|
getPlotState,
|
|
141
141
|
options,
|
|
142
|
-
datum: datum
|
|
143
|
-
}}
|
|
142
|
+
datum: datum?.datum
|
|
143
|
+
})}
|
|
144
144
|
{style}
|
|
145
145
|
>{#if title}<title>{title}</title>{/if}</path>
|
|
146
146
|
</Anchor>
|
package/dist/marks/Arrow.svelte
CHANGED
|
@@ -131,11 +131,11 @@
|
|
|
131
131
|
)}
|
|
132
132
|
<g
|
|
133
133
|
class={[className]}
|
|
134
|
-
|
|
134
|
+
{@attach addEventHandlers({
|
|
135
135
|
getPlotState,
|
|
136
|
-
options
|
|
137
|
-
datum: d
|
|
138
|
-
}}>
|
|
136
|
+
options,
|
|
137
|
+
datum: d?.datum
|
|
138
|
+
})}>
|
|
139
139
|
{#if options.onmouseenter || options.onclick}
|
|
140
140
|
<!-- add invisible path in bg for easier mouse access -->
|
|
141
141
|
<path
|
package/dist/marks/Dot.svelte
CHANGED
package/dist/marks/Geo.svelte
CHANGED
|
@@ -111,11 +111,11 @@
|
|
|
111
111
|
d={path(geometry)}
|
|
112
112
|
{style}
|
|
113
113
|
class={[styleClass]}
|
|
114
|
-
|
|
114
|
+
{@attach addEventHandlers({
|
|
115
115
|
getPlotState,
|
|
116
116
|
options: args,
|
|
117
|
-
datum: d
|
|
118
|
-
}}>
|
|
117
|
+
datum: d?.datum
|
|
118
|
+
})}>
|
|
119
119
|
{#if title}<title>{title}</title>{/if}
|
|
120
120
|
</path>
|
|
121
121
|
</Anchor>
|
package/dist/marks/RuleX.svelte
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
-->
|
|
4
4
|
<script lang="ts" generics="Datum = DataRecord | RawValue">
|
|
5
5
|
interface RuleXMarkProps extends Omit<BaseMarkProps<Datum>, 'fill' | 'fillOpacity'> {
|
|
6
|
-
data
|
|
6
|
+
data?: Datum[];
|
|
7
7
|
x?: ChannelAccessor<Datum>;
|
|
8
8
|
y1?: ChannelAccessor<Datum>;
|
|
9
9
|
y2?: ChannelAccessor<Datum>;
|
|
@@ -60,7 +60,7 @@ declare class __sveltets_Render<Datum = DataRecord | RawValue> {
|
|
|
60
60
|
class: string | null;
|
|
61
61
|
cursor: ConstantAccessor<import("csstype").Property.Cursor, Datum>;
|
|
62
62
|
}>, "fill" | "fillOpacity"> & {
|
|
63
|
-
data
|
|
63
|
+
data?: Datum[] | undefined;
|
|
64
64
|
x?: ChannelAccessor<Datum>;
|
|
65
65
|
y1?: ChannelAccessor<Datum>;
|
|
66
66
|
y2?: ChannelAccessor<Datum>;
|
package/dist/marks/Vector.svelte
CHANGED
|
@@ -201,11 +201,11 @@
|
|
|
201
201
|
? `translate(0, ${d.length})`
|
|
202
202
|
: `translate(0, ${d.length / 2})`}"
|
|
203
203
|
{style}
|
|
204
|
-
|
|
204
|
+
{@attach addEventHandlers({
|
|
205
205
|
getPlotState,
|
|
206
206
|
options: args,
|
|
207
|
-
datum: d
|
|
208
|
-
}}
|
|
207
|
+
datum: d?.datum
|
|
208
|
+
})}
|
|
209
209
|
class={[styleClass]} />
|
|
210
210
|
{/if}
|
|
211
211
|
{/each}
|
|
@@ -95,7 +95,11 @@
|
|
|
95
95
|
{transform}
|
|
96
96
|
class={className}
|
|
97
97
|
stroke-width={strokeWidth_}
|
|
98
|
-
|
|
98
|
+
{@attach addEventHandlers({
|
|
99
|
+
getPlotState,
|
|
100
|
+
options: mark.options,
|
|
101
|
+
datum: datum
|
|
102
|
+
})}>
|
|
99
103
|
{#each Object.entries( { start: markerStart, mid: markerMid, end: markerEnd, all: marker } ) as [key, marker] (key)}
|
|
100
104
|
{@const markerId = `marker-${key === 'all' ? '' : `${key}-`}${id}`}
|
|
101
105
|
{#if isSnippet(marker)}
|
|
@@ -122,7 +126,11 @@
|
|
|
122
126
|
marker-end={markerEnd || marker ? `url(#marker-${markerEnd ? 'end-' : ''}${id})` : null}
|
|
123
127
|
{d}
|
|
124
128
|
{style}
|
|
125
|
-
|
|
129
|
+
{@attach addEventHandlers({
|
|
130
|
+
getPlotState,
|
|
131
|
+
options: mark.options,
|
|
132
|
+
datum: datum
|
|
133
|
+
})} />
|
|
126
134
|
{#if text}
|
|
127
135
|
<!-- since textPath.side is not yet supported, we have to use an invisible
|
|
128
136
|
path in order to keep the text from turning upside down -->
|
|
@@ -34,6 +34,7 @@ Helper component for rendering rectangular marks in SVG
|
|
|
34
34
|
import type { BaseMarkProps, BaseRectMarkProps, BorderRadius } from '../../types/mark.js';
|
|
35
35
|
import type { DataRecord, ScaledDataRecord } from '../../types/data.js';
|
|
36
36
|
import type { PlotContext, UsedScales } from '../../types/index.js';
|
|
37
|
+
import { RAW_VALUE } from '../../transforms/recordize.js';
|
|
37
38
|
|
|
38
39
|
let {
|
|
39
40
|
datum,
|
|
@@ -110,11 +111,11 @@ Helper component for rendering rectangular marks in SVG
|
|
|
110
111
|
)}
|
|
111
112
|
class={[styleClass, className]}
|
|
112
113
|
{style}
|
|
113
|
-
|
|
114
|
+
{@attach addEventHandlers({
|
|
114
115
|
getPlotState,
|
|
115
116
|
options,
|
|
116
117
|
datum: datum?.datum
|
|
117
|
-
}} />
|
|
118
|
+
})} />
|
|
118
119
|
{:else}
|
|
119
120
|
<rect
|
|
120
121
|
transform="translate({x + insetLeft},{y + insetBottom})"
|
|
@@ -122,10 +123,10 @@ Helper component for rendering rectangular marks in SVG
|
|
|
122
123
|
height={height - insetTop - insetBottom}
|
|
123
124
|
class={[styleClass, className]}
|
|
124
125
|
{style}
|
|
125
|
-
|
|
126
|
+
{@attach addEventHandlers({
|
|
126
127
|
getPlotState,
|
|
127
128
|
options,
|
|
128
129
|
datum: datum?.datum
|
|
129
|
-
}} />
|
|
130
|
+
})} />
|
|
130
131
|
{/if}
|
|
131
132
|
</Anchor>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { BaseMarkProps, DataRecord, PlotState } from '../../types/index.js';
|
|
1
|
+
import type { BaseMarkProps, DataRecord, DataRow, PlotState } from '../../types/index.js';
|
|
2
|
+
import type { Attachment } from 'svelte/attachments';
|
|
2
3
|
declare global {
|
|
3
4
|
interface MouseEvent {
|
|
4
5
|
layerX?: number;
|
|
@@ -12,10 +13,8 @@ declare global {
|
|
|
12
13
|
* of the plot frame, regardless of which element triggered the event
|
|
13
14
|
*/
|
|
14
15
|
export declare function clientToLayerCoordinates(event: MouseEvent, plotBody: HTMLElement | null | undefined): [number, number];
|
|
15
|
-
export declare function addEventHandlers
|
|
16
|
-
options: BaseMarkProps
|
|
16
|
+
export declare function addEventHandlers<T extends DataRow>({ options, datum, getPlotState }: {
|
|
17
|
+
options: BaseMarkProps<T>;
|
|
17
18
|
datum: DataRecord;
|
|
18
19
|
getPlotState: () => PlotState;
|
|
19
|
-
}):
|
|
20
|
-
destroy(): void;
|
|
21
|
-
};
|
|
20
|
+
}): Attachment;
|
|
@@ -19,7 +19,7 @@ export function clientToLayerCoordinates(event, plotBody) {
|
|
|
19
19
|
// Calculate the coordinates relative to the plot body
|
|
20
20
|
return [event.clientX - plotBodyRect.left, event.clientY - plotBodyRect.top];
|
|
21
21
|
}
|
|
22
|
-
export function addEventHandlers(
|
|
22
|
+
export function addEventHandlers({ options, datum, getPlotState }) {
|
|
23
23
|
const events = pick(options, [
|
|
24
24
|
'onclick',
|
|
25
25
|
'oncontextmenu',
|
|
@@ -51,51 +51,51 @@ export function addEventHandlers(node, { options, datum, getPlotState }) {
|
|
|
51
51
|
'ontouchmove',
|
|
52
52
|
'onwheel'
|
|
53
53
|
]);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
54
|
+
return (node) => {
|
|
55
|
+
const listeners = new Map();
|
|
56
|
+
// attach event handlers
|
|
57
|
+
for (const [eventName, eventHandler] of Object.entries(events)) {
|
|
58
|
+
if (eventHandler) {
|
|
59
|
+
const wrappedHandler = (origEvent) => {
|
|
60
|
+
const { scales, body, options } = getPlotState();
|
|
61
|
+
if (origEvent instanceof MouseEvent || origEvent instanceof PointerEvent) {
|
|
62
|
+
let facetEl = origEvent.target;
|
|
63
|
+
while (facetEl &&
|
|
64
|
+
!facetEl.classList.contains('facet') &&
|
|
65
|
+
facetEl.parentElement) {
|
|
66
|
+
// ensure that parentElement is SVGElement
|
|
67
|
+
if (!(facetEl.parentElement instanceof SVGElement))
|
|
68
|
+
break;
|
|
69
|
+
facetEl = facetEl.parentElement;
|
|
70
|
+
}
|
|
71
|
+
const facetRect = (facetEl?.firstElementChild ?? body).getBoundingClientRect();
|
|
72
|
+
const relativeX = origEvent.clientX - facetRect.left + (options.marginLeft ?? 0);
|
|
73
|
+
const relativeY = origEvent.clientY - facetRect.top + (options.marginTop ?? 0);
|
|
74
|
+
if (scales.projection) {
|
|
75
|
+
const [x, y] = scales.projection.invert([relativeX, relativeY]);
|
|
76
|
+
origEvent.dataX = x;
|
|
77
|
+
origEvent.dataY = y;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
origEvent.dataX = invertScale(scales.x, relativeX);
|
|
81
|
+
origEvent.dataY = invertScale(scales.y, relativeY);
|
|
82
|
+
}
|
|
69
83
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
origEvent.dataX = x;
|
|
76
|
-
origEvent.dataY = y;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
origEvent.dataX = invertScale(scales.x, relativeX);
|
|
80
|
-
origEvent.dataY = invertScale(scales.y, relativeY);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
eventHandler(origEvent, datum.hasOwnProperty(RAW_VALUE) ? datum[RAW_VALUE] : datum, datum[INDEX]);
|
|
84
|
-
};
|
|
85
|
-
listeners.set(eventName, wrappedHandler);
|
|
86
|
-
node.addEventListener(eventName.substring(2), wrappedHandler);
|
|
84
|
+
eventHandler(origEvent, datum.hasOwnProperty(RAW_VALUE) ? datum[RAW_VALUE] : datum, datum[INDEX]);
|
|
85
|
+
};
|
|
86
|
+
listeners.set(eventName, wrappedHandler);
|
|
87
|
+
node.addEventListener(eventName.substring(2), wrappedHandler);
|
|
88
|
+
}
|
|
87
89
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
destroy() {
|
|
90
|
+
if (events.onclick || events.onmousedown || events.onmouseup) {
|
|
91
|
+
// force role button
|
|
92
|
+
node.setAttribute('role', 'button');
|
|
93
|
+
}
|
|
94
|
+
return () => {
|
|
95
95
|
for (const [eventName, handler] of listeners.entries()) {
|
|
96
96
|
node.removeEventListener(eventName.substring(2), handler);
|
|
97
97
|
}
|
|
98
|
-
}
|
|
98
|
+
};
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
function invertScale(scale, position) {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import type { TransformArgsRow, TransformArgsRecord } from '../types/index.js';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const X: unique symbol;
|
|
3
|
+
export declare const Y: unique symbol;
|
|
3
4
|
export declare const RAW_VALUE: unique symbol;
|
|
4
|
-
export declare function
|
|
5
|
+
export declare function indexData<T extends object>(data: T[]): (T & {})[];
|
|
6
|
+
export declare function recordizeX<T>({ data, ...channels }: TransformArgsRow<T>, { withIndex }?: {
|
|
5
7
|
withIndex: boolean;
|
|
6
|
-
}): TransformArgsRecord
|
|
7
|
-
export declare function recordizeY({ data, ...channels }: TransformArgsRow
|
|
8
|
+
}): TransformArgsRecord<T>;
|
|
9
|
+
export declare function recordizeY<T>({ data, ...channels }: TransformArgsRow<T>, { withIndex }?: {
|
|
8
10
|
withIndex: boolean;
|
|
9
|
-
}): TransformArgsRecord
|
|
11
|
+
}): TransformArgsRecord<T>;
|
|
10
12
|
/**
|
|
11
13
|
* This transform is used to allow users to pass an [[x0, y0], [x1, y1], ...] array
|
|
12
14
|
* as dataset to marks that support it. It transforms the arrays into records, so
|
|
13
15
|
* the rest of our code doesn't have to deal with this case anymore.
|
|
14
16
|
*/
|
|
15
|
-
export declare function recordizeXY({ data, ...channels }: TransformArgsRow): TransformArgsRecord
|
|
16
|
-
export declare function recordize({ data, ...channels }: TransformArgsRow): TransformArgsRecord
|
|
17
|
+
export declare function recordizeXY<T>({ data, ...channels }: TransformArgsRow<T>): TransformArgsRecord<T>;
|
|
18
|
+
export declare function recordize<T>({ data, ...channels }: TransformArgsRow<T>): TransformArgsRecord<T>;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import isDataRecord from '../helpers/isDataRecord.js';
|
|
2
|
-
|
|
2
|
+
import { INDEX } from '../constants';
|
|
3
|
+
export const X = Symbol('x');
|
|
4
|
+
export const Y = Symbol('y');
|
|
3
5
|
export const RAW_VALUE = Symbol('originalValue');
|
|
6
|
+
export function indexData(data) {
|
|
7
|
+
return data.map((d, i) => ({ ...d, [INDEX]: i }));
|
|
8
|
+
}
|
|
4
9
|
/*
|
|
5
10
|
* This transform takes an array of raw values as input and returns data records
|
|
6
11
|
* in which the values are interpreted as x channel and their index as y
|
|
@@ -10,16 +15,15 @@ export function recordizeX({ data, ...channels }, { withIndex } = { withIndex: t
|
|
|
10
15
|
if (dataIsRawValueArray) {
|
|
11
16
|
return {
|
|
12
17
|
data: data.map((value, index) => ({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[RAW_VALUE]: value
|
|
18
|
+
[RAW_VALUE]: value,
|
|
19
|
+
[INDEX]: index
|
|
16
20
|
})),
|
|
17
21
|
...channels,
|
|
18
22
|
x: RAW_VALUE,
|
|
19
23
|
...(withIndex ? { y: INDEX } : {})
|
|
20
24
|
};
|
|
21
25
|
}
|
|
22
|
-
return { data: data, ...channels };
|
|
26
|
+
return { data: indexData(data), ...channels };
|
|
23
27
|
}
|
|
24
28
|
/*
|
|
25
29
|
* This transform takes an array of raw values as input and returns data records
|
|
@@ -32,22 +36,15 @@ export function recordizeY({ data, ...channels }, { withIndex } = { withIndex: t
|
|
|
32
36
|
if (dataIsRawValueArray) {
|
|
33
37
|
return {
|
|
34
38
|
data: Array.from(data).map((value, index) => ({
|
|
35
|
-
|
|
39
|
+
[INDEX]: index,
|
|
36
40
|
[RAW_VALUE]: value
|
|
37
41
|
})),
|
|
38
42
|
...channels,
|
|
39
|
-
...(withIndex ? { x:
|
|
43
|
+
...(withIndex ? { x: INDEX } : {}),
|
|
40
44
|
y: RAW_VALUE
|
|
41
45
|
};
|
|
42
46
|
}
|
|
43
|
-
return {
|
|
44
|
-
data: Array.from(data).map((d, index) => ({
|
|
45
|
-
...d,
|
|
46
|
-
...(withIndex ? { __index: index } : {})
|
|
47
|
-
})),
|
|
48
|
-
x: '__index',
|
|
49
|
-
...channels
|
|
50
|
-
};
|
|
47
|
+
return { data: indexData(data), ...channels };
|
|
51
48
|
}
|
|
52
49
|
/**
|
|
53
50
|
* This transform is used to allow users to pass an [[x0, y0], [x1, y1], ...] array
|
|
@@ -62,28 +59,30 @@ export function recordizeXY({ data, ...channels }) {
|
|
|
62
59
|
channels.x === undefined &&
|
|
63
60
|
channels.y === undefined) {
|
|
64
61
|
return {
|
|
65
|
-
data: data.map(([x, y, ...rest]) => ({
|
|
62
|
+
data: data.map(([x, y, ...rest], i) => ({
|
|
66
63
|
[RAW_VALUE]: [x, y, ...rest],
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
[INDEX]: i,
|
|
65
|
+
[X]: x,
|
|
66
|
+
[Y]: y
|
|
69
67
|
})),
|
|
70
68
|
...channels,
|
|
71
|
-
x:
|
|
72
|
-
y:
|
|
69
|
+
x: X,
|
|
70
|
+
y: Y
|
|
73
71
|
};
|
|
74
72
|
}
|
|
75
|
-
return { data, ...channels };
|
|
73
|
+
return { data: data, ...channels };
|
|
76
74
|
}
|
|
77
75
|
export function recordize({ data, ...channels }) {
|
|
78
76
|
if (!data)
|
|
79
77
|
return { data, ...channels };
|
|
80
78
|
if (!isDataRecord(data[0])) {
|
|
81
79
|
return {
|
|
82
|
-
data: data.map((d) => ({
|
|
83
|
-
[RAW_VALUE]: d
|
|
80
|
+
data: data.map((d, i) => ({
|
|
81
|
+
[RAW_VALUE]: d,
|
|
82
|
+
[INDEX]: i
|
|
84
83
|
})),
|
|
85
84
|
...channels
|
|
86
85
|
};
|
|
87
86
|
}
|
|
88
|
-
return { data, ...channels };
|
|
87
|
+
return { data: indexData(data), ...channels };
|
|
89
88
|
}
|
package/dist/types/channel.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type ChannelAccessor<T = Record<string | symbol, RawValue>> = ChannelValu
|
|
|
6
6
|
/** you can bypass the scale by passing null */
|
|
7
7
|
scale: boolean | null;
|
|
8
8
|
};
|
|
9
|
-
export type ChannelValue<T = Record<string | symbol, RawValue>> = RawValue | keyof T | ((d: T) => RawValue) | null | undefined;
|
|
9
|
+
export type ChannelValue<T = Record<string | symbol, RawValue>> = RawValue | keyof T | ((d: T, index: number) => RawValue) | null | undefined;
|
|
10
10
|
export type ScaledChannelName = 'fill' | 'fillOpacity' | 'opacity' | 'r' | 'length' | 'stroke' | 'strokeOpacity' | 'symbol' | 'fx' | 'fy' | 'x' | 'x1' | 'x2' | 'y' | 'y1' | 'y2';
|
|
11
11
|
export type ScaledChannelType<T extends ScaledChannelName> = T extends 'fill' | 'stroke' | 'symbol' ? string : number;
|
|
12
12
|
export type ChannelName = ScaledChannelName | 'z' | 'sort' | 'filter' | 'interval';
|
package/dist/types/data.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type RawValue = number | Date | boolean | string | symbol;
|
|
|
3
3
|
export type DataRecord<T = Record<string | symbol, RawValue>> = T;
|
|
4
4
|
export type ResolvedDataRecord<T = Record<string | symbol, RawValue>> = Partial<Record<ScaledChannelName, any>> & {
|
|
5
5
|
datum: DataRecord<T>;
|
|
6
|
+
index: number;
|
|
6
7
|
};
|
|
7
8
|
export type ScaledDataRecord<T = Record<string | symbol, RawValue>> = Partial<{
|
|
8
9
|
[K in ScaledChannelName]?: ScaledChannelType<K>;
|
|
@@ -11,5 +12,6 @@ export type ScaledDataRecord<T = Record<string | symbol, RawValue>> = Partial<{
|
|
|
11
12
|
dy: number;
|
|
12
13
|
datum: DataRecord<T>;
|
|
13
14
|
valid: Boolean;
|
|
15
|
+
index: number;
|
|
14
16
|
};
|
|
15
17
|
export type DataRow<T = Record<string | symbol, RawValue>> = DataRecord<T> | RawValue | [number, number] | null;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Snippet } from 'svelte';
|
|
|
2
2
|
import type { Writable } from 'svelte/store';
|
|
3
3
|
import type { MarkerShape } from '../marks/helpers/Marker.svelte';
|
|
4
4
|
import type { Channels, ScaledChannelName } from './channel.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { RawValue } from './data.js';
|
|
6
6
|
import type { BaseMarkProps } from './mark.js';
|
|
7
7
|
export type GenericMarkOptions = Record<string | symbol, any>;
|
|
8
8
|
export type CurveName = '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';
|
|
@@ -24,18 +24,18 @@ export type MarkerOptions = {
|
|
|
24
24
|
*/
|
|
25
25
|
marker?: boolean | MarkerShape | Snippet;
|
|
26
26
|
};
|
|
27
|
-
export type ConstantAccessor<K, T = Record<string | symbol, RawValue>> = K | ((d: T) => K) | null | undefined;
|
|
27
|
+
export type ConstantAccessor<K, T = Record<string | symbol, RawValue>> = K | ((d: T, index: number) => K) | null | undefined;
|
|
28
28
|
export type TransformArg<T> = Channels<T> & BaseMarkProps<T> & {
|
|
29
29
|
data: T[];
|
|
30
30
|
};
|
|
31
31
|
export type MapArg<T> = Channels<T> & {
|
|
32
32
|
data: T[];
|
|
33
33
|
};
|
|
34
|
-
export type TransformArgsRow = Partial<Channels
|
|
35
|
-
data:
|
|
34
|
+
export type TransformArgsRow<T extends RawValue & object> = Partial<Channels<T>> & {
|
|
35
|
+
data: T[];
|
|
36
36
|
};
|
|
37
|
-
export type TransformArgsRecord = Partial<Channels
|
|
38
|
-
data:
|
|
37
|
+
export type TransformArgsRecord<T extends object> = Partial<Channels<T>> & {
|
|
38
|
+
data: T[];
|
|
39
39
|
};
|
|
40
40
|
export type AutoMarginStores = {
|
|
41
41
|
autoMarginTop: Writable<Map<string, number>>;
|