@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 CHANGED
@@ -1,105 +1,5 @@
1
1
  # @octane-xplat/charts
2
2
 
3
- Show a small dataset as a line, area, bar, pie, or scatter chart. The package
4
- provides shared chart data and interaction props with web, iOS/Android, and
5
- experimental macOS AppKit implementations.
3
+ [Documentation](https://octane-xplat.goddardai.org/package-charts).
6
4
 
7
- ## Show a bar chart
8
-
9
- Start with a [configured Xplat app](https://octane-xplat.goddardai.org/toolchain#create-and-run),
10
- then install from its directory:
11
-
12
- ```sh
13
- bun add @octane-xplat/charts
14
- ```
15
-
16
- Put this component in a `.tsx` or `.tsrx` screen. Each series has a name and
17
- an array of `{ x, y }` values; bars use category names for `x`:
18
-
19
- ```tsx
20
- import { Chart } from '@octane-xplat/charts'
21
-
22
- export function PackingChart() {
23
- return (
24
- <Chart
25
- type="bar"
26
- width={320}
27
- height={220}
28
- accessibilityLabel="Packed items by bag: carry-on 4, day bag 2"
29
- data={[
30
- {
31
- name: 'Packed items',
32
- values: [
33
- { x: 'Carry-on', y: 4 },
34
- { x: 'Day bag', y: 2 },
35
- ],
36
- },
37
- ]}
38
- />
39
- )
40
- }
41
- ```
42
-
43
- The screen should show two bars, with Carry-on twice the height of Day bag.
44
- Keep a text summary available for readers who cannot use the chart. If the
45
- chart is blank, check that its container has nonzero size and the dataset is
46
- not empty.
47
-
48
- ## Choose the data shape
49
-
50
- Bar and pie charts use category labels. Line, area, and scatter charts use
51
- numbers or dates on the horizontal axis. Use the exported types to check data
52
- before passing it to a chart:
53
-
54
- ```ts
55
- import type { SeriesSpec } from '@octane-xplat/charts'
56
-
57
- const progress: SeriesSpec[] = [
58
- {
59
- name: 'Items packed',
60
- values: [
61
- { x: 1, y: 2 },
62
- { x: 2, y: 5 },
63
- { x: 3, y: 6 },
64
- ],
65
- },
66
- ]
67
- ```
68
-
69
- ## Respond to pointing and tapping
70
-
71
- Add `tooltip` or `crosshair` to show the value under the pointer, `onScrub` to
72
- follow it, and `onPress` to react when someone picks a datum. On web and macOS
73
- AppKit, hovering moves the cursor, dragging scrubs and clicking presses the
74
- point under the pointer. On iOS and Android, touching and dragging scrubs and
75
- tapping presses.
76
-
77
- ```tsx
78
- import { useState } from 'octane'
79
- import { Chart, type ChartHit } from '@octane-xplat/charts'
80
-
81
- export function StepsChart() {
82
- const [picked, setPicked] = useState<ChartHit | null>(null)
83
- return (
84
- <Chart
85
- type="line"
86
- width={320}
87
- height={200}
88
- tooltip
89
- crosshair
90
- onPress={setPicked}
91
- accessibilityLabel={picked ? `Picked ${picked.y} steps` : 'Steps per day'}
92
- data={[{ name: 'Steps', values: [{ x: 1, y: 4200 }, { x: 2, y: 6100 }, { x: 3, y: 5300 }] }]}
93
- />
94
- )
95
- }
96
- ```
97
-
98
- AppKit hover, drag and click coordinates come from source that has not yet
99
- been checked on a running Mac.
100
-
101
- The shared geometry uses D3 and SVG. This does not establish identical font
102
- metrics, assistive-technology behavior, or OS input on every host. Check the
103
- [target limits](https://octane-xplat.goddardai.org/known-limits) and run the
104
- chart on the targets you ship. Exact options live in the
105
- [public prop declarations](https://github.com/octane-xplat/octane-xplat/blob/main/packages/charts/src/props.ts).
5
+ [API reference](https://octane-xplat.goddardai.org/api-charts).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octane-xplat/charts",
3
- "version": "0.19.0",
3
+ "version": "0.20.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",
@@ -51,30 +51,30 @@
51
51
  "pack:check": "tsrx-typegen --pack-check"
52
52
  },
53
53
  "dependencies": {
54
- "@octane-xplat/jsx": "0.19.0",
55
- "d3-array": "3.2.4",
56
- "d3-format": "3.1.2",
57
- "d3-scale": "4.0.2",
58
- "d3-shape": "3.2.0",
59
- "d3-time-format": "4.1.0"
54
+ "@octane-xplat/jsx": "0.20.0",
55
+ "d3-array": "3.2.5",
56
+ "d3-format": "3.1.3",
57
+ "d3-scale": "4.0.3",
58
+ "d3-shape": "3.2.1",
59
+ "d3-time-format": "4.1.1"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@nativescript-community/octane": "0.2.5",
63
63
  "@nativescript/core": "9.1.3",
64
- "@octane-xplat/macos-renderer": "0.19.0",
65
- "@octane-xplat/ui": "0.19.0",
64
+ "@octane-xplat/macos-appkit": "0.20.0",
65
+ "@octane-xplat/ui": "0.20.0",
66
66
  "@octanejs/vite-plugin": "0.5.0",
67
- "@tsrx/typescript-plugin": "0.4.11",
68
67
  "@types/d3-array": "3.2.2",
69
68
  "@types/d3-format": "3.0.4",
70
69
  "@types/d3-scale": "4.0.9",
71
70
  "@types/d3-shape": "3.2.0",
72
71
  "@types/d3-time-format": "4.0.3",
73
72
  "octane": "0.16.3",
74
- "tsrx-typegen": "0.5.0",
75
- "typescript": "5.9.3",
76
- "vite": "8.3.0",
77
- "vitest": "4.1.11"
73
+ "tsrx-typegen": "0.6.1",
74
+ "typescript": "7.1.0-beta",
75
+ "vite": "8.3.6",
76
+ "vitest": "4.1.11",
77
+ "@tsrx/content-mapper": "0.1.2"
78
78
  },
79
79
  "peerDependencies": {
80
80
  "@nativescript-community/octane": ">=0.2.1 <1",
@@ -19,261 +19,263 @@ const TIP_ESTIMATE_CHAR = 6.2
19
19
  * unqualified. AppKit does not deliver onTouch, so touch scrubbing is
20
20
  * unavailable. */
21
21
  export function Chart(props: ChartProps): unknown @{
22
- const measure = useMeasure()
23
- const [cursor, setCursor] = useState<SceneHit | null>(null)
24
- const sceneRef = useRef<ChartScene | null>(null)
25
- const propsRef = useRef(props)
26
- propsRef.current = props
22
+ const measure = useMeasure()
23
+ const [cursor, setCursor] = useState<SceneHit | null>(null)
24
+ const sceneRef = useRef<ChartScene | null>(null)
25
+ const propsRef = useRef(props)
27
26
 
28
- const bounds = measure.bounds
29
- const w = props.width ?? bounds?.width ?? 0
30
- const h =
31
- props.height ??
32
- (props.aspectRatio && w > 0
33
- ? w / props.aspectRatio
34
- : bounds?.height && bounds.height > 0
35
- ? bounds.height
36
- : w > 0
37
- ? w / 1.6
38
- : 0)
27
+ propsRef.current = props
39
28
 
40
- const scene = useMemo(
41
- () => (w > 0 && h > 0 ? computeScene(propsRef.current, w, h) : null),
42
- [
43
- props.type,
44
- props.data,
45
- props.margin,
46
- props.stacked,
47
- props.innerRadiusRatio,
48
- props.xAxis,
49
- props.yAxis,
50
- w,
51
- h,
52
- ],
53
- )
29
+ const bounds = measure.bounds
30
+ const w = props.width ?? bounds?.width ?? 0
31
+ const h =
32
+ props.height ??
33
+ (props.aspectRatio && w > 0
34
+ ? w / props.aspectRatio
35
+ : bounds?.height && bounds.height > 0
36
+ ? bounds.height
37
+ : w > 0
38
+ ? w / 1.6
39
+ : 0)
54
40
 
55
- sceneRef.current = scene
41
+ const scene = useMemo(
42
+ () => (w > 0 && h > 0 ? computeScene(propsRef.current, w, h) : null),
43
+ [
44
+ props.type,
45
+ props.data,
46
+ props.margin,
47
+ props.stacked,
48
+ props.innerRadiusRatio,
49
+ props.xAxis,
50
+ props.yAxis,
51
+ w,
52
+ h,
53
+ ],
54
+ )
56
55
 
57
- const interactive = !!(props.onPress || props.onScrub || props.tooltip || props.crosshair)
58
- const pointer = useMemo(
59
- () =>
60
- createAppKitChartPointer(
61
- createScrub(
62
- () => sceneRef.current,
63
- () => propsRef.current,
64
- setCursor,
65
- ),
66
- () => ({
67
- width: sceneRef.current?.width ?? 0,
68
- height: sceneRef.current?.height ?? 0,
69
- }),
70
- ),
71
- [],
72
- )
56
+ sceneRef.current = scene
73
57
 
74
- const [tapView, setTapView] = useState<any>(null)
75
- const bindTapView = useCallback((view: any) => setTapView(view), [])
76
- useEffect(() => {
77
- if (!interactive || !tapView) {
78
- return
79
- }
58
+ const interactive = !!(props.onPress || props.onScrub || props.tooltip || props.crosshair)
59
+ const pointer = useMemo(
60
+ () =>
61
+ createAppKitChartPointer(
62
+ createScrub(
63
+ () => sceneRef.current,
64
+ () => propsRef.current,
65
+ setCursor,
66
+ ),
67
+ () => ({
68
+ width: sceneRef.current?.width ?? 0,
69
+ height: sceneRef.current?.height ?? 0,
70
+ }),
71
+ ),
72
+ [],
73
+ )
80
74
 
81
- return pointer.observe(tapView)
82
- }, [interactive, tapView, pointer])
75
+ const [tapView, setTapView] = useState<any>(null)
76
+ const bindTapView = useCallback((view: any) => setTapView(view), [])
83
77
 
84
- const markup = scene?.markup ?? EMPTY_SVG
85
- const imageSource = useMemo(() => appKitImageSource(markup), [markup])
78
+ useEffect(() => {
79
+ if (!interactive || !tapView) {
80
+ return
81
+ }
86
82
 
87
- const legend = props.legend === true ? 'bottom' : props.legend
88
- const plot = scene?.plot
89
- const dotColor =
90
- cursor && scene
91
- ? scene.pie
92
- ? scene.pie.slices.find((s) => s.series === cursor.series && s.index === cursor.index)
93
- ?.color
94
- : scene.series[cursor.series]?.color
95
- : undefined
83
+ return pointer.observe(tapView)
84
+ }, [interactive, tapView, pointer])
96
85
 
97
- const tipText = cursor && scene ? hitLabel(scene, cursor) : null
98
- const tipWidth = tipText ? tipText.length * TIP_ESTIMATE_CHAR + 14 : 0
99
- const tipLeft =
100
- cursor && scene
101
- ? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth))
102
- : 0
86
+ const markup = scene?.markup ?? EMPTY_SVG
87
+ const imageSource = useMemo(() => appKitImageSource(markup), [markup])
103
88
 
104
- const tipTop = cursor ? cursor.py - 30 : 0
89
+ const legend = props.legend === true ? 'bottom' : props.legend
90
+ const plot = scene?.plot
91
+ const dotColor =
92
+ cursor && scene
93
+ ? scene.pie
94
+ ? scene.pie.slices.find((s) => s.series === cursor.series && s.index === cursor.index)
95
+ ?.color
96
+ : scene.series[cursor.series]?.color
97
+ : undefined
105
98
 
106
- <masonview
107
- id={props.id}
108
- className={props.className}
109
- style={{
110
- display: 'flex',
111
- flexDirection: 'column',
112
- ...props.style,
113
- }}
114
- accessible={props.accessibilityLabel != null}
115
- accessibilityRole={'image'}
116
- accessibilityLabel={props.accessibilityLabel}
117
- >
118
- @if (legend === 'top' && scene) {
119
- <masonview
120
- style={mergeStyle(
121
- { flexDirection: 'row', flexWrap: 'wrap' },
122
- {
123
- display: 'flex',
124
- paddingBottom: 4,
125
- },
126
- )}
127
- >
128
- {scene.legend.map((item) => (
129
- <masonview
130
- style={mergeStyle(
131
- { flexDirection: 'row', alignItems: 'center' },
132
- {
133
- display: 'flex',
134
- marginRight: 12,
135
- },
136
- )}
137
- >
138
- <masonview
139
- style={{
140
- display: 'flex',
141
- width: 10,
142
- height: 10,
143
- borderRadius: 2,
144
- backgroundColor: item.color,
145
- marginRight: 4,
146
- }}
147
- />
148
- <label text={item.text} style={{ fontSize: 11 }} />
149
- </masonview>
150
- ))}
151
- </masonview>
152
- }
153
- <masonview
154
- ref={measure.ref}
155
- style={{
156
- display: 'grid',
157
- width: props.width,
158
- height: props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : undefined),
159
- flexGrow: 1,
160
- }}
161
- >
162
- <image
163
- id={props.id ? props.id + '-image' : undefined}
164
- src={imageSource}
165
- style={{ width: w, height: h }}
166
- accessibilityLabel=""
167
- />
168
- <masonview
169
- id={props.id ? props.id + '-tap' : undefined}
170
- ref={bindTapView}
171
- style={{
172
- display: 'flex',
173
- width: w,
174
- height: h,
175
- }}
176
- onPan={interactive ? pointer.pan : undefined}
177
- onTap={interactive ? () => pointer.tap(tapView) : undefined}
178
- >
179
- <masonview
180
- id={props.id ? props.id + '-overlay' : undefined}
181
- style={{ width: w, height: h }}
182
- >
183
- {scene?.labels.map((l) => (
184
- <label
185
- text={l.text}
186
- {...{ left: l.x, top: l.y }}
187
- style={{
188
- width: l.width,
189
- fontSize: 10,
190
- opacity: 0.7,
191
- textAlign: l.align === 'center' ? 'center' : l.align === 'end' ? 'right' : 'left',
192
- position: 'absolute',
193
- }}
194
- />
195
- ))}
196
- @if (cursor && props.crosshair && !scene?.pie && plot) {
197
- <masonview
198
- style={{
199
- display: 'flex',
200
- width: 1,
201
- height: plot.height,
202
- backgroundColor: '#8a8a8a',
203
- position: 'absolute',
204
- left: cursor.px - 0.5,
205
- top: plot.y,
206
- }}
207
- />
208
- }
209
- @if (cursor && (props.crosshair || props.tooltip)) {
210
- <masonview
211
- style={{
212
- display: 'flex',
213
- width: 8,
214
- height: 8,
215
- borderRadius: 4,
216
- backgroundColor: dotColor ?? '#4e79a7',
217
- position: 'absolute',
218
- left: cursor.px - 4,
219
- top: cursor.py - 4,
220
- }}
221
- />
222
- }
223
- @if (cursor && props.tooltip && tipText) {
224
- <label
225
- id={props.id ? props.id + '-tooltip' : undefined}
226
- text={tipText}
227
- {...{ left: tipLeft, top: tipTop < 0 ? cursor.py + 12 : tipTop }}
228
- style={{
229
- width: tipWidth,
230
- height: 24,
231
- backgroundColor: 'rgba(20,20,20,0.88)',
232
- borderRadius: 4,
233
- color: '#ffffff',
234
- fontSize: 11,
235
- textAlign: 'center',
236
- position: 'absolute',
237
- }}
238
- />
239
- }
240
- </masonview>
241
- </masonview>
242
- </masonview>
243
- @if (legend === 'bottom' && scene) {
244
- <masonview
245
- style={mergeStyle(
246
- { flexDirection: 'row', flexWrap: 'wrap' },
247
- {
248
- display: 'flex',
249
- paddingTop: 4,
250
- },
251
- )}
252
- >
253
- {scene.legend.map((item) => (
254
- <masonview
255
- style={mergeStyle(
256
- { flexDirection: 'row', alignItems: 'center' },
257
- {
258
- display: 'flex',
259
- marginRight: 12,
260
- },
261
- )}
262
- >
263
- <masonview
264
- style={{
265
- display: 'flex',
266
- width: 10,
267
- height: 10,
268
- borderRadius: 2,
269
- backgroundColor: item.color,
270
- marginRight: 4,
271
- }}
272
- />
273
- <label text={item.text} style={{ fontSize: 11 }} />
274
- </masonview>
275
- ))}
276
- </masonview>
277
- }
278
- </masonview>
99
+ const tipText = cursor && scene ? hitLabel(scene, cursor) : null
100
+ const tipWidth = tipText ? tipText.length * TIP_ESTIMATE_CHAR + 14 : 0
101
+ const tipLeft =
102
+ cursor && scene
103
+ ? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth))
104
+ : 0
105
+
106
+ const tipTop = cursor ? cursor.py - 30 : 0
107
+
108
+ <masonview
109
+ id={props.id}
110
+ className={props.className}
111
+ style={{
112
+ display: 'flex',
113
+ flexDirection: 'column',
114
+ ...props.style,
115
+ }}
116
+ accessible={props.accessibilityLabel != null}
117
+ accessibilityRole={'image'}
118
+ accessibilityLabel={props.accessibilityLabel}
119
+ >
120
+ @if (legend === 'top' && scene) {
121
+ <masonview
122
+ style={mergeStyle(
123
+ { flexDirection: 'row', flexWrap: 'wrap' },
124
+ {
125
+ display: 'flex',
126
+ paddingBottom: 4,
127
+ },
128
+ )}
129
+ >
130
+ {scene.legend.map((item) => (
131
+ <masonview
132
+ style={mergeStyle(
133
+ { flexDirection: 'row', alignItems: 'center' },
134
+ {
135
+ display: 'flex',
136
+ marginRight: 12,
137
+ },
138
+ )}
139
+ >
140
+ <masonview
141
+ style={{
142
+ display: 'flex',
143
+ width: 10,
144
+ height: 10,
145
+ borderRadius: 2,
146
+ backgroundColor: item.color,
147
+ marginRight: 4,
148
+ }}
149
+ />
150
+ <label text={item.text} style={{ fontSize: 11 }} />
151
+ </masonview>
152
+ ))}
153
+ </masonview>
154
+ }
155
+ <masonview
156
+ ref={measure.ref}
157
+ style={{
158
+ display: 'grid',
159
+ width: props.width,
160
+ height: props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : undefined),
161
+ flexGrow: 1,
162
+ }}
163
+ >
164
+ <image
165
+ id={props.id ? props.id + '-image' : undefined}
166
+ src={imageSource}
167
+ style={{ width: w, height: h }}
168
+ accessibilityLabel=""
169
+ />
170
+ <masonview
171
+ id={props.id ? props.id + '-tap' : undefined}
172
+ ref={bindTapView}
173
+ style={{
174
+ display: 'flex',
175
+ width: w,
176
+ height: h,
177
+ }}
178
+ onPan={interactive ? pointer.pan : undefined}
179
+ onTap={interactive ? () => pointer.tap(tapView) : undefined}
180
+ >
181
+ <masonview
182
+ id={props.id ? props.id + '-overlay' : undefined}
183
+ style={{ width: w, height: h }}
184
+ >
185
+ {scene?.labels.map((l) => (
186
+ <label
187
+ text={l.text}
188
+ {...{ left: l.x, top: l.y }}
189
+ style={{
190
+ width: l.width,
191
+ fontSize: 10,
192
+ opacity: 0.7,
193
+ textAlign: l.align === 'center' ? 'center' : l.align === 'end' ? 'right' : 'left',
194
+ position: 'absolute',
195
+ }}
196
+ />
197
+ ))}
198
+ @if (cursor && props.crosshair && !scene?.pie && plot) {
199
+ <masonview
200
+ style={{
201
+ display: 'flex',
202
+ width: 1,
203
+ height: plot.height,
204
+ backgroundColor: '#8a8a8a',
205
+ position: 'absolute',
206
+ left: cursor.px - 0.5,
207
+ top: plot.y,
208
+ }}
209
+ />
210
+ }
211
+ @if (cursor && (props.crosshair || props.tooltip)) {
212
+ <masonview
213
+ style={{
214
+ display: 'flex',
215
+ width: 8,
216
+ height: 8,
217
+ borderRadius: 4,
218
+ backgroundColor: dotColor ?? '#4e79a7',
219
+ position: 'absolute',
220
+ left: cursor.px - 4,
221
+ top: cursor.py - 4,
222
+ }}
223
+ />
224
+ }
225
+ @if (cursor && props.tooltip && tipText) {
226
+ <label
227
+ id={props.id ? props.id + '-tooltip' : undefined}
228
+ text={tipText}
229
+ {...{ left: tipLeft, top: tipTop < 0 ? cursor.py + 12 : tipTop }}
230
+ style={{
231
+ width: tipWidth,
232
+ height: 24,
233
+ backgroundColor: 'rgba(20,20,20,0.88)',
234
+ borderRadius: 4,
235
+ color: '#ffffff',
236
+ fontSize: 11,
237
+ textAlign: 'center',
238
+ position: 'absolute',
239
+ }}
240
+ />
241
+ }
242
+ </masonview>
243
+ </masonview>
244
+ </masonview>
245
+ @if (legend === 'bottom' && scene) {
246
+ <masonview
247
+ style={mergeStyle(
248
+ { flexDirection: 'row', flexWrap: 'wrap' },
249
+ {
250
+ display: 'flex',
251
+ paddingTop: 4,
252
+ },
253
+ )}
254
+ >
255
+ {scene.legend.map((item) => (
256
+ <masonview
257
+ style={mergeStyle(
258
+ { flexDirection: 'row', alignItems: 'center' },
259
+ {
260
+ display: 'flex',
261
+ marginRight: 12,
262
+ },
263
+ )}
264
+ >
265
+ <masonview
266
+ style={{
267
+ display: 'flex',
268
+ width: 10,
269
+ height: 10,
270
+ borderRadius: 2,
271
+ backgroundColor: item.color,
272
+ marginRight: 4,
273
+ }}
274
+ />
275
+ <label text={item.text} style={{ fontSize: 11 }} />
276
+ </masonview>
277
+ ))}
278
+ </masonview>
279
+ }
280
+ </masonview>
279
281
  }