@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/core/axes.ts
CHANGED
|
@@ -10,20 +10,20 @@ import { xCenter } from './scales'
|
|
|
10
10
|
* never as svg `<text>` (androidsvg/SVGKit text is degraded). `x`/`y` is the
|
|
11
11
|
* box origin in chart space; `width` bounds it for alignment. */
|
|
12
12
|
export interface LabelSpec {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
x: number
|
|
14
|
+
y: number
|
|
15
|
+
width: number
|
|
16
|
+
align: 'start' | 'center' | 'end'
|
|
17
|
+
text: string
|
|
18
|
+
axis: 'x' | 'y'
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export interface AxisModel {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
labels: LabelSpec[]
|
|
23
|
+
/** Spine and tick stubs — painted over marks. */
|
|
24
|
+
frame: Mark[]
|
|
25
|
+
/** Gridlines — painted under marks. */
|
|
26
|
+
grid: Mark[]
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const AXIS_COLOR = '#9aa3ad'
|
|
@@ -37,175 +37,182 @@ const day = timeFormat('%b %d')
|
|
|
37
37
|
/** Default tick label formatting — SI suffixes for big magnitudes, plain
|
|
38
38
|
* significant digits otherwise, short month-day for dates. */
|
|
39
39
|
export function defaultFormat(value: number | string | Date): string {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
if (value instanceof Date) {
|
|
41
|
+
return day(value)
|
|
42
|
+
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
if (typeof value === 'number') {
|
|
45
|
+
return Math.abs(value) >= 1000 ? si(value) : plain(value)
|
|
46
|
+
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
return String(value)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/** Cap categorical label count so boxes don't collide — keep every nth. */
|
|
52
52
|
function thinDomain(domain: string[], plotWidth: number): string[] {
|
|
53
|
-
|
|
54
|
-
if (domain.length <= maxLabels) {
|
|
55
|
-
return domain
|
|
56
|
-
}
|
|
53
|
+
const maxLabels = Math.max(2, Math.floor(plotWidth / 56))
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
if (domain.length <= maxLabels) {
|
|
56
|
+
return domain
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const step = Math.ceil(domain.length / maxLabels)
|
|
60
|
+
|
|
61
|
+
return domain.filter((_, i) => i % step === 0)
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
export function xAxisModel(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
kind: XScaleKind,
|
|
66
|
+
scale: XScale,
|
|
67
|
+
spec: AxisSpec | undefined,
|
|
68
|
+
plot: PlotBox,
|
|
67
69
|
): AxisModel {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
70
|
+
const labels = spec?.labels !== false
|
|
71
|
+
const stubs = spec?.ticks !== false
|
|
72
|
+
const grid = spec?.grid === true
|
|
73
|
+
const fmt = spec?.format ?? defaultFormat
|
|
74
|
+
|
|
75
|
+
const frame: Mark[] = [
|
|
76
|
+
{
|
|
77
|
+
kind: 'line',
|
|
78
|
+
x1: plot.x,
|
|
79
|
+
y1: plot.y + plot.height,
|
|
80
|
+
x2: plot.x + plot.width,
|
|
81
|
+
y2: plot.y + plot.height,
|
|
82
|
+
stroke: AXIS_COLOR,
|
|
83
|
+
strokeWidth: 1,
|
|
84
|
+
},
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
const gridMarks: Mark[] = []
|
|
88
|
+
const out: LabelSpec[] = []
|
|
89
|
+
|
|
90
|
+
let values: (string | number | Date)[]
|
|
91
|
+
let format: (v: number | string | Date) => string = fmt
|
|
92
|
+
|
|
93
|
+
if (kind === 'band' || kind === 'point') {
|
|
94
|
+
values = thinDomain((scale as ScaleBand<string> | ScalePoint<string>).domain(), plot.width)
|
|
95
|
+
} else {
|
|
96
|
+
const continuous = scale as ScaleLinear<number, number> | ScaleTime<number, number>
|
|
97
|
+
const count = spec?.tickCount ?? 6
|
|
98
|
+
|
|
99
|
+
values = continuous.ticks(count) as (number | Date)[]
|
|
100
|
+
if (!spec?.format && kind === 'time') {
|
|
101
|
+
const tf = (continuous as ScaleTime<number, number>).tickFormat(count)
|
|
102
|
+
|
|
103
|
+
format = (v) => tf(v as Date)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
for (const v of values) {
|
|
108
|
+
const px = plot.x + xCenter(kind, scale, v)
|
|
109
|
+
|
|
110
|
+
if (stubs) {
|
|
111
|
+
frame.push({
|
|
112
|
+
kind: 'line',
|
|
113
|
+
x1: px,
|
|
114
|
+
y1: plot.y + plot.height,
|
|
115
|
+
x2: px,
|
|
116
|
+
y2: plot.y + plot.height + 4,
|
|
117
|
+
stroke: AXIS_COLOR,
|
|
118
|
+
strokeWidth: 1,
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (grid) {
|
|
123
|
+
gridMarks.push({
|
|
124
|
+
kind: 'line',
|
|
125
|
+
x1: px,
|
|
126
|
+
y1: plot.y,
|
|
127
|
+
x2: px,
|
|
128
|
+
y2: plot.y + plot.height,
|
|
129
|
+
stroke: GRID_COLOR,
|
|
130
|
+
strokeOpacity: GRID_OPACITY,
|
|
131
|
+
strokeWidth: 1,
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (labels) {
|
|
136
|
+
const width = Math.min(72, plot.width / Math.max(1, values.length))
|
|
137
|
+
const boxX = Math.min(
|
|
138
|
+
Math.max(0, px - width / 2),
|
|
139
|
+
Math.max(0, plot.x + plot.width + 8 - width),
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
out.push({
|
|
143
|
+
x: boxX,
|
|
144
|
+
y: plot.y + plot.height + 6,
|
|
145
|
+
width,
|
|
146
|
+
align: 'center',
|
|
147
|
+
text: format(v),
|
|
148
|
+
axis: 'x',
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return { labels: out, frame, grid: gridMarks }
|
|
148
154
|
}
|
|
149
155
|
|
|
150
156
|
export function yAxisModel(scale: YScale, spec: AxisSpec | undefined, plot: PlotBox): AxisModel {
|
|
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
|
-
|
|
157
|
+
const labels = spec?.labels !== false
|
|
158
|
+
const stubs = spec?.ticks !== false
|
|
159
|
+
const grid = spec?.grid === true
|
|
160
|
+
const fmt = spec?.format ?? defaultFormat
|
|
161
|
+
|
|
162
|
+
const frame: Mark[] = [
|
|
163
|
+
{
|
|
164
|
+
kind: 'line',
|
|
165
|
+
x1: plot.x,
|
|
166
|
+
y1: plot.y,
|
|
167
|
+
x2: plot.x,
|
|
168
|
+
y2: plot.y + plot.height,
|
|
169
|
+
stroke: AXIS_COLOR,
|
|
170
|
+
strokeWidth: 1,
|
|
171
|
+
},
|
|
172
|
+
]
|
|
173
|
+
|
|
174
|
+
const gridMarks: Mark[] = []
|
|
175
|
+
const out: LabelSpec[] = []
|
|
176
|
+
|
|
177
|
+
for (const v of scale.ticks(spec?.tickCount ?? 5)) {
|
|
178
|
+
const py = plot.y + scale(v)
|
|
179
|
+
|
|
180
|
+
if (stubs) {
|
|
181
|
+
frame.push({
|
|
182
|
+
kind: 'line',
|
|
183
|
+
x1: plot.x - 4,
|
|
184
|
+
y1: py,
|
|
185
|
+
x2: plot.x,
|
|
186
|
+
y2: py,
|
|
187
|
+
stroke: AXIS_COLOR,
|
|
188
|
+
strokeWidth: 1,
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (grid) {
|
|
193
|
+
gridMarks.push({
|
|
194
|
+
kind: 'line',
|
|
195
|
+
x1: plot.x,
|
|
196
|
+
y1: py,
|
|
197
|
+
x2: plot.x + plot.width,
|
|
198
|
+
y2: py,
|
|
199
|
+
stroke: GRID_COLOR,
|
|
200
|
+
strokeOpacity: GRID_OPACITY,
|
|
201
|
+
strokeWidth: 1,
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (labels) {
|
|
206
|
+
out.push({
|
|
207
|
+
x: 0,
|
|
208
|
+
y: py - 6,
|
|
209
|
+
width: Math.max(0, plot.x - 8),
|
|
210
|
+
align: 'end',
|
|
211
|
+
text: fmt(v),
|
|
212
|
+
axis: 'y',
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return { labels: out, frame, grid: gridMarks }
|
|
211
218
|
}
|