@octane-xplat/charts 0.17.1 → 0.19.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 +105 -0
- package/package.json +93 -93
- package/src/Chart.macos.tsrx +217 -57
- package/src/Chart.tsrx +191 -58
- package/src/Chart.web.tsrx +124 -76
- package/src/appkit-pointer.macos.ts +98 -0
- package/src/core/hit.ts +6 -1
- package/src/core/scene.ts +1 -1
- package/src/props.ts +27 -0
- package/src/style-merge.ts +3 -8
- package/types/generated/.tsrx-typegen-manifest.json +21 -0
- package/types/generated/Chart.d.ts +9 -0
- package/types/generated/Chart.macos.d.ts +7 -0
- package/types/generated/Chart.web.d.ts +10 -0
- package/types/generated/appkit-pointer.macos.d.ts +37 -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/generated/index.macos.d.ts +2 -0
- package/types/generated/index.web.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/types/generated/svg-image.macos.d.ts +3 -0
- package/LICENSE +0 -21
- package/types/index.d.ts +0 -17
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { ScrubPhase } from './core/hit'
|
|
2
|
+
|
|
3
|
+
export interface AppKitChartPointerBridge {
|
|
4
|
+
observePointerMotion?(
|
|
5
|
+
view: unknown,
|
|
6
|
+
handlers: { move(x: number, y: number): void; exit(): void },
|
|
7
|
+
): () => void
|
|
8
|
+
locatePointer?(view: unknown): { x: number; y: number } | null
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Raw renderer onPan event — top-left x/y and the NSPanGestureRecognizer
|
|
12
|
+
* state (1 began / 2 changed / 3 ended / anything else cancelled). */
|
|
13
|
+
export interface AppKitPanEvent {
|
|
14
|
+
x: number
|
|
15
|
+
y: number
|
|
16
|
+
deltaX: number
|
|
17
|
+
deltaY: number
|
|
18
|
+
state: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const finite = (x: number, y: number) => Number.isFinite(x) && Number.isFinite(y)
|
|
22
|
+
|
|
23
|
+
/** Normalizes the AppKit pointer sources — pan recognizer deltas, tracking-
|
|
24
|
+
* area motion and the current mouse event — onto the shared scrub phases,
|
|
25
|
+
* mirroring the DOM listeners in Chart.web. */
|
|
26
|
+
export function createAppKitChartPointer(
|
|
27
|
+
scrub: (phase: ScrubPhase, x: number, y: number) => void,
|
|
28
|
+
size: () => { width: number; height: number },
|
|
29
|
+
bridge: () => AppKitChartPointerBridge | undefined = () =>
|
|
30
|
+
Reflect.get(globalThis, '__xplatAppKit'),
|
|
31
|
+
): {
|
|
32
|
+
pan(event: { deltaX?: unknown; deltaY?: unknown; state?: unknown; x?: number; y?: number }): void
|
|
33
|
+
tap(view: unknown): void
|
|
34
|
+
observe(view: unknown): () => void
|
|
35
|
+
} {
|
|
36
|
+
let panning = false
|
|
37
|
+
return {
|
|
38
|
+
pan(event: { deltaX?: unknown; deltaY?: unknown; state?: unknown; x?: number; y?: number }): void {
|
|
39
|
+
// The AppKit driver emits a superset payload carrying x/y; the shared
|
|
40
|
+
// PanGestureEvent type only declares deltaX/deltaY/state.
|
|
41
|
+
const panEvent = event as AppKitPanEvent
|
|
42
|
+
const state = Number(panEvent.state)
|
|
43
|
+
const point = finite(panEvent.x, panEvent.y)
|
|
44
|
+
? { x: panEvent.x, y: panEvent.y }
|
|
45
|
+
: null
|
|
46
|
+
if (state === 1) {
|
|
47
|
+
if (!point) {
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// x/y includes the current delta — subtract it for the press start.
|
|
52
|
+
panning = true
|
|
53
|
+
scrub('down', point.x - Number(panEvent.deltaX ?? 0), point.y - Number(panEvent.deltaY ?? 0))
|
|
54
|
+
scrub('move', point.x, point.y)
|
|
55
|
+
} else if (state === 2) {
|
|
56
|
+
if (panning && point) {
|
|
57
|
+
scrub('move', point.x, point.y)
|
|
58
|
+
}
|
|
59
|
+
} else if (panning) {
|
|
60
|
+
// `cancel` clears without coordinates, matching web's scrub('cancel', 0, 0).
|
|
61
|
+
const ended = state === 3 ? point : null
|
|
62
|
+
scrub(ended ? 'up' : 'cancel', ended?.x ?? 0, ended?.y ?? 0)
|
|
63
|
+
panning = false
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
tap(view: unknown): void {
|
|
67
|
+
const point = bridge()?.locatePointer?.(view)
|
|
68
|
+
if (point && finite(point.x, point.y)) {
|
|
69
|
+
scrub('tap', point.x, point.y)
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const { width, height } = size()
|
|
74
|
+
scrub('tap', width / 2, height / 2)
|
|
75
|
+
},
|
|
76
|
+
observe(view: unknown): () => void {
|
|
77
|
+
const observePointerMotion = bridge()?.observePointerMotion
|
|
78
|
+
if (!view || !observePointerMotion) {
|
|
79
|
+
return () => {}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// An AppKit exit mid-drag must not reset the scrub — the pan
|
|
83
|
+
// recognizer keeps delivering while pressed outside the view.
|
|
84
|
+
return observePointerMotion(view, {
|
|
85
|
+
move(x, y): void {
|
|
86
|
+
if (!panning) {
|
|
87
|
+
scrub('hover', x, y)
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
exit(): void {
|
|
91
|
+
if (!panning) {
|
|
92
|
+
scrub('leave', 0, 0)
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
}
|
package/src/core/hit.ts
CHANGED
|
@@ -16,7 +16,12 @@ export const HIT_SLOP = 24
|
|
|
16
16
|
* snap to the nearest x group, then pick the closest point inside it —
|
|
17
17
|
* scatter gates on pointer distance instead of always snapping. Pie hits
|
|
18
18
|
* resolve by ring + angle. Coordinates outside the plot (+slop) miss. */
|
|
19
|
-
export function hitTest(
|
|
19
|
+
export function hitTest(
|
|
20
|
+
scene: ChartScene,
|
|
21
|
+
x: number,
|
|
22
|
+
y: number,
|
|
23
|
+
slop: number = HIT_SLOP,
|
|
24
|
+
): SceneHit | null {
|
|
20
25
|
if (scene.pie) {
|
|
21
26
|
return pieHit(scene, x, y, slop)
|
|
22
27
|
}
|
package/src/core/scene.ts
CHANGED
package/src/props.ts
CHANGED
|
@@ -4,27 +4,38 @@
|
|
|
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
|
/** Bar/pie: the category label. Line/area/scatter: number or Date. */
|
|
9
10
|
x: number | string | Date
|
|
11
|
+
/** Value on the quantitative axis. */
|
|
10
12
|
y: number
|
|
11
13
|
/** Per-datum color override — wins over the series color (pie slices,
|
|
12
14
|
* scatter points, individual bars). */
|
|
13
15
|
color?: string
|
|
14
16
|
}
|
|
15
17
|
|
|
18
|
+
/** One named data series. */
|
|
16
19
|
export interface SeriesSpec {
|
|
20
|
+
/** Legend/tooltip name for the series. */
|
|
17
21
|
name: string
|
|
18
22
|
/** Series color — stroke for line/scatter, fill for area/bar. Falls back
|
|
19
23
|
* to the built-in palette by series index. */
|
|
20
24
|
color?: string
|
|
25
|
+
/** The plotted values. */
|
|
21
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 {
|
|
32
|
+
/** Top margin in px/dips. */
|
|
25
33
|
top?: number
|
|
34
|
+
/** Right margin in px/dips. */
|
|
26
35
|
right?: number
|
|
36
|
+
/** Bottom margin in px/dips — x-axis labels live here by default. */
|
|
27
37
|
bottom?: number
|
|
38
|
+
/** Left margin in px/dips — y-axis labels live here by default. */
|
|
28
39
|
left?: number
|
|
29
40
|
}
|
|
30
41
|
|
|
@@ -44,20 +55,30 @@ export interface AxisSpec {
|
|
|
44
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 {
|
|
61
|
+
/** Series index into `data`. */
|
|
49
62
|
series: number
|
|
63
|
+
/** Datum index within the series. */
|
|
50
64
|
index: number
|
|
65
|
+
/** The datum's x value. */
|
|
51
66
|
x: number | string | Date
|
|
67
|
+
/** Value on the quantitative axis. */
|
|
52
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 {
|
|
74
|
+
/** Which chart kind to render. */
|
|
56
75
|
type: ChartType
|
|
76
|
+
/** Plotted series; most types read `values`, pie reads slice x/y. */
|
|
57
77
|
data: SeriesSpec[]
|
|
58
78
|
/** Explicit size in px (web) / dips (native). Without `height`, the leaf
|
|
59
79
|
* fills its parent or derives height from `aspectRatio`. */
|
|
60
80
|
width?: number
|
|
81
|
+
/** Explicit height — same units as `width`. */
|
|
61
82
|
height?: number
|
|
62
83
|
/** width/height ratio used when `height` is unset. */
|
|
63
84
|
aspectRatio?: number
|
|
@@ -70,7 +91,9 @@ export interface ChartProps {
|
|
|
70
91
|
/** Pie only: 0–<1 inner-radius fraction — any positive value renders a
|
|
71
92
|
* donut. */
|
|
72
93
|
innerRadiusRatio?: number
|
|
94
|
+
/** X-axis presentation options. */
|
|
73
95
|
xAxis?: AxisSpec
|
|
96
|
+
/** Y-axis presentation options. */
|
|
74
97
|
yAxis?: AxisSpec
|
|
75
98
|
/** Legend row of series swatches. `true` = 'bottom'. Pie legends list
|
|
76
99
|
* slices, not series. */
|
|
@@ -83,8 +106,12 @@ export interface ChartProps {
|
|
|
83
106
|
onPress?: (hit: ChartHit) => void
|
|
84
107
|
/** Scrub position changes — `null` when the gesture ends or leaves. */
|
|
85
108
|
onScrub?: (hit: ChartHit | null) => void
|
|
109
|
+
/** Accessible description of the chart for assistive tech. */
|
|
86
110
|
accessibilityLabel?: string
|
|
111
|
+
/** Class list applied to the chart element. */
|
|
87
112
|
className?: any
|
|
113
|
+
/** Inline style (string CSS or object). */
|
|
88
114
|
style?: any
|
|
115
|
+
/** Element id passed through to the host element. */
|
|
89
116
|
id?: string
|
|
90
117
|
}
|
package/src/style-merge.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
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
|
|
@@ -17,10 +10,12 @@ export function mergeStyle(
|
|
|
17
10
|
base: Record<string, any>,
|
|
18
11
|
style?: Record<string, any> | readonly (Record<string, any> | null | undefined)[] | null,
|
|
19
12
|
): Record<string, any>
|
|
13
|
+
|
|
20
14
|
export function mergeStyle(
|
|
21
15
|
base: Record<string, any>,
|
|
22
16
|
style?: StyleInput,
|
|
23
17
|
): string | Record<string, any>
|
|
18
|
+
|
|
24
19
|
export function mergeStyle(
|
|
25
20
|
base: Record<string, any>,
|
|
26
21
|
style?: StyleInput,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"files": [
|
|
4
|
+
"Chart.d.ts",
|
|
5
|
+
"Chart.macos.d.ts",
|
|
6
|
+
"Chart.web.d.ts",
|
|
7
|
+
"appkit-pointer.macos.d.ts",
|
|
8
|
+
"core/axes.d.ts",
|
|
9
|
+
"core/hit.d.ts",
|
|
10
|
+
"core/marks.d.ts",
|
|
11
|
+
"core/scales.d.ts",
|
|
12
|
+
"core/scene.d.ts",
|
|
13
|
+
"core/svg.d.ts",
|
|
14
|
+
"index.d.ts",
|
|
15
|
+
"index.macos.d.ts",
|
|
16
|
+
"index.web.d.ts",
|
|
17
|
+
"props.d.ts",
|
|
18
|
+
"style-merge.d.ts",
|
|
19
|
+
"svg-image.macos.d.ts"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -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,7 @@
|
|
|
1
|
+
import type { ChartProps } from './props.js';
|
|
2
|
+
/** AppKit leaf: one NSImage plus native label and cursor overlays.
|
|
3
|
+
* Hover/drag/click coordinates come from renderer tracking areas, pan
|
|
4
|
+
* recognizer location and the current mouse event; native delivery is
|
|
5
|
+
* unqualified. AppKit does not deliver onTouch, so touch scrubbing is
|
|
6
|
+
* unavailable. */
|
|
7
|
+
export declare function Chart(props: ChartProps): unknown;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx/dom */
|
|
2
|
+
import type { JSX } from 'octane/jsx-runtime';
|
|
3
|
+
import type { ChartProps } from './props.js';
|
|
4
|
+
/** Chart — web leaf. The core's Mark[] serialize to one svg markup string,
|
|
5
|
+
* inlined as `innerHTML` (Icon.web precedent — the same bytes feed
|
|
6
|
+
* `<svgview>` on native). Axis labels, legend, tooltip, and crosshair are
|
|
7
|
+
* real absolutely-positioned elements in the overlay — never `<text>` in
|
|
8
|
+
* the markup. Pointer handlers attach to the plot host so chart coords are
|
|
9
|
+
* client-minus-rect, matching the markup's coordinate space. */
|
|
10
|
+
export declare function Chart(props: ChartProps): JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ScrubPhase } from './core/hit.js';
|
|
2
|
+
export interface AppKitChartPointerBridge {
|
|
3
|
+
observePointerMotion?(view: unknown, handlers: {
|
|
4
|
+
move(x: number, y: number): void;
|
|
5
|
+
exit(): void;
|
|
6
|
+
}): () => void;
|
|
7
|
+
locatePointer?(view: unknown): {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
} | null;
|
|
11
|
+
}
|
|
12
|
+
/** Raw renderer onPan event — top-left x/y and the NSPanGestureRecognizer
|
|
13
|
+
* state (1 began / 2 changed / 3 ended / anything else cancelled). */
|
|
14
|
+
export interface AppKitPanEvent {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
deltaX: number;
|
|
18
|
+
deltaY: number;
|
|
19
|
+
state: number;
|
|
20
|
+
}
|
|
21
|
+
/** Normalizes the AppKit pointer sources — pan recognizer deltas, tracking-
|
|
22
|
+
* area motion and the current mouse event — onto the shared scrub phases,
|
|
23
|
+
* mirroring the DOM listeners in Chart.web. */
|
|
24
|
+
export declare function createAppKitChartPointer(scrub: (phase: ScrubPhase, x: number, y: number) => void, size: () => {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
}, bridge?: () => AppKitChartPointerBridge | undefined): {
|
|
28
|
+
pan(event: {
|
|
29
|
+
deltaX?: unknown;
|
|
30
|
+
deltaY?: unknown;
|
|
31
|
+
state?: unknown;
|
|
32
|
+
x?: number;
|
|
33
|
+
y?: number;
|
|
34
|
+
}): void;
|
|
35
|
+
tap(view: unknown): void;
|
|
36
|
+
observe(view: unknown): () => void;
|
|
37
|
+
};
|
|
@@ -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;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { ChartType } from '../props.js';
|
|
2
|
+
import type { PlotBox, ResolvedSeries, XScale, XScaleKind, YScale } from './scales.js';
|
|
3
|
+
/** Presentation attributes — the androidsvg ∩ SVGKit subset only (fills,
|
|
4
|
+
* strokes, opacity). No filters, no text, no radial gradients. */
|
|
5
|
+
export interface Paint {
|
|
6
|
+
fill?: string;
|
|
7
|
+
fillOpacity?: number;
|
|
8
|
+
stroke?: string;
|
|
9
|
+
strokeOpacity?: number;
|
|
10
|
+
strokeWidth?: number;
|
|
11
|
+
strokeLinecap?: 'butt' | 'round' | 'square';
|
|
12
|
+
}
|
|
13
|
+
/** Datum reference — lets the overlay and hit-test map marks back to data. */
|
|
14
|
+
interface DatumRef {
|
|
15
|
+
series?: number;
|
|
16
|
+
index?: number;
|
|
17
|
+
}
|
|
18
|
+
export type Mark = DatumRef & Paint & {
|
|
19
|
+
transform?: string;
|
|
20
|
+
} & ({
|
|
21
|
+
kind: 'path';
|
|
22
|
+
d: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'rect';
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'circle';
|
|
31
|
+
cx: number;
|
|
32
|
+
cy: number;
|
|
33
|
+
r: number;
|
|
34
|
+
} | {
|
|
35
|
+
kind: 'line';
|
|
36
|
+
x1: number;
|
|
37
|
+
y1: number;
|
|
38
|
+
x2: number;
|
|
39
|
+
y2: number;
|
|
40
|
+
});
|
|
41
|
+
/** One hit-testable datum position in chart space. */
|
|
42
|
+
export interface ScenePoint {
|
|
43
|
+
series: number;
|
|
44
|
+
index: number;
|
|
45
|
+
/** Snap-to-x group — String(datum.x). */
|
|
46
|
+
key: string;
|
|
47
|
+
cx: number;
|
|
48
|
+
cy: number;
|
|
49
|
+
x: number | string | Date;
|
|
50
|
+
y: number;
|
|
51
|
+
}
|
|
52
|
+
export interface PieSlice {
|
|
53
|
+
series: number;
|
|
54
|
+
index: number;
|
|
55
|
+
label: string;
|
|
56
|
+
value: number;
|
|
57
|
+
color: string;
|
|
58
|
+
startAngle: number;
|
|
59
|
+
endAngle: number;
|
|
60
|
+
/** Slice centroid relative to the pie center — the tooltip anchor. */
|
|
61
|
+
cx: number;
|
|
62
|
+
cy: number;
|
|
63
|
+
}
|
|
64
|
+
export interface PieScene {
|
|
65
|
+
/** Pie center in chart space (plot offset applied by scene.ts). */
|
|
66
|
+
cx: number;
|
|
67
|
+
cy: number;
|
|
68
|
+
rOuter: number;
|
|
69
|
+
rInner: number;
|
|
70
|
+
slices: PieSlice[];
|
|
71
|
+
}
|
|
72
|
+
export interface ChartLayout {
|
|
73
|
+
plot: PlotBox;
|
|
74
|
+
xKind: XScaleKind;
|
|
75
|
+
x: XScale;
|
|
76
|
+
y: YScale;
|
|
77
|
+
}
|
|
78
|
+
export interface BuiltMarks {
|
|
79
|
+
marks: Mark[];
|
|
80
|
+
points: ScenePoint[];
|
|
81
|
+
pie?: PieScene;
|
|
82
|
+
}
|
|
83
|
+
export declare function buildMarks(type: ChartType, layout: ChartLayout, series: ResolvedSeries[], options: {
|
|
84
|
+
stacked?: boolean;
|
|
85
|
+
innerRadiusRatio?: number;
|
|
86
|
+
palette: string[];
|
|
87
|
+
}): BuiltMarks;
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ScaleBand, ScaleLinear, ScalePoint, ScaleTime } from 'd3-scale';
|
|
2
|
+
import type { ChartType, SeriesSpec } from '../props.js';
|
|
3
|
+
export type XScaleKind = 'band' | 'point' | 'linear' | 'time';
|
|
4
|
+
export type XScale = ScaleBand<string> | ScalePoint<string> | ScaleLinear<number, number> | ScaleTime<number, number>;
|
|
5
|
+
export type YScale = ScaleLinear<number, number>;
|
|
6
|
+
export interface PlotBox {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ResolvedSeries {
|
|
13
|
+
name: string;
|
|
14
|
+
color: string;
|
|
15
|
+
values: {
|
|
16
|
+
x: number | string | Date;
|
|
17
|
+
y: number;
|
|
18
|
+
color?: string;
|
|
19
|
+
}[];
|
|
20
|
+
}
|
|
21
|
+
/** Categorical x values across all series, first-seen order — the band/point
|
|
22
|
+
* domain. */
|
|
23
|
+
export declare function categoryDomain(data: SeriesSpec[]): string[];
|
|
24
|
+
/** A categorical x lookup — band/point domains key on String(x). */
|
|
25
|
+
export declare function categoryKey(x: number | string | Date): string;
|
|
26
|
+
/** Pick the x scale family: bar is always band, other cartesian types infer
|
|
27
|
+
* from the first datum — Date → time, string → point, number → linear. */
|
|
28
|
+
export declare function inferXKind(type: ChartType, data: SeriesSpec[]): XScaleKind;
|
|
29
|
+
export declare function buildXScale(kind: XScaleKind, data: SeriesSpec[], width: number): XScale;
|
|
30
|
+
/** Y domain: bar/area pin the zero baseline; line/scatter take the data
|
|
31
|
+
* extent; stacked bars sum per category (positive stack only — negative
|
|
32
|
+
* values in stacked mode stack below zero independently). */
|
|
33
|
+
export declare function yDomain(data: SeriesSpec[], type: ChartType, stacked: boolean): [number, number];
|
|
34
|
+
export declare function buildYScale(domain: [number, number], height: number): YScale;
|
|
35
|
+
/** Pixel center of an x value — band offsets by half the band, point and
|
|
36
|
+
* continuous scales map directly. */
|
|
37
|
+
export declare function xCenter(kind: XScaleKind, scale: XScale, value: number | string | Date): number;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ChartProps } from '../props.js';
|
|
2
|
+
import type { LabelSpec } from './axes.js';
|
|
3
|
+
import type { PieScene, ScenePoint } from './marks.js';
|
|
4
|
+
import type { PlotBox } from './scales.js';
|
|
5
|
+
/** Default categorical palette — Tableau 10, embedded so the leaf stays free
|
|
6
|
+
* of d3-scale-chromatic. */
|
|
7
|
+
export declare const PALETTE: string[];
|
|
8
|
+
export interface LegendItem {
|
|
9
|
+
color: string;
|
|
10
|
+
text: string;
|
|
11
|
+
}
|
|
12
|
+
/** The fully-resolved chart: svg markup, overlay label boxes, legend items,
|
|
13
|
+
* and per-datum hit targets in chart space. `computeScene` is the core's one
|
|
14
|
+
* entry point — the leaves only render it. */
|
|
15
|
+
export interface ChartScene {
|
|
16
|
+
type: ChartProps['type'];
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
plot: PlotBox;
|
|
20
|
+
markup: string;
|
|
21
|
+
labels: LabelSpec[];
|
|
22
|
+
legend: LegendItem[];
|
|
23
|
+
series: {
|
|
24
|
+
name: string;
|
|
25
|
+
color: string;
|
|
26
|
+
}[];
|
|
27
|
+
points: ScenePoint[];
|
|
28
|
+
pie: PieScene | null;
|
|
29
|
+
}
|
|
30
|
+
export declare function computeScene(props: ChartProps, width: number, height: number): ChartScene | null;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Mark } from './marks.js';
|
|
2
|
+
import type { PlotBox } from './scales.js';
|
|
3
|
+
/** Chart marks are plot-space; axis rules are chart-space. Paint order:
|
|
4
|
+
* gridlines under the translated marks group, frame (spine + stubs) over. */
|
|
5
|
+
export declare function svgDocument(marks: Mark[], grid: Mark[], frame: Mark[], plot: PlotBox, width: number, height: number): string;
|
|
@@ -2,25 +2,36 @@
|
|
|
2
2
|
* both platform leaves and the published .d.ts. No imports: the shared
|
|
3
3
|
* contract stays dependency-free and platform-agnostic. */
|
|
4
4
|
export type ChartType = 'line' | 'area' | 'bar' | 'pie' | 'scatter';
|
|
5
|
+
/** One plotted value. */
|
|
5
6
|
export interface ChartDatum {
|
|
6
7
|
/** Bar/pie: the category label. Line/area/scatter: number or Date. */
|
|
7
8
|
x: number | string | Date;
|
|
9
|
+
/** Value on the quantitative axis. */
|
|
8
10
|
y: number;
|
|
9
11
|
/** Per-datum color override — wins over the series color (pie slices,
|
|
10
12
|
* scatter points, individual bars). */
|
|
11
13
|
color?: string;
|
|
12
14
|
}
|
|
15
|
+
/** One named data series. */
|
|
13
16
|
export interface SeriesSpec {
|
|
17
|
+
/** Legend/tooltip name for the series. */
|
|
14
18
|
name: string;
|
|
15
19
|
/** Series color — stroke for line/scatter, fill for area/bar. Falls back
|
|
16
20
|
* to the built-in palette by series index. */
|
|
17
21
|
color?: string;
|
|
22
|
+
/** The plotted values. */
|
|
18
23
|
values: ChartDatum[];
|
|
19
24
|
}
|
|
25
|
+
/** Per-edge space inside the chart box reserved for axis labels — the
|
|
26
|
+
* plot area occupies the remainder. */
|
|
20
27
|
export interface ChartMargin {
|
|
28
|
+
/** Top margin in px/dips. */
|
|
21
29
|
top?: number;
|
|
30
|
+
/** Right margin in px/dips. */
|
|
22
31
|
right?: number;
|
|
32
|
+
/** Bottom margin in px/dips — x-axis labels live here by default. */
|
|
23
33
|
bottom?: number;
|
|
34
|
+
/** Left margin in px/dips — y-axis labels live here by default. */
|
|
24
35
|
left?: number;
|
|
25
36
|
}
|
|
26
37
|
/** Axis decomposition — gridline, tick stub, and label toggle independently
|
|
@@ -39,18 +50,28 @@ export interface AxisSpec {
|
|
|
39
50
|
format?: (value: number | string | Date) => string;
|
|
40
51
|
}
|
|
41
52
|
/** A resolved datum reference — `x`/`y` are the datum's values, not pixels. */
|
|
53
|
+
/** A resolved datum reference — `x`/`y` are the datum's values, not pixels. */
|
|
42
54
|
export interface ChartHit {
|
|
55
|
+
/** Series index into `data`. */
|
|
43
56
|
series: number;
|
|
57
|
+
/** Datum index within the series. */
|
|
44
58
|
index: number;
|
|
59
|
+
/** The datum's x value. */
|
|
45
60
|
x: number | string | Date;
|
|
61
|
+
/** Value on the quantitative axis. */
|
|
46
62
|
y: number;
|
|
47
63
|
}
|
|
64
|
+
/** Props for the `<Chart>` element — one component for every chart kind,
|
|
65
|
+
* each platform leaf rendering natively. */
|
|
48
66
|
export interface ChartProps {
|
|
67
|
+
/** Which chart kind to render. */
|
|
49
68
|
type: ChartType;
|
|
69
|
+
/** Plotted series; most types read `values`, pie reads slice x/y. */
|
|
50
70
|
data: SeriesSpec[];
|
|
51
71
|
/** Explicit size in px (web) / dips (native). Without `height`, the leaf
|
|
52
72
|
* fills its parent or derives height from `aspectRatio`. */
|
|
53
73
|
width?: number;
|
|
74
|
+
/** Explicit height — same units as `width`. */
|
|
54
75
|
height?: number;
|
|
55
76
|
/** width/height ratio used when `height` is unset. */
|
|
56
77
|
aspectRatio?: number;
|
|
@@ -63,7 +84,9 @@ export interface ChartProps {
|
|
|
63
84
|
/** Pie only: 0–<1 inner-radius fraction — any positive value renders a
|
|
64
85
|
* donut. */
|
|
65
86
|
innerRadiusRatio?: number;
|
|
87
|
+
/** X-axis presentation options. */
|
|
66
88
|
xAxis?: AxisSpec;
|
|
89
|
+
/** Y-axis presentation options. */
|
|
67
90
|
yAxis?: AxisSpec;
|
|
68
91
|
/** Legend row of series swatches. `true` = 'bottom'. Pie legends list
|
|
69
92
|
* slices, not series. */
|
|
@@ -76,8 +99,12 @@ export interface ChartProps {
|
|
|
76
99
|
onPress?: (hit: ChartHit) => void;
|
|
77
100
|
/** Scrub position changes — `null` when the gesture ends or leaves. */
|
|
78
101
|
onScrub?: (hit: ChartHit | null) => void;
|
|
102
|
+
/** Accessible description of the chart for assistive tech. */
|
|
79
103
|
accessibilityLabel?: string;
|
|
104
|
+
/** Class list applied to the chart element. */
|
|
80
105
|
className?: any;
|
|
106
|
+
/** Inline style (string CSS or object). */
|
|
81
107
|
style?: any;
|
|
108
|
+
/** Element id passed through to the host element. */
|
|
82
109
|
id?: string;
|
|
83
110
|
}
|