@octane-xplat/charts 0.19.0 → 0.20.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/README.md +2 -102
- package/package.json +14 -14
- package/src/Chart.macos.tsrx +248 -246
- package/src/Chart.tsrx +249 -247
- package/src/Chart.web.tsrx +236 -226
- package/src/appkit-pointer.macos.ts +91 -76
- package/src/core/axes.ts +175 -168
- package/src/core/hit.ts +197 -177
- package/src/core/marks.ts +336 -319
- package/src/core/scales.ts +128 -115
- package/src/core/scene.ts +123 -120
- package/src/core/svg.ts +52 -50
- package/src/index.macos.ts +7 -7
- package/src/index.ts +7 -7
- package/src/index.web.ts +7 -7
- package/src/props.ts +83 -83
- package/src/style-merge.ts +40 -37
- package/src/svg-image.macos.ts +21 -20
- package/types/generated/.tsrx-typegen-manifest.json +1 -7
- package/types/generated/Chart.macos.d.ts +0 -7
- package/types/generated/Chart.web.d.ts +0 -10
- package/types/generated/appkit-pointer.macos.d.ts +0 -37
- package/types/generated/index.macos.d.ts +0 -2
- package/types/generated/index.web.d.ts +0 -2
- package/types/generated/svg-image.macos.d.ts +0 -3
package/src/Chart.tsrx
CHANGED
|
@@ -15,11 +15,11 @@ const TIP_ESTIMATE_CHAR = 6.2
|
|
|
15
15
|
// Color throws on unparseable input — user-controlled palette strings
|
|
16
16
|
// degrade to the fallback like a browser dropping a bad CSS value.
|
|
17
17
|
const safeColor = (value: string | undefined, fallback: string): Color => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
try {
|
|
19
|
+
return new Color(value ?? fallback)
|
|
20
|
+
} catch {
|
|
21
|
+
return new Color(fallback)
|
|
22
|
+
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** Chart — NativeScript leaf. The core's Mark[] serialize to one svg markup
|
|
@@ -30,257 +30,259 @@ const safeColor = (value: string | undefined, fallback: string): Color => {
|
|
|
30
30
|
* the overlay reports view-relative dips (`e.getX()/getY()`), matching the
|
|
31
31
|
* markup's coordinate space. */
|
|
32
32
|
export function Chart(props: ChartProps): unknown @{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
propsRef.current = props
|
|
33
|
+
const measure = useMeasure()
|
|
34
|
+
const [cursor, setCursor] = useState<SceneHit | null>(null)
|
|
35
|
+
const sceneRef = useRef<ChartScene | null>(null)
|
|
36
|
+
const propsRef = useRef(props)
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
const w = props.width ?? bounds?.width ?? 0
|
|
41
|
-
const h =
|
|
42
|
-
props.height ??
|
|
43
|
-
(props.aspectRatio && w > 0
|
|
44
|
-
? w / props.aspectRatio
|
|
45
|
-
: bounds?.height && bounds.height > 0
|
|
46
|
-
? bounds.height
|
|
47
|
-
: w > 0
|
|
48
|
-
? w / 1.6
|
|
49
|
-
: 0)
|
|
38
|
+
propsRef.current = props
|
|
50
39
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
h,
|
|
63
|
-
],
|
|
64
|
-
)
|
|
40
|
+
const bounds = measure.bounds
|
|
41
|
+
const w = props.width ?? bounds?.width ?? 0
|
|
42
|
+
const h =
|
|
43
|
+
props.height ??
|
|
44
|
+
(props.aspectRatio && w > 0
|
|
45
|
+
? w / props.aspectRatio
|
|
46
|
+
: bounds?.height && bounds.height > 0
|
|
47
|
+
? bounds.height
|
|
48
|
+
: w > 0
|
|
49
|
+
? w / 1.6
|
|
50
|
+
: 0)
|
|
65
51
|
|
|
66
|
-
|
|
52
|
+
const scene = useMemo(
|
|
53
|
+
() => (w > 0 && h > 0 ? computeScene(propsRef.current, w, h) : null),
|
|
54
|
+
[
|
|
55
|
+
props.type,
|
|
56
|
+
props.data,
|
|
57
|
+
props.margin,
|
|
58
|
+
props.stacked,
|
|
59
|
+
props.innerRadiusRatio,
|
|
60
|
+
props.xAxis,
|
|
61
|
+
props.yAxis,
|
|
62
|
+
w,
|
|
63
|
+
h,
|
|
64
|
+
],
|
|
65
|
+
)
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
// Stable handler identity — the driver's prop apply subscribes `onTouch`
|
|
70
|
-
// per identity change, so the closure reads scene/props through refs.
|
|
71
|
-
const onTouch = useMemo(() => {
|
|
72
|
-
const scrub = createScrub(
|
|
73
|
-
() => sceneRef.current,
|
|
74
|
-
() => propsRef.current,
|
|
75
|
-
setCursor,
|
|
76
|
-
)
|
|
67
|
+
sceneRef.current = scene
|
|
77
68
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
const interactive = !!(props.onPress || props.onScrub || props.tooltip || props.crosshair)
|
|
70
|
+
// Stable handler identity — the driver's prop apply subscribes `onTouch`
|
|
71
|
+
// per identity change, so the closure reads scene/props through refs.
|
|
72
|
+
const onTouch = useMemo(() => {
|
|
73
|
+
const scrub = createScrub(
|
|
74
|
+
() => sceneRef.current,
|
|
75
|
+
() => propsRef.current,
|
|
76
|
+
setCursor,
|
|
77
|
+
)
|
|
82
78
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
() => sceneRef.current,
|
|
88
|
-
() => propsRef.current,
|
|
89
|
-
setCursor,
|
|
90
|
-
)
|
|
79
|
+
return (e: any) => {
|
|
80
|
+
scrub(e.action, e.getX(), e.getY())
|
|
81
|
+
}
|
|
82
|
+
}, [])
|
|
91
83
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
}, [])
|
|
84
|
+
// `tap` is the completed-press phase — NS's tap recognizer (and the probe
|
|
85
|
+
// harness's tap dispatch) reach onPress without a touch-sequence guess.
|
|
86
|
+
const onTap = useMemo(() => {
|
|
87
|
+
const scrub = createScrub(
|
|
88
|
+
() => sceneRef.current,
|
|
89
|
+
() => propsRef.current,
|
|
90
|
+
setCursor,
|
|
91
|
+
)
|
|
103
92
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
? scene.pie
|
|
109
|
-
? scene.pie.slices.find((s) => s.series === cursor.series && s.index === cursor.index)
|
|
110
|
-
?.color
|
|
111
|
-
: scene.series[cursor.series]?.color
|
|
112
|
-
: undefined
|
|
93
|
+
return (e: any) => {
|
|
94
|
+
// Probe harness taps dispatch with a synthetic event lacking
|
|
95
|
+
// getX/getY — fall back to the view center there.
|
|
96
|
+
const size = e.object?.getActualSize?.()
|
|
113
97
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
98
|
+
scrub(
|
|
99
|
+
'tap',
|
|
100
|
+
e.getX?.() ?? (size ? size.width / 2 : 0),
|
|
101
|
+
e.getY?.() ?? (size ? size.height / 2 : 0),
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
}, [])
|
|
120
105
|
|
|
121
|
-
|
|
106
|
+
const legend = props.legend === true ? 'bottom' : props.legend
|
|
107
|
+
const plot = scene?.plot
|
|
108
|
+
const dotColor =
|
|
109
|
+
cursor && scene
|
|
110
|
+
? scene.pie
|
|
111
|
+
? scene.pie.slices.find((s) => s.series === cursor.series && s.index === cursor.index)
|
|
112
|
+
?.color
|
|
113
|
+
: scene.series[cursor.series]?.color
|
|
114
|
+
: undefined
|
|
122
115
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
116
|
+
const tipText = cursor && scene ? hitLabel(scene, cursor) : null
|
|
117
|
+
const tipWidth = tipText ? tipText.length * TIP_ESTIMATE_CHAR + 14 : 0
|
|
118
|
+
const tipLeft =
|
|
119
|
+
cursor && scene
|
|
120
|
+
? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth))
|
|
121
|
+
: 0
|
|
122
|
+
|
|
123
|
+
const tipTop = cursor ? cursor.py - 30 : 0
|
|
124
|
+
|
|
125
|
+
<masonview
|
|
126
|
+
id={props.id}
|
|
127
|
+
className={props.className}
|
|
128
|
+
style={{
|
|
129
|
+
display: 'flex',
|
|
130
|
+
flexDirection: 'column',
|
|
131
|
+
...props.style,
|
|
132
|
+
}}
|
|
133
|
+
accessible={props.accessibilityLabel != null}
|
|
134
|
+
accessibilityRole={AccessibilityRole.Image}
|
|
135
|
+
accessibilityLabel={props.accessibilityLabel}
|
|
136
|
+
>
|
|
137
|
+
@if (legend === 'top' && scene) {
|
|
138
|
+
<masonview
|
|
139
|
+
style={mergeStyle(
|
|
140
|
+
{ flexDirection: 'row', flexWrap: 'wrap' },
|
|
141
|
+
{
|
|
142
|
+
display: 'flex',
|
|
143
|
+
paddingBottom: 4,
|
|
144
|
+
},
|
|
145
|
+
)}
|
|
146
|
+
>
|
|
147
|
+
{scene.legend.map((item) => (
|
|
148
|
+
<masonview
|
|
149
|
+
style={mergeStyle(
|
|
150
|
+
{ flexDirection: 'row', alignItems: 'center' },
|
|
151
|
+
{
|
|
152
|
+
display: 'flex',
|
|
153
|
+
marginRight: 12,
|
|
154
|
+
},
|
|
155
|
+
)}
|
|
156
|
+
>
|
|
157
|
+
<contentview
|
|
158
|
+
style={{
|
|
159
|
+
width: 10,
|
|
160
|
+
height: 10,
|
|
161
|
+
borderRadius: 2,
|
|
162
|
+
backgroundColor: safeColor(item.color, 'transparent'),
|
|
163
|
+
marginRight: 4,
|
|
164
|
+
}}
|
|
165
|
+
/>
|
|
166
|
+
<label text={item.text} style={{ fontSize: 11 }} />
|
|
167
|
+
</masonview>
|
|
168
|
+
))}
|
|
169
|
+
</masonview>
|
|
170
|
+
}
|
|
171
|
+
<masonview
|
|
172
|
+
ref={measure.ref}
|
|
173
|
+
style={{
|
|
174
|
+
display: 'grid',
|
|
175
|
+
width: props.width,
|
|
176
|
+
height: props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : undefined),
|
|
177
|
+
flexGrow: 1,
|
|
178
|
+
}}
|
|
179
|
+
>
|
|
180
|
+
<svgview
|
|
181
|
+
src={scene?.markup ?? EMPTY_SVG}
|
|
182
|
+
stretch="aspectFit"
|
|
183
|
+
style={{ width: w, height: h }}
|
|
184
|
+
/>
|
|
185
|
+
<masonview
|
|
186
|
+
id={props.id ? props.id + '-overlay' : undefined}
|
|
187
|
+
ref={(v: View | null) => {
|
|
188
|
+
if (v) {
|
|
189
|
+
v.isUserInteractionEnabled = interactive
|
|
190
|
+
}
|
|
191
|
+
}}
|
|
192
|
+
style={{ width: w, height: h }}
|
|
193
|
+
onTouch={interactive ? onTouch : undefined}
|
|
194
|
+
onTap={interactive ? onTap : undefined}
|
|
195
|
+
>
|
|
196
|
+
{scene?.labels.map((l) => (
|
|
197
|
+
<label
|
|
198
|
+
text={l.text}
|
|
199
|
+
style={{
|
|
200
|
+
width: l.width,
|
|
201
|
+
textAlign: l.align === 'center' ? 'center' : l.align === 'end' ? 'right' : 'left',
|
|
202
|
+
fontSize: 10,
|
|
203
|
+
opacity: 0.7,
|
|
204
|
+
position: 'absolute',
|
|
205
|
+
left: l.x,
|
|
206
|
+
top: l.y,
|
|
207
|
+
}}
|
|
208
|
+
/>
|
|
209
|
+
))}
|
|
210
|
+
@if (cursor && props.crosshair && !scene?.pie && plot) {
|
|
211
|
+
<contentview
|
|
212
|
+
style={{
|
|
213
|
+
width: 1,
|
|
214
|
+
height: plot.height,
|
|
215
|
+
backgroundColor: new Color('#8a8a8a'),
|
|
216
|
+
position: 'absolute',
|
|
217
|
+
left: cursor.px - 0.5,
|
|
218
|
+
top: plot.y,
|
|
219
|
+
}}
|
|
220
|
+
/>
|
|
221
|
+
}
|
|
222
|
+
@if (cursor && (props.crosshair || props.tooltip)) {
|
|
223
|
+
<contentview
|
|
224
|
+
style={{
|
|
225
|
+
width: 8,
|
|
226
|
+
height: 8,
|
|
227
|
+
borderRadius: 4,
|
|
228
|
+
backgroundColor: safeColor(dotColor, '#4e79a7'),
|
|
229
|
+
position: 'absolute',
|
|
230
|
+
left: cursor.px - 4,
|
|
231
|
+
top: cursor.py - 4,
|
|
232
|
+
}}
|
|
233
|
+
/>
|
|
234
|
+
}
|
|
235
|
+
@if (cursor && props.tooltip && tipText) {
|
|
236
|
+
<masonview
|
|
237
|
+
style={{
|
|
238
|
+
display: 'flex',
|
|
239
|
+
position: 'absolute',
|
|
240
|
+
left: tipLeft,
|
|
241
|
+
top: tipTop < 0 ? cursor.py + 12 : tipTop,
|
|
242
|
+
paddingTop: 2,
|
|
243
|
+
paddingBottom: 2,
|
|
244
|
+
paddingLeft: 6,
|
|
245
|
+
paddingRight: 6,
|
|
246
|
+
}}
|
|
247
|
+
>
|
|
248
|
+
<label text={tipText} style={{ color: new Color('#ffffff'), fontSize: 11 }} />
|
|
249
|
+
</masonview>
|
|
250
|
+
}
|
|
251
|
+
</masonview>
|
|
252
|
+
</masonview>
|
|
253
|
+
@if (legend === 'bottom' && scene) {
|
|
254
|
+
<masonview
|
|
255
|
+
style={mergeStyle(
|
|
256
|
+
{ flexDirection: 'row', flexWrap: 'wrap' },
|
|
257
|
+
{
|
|
258
|
+
display: 'flex',
|
|
259
|
+
paddingTop: 4,
|
|
260
|
+
},
|
|
261
|
+
)}
|
|
262
|
+
>
|
|
263
|
+
{scene.legend.map((item) => (
|
|
264
|
+
<masonview
|
|
265
|
+
style={mergeStyle(
|
|
266
|
+
{ flexDirection: 'row', alignItems: 'center' },
|
|
267
|
+
{
|
|
268
|
+
display: 'flex',
|
|
269
|
+
marginRight: 12,
|
|
270
|
+
},
|
|
271
|
+
)}
|
|
272
|
+
>
|
|
273
|
+
<contentview
|
|
274
|
+
style={{
|
|
275
|
+
width: 10,
|
|
276
|
+
height: 10,
|
|
277
|
+
borderRadius: 2,
|
|
278
|
+
backgroundColor: safeColor(item.color, 'transparent'),
|
|
279
|
+
marginRight: 4,
|
|
280
|
+
}}
|
|
281
|
+
/>
|
|
282
|
+
<label text={item.text} style={{ fontSize: 11 }} />
|
|
283
|
+
</masonview>
|
|
284
|
+
))}
|
|
285
|
+
</masonview>
|
|
286
|
+
}
|
|
287
|
+
</masonview>
|
|
286
288
|
}
|