svelteplot 0.2.0 → 0.2.2
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 +12 -1
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/resolve.d.ts +1 -1
- package/dist/helpers/resolve.js +6 -5
- package/dist/helpers/scales.d.ts +2 -2
- package/dist/helpers/scales.js +5 -4
- package/dist/helpers/typeChecks.js +14 -10
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -2
- package/dist/marks/BarX.svelte +11 -37
- package/dist/marks/BarY.svelte +27 -58
- package/dist/marks/BarY.svelte.d.ts +2 -8
- package/dist/marks/Cell.svelte +12 -36
- package/dist/marks/ColorLegend.svelte +6 -10
- package/dist/marks/Dot.svelte +2 -2
- package/dist/marks/Geo.svelte +50 -41
- package/dist/marks/Geo.svelte.d.ts +3 -1
- package/dist/marks/GridX.svelte +2 -2
- package/dist/marks/GridY.svelte +2 -2
- package/dist/marks/Line.svelte +98 -80
- package/dist/marks/Line.svelte.d.ts +5 -3
- package/dist/marks/Pointer.svelte +2 -1
- package/dist/marks/Rect.svelte +10 -24
- package/dist/marks/helpers/CanvasLayer.svelte +10 -16
- package/dist/marks/helpers/CanvasLayer.svelte.d.ts +2 -6
- package/dist/marks/helpers/DotCanvas.svelte +72 -159
- package/dist/marks/helpers/DotCanvas.svelte.d.ts +2 -4
- package/dist/marks/helpers/GeoCanvas.svelte +95 -145
- package/dist/marks/helpers/GeoCanvas.svelte.d.ts +3 -5
- package/dist/marks/helpers/LineCanvas.svelte +116 -0
- package/dist/marks/helpers/LineCanvas.svelte.d.ts +12 -0
- package/dist/marks/helpers/LinearGradientX.svelte +27 -0
- package/dist/marks/helpers/LinearGradientX.svelte.d.ts +11 -0
- package/dist/marks/helpers/LinearGradientY.svelte +27 -0
- package/dist/marks/helpers/LinearGradientY.svelte.d.ts +11 -0
- package/dist/marks/helpers/RectPath.svelte +129 -0
- package/dist/marks/helpers/RectPath.svelte.d.ts +27 -0
- package/dist/marks/helpers/canvas.d.ts +1 -0
- package/dist/marks/helpers/canvas.js +34 -0
- package/dist/transforms/recordize.d.ts +1 -0
- package/dist/transforms/recordize.js +16 -5
- package/dist/transforms/stack.js +10 -7
- package/dist/types.d.ts +12 -6
- package/package.json +19 -17
package/dist/marks/Geo.svelte
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { getContext } from 'svelte';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
DataRecord,
|
|
5
|
+
PlotContext,
|
|
6
|
+
BaseMarkProps,
|
|
7
|
+
FacetContext,
|
|
8
|
+
ConstantAccessor,
|
|
9
|
+
UsedScales
|
|
10
|
+
} from '../types.js';
|
|
4
11
|
import Mark from '../Mark.svelte';
|
|
5
12
|
import { geoPath } from 'd3-geo';
|
|
6
|
-
import { resolveChannel, resolveProp,
|
|
7
|
-
import { getUsedScales } from '../helpers/scales.js';
|
|
13
|
+
import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
|
|
8
14
|
import callWithProps from '../helpers/callWithProps.js';
|
|
9
15
|
import { sort } from '../index.js';
|
|
10
|
-
import { testFilter } from '../helpers/index.js';
|
|
11
16
|
import { addEventHandlers } from './helpers/events.js';
|
|
12
17
|
import GeoCanvas from './helpers/GeoCanvas.svelte';
|
|
18
|
+
import { recordize } from '../transforms/recordize.js';
|
|
19
|
+
import { GEOJSON_PREFER_STROKE } from '../helpers/index.js';
|
|
13
20
|
|
|
14
21
|
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
15
22
|
const plot = $derived(getPlotState());
|
|
@@ -19,6 +26,8 @@
|
|
|
19
26
|
geoType?: 'sphere' | 'graticule';
|
|
20
27
|
dragRotate: boolean;
|
|
21
28
|
canvas: boolean;
|
|
29
|
+
href: ConstantAccessor<string>;
|
|
30
|
+
target: ConstantAccessor<string>;
|
|
22
31
|
} & BaseMarkProps;
|
|
23
32
|
|
|
24
33
|
let {
|
|
@@ -39,60 +48,60 @@
|
|
|
39
48
|
);
|
|
40
49
|
|
|
41
50
|
const args = $derived(
|
|
42
|
-
sort(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
sort(
|
|
52
|
+
recordize({
|
|
53
|
+
data,
|
|
54
|
+
...(options.r ? { sort: { channel: '-r' } } : {}),
|
|
55
|
+
...options
|
|
56
|
+
})
|
|
57
|
+
)
|
|
47
58
|
);
|
|
48
|
-
const preferStroke = new Set(['MultiLineString', 'LineString']);
|
|
49
|
-
|
|
50
|
-
const { getTestFacet } = getContext<FacetContext>('svelteplot/facet');
|
|
51
|
-
const testFacet = $derived(getTestFacet());
|
|
52
59
|
</script>
|
|
53
60
|
|
|
54
61
|
<Mark
|
|
55
62
|
type="geo"
|
|
56
63
|
channels={['fill', 'stroke', 'opacity', 'fillOpacity', 'strokeOpacity', 'r']}
|
|
57
64
|
{...args}>
|
|
58
|
-
{#snippet children({ mark, usedScales })}
|
|
65
|
+
{#snippet children({ mark, scaledData, usedScales })}
|
|
66
|
+
{#snippet el(d)}
|
|
67
|
+
{@const title = resolveProp(args.title, d.datum, '')}
|
|
68
|
+
{@const geometry = resolveProp(args.geometry, d.datum, d.datum)}
|
|
69
|
+
{@const [style, styleClass] = resolveStyles(
|
|
70
|
+
plot,
|
|
71
|
+
d,
|
|
72
|
+
args,
|
|
73
|
+
GEOJSON_PREFER_STROKE.has(geometry.type) ? 'stroke' : 'fill',
|
|
74
|
+
usedScales
|
|
75
|
+
)}
|
|
76
|
+
<path
|
|
77
|
+
d={path(geometry)}
|
|
78
|
+
{style}
|
|
79
|
+
class={[styleClass]}
|
|
80
|
+
use:addEventHandlers={{
|
|
81
|
+
getPlotState,
|
|
82
|
+
options: args,
|
|
83
|
+
datum: d.datum
|
|
84
|
+
}}>
|
|
85
|
+
{#if title}<title>{title}</title>{/if}
|
|
86
|
+
</path>
|
|
87
|
+
{/snippet}
|
|
59
88
|
<g
|
|
60
89
|
aria-label="geo"
|
|
61
90
|
class={['geo', geoType && `geo-${geoType}`, className]}
|
|
62
91
|
style="fill:currentColor">
|
|
63
92
|
{#if canvas}
|
|
64
|
-
<GeoCanvas data={
|
|
93
|
+
<GeoCanvas data={scaledData} {path} {mark} {usedScales} />
|
|
65
94
|
{:else}
|
|
66
|
-
{#each
|
|
67
|
-
{#if
|
|
68
|
-
{#snippet el(datum)}
|
|
69
|
-
{@const title = resolveProp(args.title, datum, '')}
|
|
70
|
-
{@const geometry = resolveProp(args.geometry, datum, datum)}
|
|
71
|
-
<path
|
|
72
|
-
d={path(geometry)}
|
|
73
|
-
style={resolveScaledStyles(
|
|
74
|
-
datum,
|
|
75
|
-
args,
|
|
76
|
-
usedScales,
|
|
77
|
-
plot,
|
|
78
|
-
preferStroke.has(geometry.type) ? 'stroke' : 'fill'
|
|
79
|
-
)}
|
|
80
|
-
use:addEventHandlers={{
|
|
81
|
-
getPlotState,
|
|
82
|
-
options: args,
|
|
83
|
-
datum
|
|
84
|
-
}}>
|
|
85
|
-
{#if title}<title>{title}</title>{/if}
|
|
86
|
-
</path>
|
|
87
|
-
{/snippet}
|
|
95
|
+
{#each scaledData as d}
|
|
96
|
+
{#if d.valid}
|
|
88
97
|
{#if options.href}
|
|
89
98
|
<a
|
|
90
|
-
href={resolveProp(args.href, datum, '')}
|
|
91
|
-
target={resolveProp(args.target, datum, '_self')}>
|
|
92
|
-
{@render el(
|
|
99
|
+
href={resolveProp(args.href, d.datum, '')}
|
|
100
|
+
target={resolveProp(args.target, d.datum, '_self')}>
|
|
101
|
+
{@render el(d)}
|
|
93
102
|
</a>
|
|
94
103
|
{:else}
|
|
95
|
-
{@render el(
|
|
104
|
+
{@render el(d)}
|
|
96
105
|
{/if}
|
|
97
106
|
{/if}
|
|
98
107
|
{/each}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { DataRecord, BaseMarkProps } from '../types.js';
|
|
1
|
+
import type { DataRecord, BaseMarkProps, ConstantAccessor } from '../types.js';
|
|
2
2
|
type GeoMarkProps = {
|
|
3
3
|
data: DataRecord[];
|
|
4
4
|
geoType?: 'sphere' | 'graticule';
|
|
5
5
|
dragRotate: boolean;
|
|
6
6
|
canvas: boolean;
|
|
7
|
+
href: ConstantAccessor<string>;
|
|
8
|
+
target: ConstantAccessor<string>;
|
|
7
9
|
} & BaseMarkProps;
|
|
8
10
|
declare const Geo: import("svelte").Component<GeoMarkProps, {}, "">;
|
|
9
11
|
type Geo = ReturnType<typeof Geo>;
|
package/dist/marks/GridX.svelte
CHANGED
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
|
|
40
40
|
<Mark
|
|
41
41
|
type="gridX"
|
|
42
|
-
data={data.length ? data.map((tick) => ({
|
|
42
|
+
data={data.length ? data.map((tick) => ({ [RAW_VALUE]: tick })) : []}
|
|
43
43
|
channels={['y1', 'y2', 'x', 'stroke', 'strokeOpacity']}
|
|
44
|
-
{...{ ...options, x:
|
|
44
|
+
{...{ ...options, x: RAW_VALUE }}
|
|
45
45
|
{automatic}>
|
|
46
46
|
{#snippet children({ usedScales })}
|
|
47
47
|
<g class="grid-x">
|
package/dist/marks/GridY.svelte
CHANGED
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
|
|
37
37
|
<Mark
|
|
38
38
|
type="gridY"
|
|
39
|
-
data={data.length ? data.map((tick) => ({
|
|
39
|
+
data={data.length ? data.map((tick) => ({ [RAW_VALUE]: tick })) : []}
|
|
40
40
|
channels={['x1', 'x2', 'y', 'stroke', 'strokeOpacity']}
|
|
41
|
-
{...{ ...options, y:
|
|
41
|
+
{...{ ...options, y: RAW_VALUE }}
|
|
42
42
|
{automatic}>
|
|
43
43
|
{#snippet children({ usedScales })}
|
|
44
44
|
<g class="grid-y">
|
package/dist/marks/Line.svelte
CHANGED
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
data: DataRecord[];
|
|
19
19
|
z?: ChannelAccessor;
|
|
20
20
|
stroke?: ChannelAccessor;
|
|
21
|
-
outlineStroke?:
|
|
22
|
-
outlineStrokeWidth?:
|
|
21
|
+
outlineStroke?: string;
|
|
22
|
+
outlineStrokeWidth?: number;
|
|
23
|
+
outlineStrokeOpacity?: number;
|
|
23
24
|
dx?: ConstantAccessor<number>;
|
|
24
25
|
dy?: ConstantAccessor<number>;
|
|
25
26
|
curve?: CurveName | CurveFactory;
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
textStartOffset?: ConstantAccessor<string>;
|
|
32
33
|
textStrokeWidth?: ConstantAccessor<number>;
|
|
33
34
|
lineClass?: ConstantAccessor<string>;
|
|
35
|
+
canvas?: boolean;
|
|
34
36
|
} & MarkerOptions;
|
|
35
37
|
</script>
|
|
36
38
|
|
|
@@ -39,11 +41,12 @@
|
|
|
39
41
|
import MarkerPath from './helpers/MarkerPath.svelte';
|
|
40
42
|
import { getContext } from 'svelte';
|
|
41
43
|
import { resolveProp, resolveStyles } from '../helpers/resolve.js';
|
|
42
|
-
import { line, type CurveFactory } from 'd3-shape';
|
|
44
|
+
import { line, type CurveFactory, type Line } from 'd3-shape';
|
|
43
45
|
import { geoPath } from 'd3-geo';
|
|
44
46
|
import callWithProps from '../helpers/callWithProps.js';
|
|
45
47
|
import { maybeCurve } from '../helpers/curves.js';
|
|
46
48
|
import { pick } from 'es-toolkit';
|
|
49
|
+
import LineCanvas from './helpers/LineCanvas.svelte';
|
|
47
50
|
|
|
48
51
|
type LineMarkProps = BaseMarkProps & {
|
|
49
52
|
x?: ChannelAccessor;
|
|
@@ -61,6 +64,7 @@
|
|
|
61
64
|
curve = 'auto',
|
|
62
65
|
tension = 0,
|
|
63
66
|
text,
|
|
67
|
+
canvas = false,
|
|
64
68
|
class: className = null,
|
|
65
69
|
lineClass = null,
|
|
66
70
|
...options
|
|
@@ -96,9 +100,7 @@
|
|
|
96
100
|
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
97
101
|
const plot = $derived(getPlotState());
|
|
98
102
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const linePath: LinePath = $derived(
|
|
103
|
+
const linePath: Line<ScaledDataRecord> = $derived(
|
|
102
104
|
plot.scales.projection && curve === 'auto'
|
|
103
105
|
? sphereLine(plot.scales.projection)
|
|
104
106
|
: callWithProps(line, [], {
|
|
@@ -111,7 +113,7 @@
|
|
|
111
113
|
|
|
112
114
|
function sphereLine(projection) {
|
|
113
115
|
const path = geoPath(projection);
|
|
114
|
-
|
|
116
|
+
const fn = (lineData: ScaledDataRecord[]) => {
|
|
115
117
|
let line = [];
|
|
116
118
|
const lines = [line];
|
|
117
119
|
for (const { x, y } of lineData) {
|
|
@@ -125,6 +127,8 @@
|
|
|
125
127
|
}
|
|
126
128
|
return path({ type: 'MultiLineString', coordinates: lines });
|
|
127
129
|
};
|
|
130
|
+
fn.context = path.context;
|
|
131
|
+
return fn;
|
|
128
132
|
}
|
|
129
133
|
</script>
|
|
130
134
|
|
|
@@ -135,88 +139,102 @@
|
|
|
135
139
|
{...args}>
|
|
136
140
|
{#snippet children({ mark, usedScales, scaledData })}
|
|
137
141
|
{#if scaledData.length > 0}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
{@const groupedLineData = groupIndex(scaledData, groupByKey)};
|
|
143
|
+
{#if canvas}
|
|
144
|
+
<LineCanvas {groupedLineData} {mark} {usedScales} {linePath} {groupByKey} />
|
|
145
|
+
{:else}
|
|
146
|
+
<g class={['lines', className]}>
|
|
147
|
+
{#each groupedLineData as lineData, i}
|
|
148
|
+
{@const pathString = linePath(lineData)}
|
|
149
|
+
{#if pathString}
|
|
150
|
+
<GroupMultiple class={resolveProp(lineClass, lineData[0])}>
|
|
151
|
+
{#if options.outlineStroke}
|
|
152
|
+
{@const [outlineStyle, outlineStyleClass] = resolveStyles(
|
|
153
|
+
plot,
|
|
154
|
+
{ ...lineData[0], stroke: options.outlineStroke },
|
|
155
|
+
{
|
|
156
|
+
strokeLinejoin: 'round',
|
|
157
|
+
...args,
|
|
158
|
+
stroke: options.outlineStroke,
|
|
159
|
+
strokeOpacity: options.outlineStrokeOpacity ?? 1,
|
|
160
|
+
strokeWidth:
|
|
161
|
+
options.outlineStrokeWidth ||
|
|
162
|
+
resolveProp(
|
|
163
|
+
options.strokeWidth,
|
|
164
|
+
lineData[0].datum,
|
|
165
|
+
1.4
|
|
166
|
+
) + 2
|
|
167
|
+
},
|
|
168
|
+
'stroke',
|
|
169
|
+
usedScales
|
|
170
|
+
)}
|
|
171
|
+
<path
|
|
172
|
+
d={pathString}
|
|
173
|
+
style={outlineStyle}
|
|
174
|
+
class={['is-outline', outlineStyleClass]} />
|
|
175
|
+
{/if}
|
|
176
|
+
{@const [style, styleClass] = resolveStyles(
|
|
145
177
|
plot,
|
|
146
|
-
|
|
178
|
+
lineData[0],
|
|
147
179
|
{
|
|
180
|
+
strokeWidth: 1.4,
|
|
148
181
|
strokeLinejoin: 'round',
|
|
149
182
|
...args,
|
|
150
|
-
stroke:
|
|
151
|
-
strokeWidth:
|
|
152
|
-
options.outlineStrokeWidth ||
|
|
153
|
-
(+options.strokeWidth || 1.4) + 2
|
|
183
|
+
stroke: lineData[0].stroke
|
|
154
184
|
},
|
|
155
185
|
'stroke',
|
|
156
186
|
usedScales
|
|
157
187
|
)}
|
|
158
|
-
|
|
188
|
+
{@const [textStyle, textStyleClass] = resolveStyles(
|
|
189
|
+
plot,
|
|
190
|
+
lineData[0],
|
|
191
|
+
{
|
|
192
|
+
textAnchor: 'middle',
|
|
193
|
+
...pick(args, [
|
|
194
|
+
'fontSize',
|
|
195
|
+
'fontWeight',
|
|
196
|
+
'fontStyle',
|
|
197
|
+
'textAnchor'
|
|
198
|
+
]),
|
|
199
|
+
strokeWidth: args.textStrokeWidth
|
|
200
|
+
? args.textStrokeWidth
|
|
201
|
+
: args.textStroke
|
|
202
|
+
? 2
|
|
203
|
+
: 0,
|
|
204
|
+
fill: args.textFill || args.stroke,
|
|
205
|
+
stroke: args.textStroke
|
|
206
|
+
},
|
|
207
|
+
'fill',
|
|
208
|
+
usedScales,
|
|
209
|
+
true
|
|
210
|
+
)}
|
|
211
|
+
<MarkerPath
|
|
212
|
+
{mark}
|
|
213
|
+
scales={plot.scales}
|
|
214
|
+
markerStart={args.markerStart}
|
|
215
|
+
markerMid={args.markerMid}
|
|
216
|
+
markerEnd={args.markerEnd}
|
|
217
|
+
marker={args.marker}
|
|
218
|
+
strokeWidth={args.strokeWidth}
|
|
219
|
+
datum={lineData[0]}
|
|
159
220
|
d={pathString}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
lineData[0],
|
|
178
|
-
{
|
|
179
|
-
textAnchor: 'middle',
|
|
180
|
-
...pick(args, [
|
|
181
|
-
'fontSize',
|
|
182
|
-
'fontWeight',
|
|
183
|
-
'fontStyle',
|
|
184
|
-
'textAnchor'
|
|
185
|
-
]),
|
|
186
|
-
strokeWidth: args.textStrokeWidth
|
|
187
|
-
? args.textStrokeWidth
|
|
188
|
-
: args.textStroke
|
|
189
|
-
? 2
|
|
190
|
-
: 0,
|
|
191
|
-
fill: args.textFill || args.stroke,
|
|
192
|
-
stroke: args.textStroke
|
|
193
|
-
},
|
|
194
|
-
'fill',
|
|
195
|
-
usedScales,
|
|
196
|
-
true
|
|
197
|
-
)}
|
|
198
|
-
<MarkerPath
|
|
199
|
-
{mark}
|
|
200
|
-
scales={plot.scales}
|
|
201
|
-
markerStart={args.markerStart}
|
|
202
|
-
markerMid={args.markerMid}
|
|
203
|
-
markerEnd={args.markerEnd}
|
|
204
|
-
marker={args.marker}
|
|
205
|
-
strokeWidth={args.strokeWidth}
|
|
206
|
-
datum={lineData[0]}
|
|
207
|
-
d={pathString}
|
|
208
|
-
dInv={text ? linePath(lineData.toReversed()) : null}
|
|
209
|
-
color={lineData[0].stroke || 'currentColor'}
|
|
210
|
-
{style}
|
|
211
|
-
class={styleClass}
|
|
212
|
-
text={text ? resolveProp(text, lineData[0]) : null}
|
|
213
|
-
startOffset={resolveProp(args.textStartOffset, lineData[0], '50%')}
|
|
214
|
-
{textStyle}
|
|
215
|
-
{textStyleClass} />
|
|
216
|
-
</GroupMultiple>
|
|
217
|
-
{/if}
|
|
218
|
-
{/each}
|
|
219
|
-
</g>
|
|
221
|
+
dInv={text ? linePath(lineData.toReversed()) : null}
|
|
222
|
+
color={lineData[0].stroke || 'currentColor'}
|
|
223
|
+
{style}
|
|
224
|
+
class={styleClass}
|
|
225
|
+
text={text ? resolveProp(text, lineData[0]) : null}
|
|
226
|
+
startOffset={resolveProp(
|
|
227
|
+
args.textStartOffset,
|
|
228
|
+
lineData[0],
|
|
229
|
+
'50%'
|
|
230
|
+
)}
|
|
231
|
+
{textStyle}
|
|
232
|
+
{textStyleClass} />
|
|
233
|
+
</GroupMultiple>
|
|
234
|
+
{/if}
|
|
235
|
+
{/each}
|
|
236
|
+
</g>
|
|
237
|
+
{/if}
|
|
220
238
|
{/if}
|
|
221
239
|
{/snippet}
|
|
222
240
|
</Mark>
|
|
@@ -3,8 +3,9 @@ export type BaseLineMarkProps = {
|
|
|
3
3
|
data: DataRecord[];
|
|
4
4
|
z?: ChannelAccessor;
|
|
5
5
|
stroke?: ChannelAccessor;
|
|
6
|
-
outlineStroke?:
|
|
7
|
-
outlineStrokeWidth?:
|
|
6
|
+
outlineStroke?: string;
|
|
7
|
+
outlineStrokeWidth?: number;
|
|
8
|
+
outlineStrokeOpacity?: number;
|
|
8
9
|
dx?: ConstantAccessor<number>;
|
|
9
10
|
dy?: ConstantAccessor<number>;
|
|
10
11
|
curve?: CurveName | CurveFactory;
|
|
@@ -18,8 +19,9 @@ export type BaseLineMarkProps = {
|
|
|
18
19
|
textStartOffset?: ConstantAccessor<string>;
|
|
19
20
|
textStrokeWidth?: ConstantAccessor<number>;
|
|
20
21
|
lineClass?: ConstantAccessor<string>;
|
|
22
|
+
canvas?: boolean;
|
|
21
23
|
} & MarkerOptions;
|
|
22
|
-
import { type CurveFactory } from 'd3-shape';
|
|
24
|
+
import { type CurveFactory, type Line } from 'd3-shape';
|
|
23
25
|
import type { RawValue } from '../types.js';
|
|
24
26
|
type LineMarkProps = BaseMarkProps & {
|
|
25
27
|
x?: ChannelAccessor;
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
import { quadtree } from 'd3-quadtree';
|
|
32
32
|
import { projectXY } from '../helpers/scales.js';
|
|
33
33
|
import isDataRecord from '../helpers/isDataRecord.js';
|
|
34
|
+
import { RAW_VALUE } from '../transforms/recordize.js';
|
|
34
35
|
|
|
35
36
|
let {
|
|
36
37
|
data = [{}],
|
|
@@ -109,7 +110,7 @@
|
|
|
109
110
|
true
|
|
110
111
|
);
|
|
111
112
|
return {
|
|
112
|
-
...(isDataRecord(d) ? d : {
|
|
113
|
+
...(isDataRecord(d) ? d : { [RAW_VALUE]: d }),
|
|
113
114
|
__pointerX: px,
|
|
114
115
|
__pointerY: py
|
|
115
116
|
};
|
package/dist/marks/Rect.svelte
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
} from '../types.js';
|
|
18
18
|
import { addEventHandlers } from './helpers/events.js';
|
|
19
19
|
import GroupMultiple from './helpers/GroupMultiple.svelte';
|
|
20
|
+
import RectPath from './helpers/RectPath.svelte';
|
|
20
21
|
|
|
21
22
|
type RectMarkProps = BaseMarkProps & {
|
|
22
23
|
data: DataRecord[];
|
|
@@ -57,31 +58,16 @@
|
|
|
57
58
|
{@const maxy = Math.max(y1, y2)}
|
|
58
59
|
{@const minx = Math.min(x1, x2)}
|
|
59
60
|
{@const maxx = Math.max(x1, x2)}
|
|
60
|
-
{@const inset = resolveProp(args.inset, d.datum, 0)}
|
|
61
|
-
{@const insetLeft = resolveProp(args.insetLeft, d.datum)}
|
|
62
|
-
{@const insetRight = resolveProp(args.insetRight, d.datum)}
|
|
63
|
-
{@const insetTop = resolveProp(args.insetTop, d.datum)}
|
|
64
|
-
{@const insetBottom = resolveProp(args.insetBottom, d.datum)}
|
|
65
|
-
{@const insetL = maybeNumber(coalesce(insetLeft, inset, 0)) ?? 0}
|
|
66
|
-
{@const insetT = maybeNumber(coalesce(insetTop, inset, 0)) ?? 0}
|
|
67
|
-
{@const insetR = maybeNumber(coalesce(insetRight, inset, 0)) ?? 0}
|
|
68
|
-
{@const insetB = maybeNumber(coalesce(insetBottom, inset, 0)) ?? 0}
|
|
69
61
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
class={
|
|
73
|
-
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
ry={resolveProp(args.ry, d.datum, null)}
|
|
80
|
-
use:addEventHandlers={{
|
|
81
|
-
getPlotState,
|
|
82
|
-
options: args,
|
|
83
|
-
datum: d.datum
|
|
84
|
-
}} />
|
|
62
|
+
<RectPath
|
|
63
|
+
datum={d}
|
|
64
|
+
class={scaledData.length === 1 ? className : null}
|
|
65
|
+
x={minx}
|
|
66
|
+
y={miny}
|
|
67
|
+
width={maxx - minx}
|
|
68
|
+
height={maxy - miny}
|
|
69
|
+
options={args}
|
|
70
|
+
{usedScales} />
|
|
85
71
|
{/if}
|
|
86
72
|
{/each}
|
|
87
73
|
</GroupMultiple>
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
plot
|
|
6
|
-
}: {
|
|
7
|
-
canvas: HTMLCanvasElement;
|
|
8
|
-
devicePixelRatio: number;
|
|
9
|
-
plot: PlotState;
|
|
10
|
-
} = $props();
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import type { PlotContext } from '../../types';
|
|
4
|
+
import { devicePixelRatio } from 'svelte/reactivity/window';
|
|
11
5
|
|
|
12
|
-
$
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
let restProps: {} = $props();
|
|
7
|
+
|
|
8
|
+
const { getPlotState } = getContext<PlotContext>('svelteplot');
|
|
9
|
+
const plot = $derived(getPlotState());
|
|
16
10
|
</script>
|
|
17
11
|
|
|
18
12
|
<!--
|
|
@@ -24,9 +18,9 @@
|
|
|
24
18
|
<foreignObject x="0" y="0" width={plot.width} height={plot.height}>
|
|
25
19
|
<canvas
|
|
26
20
|
xmlns="http://www.w3.org/1999/xhtml"
|
|
27
|
-
|
|
28
|
-
width={plot.width * devicePixelRatio}
|
|
29
|
-
height={plot.height * devicePixelRatio}
|
|
21
|
+
{...restProps}
|
|
22
|
+
width={plot.width * (devicePixelRatio.current ?? 1)}
|
|
23
|
+
height={plot.height * (devicePixelRatio.current ?? 1)}
|
|
30
24
|
style="width: {plot.width}px; height: {plot.height}px;"></canvas>
|
|
31
25
|
</foreignObject>
|
|
32
26
|
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
type $$ComponentProps = {
|
|
2
|
-
canvas: HTMLCanvasElement;
|
|
3
|
-
devicePixelRatio: number;
|
|
4
|
-
plot: PlotState;
|
|
5
|
-
};
|
|
1
|
+
type $$ComponentProps = {};
|
|
6
2
|
/**
|
|
7
3
|
* The CanvasLayer component is a helper component that inserts a
|
|
8
4
|
* canvas element inside a foreignObject for use in a plot and takes care of
|
|
9
5
|
* scaling it to the device pixel ratio.
|
|
10
6
|
*/
|
|
11
|
-
declare const CanvasLayer: import("svelte").Component<$$ComponentProps, {}, "
|
|
7
|
+
declare const CanvasLayer: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
12
8
|
type CanvasLayer = ReturnType<typeof CanvasLayer>;
|
|
13
9
|
export default CanvasLayer;
|