@octane-xplat/charts 0.18.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 +5 -0
- package/package.json +93 -93
- package/src/Chart.macos.tsrx +269 -107
- package/src/Chart.tsrx +274 -139
- package/src/Chart.web.tsrx +264 -206
- package/src/appkit-pointer.macos.ts +113 -0
- package/src/core/axes.ts +175 -168
- package/src/core/hit.ts +199 -174
- package/src/core/marks.ts +336 -319
- package/src/core/scales.ts +128 -115
- package/src/core/scene.ts +124 -121
- 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 +90 -63
- package/src/style-merge.ts +43 -45
- package/src/svg-image.macos.ts +21 -20
- package/types/generated/.tsrx-typegen-manifest.json +15 -0
- package/types/generated/Chart.d.ts +9 -0
- package/types/generated/core/axes.d.ts +26 -0
- package/types/generated/core/hit.d.ts +34 -0
- package/types/generated/core/marks.d.ts +88 -0
- package/types/generated/core/scales.d.ts +37 -0
- package/types/generated/core/scene.d.ts +30 -0
- package/types/generated/core/svg.d.ts +5 -0
- package/types/generated/index.d.ts +2 -0
- package/types/{props.d.ts → generated/props.d.ts} +27 -0
- package/types/generated/style-merge.d.ts +8 -0
- package/LICENSE +0 -21
- package/types/index.d.ts +0 -17
package/src/core/svg.ts
CHANGED
|
@@ -8,77 +8,79 @@ import type { PlotBox } from './scales'
|
|
|
8
8
|
* leaf overlay (.agents/docs/notes/primitive-notes.md). */
|
|
9
9
|
|
|
10
10
|
function num(v: number): string {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (!Number.isFinite(v)) {
|
|
12
|
+
return '0'
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
return Number.isInteger(v) ? String(v) : String(+v.toFixed(2))
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function esc(v: string): string {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
return v
|
|
20
|
+
.replaceAll('&', '&')
|
|
21
|
+
.replaceAll('"', '"')
|
|
22
|
+
.replaceAll('<', '<')
|
|
23
|
+
.replaceAll('>', '>')
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function paintAttrs(m: Mark): string {
|
|
27
|
-
|
|
28
|
-
if (m.fill !== undefined) {
|
|
29
|
-
out += ` fill="${esc(m.fill)}"`
|
|
30
|
-
}
|
|
27
|
+
let out = ''
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
if (m.fill !== undefined) {
|
|
30
|
+
out += ` fill="${esc(m.fill)}"`
|
|
31
|
+
}
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
if (m.fillOpacity !== undefined) {
|
|
34
|
+
out += ` fill-opacity="${num(m.fillOpacity)}"`
|
|
35
|
+
}
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
if (m.stroke !== undefined) {
|
|
38
|
+
out += ` stroke="${esc(m.stroke)}"`
|
|
39
|
+
}
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
if (m.strokeOpacity !== undefined) {
|
|
42
|
+
out += ` stroke-opacity="${num(m.strokeOpacity)}"`
|
|
43
|
+
}
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
if (m.strokeWidth !== undefined) {
|
|
46
|
+
out += ` stroke-width="${num(m.strokeWidth)}"`
|
|
47
|
+
}
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
if (m.strokeLinecap !== undefined) {
|
|
50
|
+
out += ` stroke-linecap="${m.strokeLinecap}"`
|
|
51
|
+
}
|
|
55
52
|
|
|
56
|
-
|
|
53
|
+
if (m.transform !== undefined) {
|
|
54
|
+
out += ` transform="${esc(m.transform)}"`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return out
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
function markXml(m: Mark): string {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
switch (m.kind) {
|
|
62
|
+
case 'path':
|
|
63
|
+
return `<path d="${esc(m.d)}"${paintAttrs(m)}/>`
|
|
64
|
+
case 'rect':
|
|
65
|
+
return `<rect x="${num(m.x)}" y="${num(m.y)}" width="${num(m.width)}" height="${num(m.height)}"${paintAttrs(m)}/>`
|
|
66
|
+
case 'circle':
|
|
67
|
+
return `<circle cx="${num(m.cx)}" cy="${num(m.cy)}" r="${num(m.r)}"${paintAttrs(m)}/>`
|
|
68
|
+
case 'line':
|
|
69
|
+
return `<line x1="${num(m.x1)}" y1="${num(m.y1)}" x2="${num(m.x2)}" y2="${num(m.y2)}"${paintAttrs(m)}/>`
|
|
70
|
+
}
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
/** Chart marks are plot-space; axis rules are chart-space. Paint order:
|
|
73
74
|
* gridlines under the translated marks group, frame (spine + stubs) over. */
|
|
74
75
|
export function svgDocument(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
marks: Mark[],
|
|
77
|
+
grid: Mark[],
|
|
78
|
+
frame: Mark[],
|
|
79
|
+
plot: PlotBox,
|
|
80
|
+
width: number,
|
|
81
|
+
height: number,
|
|
81
82
|
): string {
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
const body = `${grid.map(markXml).join('')}<g transform="translate(${num(plot.x)} ${num(plot.y)})">${marks.map(markXml).join('')}</g>${frame.map(markXml).join('')}`
|
|
84
|
+
|
|
85
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${num(width)} ${num(height)}" width="${num(width)}" height="${num(height)}">${body}</svg>`
|
|
84
86
|
}
|
package/src/index.macos.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// reach .tsrx; same convention as @octane-xplat/ui index.*.ts).
|
|
3
3
|
export { Chart } from './Chart.macos.tsrx'
|
|
4
4
|
export type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
AxisSpec,
|
|
6
|
+
ChartDatum,
|
|
7
|
+
ChartHit,
|
|
8
|
+
ChartMargin,
|
|
9
|
+
ChartProps,
|
|
10
|
+
ChartType,
|
|
11
|
+
SeriesSpec,
|
|
12
12
|
} from './props'
|
package/src/index.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// reach .tsrx; same convention as @octane-xplat/ui index.*.ts).
|
|
3
3
|
export { Chart } from './Chart.tsrx'
|
|
4
4
|
export type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
AxisSpec,
|
|
6
|
+
ChartDatum,
|
|
7
|
+
ChartHit,
|
|
8
|
+
ChartMargin,
|
|
9
|
+
ChartProps,
|
|
10
|
+
ChartType,
|
|
11
|
+
SeriesSpec,
|
|
12
12
|
} from './props'
|
package/src/index.web.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// reach .tsrx; same convention as @octane-xplat/ui index.*.ts).
|
|
3
3
|
export { Chart } from './Chart.web.tsrx'
|
|
4
4
|
export type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
AxisSpec,
|
|
6
|
+
ChartDatum,
|
|
7
|
+
ChartHit,
|
|
8
|
+
ChartMargin,
|
|
9
|
+
ChartProps,
|
|
10
|
+
ChartType,
|
|
11
|
+
SeriesSpec,
|
|
12
12
|
} from './props'
|
package/src/props.ts
CHANGED
|
@@ -4,87 +4,114 @@
|
|
|
4
4
|
|
|
5
5
|
export type ChartType = 'line' | 'area' | 'bar' | 'pie' | 'scatter'
|
|
6
6
|
|
|
7
|
+
/** One plotted value. */
|
|
7
8
|
export interface ChartDatum {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
/** Bar/pie: the category label. Line/area/scatter: number or Date. */
|
|
10
|
+
x: number | string | Date
|
|
11
|
+
/** Value on the quantitative axis. */
|
|
12
|
+
y: number
|
|
13
|
+
/** Per-datum color override — wins over the series color (pie slices,
|
|
14
|
+
* scatter points, individual bars). */
|
|
15
|
+
color?: string
|
|
14
16
|
}
|
|
15
17
|
|
|
18
|
+
/** One named data series. */
|
|
16
19
|
export interface SeriesSpec {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/** Legend/tooltip name for the series. */
|
|
21
|
+
name: string
|
|
22
|
+
/** Series color — stroke for line/scatter, fill for area/bar. Falls back
|
|
23
|
+
* to the built-in palette by series index. */
|
|
24
|
+
color?: string
|
|
25
|
+
/** The plotted values. */
|
|
26
|
+
values: ChartDatum[]
|
|
22
27
|
}
|
|
23
28
|
|
|
29
|
+
/** Per-edge space inside the chart box reserved for axis labels — the
|
|
30
|
+
* plot area occupies the remainder. */
|
|
24
31
|
export interface ChartMargin {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
/** Top margin in px/dips. */
|
|
33
|
+
top?: number
|
|
34
|
+
/** Right margin in px/dips. */
|
|
35
|
+
right?: number
|
|
36
|
+
/** Bottom margin in px/dips — x-axis labels live here by default. */
|
|
37
|
+
bottom?: number
|
|
38
|
+
/** Left margin in px/dips — y-axis labels live here by default. */
|
|
39
|
+
left?: number
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
/** Axis decomposition — gridline, tick stub, and label toggle independently
|
|
32
43
|
* (Swift Charts `AxisMarks` shape). Labels render as real positioned
|
|
33
44
|
* elements in the overlay, never `<text>` in markup. */
|
|
34
45
|
export interface AxisSpec {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
/** Tick labels in the margin. Default true. */
|
|
47
|
+
labels?: boolean
|
|
48
|
+
/** Tick stubs on the axis spine. Default true. */
|
|
49
|
+
ticks?: boolean
|
|
50
|
+
/** Gridlines across the plot area. Default false. */
|
|
51
|
+
grid?: boolean
|
|
52
|
+
/** Desired tick count hint — a hint, not a guarantee. */
|
|
53
|
+
tickCount?: number
|
|
54
|
+
/** Tick label formatter; receives the domain value. */
|
|
55
|
+
format?: (value: number | string | Date) => string
|
|
45
56
|
}
|
|
46
57
|
|
|
58
|
+
/** A resolved datum reference — `x`/`y` are the datum's values, not pixels. */
|
|
47
59
|
/** A resolved datum reference — `x`/`y` are the datum's values, not pixels. */
|
|
48
60
|
export interface ChartHit {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
/** Series index into `data`. */
|
|
62
|
+
series: number
|
|
63
|
+
/** Datum index within the series. */
|
|
64
|
+
index: number
|
|
65
|
+
/** The datum's x value. */
|
|
66
|
+
x: number | string | Date
|
|
67
|
+
/** Value on the quantitative axis. */
|
|
68
|
+
y: number
|
|
53
69
|
}
|
|
54
70
|
|
|
71
|
+
/** Props for the `<Chart>` element — one component for every chart kind,
|
|
72
|
+
* each platform leaf rendering natively. */
|
|
55
73
|
export interface ChartProps {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
/** Which chart kind to render. */
|
|
75
|
+
type: ChartType
|
|
76
|
+
/** Plotted series; most types read `values`, pie reads slice x/y. */
|
|
77
|
+
data: SeriesSpec[]
|
|
78
|
+
/** Explicit size in px (web) / dips (native). Without `height`, the leaf
|
|
79
|
+
* fills its parent or derives height from `aspectRatio`. */
|
|
80
|
+
width?: number
|
|
81
|
+
/** Explicit height — same units as `width`. */
|
|
82
|
+
height?: number
|
|
83
|
+
/** width/height ratio used when `height` is unset. */
|
|
84
|
+
aspectRatio?: number
|
|
85
|
+
/** Space reserved inside the chart box for axis labels — labels live in
|
|
86
|
+
* the margin band, the plot in the remainder. Defaults reserve room for
|
|
87
|
+
* x labels (bottom) and y labels (left) when those axes show labels. */
|
|
88
|
+
margin?: ChartMargin
|
|
89
|
+
/** Bar only: stack series instead of grouping side by side. */
|
|
90
|
+
stacked?: boolean
|
|
91
|
+
/** Pie only: 0–<1 inner-radius fraction — any positive value renders a
|
|
92
|
+
* donut. */
|
|
93
|
+
innerRadiusRatio?: number
|
|
94
|
+
/** X-axis presentation options. */
|
|
95
|
+
xAxis?: AxisSpec
|
|
96
|
+
/** Y-axis presentation options. */
|
|
97
|
+
yAxis?: AxisSpec
|
|
98
|
+
/** Legend row of series swatches. `true` = 'bottom'. Pie legends list
|
|
99
|
+
* slices, not series. */
|
|
100
|
+
legend?: boolean | 'top' | 'bottom'
|
|
101
|
+
/** Show a value callout at the scrub/hover cursor. */
|
|
102
|
+
tooltip?: boolean
|
|
103
|
+
/** Show a snap-to-x cursor rule while scrubbing. */
|
|
104
|
+
crosshair?: boolean
|
|
105
|
+
/** Tap/click a datum. */
|
|
106
|
+
onPress?: (hit: ChartHit) => void
|
|
107
|
+
/** Scrub position changes — `null` when the gesture ends or leaves. */
|
|
108
|
+
onScrub?: (hit: ChartHit | null) => void
|
|
109
|
+
/** Accessible description of the chart for assistive tech. */
|
|
110
|
+
accessibilityLabel?: string
|
|
111
|
+
/** Class list applied to the chart element. */
|
|
112
|
+
className?: any
|
|
113
|
+
/** Inline style (string CSS or object). */
|
|
114
|
+
style?: any
|
|
115
|
+
/** Element id passed through to the host element. */
|
|
116
|
+
id?: string
|
|
90
117
|
}
|
package/src/style-merge.ts
CHANGED
|
@@ -1,61 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
const kebab = (key: string) => key.replace(/[A-Z]/g, (c) => '-' + c.toLowerCase())
|
|
4
2
|
|
|
5
3
|
/** 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[]
|
|
4
|
+
export type StyleInput = string | Record<string, any> | null | undefined | readonly StyleInput[]
|
|
12
5
|
|
|
13
6
|
/** Merge component-emitted style defaults under the authored `style` prop.
|
|
14
7
|
* Authored keys win; array styles fold in order; a string style is appended
|
|
15
8
|
* after the serialized defaults so its declarations override them too. */
|
|
16
9
|
export function mergeStyle(
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
base: Record<string, any>,
|
|
11
|
+
style?: Record<string, any> | readonly (Record<string, any> | null | undefined)[] | null,
|
|
19
12
|
): Record<string, any>
|
|
13
|
+
|
|
20
14
|
export function mergeStyle(
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
base: Record<string, any>,
|
|
16
|
+
style?: StyleInput,
|
|
23
17
|
): string | Record<string, any>
|
|
18
|
+
|
|
24
19
|
export function mergeStyle(
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
base: Record<string, any>,
|
|
21
|
+
style?: StyleInput,
|
|
27
22
|
): string | Record<string, any> {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
23
|
+
if (style == null) {
|
|
24
|
+
return base
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let obj: Record<string, any> = { ...base }
|
|
28
|
+
const strings: string[] = []
|
|
29
|
+
const add = (s: StyleInput) => {
|
|
30
|
+
if (s == null) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (typeof s === 'string') {
|
|
35
|
+
strings.push(s)
|
|
36
|
+
} else if (Array.isArray(s)) {
|
|
37
|
+
for (const part of s) {
|
|
38
|
+
add(part)
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
obj = { ...obj, ...s }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
add(style)
|
|
46
|
+
|
|
47
|
+
if (strings.length === 0) {
|
|
48
|
+
return obj
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const prefix = Object.entries(obj)
|
|
52
|
+
.filter(([, v]) => v != null)
|
|
53
|
+
.map(([k, v]) => `${kebab(k)}:${v}`)
|
|
54
|
+
.join(';')
|
|
55
|
+
|
|
56
|
+
return [prefix, ...strings].filter(Boolean).join(';')
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
export type StyleProp = string | Record<string, any> | readonly StyleProp[] | null | undefined
|
package/src/svg-image.macos.ts
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
// Kept local to avoid coupling the charts leaf to private UI helpers.
|
|
2
2
|
// Foundation's public ObjC API is available through the AppKit metadata bridge.
|
|
3
3
|
declare const NSString: {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
stringWithString(value: string): {
|
|
5
|
+
dataUsingEncoding(encoding: number): {
|
|
6
|
+
base64EncodedStringWithOptions(options: number): string
|
|
7
|
+
} | null
|
|
8
|
+
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function svgDataUri(markup: string): string {
|
|
12
|
-
|
|
13
|
-
if (!data) {
|
|
14
|
-
throw new Error('Unable to encode SVG as UTF-8')
|
|
15
|
-
}
|
|
12
|
+
const data = NSString.stringWithString(markup).dataUsingEncoding(4) // NSUTF8StringEncoding
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
if (!data) {
|
|
15
|
+
throw new Error('Unable to encode SVG as UTF-8')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return `data:image/svg+xml;base64,${data.base64EncodedStringWithOptions(0)}`
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
/** Normalize bundled markup and SVG data URIs for AppKit's image host. */
|
|
21
22
|
export function appKitImageSource(src: string): string {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (src.trimStart().startsWith('<svg') || src.trimStart().startsWith('<?xml')) {
|
|
24
|
+
return svgDataUri(src)
|
|
25
|
+
}
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
if (
|
|
28
|
+
/^data:image\/svg\+xml[;,]/i.test(src) &&
|
|
29
|
+
!src.slice(0, src.indexOf(',')).endsWith(';base64')
|
|
30
|
+
) {
|
|
31
|
+
return svgDataUri(decodeURIComponent(src.slice(src.indexOf(',') + 1)))
|
|
32
|
+
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
return src
|
|
34
35
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ChartProps } from './props.js';
|
|
2
|
+
/** Chart — NativeScript leaf. The core's Mark[] serialize to one svg markup
|
|
3
|
+
* string fed to `<svgview>` (vendored ui-svg → SVGKit/androidsvg — its
|
|
4
|
+
* registration arrives transitively through `@octane-xplat/ui`'s native
|
|
5
|
+
* entry). Axis labels, legend, tooltip, and crosshair are real views in an
|
|
6
|
+
* `absolutelayout` overlay — never `<text>` in the markup. Touch input on
|
|
7
|
+
* the overlay reports view-relative dips (`e.getX()/getY()`), matching the
|
|
8
|
+
* markup's coordinate space. */
|
|
9
|
+
export declare function Chart(props: ChartProps): unknown;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AxisSpec } from '../props.js';
|
|
2
|
+
import type { Mark } from './marks.js';
|
|
3
|
+
import type { PlotBox, XScale, XScaleKind, YScale } from './scales.js';
|
|
4
|
+
/** A positioned text label — rendered as a real element in the overlay,
|
|
5
|
+
* never as svg `<text>` (androidsvg/SVGKit text is degraded). `x`/`y` is the
|
|
6
|
+
* box origin in chart space; `width` bounds it for alignment. */
|
|
7
|
+
export interface LabelSpec {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
width: number;
|
|
11
|
+
align: 'start' | 'center' | 'end';
|
|
12
|
+
text: string;
|
|
13
|
+
axis: 'x' | 'y';
|
|
14
|
+
}
|
|
15
|
+
export interface AxisModel {
|
|
16
|
+
labels: LabelSpec[];
|
|
17
|
+
/** Spine and tick stubs — painted over marks. */
|
|
18
|
+
frame: Mark[];
|
|
19
|
+
/** Gridlines — painted under marks. */
|
|
20
|
+
grid: Mark[];
|
|
21
|
+
}
|
|
22
|
+
/** Default tick label formatting — SI suffixes for big magnitudes, plain
|
|
23
|
+
* significant digits otherwise, short month-day for dates. */
|
|
24
|
+
export declare function defaultFormat(value: number | string | Date): string;
|
|
25
|
+
export declare function xAxisModel(kind: XScaleKind, scale: XScale, spec: AxisSpec | undefined, plot: PlotBox): AxisModel;
|
|
26
|
+
export declare function yAxisModel(scale: YScale, spec: AxisSpec | undefined, plot: PlotBox): AxisModel;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ChartHit } from '../props.js';
|
|
2
|
+
import type { ChartScene } from './scene.js';
|
|
3
|
+
export interface SceneHit extends ChartHit {
|
|
4
|
+
/** Datum anchor in chart space — tooltip/crosshair position. */
|
|
5
|
+
px: number;
|
|
6
|
+
py: number;
|
|
7
|
+
}
|
|
8
|
+
/** Touch slop — how far outside the plot a pointer may sit and still hit.
|
|
9
|
+
* Also the nearest-point distance gate for scatter. */
|
|
10
|
+
export declare const HIT_SLOP = 24;
|
|
11
|
+
/** Map a chart-space pointer position to the nearest datum. Cartesian charts
|
|
12
|
+
* snap to the nearest x group, then pick the closest point inside it —
|
|
13
|
+
* scatter gates on pointer distance instead of always snapping. Pie hits
|
|
14
|
+
* resolve by ring + angle. Coordinates outside the plot (+slop) miss. */
|
|
15
|
+
export declare function hitTest(scene: ChartScene, x: number, y: number, slop?: number): SceneHit | null;
|
|
16
|
+
export type ScrubPhase = 'down' | 'move' | 'up' | 'cancel' | 'hover' | 'leave' | 'tap';
|
|
17
|
+
export interface ScrubProps {
|
|
18
|
+
tooltip?: boolean;
|
|
19
|
+
crosshair?: boolean;
|
|
20
|
+
onPress?: (hit: ChartHit) => void;
|
|
21
|
+
onScrub?: (hit: ChartHit | null) => void;
|
|
22
|
+
}
|
|
23
|
+
/** Shared gesture → cursor state machine. Both leaves normalize their pointer
|
|
24
|
+
* source (DOM pointer/click events, NS `touch`+`tap`) to phases and call
|
|
25
|
+
* this; hit math stays identical across targets. `move` while pressed
|
|
26
|
+
* scrubs and fires `onScrub`; `hover` (web-only, unpressed move) moves the
|
|
27
|
+
* cursor without scrubbing; `up` ends the scrub and persists the cursor;
|
|
28
|
+
* `tap` is a completed press — fires `onPress` and updates the cursor;
|
|
29
|
+
* `cancel`/`leave` clear. `onPress` lives only on `tap` so NS's tap
|
|
30
|
+
* recognizer and the web click both reach it exactly once. */
|
|
31
|
+
export declare function createScrub(getScene: () => ChartScene | null, getProps: () => ScrubProps, setCursor: (hit: SceneHit | null) => void): (phase: ScrubPhase, x: number, y: number) => void;
|
|
32
|
+
/** Tooltip body for a hit — series name + formatted y for cartesian charts,
|
|
33
|
+
* slice label + value for pie. */
|
|
34
|
+
export declare function hitLabel(scene: ChartScene, hit: ChartHit): string;
|