@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.
@@ -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;
@@ -0,0 +1,2 @@
1
+ export { Chart } from './Chart.js';
2
+ export type { AxisSpec, ChartDatum, ChartHit, ChartMargin, ChartProps, ChartType, SeriesSpec, } from './props.js';
@@ -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
  }
@@ -0,0 +1,8 @@
1
+ /** Anything accepted as a style value, including nested arrays. */
2
+ export type StyleInput = string | Record<string, any> | null | undefined | readonly StyleInput[];
3
+ /** Merge component-emitted style defaults under the authored `style` prop.
4
+ * Authored keys win; array styles fold in order; a string style is appended
5
+ * after the serialized defaults so its declarations override them too. */
6
+ export declare function mergeStyle(base: Record<string, any>, style?: Record<string, any> | readonly (Record<string, any> | null | undefined)[] | null): Record<string, any>;
7
+ export declare function mergeStyle(base: Record<string, any>, style?: StyleInput): string | Record<string, any>;
8
+ export type StyleProp = string | Record<string, any> | readonly StyleProp[] | null | undefined;
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2026 Alec Larson
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
package/types/index.d.ts DELETED
@@ -1,17 +0,0 @@
1
- // Boundary types for @octane-xplat/charts — the mechanical wrapper over
2
- // props.ts (tsrx-tsc can't emit .tsrx declarations; see ui/types/index.d.ts
3
- // for the same pattern).
4
- import type { UniversalComponent } from 'octane/universal'
5
- import type { ChartProps } from './props.js'
6
-
7
- export declare const Chart: UniversalComponent<ChartProps>
8
-
9
- export type {
10
- AxisSpec,
11
- ChartDatum,
12
- ChartHit,
13
- ChartMargin,
14
- ChartProps,
15
- ChartType,
16
- SeriesSpec,
17
- } from './props.js'