@octane-xplat/charts 0.14.0 → 0.16.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/package.json +14 -14
- package/src/Chart.macos.tsrx +24 -39
- package/src/Chart.tsrx +33 -54
- package/src/core/hit.ts +25 -10
- package/src/core/marks.ts +23 -21
- package/src/core/scales.ts +4 -0
- package/src/core/svg.ts +1 -1
- package/src/style-merge.ts +61 -0
- package/dist/macos/Chart.macos.tsrx.js +0 -351
- package/dist/macos/core/axes.js +0 -146
- package/dist/macos/core/hit.js +0 -131
- package/dist/macos/core/marks.js +0 -262
- package/dist/macos/core/scales.js +0 -99
- package/dist/macos/core/scene.js +0 -120
- package/dist/macos/core/svg.js +0 -40
- package/dist/macos/index.js +0 -2
- package/dist/macos/octane-client-build.json +0 -8
- package/dist/macos/svg-image.macos.js +0 -14
- package/dist/native/Chart.tsrx.js +0 -340
- package/dist/native/core/axes.js +0 -146
- package/dist/native/core/hit.js +0 -131
- package/dist/native/core/marks.js +0 -262
- package/dist/native/core/scales.js +0 -99
- package/dist/native/core/scene.js +0 -120
- package/dist/native/core/svg.js +0 -40
- package/dist/native/index.js +0 -2
- package/dist/native/octane-client-build.json +0 -8
- package/dist/web/Chart.web.tsrx.js +0 -493
- package/dist/web/core/axes.js +0 -146
- package/dist/web/core/hit.js +0 -131
- package/dist/web/core/marks.js +0 -262
- package/dist/web/core/scales.js +0 -99
- package/dist/web/core/scene.js +0 -120
- package/dist/web/core/svg.js +0 -40
- package/dist/web/index.js +0 -2
- package/dist/web/octane-client-build.json +0 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octane-xplat/charts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Cross-platform SVG charts for Octane xplat — a DOM-free d3 core with web, iOS/Android, and macOS AppKit leaves",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"android",
|
|
@@ -24,21 +24,22 @@
|
|
|
24
24
|
"directory": "packages/charts"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"dist",
|
|
28
27
|
"types",
|
|
29
|
-
"src"
|
|
28
|
+
"src",
|
|
29
|
+
"!src/**/*.test.*",
|
|
30
|
+
"!src/**/*.spec.*"
|
|
30
31
|
],
|
|
31
32
|
"type": "module",
|
|
32
33
|
"exports": {
|
|
33
34
|
".": {
|
|
34
35
|
"macos": {
|
|
35
36
|
"types": "./types/index.d.ts",
|
|
36
|
-
"default": "./
|
|
37
|
+
"default": "./src/index.macos.ts"
|
|
37
38
|
},
|
|
38
39
|
"types": "./types/index.d.ts",
|
|
39
|
-
"web": "./
|
|
40
|
-
"native": "./
|
|
41
|
-
"default": "./
|
|
40
|
+
"web": "./src/index.web.ts",
|
|
41
|
+
"native": "./src/index.ts",
|
|
42
|
+
"default": "./src/index.ts"
|
|
42
43
|
}
|
|
43
44
|
},
|
|
44
45
|
"publishConfig": {
|
|
@@ -52,10 +53,10 @@
|
|
|
52
53
|
"d3-time-format": "4.1.0"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"@nativescript-community/octane": "0.2.
|
|
56
|
+
"@nativescript-community/octane": "0.2.5",
|
|
56
57
|
"@nativescript/core": "9.1.3",
|
|
57
|
-
"@octane-xplat/macos-renderer": "0.
|
|
58
|
-
"@octane-xplat/ui": "0.
|
|
58
|
+
"@octane-xplat/macos-renderer": "0.16.0",
|
|
59
|
+
"@octane-xplat/ui": "0.16.0",
|
|
59
60
|
"@octanejs/vite-plugin": "0.1.61",
|
|
60
61
|
"@tsrx/typescript-plugin": "0.4.11",
|
|
61
62
|
"@types/d3-array": "3.2.2",
|
|
@@ -64,10 +65,10 @@
|
|
|
64
65
|
"@types/d3-shape": "3.2.0",
|
|
65
66
|
"@types/d3-time-format": "4.0.3",
|
|
66
67
|
"octane": "0.11.0",
|
|
67
|
-
"tsrx-typegen": "0.
|
|
68
|
+
"tsrx-typegen": "0.3.1",
|
|
68
69
|
"typescript": "5.9.3",
|
|
69
70
|
"vite": "8.3.0",
|
|
70
|
-
"vitest": "
|
|
71
|
+
"vitest": "4.1.11"
|
|
71
72
|
},
|
|
72
73
|
"peerDependencies": {
|
|
73
74
|
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
@@ -84,9 +85,8 @@
|
|
|
84
85
|
}
|
|
85
86
|
},
|
|
86
87
|
"scripts": {
|
|
87
|
-
"build": "vite build && vite build --mode native && vite build --mode macos && pnpm typegen && node ../../scripts/check-native-dist.mjs",
|
|
88
88
|
"typegen": "tsc -p tsconfig.types.json",
|
|
89
|
-
"typecheck": "
|
|
89
|
+
"typecheck": "node ../../scripts/typecheck.ts",
|
|
90
90
|
"test": "vitest run",
|
|
91
91
|
"test:packed": "node tests/packed-consumer.mjs",
|
|
92
92
|
"pack:check": "tsrx-typegen --pack-check"
|
package/src/Chart.macos.tsrx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsxImportSource @octane-xplat/macos-renderer */
|
|
2
|
+
import { mergeStyle } from './style-merge'
|
|
2
3
|
import { useMemo, useRef, useState } from 'octane';
|
|
3
4
|
import { appKitImageSource } from './svg-image.macos';
|
|
4
5
|
import { useMeasure } from '@octane-xplat/ui';
|
|
@@ -70,65 +71,49 @@ export function Chart(props: ChartProps) @{
|
|
|
70
71
|
const tipLeft = cursor && scene ? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth)) : 0;
|
|
71
72
|
const tipTop = cursor ? cursor.py - 30 : 0;
|
|
72
73
|
|
|
73
|
-
<
|
|
74
|
-
id={props.id}
|
|
75
|
-
className={props.className}
|
|
76
|
-
style={{ flexDirection: 'column', ...props.style }}
|
|
77
|
-
accessible={props.accessibilityLabel != null}
|
|
78
|
-
accessibilityRole={'image'}
|
|
79
|
-
accessibilityLabel={props.accessibilityLabel}
|
|
80
|
-
>
|
|
74
|
+
<masonview id={props.id} className={props.className} style={{display: "flex", ...({ flexDirection: 'column', ...props.style })}} accessible={props.accessibilityLabel != null} accessibilityRole={'image'} accessibilityLabel={props.accessibilityLabel}>
|
|
81
75
|
@if (legend === 'top' && scene) {
|
|
82
|
-
<
|
|
76
|
+
<masonview style={mergeStyle({flexDirection: "row", flexWrap: "wrap"}, {display: "flex", ...({ paddingBottom: 4 })})}>
|
|
83
77
|
{scene.legend.map((item) => (
|
|
84
|
-
<
|
|
85
|
-
<
|
|
78
|
+
<masonview style={mergeStyle({flexDirection: "row", alignItems: "center"}, {display: "flex", ...({ marginRight: 12 })})}>
|
|
79
|
+
<masonview style={{display: "flex", ...({ width: 10, height: 10, borderRadius: 2, backgroundColor: item.color, marginRight: 4 })}}/>
|
|
86
80
|
<label text={item.text} style={{ fontSize: 11 }} />
|
|
87
|
-
</
|
|
81
|
+
</masonview>
|
|
88
82
|
))}
|
|
89
|
-
</
|
|
83
|
+
</masonview>
|
|
90
84
|
}
|
|
91
|
-
<
|
|
92
|
-
ref={measure.ref}
|
|
93
|
-
style={{
|
|
85
|
+
<masonview ref={measure.ref} style={{display: "grid", ...({
|
|
94
86
|
width: props.width,
|
|
95
87
|
height: props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : undefined),
|
|
96
88
|
flexGrow: 1,
|
|
97
|
-
}}
|
|
98
|
-
>
|
|
89
|
+
})}}>
|
|
99
90
|
<image id={props.id ? props.id + '-image' : undefined} src={imageSource} style={{ width: w, height: h }} accessibilityLabel="" />
|
|
100
|
-
<
|
|
101
|
-
<
|
|
102
|
-
id={props.id ? props.id + '-overlay' : undefined}
|
|
103
|
-
style={{ width: w, height: h }}
|
|
104
|
-
>
|
|
91
|
+
<masonview id={props.id ? props.id + '-tap' : undefined} style={{display: "flex", ...({ width: w, height: h })}} onTap={interactive ? onTap : undefined}>
|
|
92
|
+
<masonview id={props.id ? props.id + '-overlay' : undefined} style={{ width: w, height: h }}>
|
|
105
93
|
{scene?.labels.map((l) => (
|
|
106
|
-
<label
|
|
107
|
-
text={l.text}
|
|
108
|
-
{...{ left: l.x, top: l.y }} style={{ width: l.width, fontSize: 10, opacity: 0.7, textAlign: l.align === 'center' ? 'center' : l.align === 'end' ? 'right' : 'left' }}
|
|
109
|
-
/>
|
|
94
|
+
<label text={l.text} {...{ left: l.x, top: l.y }} style={{ width: l.width, fontSize: 10, opacity: 0.7, textAlign: l.align === 'center' ? 'center' : l.align === 'end' ? 'right' : 'left' , position: 'absolute'}} />
|
|
110
95
|
))}
|
|
111
96
|
@if (cursor && props.crosshair && !scene?.pie && plot) {
|
|
112
|
-
<
|
|
97
|
+
<masonview style={{display: "flex", ...({ width: 1, height: plot.height, backgroundColor: '#8a8a8a' , position: 'absolute', left: cursor.px - 0.5, top: plot.y})}}/>
|
|
113
98
|
}
|
|
114
99
|
@if (cursor && (props.crosshair || props.tooltip)) {
|
|
115
|
-
<
|
|
100
|
+
<masonview style={{display: "flex", ...({ width: 8, height: 8, borderRadius: 4, backgroundColor: dotColor ?? '#4e79a7' , position: 'absolute', left: cursor.px - 4, top: cursor.py - 4})}}/>
|
|
116
101
|
}
|
|
117
102
|
@if (cursor && props.tooltip && tipText) {
|
|
118
|
-
<label id={props.id ? props.id + '-tooltip' : undefined} text={tipText} {...{ left: tipLeft, top: tipTop < 0 ? cursor.py + 12 : tipTop }} style={{ width: tipWidth, height: 24, backgroundColor: 'rgba(20,20,20,0.88)', borderRadius: 4, color: '#ffffff', fontSize: 11, textAlign: 'center' }} />
|
|
103
|
+
<label id={props.id ? props.id + '-tooltip' : undefined} text={tipText} {...{ left: tipLeft, top: tipTop < 0 ? cursor.py + 12 : tipTop }} style={{ width: tipWidth, height: 24, backgroundColor: 'rgba(20,20,20,0.88)', borderRadius: 4, color: '#ffffff', fontSize: 11, textAlign: 'center' , position: 'absolute'}} />
|
|
119
104
|
}
|
|
120
|
-
</
|
|
121
|
-
</
|
|
122
|
-
</
|
|
105
|
+
</masonview>
|
|
106
|
+
</masonview>
|
|
107
|
+
</masonview>
|
|
123
108
|
@if (legend === 'bottom' && scene) {
|
|
124
|
-
<
|
|
109
|
+
<masonview style={mergeStyle({flexDirection: "row", flexWrap: "wrap"}, {display: "flex", ...({ paddingTop: 4 })})}>
|
|
125
110
|
{scene.legend.map((item) => (
|
|
126
|
-
<
|
|
127
|
-
<
|
|
111
|
+
<masonview style={mergeStyle({flexDirection: "row", alignItems: "center"}, {display: "flex", ...({ marginRight: 12 })})}>
|
|
112
|
+
<masonview style={{display: "flex", ...({ width: 10, height: 10, borderRadius: 2, backgroundColor: item.color, marginRight: 4 })}}/>
|
|
128
113
|
<label text={item.text} style={{ fontSize: 11 }} />
|
|
129
|
-
</
|
|
114
|
+
</masonview>
|
|
130
115
|
))}
|
|
131
|
-
</
|
|
116
|
+
</masonview>
|
|
132
117
|
}
|
|
133
|
-
</
|
|
118
|
+
</masonview>
|
|
134
119
|
}
|
package/src/Chart.tsrx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsxImportSource @nativescript-community/octane */
|
|
2
|
+
import { mergeStyle } from './style-merge'
|
|
2
3
|
import { useMemo, useRef, useState } from 'octane';
|
|
3
4
|
import { AccessibilityRole, Color } from '@nativescript/core';
|
|
4
5
|
import { useMeasure } from '@octane-xplat/ui';
|
|
@@ -11,6 +12,16 @@ import type { SceneHit } from './core/hit';
|
|
|
11
12
|
const EMPTY_SVG = '<svg xmlns="http://www.w3.org/2000/svg"/>';
|
|
12
13
|
const TIP_ESTIMATE_CHAR = 6.2;
|
|
13
14
|
|
|
15
|
+
// Color throws on unparseable input — user-controlled palette strings
|
|
16
|
+
// degrade to the fallback like a browser dropping a bad CSS value.
|
|
17
|
+
const safeColor = (value: string | undefined, fallback: string): Color => {
|
|
18
|
+
try {
|
|
19
|
+
return new Color(value ?? fallback);
|
|
20
|
+
} catch {
|
|
21
|
+
return new Color(fallback);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
14
25
|
/** Chart — NativeScript leaf. The core's Mark[] serialize to one svg markup
|
|
15
26
|
* string fed to `<svgview>` (vendored ui-svg → SVGKit/androidsvg — its
|
|
16
27
|
* registration arrives transitively through `@octane-xplat/ui`'s native
|
|
@@ -94,81 +105,49 @@ export function Chart(props: ChartProps) @{
|
|
|
94
105
|
const tipLeft = cursor && scene ? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth)) : 0;
|
|
95
106
|
const tipTop = cursor ? cursor.py - 30 : 0;
|
|
96
107
|
|
|
97
|
-
<
|
|
98
|
-
id={props.id}
|
|
99
|
-
className={props.className}
|
|
100
|
-
style={{ flexDirection: 'column', ...props.style }}
|
|
101
|
-
accessible={props.accessibilityLabel != null}
|
|
102
|
-
accessibilityRole={AccessibilityRole.Image}
|
|
103
|
-
accessibilityLabel={props.accessibilityLabel}
|
|
104
|
-
>
|
|
108
|
+
<masonview id={props.id} className={props.className} style={{display: "flex", ...({ flexDirection: 'column', ...props.style })}} accessible={props.accessibilityLabel != null} accessibilityRole={AccessibilityRole.Image} accessibilityLabel={props.accessibilityLabel}>
|
|
105
109
|
@if (legend === 'top' && scene) {
|
|
106
|
-
<
|
|
110
|
+
<masonview style={mergeStyle({flexDirection: "row", flexWrap: "wrap"}, {display: "flex", ...({ paddingBottom: 4 })})}>
|
|
107
111
|
{scene.legend.map((item) => (
|
|
108
|
-
<
|
|
109
|
-
<contentview style={{ width: 10, height: 10, borderRadius: 2, backgroundColor:
|
|
112
|
+
<masonview style={mergeStyle({flexDirection: "row", alignItems: "center"}, {display: "flex", ...({ marginRight: 12 })})}>
|
|
113
|
+
<contentview style={{ width: 10, height: 10, borderRadius: 2, backgroundColor: safeColor(item.color, 'transparent'), marginRight: 4 }} />
|
|
110
114
|
<label text={item.text} style={{ fontSize: 11 }} />
|
|
111
|
-
</
|
|
115
|
+
</masonview>
|
|
112
116
|
))}
|
|
113
|
-
</
|
|
117
|
+
</masonview>
|
|
114
118
|
}
|
|
115
|
-
<
|
|
116
|
-
ref={measure.ref}
|
|
117
|
-
style={{
|
|
119
|
+
<masonview ref={measure.ref} style={{display: "grid", ...({
|
|
118
120
|
width: props.width,
|
|
119
121
|
height: props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : undefined),
|
|
120
122
|
flexGrow: 1,
|
|
121
|
-
}}
|
|
122
|
-
>
|
|
123
|
+
})}}>
|
|
123
124
|
<svgview src={scene?.markup ?? EMPTY_SVG} stretch="aspectFit" style={{ width: w, height: h }} />
|
|
124
|
-
<
|
|
125
|
-
id={props.id ? props.id + '-overlay' : undefined}
|
|
126
|
-
style={{ width: w, height: h }}
|
|
127
|
-
isUserInteractionEnabled={interactive}
|
|
128
|
-
onTouch={interactive ? onTouch : undefined}
|
|
129
|
-
onTap={interactive ? onTap : undefined}
|
|
130
|
-
>
|
|
125
|
+
<masonview id={props.id ? props.id + '-overlay' : undefined} style={{ width: w, height: h }} isUserInteractionEnabled={interactive} onTouch={interactive ? onTouch : undefined} onTap={interactive ? onTap : undefined}>
|
|
131
126
|
{scene?.labels.map((l) => (
|
|
132
|
-
<label
|
|
133
|
-
left={l.x}
|
|
134
|
-
top={l.y}
|
|
135
|
-
width={l.width}
|
|
136
|
-
text={l.text}
|
|
137
|
-
textAlignment={l.align === 'center' ? 'center' : l.align === 'end' ? 'right' : 'left'}
|
|
138
|
-
style={{ fontSize: 10, opacity: 0.7 }}
|
|
139
|
-
/>
|
|
127
|
+
<label width={l.width} text={l.text} textAlignment={l.align === 'center' ? 'center' : l.align === 'end' ? 'right' : 'left'} style={{ fontSize: 10, opacity: 0.7 , position: 'absolute', left: l.x, top: l.y}} />
|
|
140
128
|
))}
|
|
141
129
|
@if (cursor && props.crosshair && !scene?.pie && plot) {
|
|
142
|
-
<contentview
|
|
130
|
+
<contentview width={1} height={plot.height} backgroundColor={new Color('#8a8a8a')} style={{position: 'absolute', left: cursor.px - 0.5, top: plot.y}} />
|
|
143
131
|
}
|
|
144
132
|
@if (cursor && (props.crosshair || props.tooltip)) {
|
|
145
|
-
<contentview
|
|
133
|
+
<contentview width={8} height={8} borderRadius={4} backgroundColor={safeColor(dotColor, '#4e79a7')} style={{position: 'absolute', left: cursor.px - 4, top: cursor.py - 4}} />
|
|
146
134
|
}
|
|
147
135
|
@if (cursor && props.tooltip && tipText) {
|
|
148
|
-
<
|
|
149
|
-
left={tipLeft}
|
|
150
|
-
top={tipTop < 0 ? cursor.py + 12 : tipTop}
|
|
151
|
-
backgroundColor={new Color('rgba(20,20,20,0.88)')}
|
|
152
|
-
borderRadius={4}
|
|
153
|
-
paddingTop={2}
|
|
154
|
-
paddingBottom={2}
|
|
155
|
-
paddingLeft={6}
|
|
156
|
-
paddingRight={6}
|
|
157
|
-
>
|
|
136
|
+
<masonview style={{display: "flex", position: 'absolute', left: tipLeft, top: tipTop < 0 ? cursor.py + 12 : tipTop, paddingTop: 2, paddingBottom: 2, paddingLeft: 6, paddingRight: 6}}>
|
|
158
137
|
<label text={tipText} color={new Color('#ffffff')} style={{ fontSize: 11 }} />
|
|
159
|
-
</
|
|
138
|
+
</masonview>
|
|
160
139
|
}
|
|
161
|
-
</
|
|
162
|
-
</
|
|
140
|
+
</masonview>
|
|
141
|
+
</masonview>
|
|
163
142
|
@if (legend === 'bottom' && scene) {
|
|
164
|
-
<
|
|
143
|
+
<masonview style={mergeStyle({flexDirection: "row", flexWrap: "wrap"}, {display: "flex", ...({ paddingTop: 4 })})}>
|
|
165
144
|
{scene.legend.map((item) => (
|
|
166
|
-
<
|
|
167
|
-
<contentview style={{ width: 10, height: 10, borderRadius: 2, backgroundColor:
|
|
145
|
+
<masonview style={mergeStyle({flexDirection: "row", alignItems: "center"}, {display: "flex", ...({ marginRight: 12 })})}>
|
|
146
|
+
<contentview style={{ width: 10, height: 10, borderRadius: 2, backgroundColor: safeColor(item.color, 'transparent'), marginRight: 4 }} />
|
|
168
147
|
<label text={item.text} style={{ fontSize: 11 }} />
|
|
169
|
-
</
|
|
148
|
+
</masonview>
|
|
170
149
|
))}
|
|
171
|
-
</
|
|
150
|
+
</masonview>
|
|
172
151
|
}
|
|
173
|
-
</
|
|
152
|
+
</masonview>
|
|
174
153
|
}
|
package/src/core/hit.ts
CHANGED
|
@@ -35,16 +35,37 @@ export function hitTest(scene: ChartScene, x: number, y: number, slop = HIT_SLOP
|
|
|
35
35
|
return null
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
if (scene.type === 'scatter') {
|
|
39
|
+
// Scatter is a point cloud, not a snapped axis — pick the datum
|
|
40
|
+
// nearest the pointer in 2D and miss when nothing is actually near.
|
|
41
|
+
let best: SceneHit | null = null
|
|
42
|
+
let bestDist = Infinity
|
|
43
|
+
for (const p of points) {
|
|
44
|
+
const d = Math.hypot(p.cx - x, p.cy - y)
|
|
45
|
+
if (d < bestDist) {
|
|
46
|
+
bestDist = d
|
|
47
|
+
best = { series: p.series, index: p.index, x: p.x, y: p.y, px: p.cx, py: p.cy }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return best !== null && bestDist <= slop ? best : null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const centers = new Map<string, { total: number; count: number }>()
|
|
39
55
|
for (const p of points) {
|
|
40
56
|
const cur = centers.get(p.key)
|
|
41
|
-
|
|
57
|
+
if (cur === undefined) {
|
|
58
|
+
centers.set(p.key, { total: p.cx, count: 1 })
|
|
59
|
+
} else {
|
|
60
|
+
cur.total += p.cx
|
|
61
|
+
cur.count += 1
|
|
62
|
+
}
|
|
42
63
|
}
|
|
43
64
|
|
|
44
65
|
let key: string | null = null
|
|
45
66
|
let keyDist = Infinity
|
|
46
|
-
for (const [k,
|
|
47
|
-
const d = Math.abs(
|
|
67
|
+
for (const [k, sum] of centers) {
|
|
68
|
+
const d = Math.abs(sum.total / sum.count - x)
|
|
48
69
|
if (d < keyDist) {
|
|
49
70
|
keyDist = d
|
|
50
71
|
key = k
|
|
@@ -69,12 +90,6 @@ export function hitTest(scene: ChartScene, x: number, y: number, slop = HIT_SLOP
|
|
|
69
90
|
}
|
|
70
91
|
}
|
|
71
92
|
|
|
72
|
-
// Scatter is a point cloud, not a snapped axis — miss when nothing is
|
|
73
|
-
// actually near the pointer.
|
|
74
|
-
if (best && scene.type === 'scatter' && bestDist > slop) {
|
|
75
|
-
return null
|
|
76
|
-
}
|
|
77
|
-
|
|
78
93
|
return best
|
|
79
94
|
}
|
|
80
95
|
|
package/src/core/marks.ts
CHANGED
|
@@ -107,7 +107,7 @@ export function buildMarks(
|
|
|
107
107
|
function lineMarks(layout: ChartLayout, series: ResolvedSeries[]): BuiltMarks {
|
|
108
108
|
const { xKind, x, y } = layout
|
|
109
109
|
const gen = linePath<ChartDatum>()
|
|
110
|
-
.defined((d) => Number.isFinite(d.y))
|
|
110
|
+
.defined((d) => Number.isFinite(d.y) && Number.isFinite(xCenter(xKind, x, d.x)))
|
|
111
111
|
.x((d) => xCenter(xKind, x, d.x))
|
|
112
112
|
.y((d) => y(d.y))
|
|
113
113
|
.curve(curveMonotoneX)
|
|
@@ -126,15 +126,13 @@ function lineMarks(layout: ChartLayout, series: ResolvedSeries[]): BuiltMarks {
|
|
|
126
126
|
})
|
|
127
127
|
|
|
128
128
|
s.values.forEach((d, i) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
y: d.y,
|
|
137
|
-
})
|
|
129
|
+
const cx = xCenter(xKind, x, d.x)
|
|
130
|
+
const cy = y(d.y)
|
|
131
|
+
if (!Number.isFinite(cx) || !Number.isFinite(cy)) {
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
points.push({ series: si, index: i, key: categoryKey(d.x), cx, cy, x: d.x, y: d.y })
|
|
138
136
|
})
|
|
139
137
|
})
|
|
140
138
|
|
|
@@ -144,15 +142,17 @@ function lineMarks(layout: ChartLayout, series: ResolvedSeries[]): BuiltMarks {
|
|
|
144
142
|
function areaMarks(layout: ChartLayout, series: ResolvedSeries[]): BuiltMarks {
|
|
145
143
|
const { xKind, x, y } = layout
|
|
146
144
|
const zero = y(Math.max(y.domain()[0], Math.min(0, y.domain()[1])))
|
|
145
|
+
const defined = (d: ChartDatum) => Number.isFinite(d.y) && Number.isFinite(xCenter(xKind, x, d.x))
|
|
146
|
+
|
|
147
147
|
const gen = areaPath<ChartDatum>()
|
|
148
|
-
.defined(
|
|
148
|
+
.defined(defined)
|
|
149
149
|
.x((d) => xCenter(xKind, x, d.x))
|
|
150
150
|
.y0(zero)
|
|
151
151
|
.y1((d) => y(d.y))
|
|
152
152
|
.curve(curveMonotoneX)
|
|
153
153
|
|
|
154
154
|
const stroke = linePath<ChartDatum>()
|
|
155
|
-
.defined(
|
|
155
|
+
.defined(defined)
|
|
156
156
|
.x((d) => xCenter(xKind, x, d.x))
|
|
157
157
|
.y((d) => y(d.y))
|
|
158
158
|
.curve(curveMonotoneX)
|
|
@@ -178,15 +178,13 @@ function areaMarks(layout: ChartLayout, series: ResolvedSeries[]): BuiltMarks {
|
|
|
178
178
|
})
|
|
179
179
|
|
|
180
180
|
s.values.forEach((d, i) => {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
y: d.y,
|
|
189
|
-
})
|
|
181
|
+
const cx = xCenter(xKind, x, d.x)
|
|
182
|
+
const cy = y(d.y)
|
|
183
|
+
if (!Number.isFinite(cx) || !Number.isFinite(cy)) {
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
points.push({ series: si, index: i, key: categoryKey(d.x), cx, cy, x: d.x, y: d.y })
|
|
190
188
|
})
|
|
191
189
|
})
|
|
192
190
|
|
|
@@ -201,6 +199,10 @@ function scatterMarks(layout: ChartLayout, series: ResolvedSeries[]): BuiltMarks
|
|
|
201
199
|
s.values.forEach((d, i) => {
|
|
202
200
|
const cx = xCenter(xKind, x, d.x)
|
|
203
201
|
const cy = y(d.y)
|
|
202
|
+
if (!Number.isFinite(cx) || !Number.isFinite(cy)) {
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
204
206
|
marks.push({
|
|
205
207
|
kind: 'circle',
|
|
206
208
|
cx,
|
package/src/core/scales.ts
CHANGED
|
@@ -122,6 +122,10 @@ export function yDomain(data: SeriesSpec[], type: ChartType, stacked: boolean):
|
|
|
122
122
|
const neg = new Map<string, number>()
|
|
123
123
|
for (const series of data) {
|
|
124
124
|
for (const d of series.values) {
|
|
125
|
+
if (!Number.isFinite(d.y)) {
|
|
126
|
+
continue
|
|
127
|
+
}
|
|
128
|
+
|
|
125
129
|
const key = String(d.x)
|
|
126
130
|
if (d.y >= 0) {
|
|
127
131
|
pos.set(key, (pos.get(key) ?? 0) + d.y)
|
package/src/core/svg.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { PlotBox } from './scales'
|
|
|
5
5
|
* subset: `<svg>`/`<g>` structure, path/rect/circle/line shapes, solid fills
|
|
6
6
|
* and strokes, `translate` transforms, opacity attributes. Never `<text>`,
|
|
7
7
|
* filters, masks, patterns, or gradients — labels are real elements in the
|
|
8
|
-
* leaf overlay (docs/notes/primitive-notes.md). */
|
|
8
|
+
* leaf overlay (.agents/docs/notes/primitive-notes.md). */
|
|
9
9
|
|
|
10
10
|
function num(v: number): string {
|
|
11
11
|
if (!Number.isFinite(v)) {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const kebab = (key: string) => key.replace(/[A-Z]/g, (c) => '-' + c.toLowerCase())
|
|
4
|
+
|
|
5
|
+
/** Anything accepted as a style value, including nested arrays. */
|
|
6
|
+
export type StyleInput =
|
|
7
|
+
| string
|
|
8
|
+
| Record<string, any>
|
|
9
|
+
| null
|
|
10
|
+
| undefined
|
|
11
|
+
| readonly StyleInput[]
|
|
12
|
+
|
|
13
|
+
/** Merge component-emitted style defaults under the authored `style` prop.
|
|
14
|
+
* Authored keys win; array styles fold in order; a string style is appended
|
|
15
|
+
* after the serialized defaults so its declarations override them too. */
|
|
16
|
+
export function mergeStyle(
|
|
17
|
+
base: Record<string, any>,
|
|
18
|
+
style?: Record<string, any> | readonly (Record<string, any> | null | undefined)[] | null,
|
|
19
|
+
): Record<string, any>
|
|
20
|
+
export function mergeStyle(
|
|
21
|
+
base: Record<string, any>,
|
|
22
|
+
style?: StyleInput,
|
|
23
|
+
): string | Record<string, any>
|
|
24
|
+
export function mergeStyle(
|
|
25
|
+
base: Record<string, any>,
|
|
26
|
+
style?: StyleInput,
|
|
27
|
+
): string | Record<string, any> {
|
|
28
|
+
if (style == null) {
|
|
29
|
+
return base
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let obj: Record<string, any> = { ...base }
|
|
33
|
+
const strings: string[] = []
|
|
34
|
+
const add = (s: StyleInput) => {
|
|
35
|
+
if (s == null) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
if (typeof s === 'string') {
|
|
39
|
+
strings.push(s)
|
|
40
|
+
} else if (Array.isArray(s)) {
|
|
41
|
+
for (const part of s) {
|
|
42
|
+
add(part)
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
obj = { ...obj, ...s }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
add(style)
|
|
49
|
+
|
|
50
|
+
if (strings.length === 0) {
|
|
51
|
+
return obj
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const prefix = Object.entries(obj)
|
|
55
|
+
.filter(([, v]) => v != null)
|
|
56
|
+
.map(([k, v]) => `${kebab(k)}:${v}`)
|
|
57
|
+
.join(';')
|
|
58
|
+
return [prefix, ...strings].filter(Boolean).join(';')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type StyleProp = string | Record<string, any> | readonly StyleProp[] | null | undefined
|