@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
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @octane-xplat/charts
|
|
2
|
+
|
|
3
|
+
Show a small dataset as a line, area, bar, pie, or scatter chart. The package
|
|
4
|
+
provides shared chart data and interaction props with web, iOS/Android, and
|
|
5
|
+
experimental macOS AppKit implementations.
|
|
6
|
+
|
|
7
|
+
## Show a bar chart
|
|
8
|
+
|
|
9
|
+
Start with a [configured Xplat app](https://octane-xplat.goddardai.org/toolchain#create-and-run),
|
|
10
|
+
then install from its directory:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
bun add @octane-xplat/charts
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Put this component in a `.tsx` or `.tsrx` screen. Each series has a name and
|
|
17
|
+
an array of `{ x, y }` values; bars use category names for `x`:
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { Chart } from '@octane-xplat/charts'
|
|
21
|
+
|
|
22
|
+
export function PackingChart() {
|
|
23
|
+
return (
|
|
24
|
+
<Chart
|
|
25
|
+
type="bar"
|
|
26
|
+
width={320}
|
|
27
|
+
height={220}
|
|
28
|
+
accessibilityLabel="Packed items by bag: carry-on 4, day bag 2"
|
|
29
|
+
data={[
|
|
30
|
+
{
|
|
31
|
+
name: 'Packed items',
|
|
32
|
+
values: [
|
|
33
|
+
{ x: 'Carry-on', y: 4 },
|
|
34
|
+
{ x: 'Day bag', y: 2 },
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
]}
|
|
38
|
+
/>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The screen should show two bars, with Carry-on twice the height of Day bag.
|
|
44
|
+
Keep a text summary available for readers who cannot use the chart. If the
|
|
45
|
+
chart is blank, check that its container has nonzero size and the dataset is
|
|
46
|
+
not empty.
|
|
47
|
+
|
|
48
|
+
## Choose the data shape
|
|
49
|
+
|
|
50
|
+
Bar and pie charts use category labels. Line, area, and scatter charts use
|
|
51
|
+
numbers or dates on the horizontal axis. Use the exported types to check data
|
|
52
|
+
before passing it to a chart:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import type { SeriesSpec } from '@octane-xplat/charts'
|
|
56
|
+
|
|
57
|
+
const progress: SeriesSpec[] = [
|
|
58
|
+
{
|
|
59
|
+
name: 'Items packed',
|
|
60
|
+
values: [
|
|
61
|
+
{ x: 1, y: 2 },
|
|
62
|
+
{ x: 2, y: 5 },
|
|
63
|
+
{ x: 3, y: 6 },
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Respond to pointing and tapping
|
|
70
|
+
|
|
71
|
+
Add `tooltip` or `crosshair` to show the value under the pointer, `onScrub` to
|
|
72
|
+
follow it, and `onPress` to react when someone picks a datum. On web and macOS
|
|
73
|
+
AppKit, hovering moves the cursor, dragging scrubs and clicking presses the
|
|
74
|
+
point under the pointer. On iOS and Android, touching and dragging scrubs and
|
|
75
|
+
tapping presses.
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import { useState } from 'octane'
|
|
79
|
+
import { Chart, type ChartHit } from '@octane-xplat/charts'
|
|
80
|
+
|
|
81
|
+
export function StepsChart() {
|
|
82
|
+
const [picked, setPicked] = useState<ChartHit | null>(null)
|
|
83
|
+
return (
|
|
84
|
+
<Chart
|
|
85
|
+
type="line"
|
|
86
|
+
width={320}
|
|
87
|
+
height={200}
|
|
88
|
+
tooltip
|
|
89
|
+
crosshair
|
|
90
|
+
onPress={setPicked}
|
|
91
|
+
accessibilityLabel={picked ? `Picked ${picked.y} steps` : 'Steps per day'}
|
|
92
|
+
data={[{ name: 'Steps', values: [{ x: 1, y: 4200 }, { x: 2, y: 6100 }, { x: 3, y: 5300 }] }]}
|
|
93
|
+
/>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
AppKit hover, drag and click coordinates come from source that has not yet
|
|
99
|
+
been checked on a running Mac.
|
|
100
|
+
|
|
101
|
+
The shared geometry uses D3 and SVG. This does not establish identical font
|
|
102
|
+
metrics, assistive-technology behavior, or OS input on every host. Check the
|
|
103
|
+
[target limits](https://octane-xplat.goddardai.org/known-limits) and run the
|
|
104
|
+
chart on the targets you ship. Exact options live in the
|
|
105
|
+
[public prop declarations](https://github.com/octane-xplat/octane-xplat/blob/main/packages/charts/src/props.ts).
|
package/package.json
CHANGED
|
@@ -1,94 +1,94 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
2
|
+
"name": "@octane-xplat/charts",
|
|
3
|
+
"version": "0.19.0",
|
|
4
|
+
"description": "Cross-platform SVG charts for Octane xplat — a DOM-free d3 core with web, iOS/Android, and macOS AppKit leaves",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"android",
|
|
7
|
+
"charts",
|
|
8
|
+
"cross-platform",
|
|
9
|
+
"d3",
|
|
10
|
+
"graph",
|
|
11
|
+
"ios",
|
|
12
|
+
"macos",
|
|
13
|
+
"nativescript",
|
|
14
|
+
"octane",
|
|
15
|
+
"svg",
|
|
16
|
+
"visualization",
|
|
17
|
+
"xplat"
|
|
18
|
+
],
|
|
19
|
+
"homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/charts",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/octane-xplat/octane-xplat",
|
|
24
|
+
"directory": "packages/charts"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"types/generated",
|
|
28
|
+
"src",
|
|
29
|
+
"!src/**/*.test.*",
|
|
30
|
+
"!src/**/*.spec.*"
|
|
31
|
+
],
|
|
32
|
+
"type": "module",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./types/generated/index.d.ts",
|
|
36
|
+
"macos": "./src/index.macos.ts",
|
|
37
|
+
"web": "./src/index.web.ts",
|
|
38
|
+
"native": "./src/index.ts",
|
|
39
|
+
"default": "./src/index.ts"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"typegen": "tsrx-typegen --target charts",
|
|
47
|
+
"typecheck": "node ../../scripts/typecheck.ts",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"prepack": "bun run typegen && tsrx-typegen --pack-check",
|
|
50
|
+
"test:packed": "node tests/packed-consumer.mjs",
|
|
51
|
+
"pack:check": "tsrx-typegen --pack-check"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@octane-xplat/jsx": "0.19.0",
|
|
55
|
+
"d3-array": "3.2.4",
|
|
56
|
+
"d3-format": "3.1.2",
|
|
57
|
+
"d3-scale": "4.0.2",
|
|
58
|
+
"d3-shape": "3.2.0",
|
|
59
|
+
"d3-time-format": "4.1.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@nativescript-community/octane": "0.2.5",
|
|
63
|
+
"@nativescript/core": "9.1.3",
|
|
64
|
+
"@octane-xplat/macos-renderer": "0.19.0",
|
|
65
|
+
"@octane-xplat/ui": "0.19.0",
|
|
66
|
+
"@octanejs/vite-plugin": "0.5.0",
|
|
67
|
+
"@tsrx/typescript-plugin": "0.4.11",
|
|
68
|
+
"@types/d3-array": "3.2.2",
|
|
69
|
+
"@types/d3-format": "3.0.4",
|
|
70
|
+
"@types/d3-scale": "4.0.9",
|
|
71
|
+
"@types/d3-shape": "3.2.0",
|
|
72
|
+
"@types/d3-time-format": "4.0.3",
|
|
73
|
+
"octane": "0.16.3",
|
|
74
|
+
"tsrx-typegen": "0.5.0",
|
|
75
|
+
"typescript": "5.9.3",
|
|
76
|
+
"vite": "8.3.0",
|
|
77
|
+
"vitest": "4.1.11"
|
|
78
|
+
},
|
|
79
|
+
"peerDependencies": {
|
|
80
|
+
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
81
|
+
"@nativescript/core": ">=9.1.0 <10",
|
|
82
|
+
"@octane-xplat/ui": ">=0.6.0 <1",
|
|
83
|
+
"octane": ">=0.6.3 <1"
|
|
84
|
+
},
|
|
85
|
+
"peerDependenciesMeta": {
|
|
86
|
+
"@nativescript-community/octane": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"@nativescript/core": {
|
|
90
|
+
"optional": true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"types": "./types/generated/index.d.ts"
|
|
94
|
+
}
|
package/src/Chart.macos.tsrx
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
/** @jsxImportSource @octane-xplat/
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
2
|
import { mergeStyle } from './style-merge'
|
|
3
|
-
import { useMemo, useRef, useState } from 'octane'
|
|
4
|
-
import { appKitImageSource } from './svg-image.macos'
|
|
5
|
-
import { useMeasure } from '@octane-xplat/ui'
|
|
6
|
-
import type { ChartProps } from './props'
|
|
7
|
-
import { computeScene } from './core/scene'
|
|
8
|
-
import type { ChartScene } from './core/scene'
|
|
9
|
-
import { createScrub, hitLabel } from './core/hit'
|
|
10
|
-
import type { SceneHit } from './core/hit'
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'octane'
|
|
4
|
+
import { appKitImageSource } from './svg-image.macos'
|
|
5
|
+
import { useMeasure } from '@octane-xplat/ui'
|
|
6
|
+
import type { ChartProps } from './props'
|
|
7
|
+
import { computeScene } from './core/scene'
|
|
8
|
+
import type { ChartScene } from './core/scene'
|
|
9
|
+
import { createScrub, hitLabel } from './core/hit'
|
|
10
|
+
import type { SceneHit } from './core/hit'
|
|
11
|
+
import { createAppKitChartPointer } from './appkit-pointer.macos'
|
|
11
12
|
|
|
12
|
-
const EMPTY_SVG = '<svg xmlns="http://www.w3.org/2000/svg"/>'
|
|
13
|
-
const TIP_ESTIMATE_CHAR = 6.2
|
|
13
|
+
const EMPTY_SVG = '<svg xmlns="http://www.w3.org/2000/svg"/>'
|
|
14
|
+
const TIP_ESTIMATE_CHAR = 6.2
|
|
14
15
|
|
|
15
16
|
/** AppKit leaf: one NSImage plus native label and cursor overlays.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
17
|
+
* Hover/drag/click coordinates come from renderer tracking areas, pan
|
|
18
|
+
* recognizer location and the current mouse event; native delivery is
|
|
19
|
+
* unqualified. AppKit does not deliver onTouch, so touch scrubbing is
|
|
20
|
+
* unavailable. */
|
|
21
|
+
export function Chart(props: ChartProps): unknown @{
|
|
22
|
+
const measure = useMeasure()
|
|
23
|
+
const [cursor, setCursor] = useState<SceneHit | null>(null)
|
|
24
|
+
const sceneRef = useRef<ChartScene | null>(null)
|
|
25
|
+
const propsRef = useRef(props)
|
|
26
|
+
propsRef.current = props
|
|
24
27
|
|
|
25
|
-
const bounds = measure.bounds
|
|
26
|
-
const w = props.width ?? bounds?.width ?? 0
|
|
28
|
+
const bounds = measure.bounds
|
|
29
|
+
const w = props.width ?? bounds?.width ?? 0
|
|
27
30
|
const h =
|
|
28
31
|
props.height ??
|
|
29
32
|
(props.aspectRatio && w > 0
|
|
@@ -32,7 +35,7 @@ export function Chart(props: ChartProps) @{
|
|
|
32
35
|
? bounds.height
|
|
33
36
|
: w > 0
|
|
34
37
|
? w / 1.6
|
|
35
|
-
: 0)
|
|
38
|
+
: 0)
|
|
36
39
|
|
|
37
40
|
const scene = useMemo(
|
|
38
41
|
() => (w > 0 && h > 0 ? computeScene(propsRef.current, w, h) : null),
|
|
@@ -47,69 +50,226 @@ export function Chart(props: ChartProps) @{
|
|
|
47
50
|
w,
|
|
48
51
|
h,
|
|
49
52
|
],
|
|
50
|
-
)
|
|
53
|
+
)
|
|
51
54
|
|
|
52
|
-
sceneRef.current = scene
|
|
55
|
+
sceneRef.current = scene
|
|
53
56
|
|
|
54
|
-
const interactive = !!(props.onPress || props.onScrub || props.tooltip || props.crosshair)
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
const interactive = !!(props.onPress || props.onScrub || props.tooltip || props.crosshair)
|
|
58
|
+
const pointer = useMemo(
|
|
59
|
+
() =>
|
|
60
|
+
createAppKitChartPointer(
|
|
61
|
+
createScrub(
|
|
62
|
+
() => sceneRef.current,
|
|
63
|
+
() => propsRef.current,
|
|
64
|
+
setCursor,
|
|
65
|
+
),
|
|
66
|
+
() => ({
|
|
67
|
+
width: sceneRef.current?.width ?? 0,
|
|
68
|
+
height: sceneRef.current?.height ?? 0,
|
|
69
|
+
}),
|
|
70
|
+
),
|
|
71
|
+
[],
|
|
72
|
+
)
|
|
62
73
|
|
|
63
|
-
const
|
|
64
|
-
const
|
|
74
|
+
const [tapView, setTapView] = useState<any>(null)
|
|
75
|
+
const bindTapView = useCallback((view: any) => setTapView(view), [])
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!interactive || !tapView) {
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return pointer.observe(tapView)
|
|
82
|
+
}, [interactive, tapView, pointer])
|
|
83
|
+
|
|
84
|
+
const markup = scene?.markup ?? EMPTY_SVG
|
|
85
|
+
const imageSource = useMemo(() => appKitImageSource(markup), [markup])
|
|
86
|
+
|
|
87
|
+
const legend = props.legend === true ? 'bottom' : props.legend
|
|
88
|
+
const plot = scene?.plot
|
|
89
|
+
const dotColor =
|
|
90
|
+
cursor && scene
|
|
91
|
+
? scene.pie
|
|
92
|
+
? scene.pie.slices.find((s) => s.series === cursor.series && s.index === cursor.index)
|
|
93
|
+
?.color
|
|
94
|
+
: scene.series[cursor.series]?.color
|
|
95
|
+
: undefined
|
|
96
|
+
|
|
97
|
+
const tipText = cursor && scene ? hitLabel(scene, cursor) : null
|
|
98
|
+
const tipWidth = tipText ? tipText.length * TIP_ESTIMATE_CHAR + 14 : 0
|
|
99
|
+
const tipLeft =
|
|
100
|
+
cursor && scene
|
|
101
|
+
? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth))
|
|
102
|
+
: 0
|
|
65
103
|
|
|
66
|
-
const
|
|
67
|
-
const plot = scene?.plot;
|
|
68
|
-
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) : undefined;
|
|
69
|
-
const tipText = cursor && scene ? hitLabel(scene, cursor) : null;
|
|
70
|
-
const tipWidth = tipText ? tipText.length * TIP_ESTIMATE_CHAR + 14 : 0;
|
|
71
|
-
const tipLeft = cursor && scene ? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth)) : 0;
|
|
72
|
-
const tipTop = cursor ? cursor.py - 30 : 0;
|
|
104
|
+
const tipTop = cursor ? cursor.py - 30 : 0
|
|
73
105
|
|
|
74
|
-
<masonview
|
|
106
|
+
<masonview
|
|
107
|
+
id={props.id}
|
|
108
|
+
className={props.className}
|
|
109
|
+
style={{
|
|
110
|
+
display: 'flex',
|
|
111
|
+
flexDirection: 'column',
|
|
112
|
+
...props.style,
|
|
113
|
+
}}
|
|
114
|
+
accessible={props.accessibilityLabel != null}
|
|
115
|
+
accessibilityRole={'image'}
|
|
116
|
+
accessibilityLabel={props.accessibilityLabel}
|
|
117
|
+
>
|
|
75
118
|
@if (legend === 'top' && scene) {
|
|
76
|
-
<masonview
|
|
119
|
+
<masonview
|
|
120
|
+
style={mergeStyle(
|
|
121
|
+
{ flexDirection: 'row', flexWrap: 'wrap' },
|
|
122
|
+
{
|
|
123
|
+
display: 'flex',
|
|
124
|
+
paddingBottom: 4,
|
|
125
|
+
},
|
|
126
|
+
)}
|
|
127
|
+
>
|
|
77
128
|
{scene.legend.map((item) => (
|
|
78
|
-
<masonview
|
|
79
|
-
|
|
129
|
+
<masonview
|
|
130
|
+
style={mergeStyle(
|
|
131
|
+
{ flexDirection: 'row', alignItems: 'center' },
|
|
132
|
+
{
|
|
133
|
+
display: 'flex',
|
|
134
|
+
marginRight: 12,
|
|
135
|
+
},
|
|
136
|
+
)}
|
|
137
|
+
>
|
|
138
|
+
<masonview
|
|
139
|
+
style={{
|
|
140
|
+
display: 'flex',
|
|
141
|
+
width: 10,
|
|
142
|
+
height: 10,
|
|
143
|
+
borderRadius: 2,
|
|
144
|
+
backgroundColor: item.color,
|
|
145
|
+
marginRight: 4,
|
|
146
|
+
}}
|
|
147
|
+
/>
|
|
80
148
|
<label text={item.text} style={{ fontSize: 11 }} />
|
|
81
149
|
</masonview>
|
|
82
150
|
))}
|
|
83
151
|
</masonview>
|
|
84
152
|
}
|
|
85
|
-
<masonview
|
|
153
|
+
<masonview
|
|
154
|
+
ref={measure.ref}
|
|
155
|
+
style={{
|
|
156
|
+
display: 'grid',
|
|
86
157
|
width: props.width,
|
|
87
158
|
height: props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : undefined),
|
|
88
159
|
flexGrow: 1,
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
<
|
|
92
|
-
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
<image
|
|
163
|
+
id={props.id ? props.id + '-image' : undefined}
|
|
164
|
+
src={imageSource}
|
|
165
|
+
style={{ width: w, height: h }}
|
|
166
|
+
accessibilityLabel=""
|
|
167
|
+
/>
|
|
168
|
+
<masonview
|
|
169
|
+
id={props.id ? props.id + '-tap' : undefined}
|
|
170
|
+
ref={bindTapView}
|
|
171
|
+
style={{
|
|
172
|
+
display: 'flex',
|
|
173
|
+
width: w,
|
|
174
|
+
height: h,
|
|
175
|
+
}}
|
|
176
|
+
onPan={interactive ? pointer.pan : undefined}
|
|
177
|
+
onTap={interactive ? () => pointer.tap(tapView) : undefined}
|
|
178
|
+
>
|
|
179
|
+
<masonview
|
|
180
|
+
id={props.id ? props.id + '-overlay' : undefined}
|
|
181
|
+
style={{ width: w, height: h }}
|
|
182
|
+
>
|
|
93
183
|
{scene?.labels.map((l) => (
|
|
94
|
-
<label
|
|
184
|
+
<label
|
|
185
|
+
text={l.text}
|
|
186
|
+
{...{ left: l.x, top: l.y }}
|
|
187
|
+
style={{
|
|
188
|
+
width: l.width,
|
|
189
|
+
fontSize: 10,
|
|
190
|
+
opacity: 0.7,
|
|
191
|
+
textAlign: l.align === 'center' ? 'center' : l.align === 'end' ? 'right' : 'left',
|
|
192
|
+
position: 'absolute',
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
95
195
|
))}
|
|
96
196
|
@if (cursor && props.crosshair && !scene?.pie && plot) {
|
|
97
|
-
<masonview
|
|
197
|
+
<masonview
|
|
198
|
+
style={{
|
|
199
|
+
display: 'flex',
|
|
200
|
+
width: 1,
|
|
201
|
+
height: plot.height,
|
|
202
|
+
backgroundColor: '#8a8a8a',
|
|
203
|
+
position: 'absolute',
|
|
204
|
+
left: cursor.px - 0.5,
|
|
205
|
+
top: plot.y,
|
|
206
|
+
}}
|
|
207
|
+
/>
|
|
98
208
|
}
|
|
99
209
|
@if (cursor && (props.crosshair || props.tooltip)) {
|
|
100
|
-
<masonview
|
|
210
|
+
<masonview
|
|
211
|
+
style={{
|
|
212
|
+
display: 'flex',
|
|
213
|
+
width: 8,
|
|
214
|
+
height: 8,
|
|
215
|
+
borderRadius: 4,
|
|
216
|
+
backgroundColor: dotColor ?? '#4e79a7',
|
|
217
|
+
position: 'absolute',
|
|
218
|
+
left: cursor.px - 4,
|
|
219
|
+
top: cursor.py - 4,
|
|
220
|
+
}}
|
|
221
|
+
/>
|
|
101
222
|
}
|
|
102
223
|
@if (cursor && props.tooltip && tipText) {
|
|
103
|
-
<label
|
|
224
|
+
<label
|
|
225
|
+
id={props.id ? props.id + '-tooltip' : undefined}
|
|
226
|
+
text={tipText}
|
|
227
|
+
{...{ left: tipLeft, top: tipTop < 0 ? cursor.py + 12 : tipTop }}
|
|
228
|
+
style={{
|
|
229
|
+
width: tipWidth,
|
|
230
|
+
height: 24,
|
|
231
|
+
backgroundColor: 'rgba(20,20,20,0.88)',
|
|
232
|
+
borderRadius: 4,
|
|
233
|
+
color: '#ffffff',
|
|
234
|
+
fontSize: 11,
|
|
235
|
+
textAlign: 'center',
|
|
236
|
+
position: 'absolute',
|
|
237
|
+
}}
|
|
238
|
+
/>
|
|
104
239
|
}
|
|
105
240
|
</masonview>
|
|
106
241
|
</masonview>
|
|
107
242
|
</masonview>
|
|
108
243
|
@if (legend === 'bottom' && scene) {
|
|
109
|
-
<masonview
|
|
244
|
+
<masonview
|
|
245
|
+
style={mergeStyle(
|
|
246
|
+
{ flexDirection: 'row', flexWrap: 'wrap' },
|
|
247
|
+
{
|
|
248
|
+
display: 'flex',
|
|
249
|
+
paddingTop: 4,
|
|
250
|
+
},
|
|
251
|
+
)}
|
|
252
|
+
>
|
|
110
253
|
{scene.legend.map((item) => (
|
|
111
|
-
<masonview
|
|
112
|
-
|
|
254
|
+
<masonview
|
|
255
|
+
style={mergeStyle(
|
|
256
|
+
{ flexDirection: 'row', alignItems: 'center' },
|
|
257
|
+
{
|
|
258
|
+
display: 'flex',
|
|
259
|
+
marginRight: 12,
|
|
260
|
+
},
|
|
261
|
+
)}
|
|
262
|
+
>
|
|
263
|
+
<masonview
|
|
264
|
+
style={{
|
|
265
|
+
display: 'flex',
|
|
266
|
+
width: 10,
|
|
267
|
+
height: 10,
|
|
268
|
+
borderRadius: 2,
|
|
269
|
+
backgroundColor: item.color,
|
|
270
|
+
marginRight: 4,
|
|
271
|
+
}}
|
|
272
|
+
/>
|
|
113
273
|
<label text={item.text} style={{ fontSize: 11 }} />
|
|
114
274
|
</masonview>
|
|
115
275
|
))}
|