@octane-xplat/charts 0.14.0 → 0.15.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/package.json +14 -14
- package/src/Chart.tsrx +13 -3
- package/src/core/hit.ts +25 -10
- package/src/core/marks.ts +23 -21
- package/src/core/scales.ts +4 -0
- package/src/core/svg.ts +1 -1
- package/dist/macos/Chart.macos.tsrx.js +0 -351
- package/dist/macos/core/axes.js +0 -146
- package/dist/macos/core/hit.js +0 -131
- package/dist/macos/core/marks.js +0 -262
- package/dist/macos/core/scales.js +0 -99
- package/dist/macos/core/scene.js +0 -120
- package/dist/macos/core/svg.js +0 -40
- package/dist/macos/index.js +0 -2
- package/dist/macos/octane-client-build.json +0 -8
- package/dist/macos/svg-image.macos.js +0 -14
- package/dist/native/Chart.tsrx.js +0 -340
- package/dist/native/core/axes.js +0 -146
- package/dist/native/core/hit.js +0 -131
- package/dist/native/core/marks.js +0 -262
- package/dist/native/core/scales.js +0 -99
- package/dist/native/core/scene.js +0 -120
- package/dist/native/core/svg.js +0 -40
- package/dist/native/index.js +0 -2
- package/dist/native/octane-client-build.json +0 -8
- package/dist/web/Chart.web.tsrx.js +0 -493
- package/dist/web/core/axes.js +0 -146
- package/dist/web/core/hit.js +0 -131
- package/dist/web/core/marks.js +0 -262
- package/dist/web/core/scales.js +0 -99
- package/dist/web/core/scene.js +0 -120
- package/dist/web/core/svg.js +0 -40
- package/dist/web/index.js +0 -2
- package/dist/web/octane-client-build.json +0 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octane-xplat/charts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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",
|
|
@@ -24,21 +24,22 @@
|
|
|
24
24
|
"directory": "packages/charts"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"dist",
|
|
28
27
|
"types",
|
|
29
|
-
"src"
|
|
28
|
+
"src",
|
|
29
|
+
"!src/**/*.test.*",
|
|
30
|
+
"!src/**/*.spec.*"
|
|
30
31
|
],
|
|
31
32
|
"type": "module",
|
|
32
33
|
"exports": {
|
|
33
34
|
".": {
|
|
34
35
|
"macos": {
|
|
35
36
|
"types": "./types/index.d.ts",
|
|
36
|
-
"default": "./
|
|
37
|
+
"default": "./src/index.macos.ts"
|
|
37
38
|
},
|
|
38
39
|
"types": "./types/index.d.ts",
|
|
39
|
-
"web": "./
|
|
40
|
-
"native": "./
|
|
41
|
-
"default": "./
|
|
40
|
+
"web": "./src/index.web.ts",
|
|
41
|
+
"native": "./src/index.ts",
|
|
42
|
+
"default": "./src/index.ts"
|
|
42
43
|
}
|
|
43
44
|
},
|
|
44
45
|
"publishConfig": {
|
|
@@ -52,10 +53,10 @@
|
|
|
52
53
|
"d3-time-format": "4.1.0"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"@nativescript-community/octane": "0.2.
|
|
56
|
+
"@nativescript-community/octane": "0.2.5",
|
|
56
57
|
"@nativescript/core": "9.1.3",
|
|
57
|
-
"@octane-xplat/macos-renderer": "0.
|
|
58
|
-
"@octane-xplat/ui": "0.
|
|
58
|
+
"@octane-xplat/macos-renderer": "0.15.0",
|
|
59
|
+
"@octane-xplat/ui": "0.15.0",
|
|
59
60
|
"@octanejs/vite-plugin": "0.1.61",
|
|
60
61
|
"@tsrx/typescript-plugin": "0.4.11",
|
|
61
62
|
"@types/d3-array": "3.2.2",
|
|
@@ -64,10 +65,10 @@
|
|
|
64
65
|
"@types/d3-shape": "3.2.0",
|
|
65
66
|
"@types/d3-time-format": "4.0.3",
|
|
66
67
|
"octane": "0.11.0",
|
|
67
|
-
"tsrx-typegen": "0.
|
|
68
|
+
"tsrx-typegen": "0.3.0",
|
|
68
69
|
"typescript": "5.9.3",
|
|
69
70
|
"vite": "8.3.0",
|
|
70
|
-
"vitest": "
|
|
71
|
+
"vitest": "4.1.11"
|
|
71
72
|
},
|
|
72
73
|
"peerDependencies": {
|
|
73
74
|
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
@@ -84,9 +85,8 @@
|
|
|
84
85
|
}
|
|
85
86
|
},
|
|
86
87
|
"scripts": {
|
|
87
|
-
"build": "vite build && vite build --mode native && vite build --mode macos && pnpm typegen && node ../../scripts/check-native-dist.mjs",
|
|
88
88
|
"typegen": "tsc -p tsconfig.types.json",
|
|
89
|
-
"typecheck": "
|
|
89
|
+
"typecheck": "node ../../scripts/typecheck.mjs",
|
|
90
90
|
"test": "vitest run",
|
|
91
91
|
"test:packed": "node tests/packed-consumer.mjs",
|
|
92
92
|
"pack:check": "tsrx-typegen --pack-check"
|
package/src/Chart.tsrx
CHANGED
|
@@ -11,6 +11,16 @@ import type { SceneHit } from './core/hit';
|
|
|
11
11
|
const EMPTY_SVG = '<svg xmlns="http://www.w3.org/2000/svg"/>';
|
|
12
12
|
const TIP_ESTIMATE_CHAR = 6.2;
|
|
13
13
|
|
|
14
|
+
// Color throws on unparseable input — user-controlled palette strings
|
|
15
|
+
// degrade to the fallback like a browser dropping a bad CSS value.
|
|
16
|
+
const safeColor = (value: string | undefined, fallback: string): Color => {
|
|
17
|
+
try {
|
|
18
|
+
return new Color(value ?? fallback);
|
|
19
|
+
} catch {
|
|
20
|
+
return new Color(fallback);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
14
24
|
/** Chart — NativeScript leaf. The core's Mark[] serialize to one svg markup
|
|
15
25
|
* string fed to `<svgview>` (vendored ui-svg → SVGKit/androidsvg — its
|
|
16
26
|
* registration arrives transitively through `@octane-xplat/ui`'s native
|
|
@@ -106,7 +116,7 @@ export function Chart(props: ChartProps) @{
|
|
|
106
116
|
<flexboxlayout flexDirection="row" flexWrap="wrap" style={{ paddingBottom: 4 }}>
|
|
107
117
|
{scene.legend.map((item) => (
|
|
108
118
|
<flexboxlayout flexDirection="row" alignItems="center" style={{ marginRight: 12 }}>
|
|
109
|
-
<contentview style={{ width: 10, height: 10, borderRadius: 2, backgroundColor:
|
|
119
|
+
<contentview style={{ width: 10, height: 10, borderRadius: 2, backgroundColor: safeColor(item.color, 'transparent'), marginRight: 4 }} />
|
|
110
120
|
<label text={item.text} style={{ fontSize: 11 }} />
|
|
111
121
|
</flexboxlayout>
|
|
112
122
|
))}
|
|
@@ -142,7 +152,7 @@ export function Chart(props: ChartProps) @{
|
|
|
142
152
|
<contentview left={cursor.px - 0.5} top={plot.y} width={1} height={plot.height} backgroundColor={new Color('#8a8a8a')} />
|
|
143
153
|
}
|
|
144
154
|
@if (cursor && (props.crosshair || props.tooltip)) {
|
|
145
|
-
<contentview left={cursor.px - 4} top={cursor.py - 4} width={8} height={8} borderRadius={4} backgroundColor={
|
|
155
|
+
<contentview left={cursor.px - 4} top={cursor.py - 4} width={8} height={8} borderRadius={4} backgroundColor={safeColor(dotColor, '#4e79a7')} />
|
|
146
156
|
}
|
|
147
157
|
@if (cursor && props.tooltip && tipText) {
|
|
148
158
|
<flexboxlayout
|
|
@@ -164,7 +174,7 @@ export function Chart(props: ChartProps) @{
|
|
|
164
174
|
<flexboxlayout flexDirection="row" flexWrap="wrap" style={{ paddingTop: 4 }}>
|
|
165
175
|
{scene.legend.map((item) => (
|
|
166
176
|
<flexboxlayout flexDirection="row" alignItems="center" style={{ marginRight: 12 }}>
|
|
167
|
-
<contentview style={{ width: 10, height: 10, borderRadius: 2, backgroundColor:
|
|
177
|
+
<contentview style={{ width: 10, height: 10, borderRadius: 2, backgroundColor: safeColor(item.color, 'transparent'), marginRight: 4 }} />
|
|
168
178
|
<label text={item.text} style={{ fontSize: 11 }} />
|
|
169
179
|
</flexboxlayout>
|
|
170
180
|
))}
|
package/src/core/hit.ts
CHANGED
|
@@ -35,16 +35,37 @@ export function hitTest(scene: ChartScene, x: number, y: number, slop = HIT_SLOP
|
|
|
35
35
|
return null
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
if (scene.type === 'scatter') {
|
|
39
|
+
// Scatter is a point cloud, not a snapped axis — pick the datum
|
|
40
|
+
// nearest the pointer in 2D and miss when nothing is actually near.
|
|
41
|
+
let best: SceneHit | null = null
|
|
42
|
+
let bestDist = Infinity
|
|
43
|
+
for (const p of points) {
|
|
44
|
+
const d = Math.hypot(p.cx - x, p.cy - y)
|
|
45
|
+
if (d < bestDist) {
|
|
46
|
+
bestDist = d
|
|
47
|
+
best = { series: p.series, index: p.index, x: p.x, y: p.y, px: p.cx, py: p.cy }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return best !== null && bestDist <= slop ? best : null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const centers = new Map<string, { total: number; count: number }>()
|
|
39
55
|
for (const p of points) {
|
|
40
56
|
const cur = centers.get(p.key)
|
|
41
|
-
|
|
57
|
+
if (cur === undefined) {
|
|
58
|
+
centers.set(p.key, { total: p.cx, count: 1 })
|
|
59
|
+
} else {
|
|
60
|
+
cur.total += p.cx
|
|
61
|
+
cur.count += 1
|
|
62
|
+
}
|
|
42
63
|
}
|
|
43
64
|
|
|
44
65
|
let key: string | null = null
|
|
45
66
|
let keyDist = Infinity
|
|
46
|
-
for (const [k,
|
|
47
|
-
const d = Math.abs(
|
|
67
|
+
for (const [k, sum] of centers) {
|
|
68
|
+
const d = Math.abs(sum.total / sum.count - x)
|
|
48
69
|
if (d < keyDist) {
|
|
49
70
|
keyDist = d
|
|
50
71
|
key = k
|
|
@@ -69,12 +90,6 @@ export function hitTest(scene: ChartScene, x: number, y: number, slop = HIT_SLOP
|
|
|
69
90
|
}
|
|
70
91
|
}
|
|
71
92
|
|
|
72
|
-
// Scatter is a point cloud, not a snapped axis — miss when nothing is
|
|
73
|
-
// actually near the pointer.
|
|
74
|
-
if (best && scene.type === 'scatter' && bestDist > slop) {
|
|
75
|
-
return null
|
|
76
|
-
}
|
|
77
|
-
|
|
78
93
|
return best
|
|
79
94
|
}
|
|
80
95
|
|
package/src/core/marks.ts
CHANGED
|
@@ -107,7 +107,7 @@ export function buildMarks(
|
|
|
107
107
|
function lineMarks(layout: ChartLayout, series: ResolvedSeries[]): BuiltMarks {
|
|
108
108
|
const { xKind, x, y } = layout
|
|
109
109
|
const gen = linePath<ChartDatum>()
|
|
110
|
-
.defined((d) => Number.isFinite(d.y))
|
|
110
|
+
.defined((d) => Number.isFinite(d.y) && Number.isFinite(xCenter(xKind, x, d.x)))
|
|
111
111
|
.x((d) => xCenter(xKind, x, d.x))
|
|
112
112
|
.y((d) => y(d.y))
|
|
113
113
|
.curve(curveMonotoneX)
|
|
@@ -126,15 +126,13 @@ function lineMarks(layout: ChartLayout, series: ResolvedSeries[]): BuiltMarks {
|
|
|
126
126
|
})
|
|
127
127
|
|
|
128
128
|
s.values.forEach((d, i) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
y: d.y,
|
|
137
|
-
})
|
|
129
|
+
const cx = xCenter(xKind, x, d.x)
|
|
130
|
+
const cy = y(d.y)
|
|
131
|
+
if (!Number.isFinite(cx) || !Number.isFinite(cy)) {
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
points.push({ series: si, index: i, key: categoryKey(d.x), cx, cy, x: d.x, y: d.y })
|
|
138
136
|
})
|
|
139
137
|
})
|
|
140
138
|
|
|
@@ -144,15 +142,17 @@ function lineMarks(layout: ChartLayout, series: ResolvedSeries[]): BuiltMarks {
|
|
|
144
142
|
function areaMarks(layout: ChartLayout, series: ResolvedSeries[]): BuiltMarks {
|
|
145
143
|
const { xKind, x, y } = layout
|
|
146
144
|
const zero = y(Math.max(y.domain()[0], Math.min(0, y.domain()[1])))
|
|
145
|
+
const defined = (d: ChartDatum) => Number.isFinite(d.y) && Number.isFinite(xCenter(xKind, x, d.x))
|
|
146
|
+
|
|
147
147
|
const gen = areaPath<ChartDatum>()
|
|
148
|
-
.defined(
|
|
148
|
+
.defined(defined)
|
|
149
149
|
.x((d) => xCenter(xKind, x, d.x))
|
|
150
150
|
.y0(zero)
|
|
151
151
|
.y1((d) => y(d.y))
|
|
152
152
|
.curve(curveMonotoneX)
|
|
153
153
|
|
|
154
154
|
const stroke = linePath<ChartDatum>()
|
|
155
|
-
.defined(
|
|
155
|
+
.defined(defined)
|
|
156
156
|
.x((d) => xCenter(xKind, x, d.x))
|
|
157
157
|
.y((d) => y(d.y))
|
|
158
158
|
.curve(curveMonotoneX)
|
|
@@ -178,15 +178,13 @@ function areaMarks(layout: ChartLayout, series: ResolvedSeries[]): BuiltMarks {
|
|
|
178
178
|
})
|
|
179
179
|
|
|
180
180
|
s.values.forEach((d, i) => {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
y: d.y,
|
|
189
|
-
})
|
|
181
|
+
const cx = xCenter(xKind, x, d.x)
|
|
182
|
+
const cy = y(d.y)
|
|
183
|
+
if (!Number.isFinite(cx) || !Number.isFinite(cy)) {
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
points.push({ series: si, index: i, key: categoryKey(d.x), cx, cy, x: d.x, y: d.y })
|
|
190
188
|
})
|
|
191
189
|
})
|
|
192
190
|
|
|
@@ -201,6 +199,10 @@ function scatterMarks(layout: ChartLayout, series: ResolvedSeries[]): BuiltMarks
|
|
|
201
199
|
s.values.forEach((d, i) => {
|
|
202
200
|
const cx = xCenter(xKind, x, d.x)
|
|
203
201
|
const cy = y(d.y)
|
|
202
|
+
if (!Number.isFinite(cx) || !Number.isFinite(cy)) {
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
204
206
|
marks.push({
|
|
205
207
|
kind: 'circle',
|
|
206
208
|
cx,
|
package/src/core/scales.ts
CHANGED
|
@@ -122,6 +122,10 @@ export function yDomain(data: SeriesSpec[], type: ChartType, stacked: boolean):
|
|
|
122
122
|
const neg = new Map<string, number>()
|
|
123
123
|
for (const series of data) {
|
|
124
124
|
for (const d of series.values) {
|
|
125
|
+
if (!Number.isFinite(d.y)) {
|
|
126
|
+
continue
|
|
127
|
+
}
|
|
128
|
+
|
|
125
129
|
const key = String(d.x)
|
|
126
130
|
if (d.y >= 0) {
|
|
127
131
|
pos.set(key, (pos.get(key) ?? 0) + d.y)
|
package/src/core/svg.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { PlotBox } from './scales'
|
|
|
5
5
|
* subset: `<svg>`/`<g>` structure, path/rect/circle/line shapes, solid fills
|
|
6
6
|
* and strokes, `translate` transforms, opacity attributes. Never `<text>`,
|
|
7
7
|
* filters, masks, patterns, or gradients — labels are real elements in the
|
|
8
|
-
* leaf overlay (docs/notes/primitive-notes.md). */
|
|
8
|
+
* leaf overlay (.agents/docs/notes/primitive-notes.md). */
|
|
9
9
|
|
|
10
10
|
function num(v: number): string {
|
|
11
11
|
if (!Number.isFinite(v)) {
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
import { appKitImageSource } from "./svg-image.macos.js";
|
|
2
|
-
import { computeScene } from "./core/scene.js";
|
|
3
|
-
import { createScrub, hitLabel } from "./core/hit.js";
|
|
4
|
-
import { defineUniversalComponent, hookSlots, universalIf, universalPlan, universalProps, universalValue, useMemo, useRef, useState, withSlot } from "@nativescript-community/octane";
|
|
5
|
-
import { useMeasure } from "@octane-xplat/ui";
|
|
6
|
-
//#region src/Chart.macos.tsrx
|
|
7
|
-
var _hs$ = /* @__PURE__ */ hookSlots(7);
|
|
8
|
-
var _h$0 = /* @__PURE__ */ Symbol(_hs$);
|
|
9
|
-
var _h$1 = /* @__PURE__ */ Symbol(_hs$ + 1);
|
|
10
|
-
var _h$2 = /* @__PURE__ */ Symbol(_hs$ + 2);
|
|
11
|
-
var _h$3 = /* @__PURE__ */ Symbol(_hs$ + 3);
|
|
12
|
-
var _h$4 = /* @__PURE__ */ Symbol(_hs$ + 4);
|
|
13
|
-
var _h$5 = /* @__PURE__ */ Symbol(_hs$ + 5);
|
|
14
|
-
var _h$6 = /* @__PURE__ */ Symbol(_hs$ + 6);
|
|
15
|
-
var __octaneUniversalPlan0 = universalPlan("macos", {
|
|
16
|
-
"kind": "host",
|
|
17
|
-
"type": "flexboxlayout",
|
|
18
|
-
"props": {
|
|
19
|
-
"flexDirection": "row",
|
|
20
|
-
"alignItems": "center"
|
|
21
|
-
},
|
|
22
|
-
"bindings": [["style", 0]],
|
|
23
|
-
"children": [{
|
|
24
|
-
"kind": "host",
|
|
25
|
-
"type": "flexboxlayout",
|
|
26
|
-
"bindings": [["style", 1]]
|
|
27
|
-
}, {
|
|
28
|
-
"kind": "host",
|
|
29
|
-
"type": "label",
|
|
30
|
-
"bindings": [["text", 2], ["style", 3]]
|
|
31
|
-
}]
|
|
32
|
-
});
|
|
33
|
-
var __octaneUniversalPlan1 = universalPlan("macos", {
|
|
34
|
-
"kind": "host",
|
|
35
|
-
"type": "flexboxlayout",
|
|
36
|
-
"props": {
|
|
37
|
-
"flexDirection": "row",
|
|
38
|
-
"flexWrap": "wrap"
|
|
39
|
-
},
|
|
40
|
-
"bindings": [["style", 0]],
|
|
41
|
-
"children": [{
|
|
42
|
-
"kind": "slot",
|
|
43
|
-
"slot": 1
|
|
44
|
-
}]
|
|
45
|
-
});
|
|
46
|
-
var __octaneUniversalPlan2 = universalPlan("macos", {
|
|
47
|
-
"kind": "host",
|
|
48
|
-
"type": "label",
|
|
49
|
-
"propsSlot": 0
|
|
50
|
-
});
|
|
51
|
-
var __octaneUniversalPlan3 = universalPlan("macos", {
|
|
52
|
-
"kind": "host",
|
|
53
|
-
"type": "flexboxlayout",
|
|
54
|
-
"bindings": [
|
|
55
|
-
["left", 0],
|
|
56
|
-
["top", 1],
|
|
57
|
-
["style", 2]
|
|
58
|
-
]
|
|
59
|
-
});
|
|
60
|
-
var __octaneUniversalPlan4 = universalPlan("macos", {
|
|
61
|
-
"kind": "host",
|
|
62
|
-
"type": "flexboxlayout",
|
|
63
|
-
"bindings": [
|
|
64
|
-
["left", 0],
|
|
65
|
-
["top", 1],
|
|
66
|
-
["style", 2]
|
|
67
|
-
]
|
|
68
|
-
});
|
|
69
|
-
var __octaneUniversalPlan5 = universalPlan("macos", {
|
|
70
|
-
"kind": "host",
|
|
71
|
-
"type": "label",
|
|
72
|
-
"propsSlot": 0
|
|
73
|
-
});
|
|
74
|
-
var __octaneUniversalPlan6 = universalPlan("macos", {
|
|
75
|
-
"kind": "host",
|
|
76
|
-
"type": "flexboxlayout",
|
|
77
|
-
"props": {
|
|
78
|
-
"flexDirection": "row",
|
|
79
|
-
"alignItems": "center"
|
|
80
|
-
},
|
|
81
|
-
"bindings": [["style", 0]],
|
|
82
|
-
"children": [{
|
|
83
|
-
"kind": "host",
|
|
84
|
-
"type": "flexboxlayout",
|
|
85
|
-
"bindings": [["style", 1]]
|
|
86
|
-
}, {
|
|
87
|
-
"kind": "host",
|
|
88
|
-
"type": "label",
|
|
89
|
-
"bindings": [["text", 2], ["style", 3]]
|
|
90
|
-
}]
|
|
91
|
-
});
|
|
92
|
-
var __octaneUniversalPlan7 = universalPlan("macos", {
|
|
93
|
-
"kind": "host",
|
|
94
|
-
"type": "flexboxlayout",
|
|
95
|
-
"props": {
|
|
96
|
-
"flexDirection": "row",
|
|
97
|
-
"flexWrap": "wrap"
|
|
98
|
-
},
|
|
99
|
-
"bindings": [["style", 0]],
|
|
100
|
-
"children": [{
|
|
101
|
-
"kind": "slot",
|
|
102
|
-
"slot": 1
|
|
103
|
-
}]
|
|
104
|
-
});
|
|
105
|
-
var __octaneUniversalPlan8 = universalPlan("macos", {
|
|
106
|
-
"kind": "host",
|
|
107
|
-
"type": "flexboxlayout",
|
|
108
|
-
"props": { "accessibilityRole": "image" },
|
|
109
|
-
"bindings": [
|
|
110
|
-
["id", 0],
|
|
111
|
-
["className", 1],
|
|
112
|
-
["style", 2],
|
|
113
|
-
["accessible", 3],
|
|
114
|
-
["accessibilityLabel", 4]
|
|
115
|
-
],
|
|
116
|
-
"children": [
|
|
117
|
-
{
|
|
118
|
-
"kind": "slot",
|
|
119
|
-
"slot": 5
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
"kind": "host",
|
|
123
|
-
"type": "gridlayout",
|
|
124
|
-
"bindings": [["ref", 6], ["style", 7]],
|
|
125
|
-
"children": [{
|
|
126
|
-
"kind": "host",
|
|
127
|
-
"type": "image",
|
|
128
|
-
"props": { "accessibilityLabel": "" },
|
|
129
|
-
"bindings": [
|
|
130
|
-
["id", 8],
|
|
131
|
-
["src", 9],
|
|
132
|
-
["style", 10]
|
|
133
|
-
]
|
|
134
|
-
}, {
|
|
135
|
-
"kind": "host",
|
|
136
|
-
"type": "flexboxlayout",
|
|
137
|
-
"bindings": [
|
|
138
|
-
["id", 11],
|
|
139
|
-
["style", 12],
|
|
140
|
-
["onTap", 13]
|
|
141
|
-
],
|
|
142
|
-
"children": [{
|
|
143
|
-
"kind": "host",
|
|
144
|
-
"type": "absolutelayout",
|
|
145
|
-
"bindings": [["id", 14], ["style", 15]],
|
|
146
|
-
"children": [
|
|
147
|
-
{
|
|
148
|
-
"kind": "slot",
|
|
149
|
-
"slot": 16
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
"kind": "slot",
|
|
153
|
-
"slot": 17
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
"kind": "slot",
|
|
157
|
-
"slot": 18
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
"kind": "slot",
|
|
161
|
-
"slot": 19
|
|
162
|
-
}
|
|
163
|
-
]
|
|
164
|
-
}]
|
|
165
|
-
}]
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
"kind": "slot",
|
|
169
|
-
"slot": 20
|
|
170
|
-
}
|
|
171
|
-
]
|
|
172
|
-
});
|
|
173
|
-
var EMPTY_SVG = "<svg xmlns=\"http://www.w3.org/2000/svg\"/>";
|
|
174
|
-
var TIP_ESTIMATE_CHAR = 6.2;
|
|
175
|
-
var Chart = defineUniversalComponent("macos", function Chart(props) {
|
|
176
|
-
const measure = withSlot(_h$0, useMeasure);
|
|
177
|
-
const [cursor, setCursor] = useState(null, _h$1);
|
|
178
|
-
const sceneRef = useRef(null, _h$2);
|
|
179
|
-
const propsRef = useRef(props, _h$3);
|
|
180
|
-
propsRef.current = props;
|
|
181
|
-
const bounds = measure.bounds;
|
|
182
|
-
const w = props.width ?? bounds?.width ?? 0;
|
|
183
|
-
const h = props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : bounds?.height && bounds.height > 0 ? bounds.height : w > 0 ? w / 1.6 : 0);
|
|
184
|
-
const scene = useMemo(() => w > 0 && h > 0 ? computeScene(propsRef.current, w, h) : null, [
|
|
185
|
-
props.type,
|
|
186
|
-
props.data,
|
|
187
|
-
props.margin,
|
|
188
|
-
props.stacked,
|
|
189
|
-
props.innerRadiusRatio,
|
|
190
|
-
props.xAxis,
|
|
191
|
-
props.yAxis,
|
|
192
|
-
w,
|
|
193
|
-
h
|
|
194
|
-
], _h$4);
|
|
195
|
-
sceneRef.current = scene;
|
|
196
|
-
const interactive = !!(props.onPress || props.onScrub || props.tooltip || props.crosshair);
|
|
197
|
-
const onTap = useMemo(() => {
|
|
198
|
-
const scrub = createScrub(() => sceneRef.current, () => propsRef.current, setCursor);
|
|
199
|
-
return (e) => {
|
|
200
|
-
const scene = sceneRef.current;
|
|
201
|
-
scrub("tap", e?.getX?.() ?? (scene?.width ?? 0) / 2, e?.getY?.() ?? (scene?.height ?? 0) / 2);
|
|
202
|
-
};
|
|
203
|
-
}, [], _h$5);
|
|
204
|
-
const markup = scene?.markup ?? EMPTY_SVG;
|
|
205
|
-
const imageSource = useMemo(() => appKitImageSource(markup), [markup], _h$6);
|
|
206
|
-
const legend = props.legend === true ? "bottom" : props.legend;
|
|
207
|
-
const plot = scene?.plot;
|
|
208
|
-
const dotColor = cursor && scene ? scene.pie ? scene.pie.slices.find((s) => s.series === cursor.series && s.index === cursor.index)?.color : scene.series[cursor.series]?.color : void 0;
|
|
209
|
-
const tipText = cursor && scene ? hitLabel(scene, cursor) : null;
|
|
210
|
-
const tipWidth = tipText ? tipText.length * TIP_ESTIMATE_CHAR + 14 : 0;
|
|
211
|
-
const tipLeft = cursor && scene ? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth)) : 0;
|
|
212
|
-
const tipTop = cursor ? cursor.py - 30 : 0;
|
|
213
|
-
return universalValue(__octaneUniversalPlan8, [
|
|
214
|
-
props.id,
|
|
215
|
-
props.className,
|
|
216
|
-
{
|
|
217
|
-
flexDirection: "column",
|
|
218
|
-
...props.style
|
|
219
|
-
},
|
|
220
|
-
props.accessibilityLabel != null,
|
|
221
|
-
props.accessibilityLabel,
|
|
222
|
-
universalIf(legend === "top" && scene, () => {
|
|
223
|
-
return universalValue(__octaneUniversalPlan1, [{ paddingBottom: 4 }, scene.legend.map((item) => universalValue(__octaneUniversalPlan0, [
|
|
224
|
-
{ marginRight: 12 },
|
|
225
|
-
{
|
|
226
|
-
width: 10,
|
|
227
|
-
height: 10,
|
|
228
|
-
borderRadius: 2,
|
|
229
|
-
backgroundColor: item.color,
|
|
230
|
-
marginRight: 4
|
|
231
|
-
},
|
|
232
|
-
item.text,
|
|
233
|
-
{ fontSize: 11 }
|
|
234
|
-
]))]);
|
|
235
|
-
}),
|
|
236
|
-
measure.ref,
|
|
237
|
-
{
|
|
238
|
-
width: props.width,
|
|
239
|
-
height: props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : void 0),
|
|
240
|
-
flexGrow: 1
|
|
241
|
-
},
|
|
242
|
-
props.id ? props.id + "-image" : void 0,
|
|
243
|
-
imageSource,
|
|
244
|
-
{
|
|
245
|
-
width: w,
|
|
246
|
-
height: h
|
|
247
|
-
},
|
|
248
|
-
props.id ? props.id + "-tap" : void 0,
|
|
249
|
-
{
|
|
250
|
-
width: w,
|
|
251
|
-
height: h
|
|
252
|
-
},
|
|
253
|
-
interactive ? onTap : void 0,
|
|
254
|
-
props.id ? props.id + "-overlay" : void 0,
|
|
255
|
-
{
|
|
256
|
-
width: w,
|
|
257
|
-
height: h
|
|
258
|
-
},
|
|
259
|
-
scene?.labels.map((l) => universalValue(__octaneUniversalPlan2, [universalProps([
|
|
260
|
-
[
|
|
261
|
-
"set",
|
|
262
|
-
"text",
|
|
263
|
-
l.text
|
|
264
|
-
],
|
|
265
|
-
["spread", {
|
|
266
|
-
left: l.x,
|
|
267
|
-
top: l.y
|
|
268
|
-
}],
|
|
269
|
-
[
|
|
270
|
-
"set",
|
|
271
|
-
"style",
|
|
272
|
-
{
|
|
273
|
-
width: l.width,
|
|
274
|
-
fontSize: 10,
|
|
275
|
-
opacity: .7,
|
|
276
|
-
textAlign: l.align === "center" ? "center" : l.align === "end" ? "right" : "left"
|
|
277
|
-
}
|
|
278
|
-
]
|
|
279
|
-
])])),
|
|
280
|
-
universalIf(cursor && props.crosshair && !scene?.pie && plot, () => {
|
|
281
|
-
return universalValue(__octaneUniversalPlan3, [
|
|
282
|
-
cursor.px - .5,
|
|
283
|
-
plot.y,
|
|
284
|
-
{
|
|
285
|
-
width: 1,
|
|
286
|
-
height: plot.height,
|
|
287
|
-
backgroundColor: "#8a8a8a"
|
|
288
|
-
}
|
|
289
|
-
]);
|
|
290
|
-
}),
|
|
291
|
-
universalIf(cursor && (props.crosshair || props.tooltip), () => {
|
|
292
|
-
return universalValue(__octaneUniversalPlan4, [
|
|
293
|
-
cursor.px - 4,
|
|
294
|
-
cursor.py - 4,
|
|
295
|
-
{
|
|
296
|
-
width: 8,
|
|
297
|
-
height: 8,
|
|
298
|
-
borderRadius: 4,
|
|
299
|
-
backgroundColor: dotColor ?? "#4e79a7"
|
|
300
|
-
}
|
|
301
|
-
]);
|
|
302
|
-
}),
|
|
303
|
-
universalIf(cursor && props.tooltip && tipText, () => {
|
|
304
|
-
return universalValue(__octaneUniversalPlan5, [universalProps([
|
|
305
|
-
[
|
|
306
|
-
"set",
|
|
307
|
-
"id",
|
|
308
|
-
props.id ? props.id + "-tooltip" : void 0
|
|
309
|
-
],
|
|
310
|
-
[
|
|
311
|
-
"set",
|
|
312
|
-
"text",
|
|
313
|
-
tipText
|
|
314
|
-
],
|
|
315
|
-
["spread", {
|
|
316
|
-
left: tipLeft,
|
|
317
|
-
top: tipTop < 0 ? cursor.py + 12 : tipTop
|
|
318
|
-
}],
|
|
319
|
-
[
|
|
320
|
-
"set",
|
|
321
|
-
"style",
|
|
322
|
-
{
|
|
323
|
-
width: tipWidth,
|
|
324
|
-
height: 24,
|
|
325
|
-
backgroundColor: "rgba(20,20,20,0.88)",
|
|
326
|
-
borderRadius: 4,
|
|
327
|
-
color: "#ffffff",
|
|
328
|
-
fontSize: 11,
|
|
329
|
-
textAlign: "center"
|
|
330
|
-
}
|
|
331
|
-
]
|
|
332
|
-
])]);
|
|
333
|
-
}),
|
|
334
|
-
universalIf(legend === "bottom" && scene, () => {
|
|
335
|
-
return universalValue(__octaneUniversalPlan7, [{ paddingTop: 4 }, scene.legend.map((item) => universalValue(__octaneUniversalPlan6, [
|
|
336
|
-
{ marginRight: 12 },
|
|
337
|
-
{
|
|
338
|
-
width: 10,
|
|
339
|
-
height: 10,
|
|
340
|
-
borderRadius: 2,
|
|
341
|
-
backgroundColor: item.color,
|
|
342
|
-
marginRight: 4
|
|
343
|
-
},
|
|
344
|
-
item.text,
|
|
345
|
-
{ fontSize: 11 }
|
|
346
|
-
]))]);
|
|
347
|
-
})
|
|
348
|
-
]);
|
|
349
|
-
}, { "module": "@octane-xplat/macos-renderer" });
|
|
350
|
-
//#endregion
|
|
351
|
-
export { Chart };
|