@octane-xplat/charts 0.15.0 → 0.16.1
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 +5 -5
- package/src/Chart.macos.tsrx +24 -39
- package/src/Chart.tsrx +21 -52
- package/src/style-merge.ts +61 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octane-xplat/charts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
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",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@nativescript-community/octane": "0.2.5",
|
|
57
57
|
"@nativescript/core": "9.1.3",
|
|
58
|
-
"@octane-xplat/macos-renderer": "0.
|
|
59
|
-
"@octane-xplat/ui": "0.
|
|
58
|
+
"@octane-xplat/macos-renderer": "0.16.1",
|
|
59
|
+
"@octane-xplat/ui": "0.16.1",
|
|
60
60
|
"@octanejs/vite-plugin": "0.1.61",
|
|
61
61
|
"@tsrx/typescript-plugin": "0.4.11",
|
|
62
62
|
"@types/d3-array": "3.2.2",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@types/d3-shape": "3.2.0",
|
|
66
66
|
"@types/d3-time-format": "4.0.3",
|
|
67
67
|
"octane": "0.11.0",
|
|
68
|
-
"tsrx-typegen": "0.3.
|
|
68
|
+
"tsrx-typegen": "0.3.1",
|
|
69
69
|
"typescript": "5.9.3",
|
|
70
70
|
"vite": "8.3.0",
|
|
71
71
|
"vitest": "4.1.11"
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"typegen": "tsc -p tsconfig.types.json",
|
|
89
|
-
"typecheck": "node ../../scripts/typecheck.
|
|
89
|
+
"typecheck": "node ../../scripts/typecheck.ts",
|
|
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.macos.tsrx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsxImportSource @octane-xplat/macos-renderer */
|
|
2
|
+
import { mergeStyle } from './style-merge'
|
|
2
3
|
import { useMemo, useRef, useState } from 'octane';
|
|
3
4
|
import { appKitImageSource } from './svg-image.macos';
|
|
4
5
|
import { useMeasure } from '@octane-xplat/ui';
|
|
@@ -70,65 +71,49 @@ export function Chart(props: ChartProps) @{
|
|
|
70
71
|
const tipLeft = cursor && scene ? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth)) : 0;
|
|
71
72
|
const tipTop = cursor ? cursor.py - 30 : 0;
|
|
72
73
|
|
|
73
|
-
<
|
|
74
|
-
id={props.id}
|
|
75
|
-
className={props.className}
|
|
76
|
-
style={{ flexDirection: 'column', ...props.style }}
|
|
77
|
-
accessible={props.accessibilityLabel != null}
|
|
78
|
-
accessibilityRole={'image'}
|
|
79
|
-
accessibilityLabel={props.accessibilityLabel}
|
|
80
|
-
>
|
|
74
|
+
<masonview id={props.id} className={props.className} style={{display: "flex", ...({ flexDirection: 'column', ...props.style })}} accessible={props.accessibilityLabel != null} accessibilityRole={'image'} accessibilityLabel={props.accessibilityLabel}>
|
|
81
75
|
@if (legend === 'top' && scene) {
|
|
82
|
-
<
|
|
76
|
+
<masonview style={mergeStyle({flexDirection: "row", flexWrap: "wrap"}, {display: "flex", ...({ paddingBottom: 4 })})}>
|
|
83
77
|
{scene.legend.map((item) => (
|
|
84
|
-
<
|
|
85
|
-
<
|
|
78
|
+
<masonview style={mergeStyle({flexDirection: "row", alignItems: "center"}, {display: "flex", ...({ marginRight: 12 })})}>
|
|
79
|
+
<masonview style={{display: "flex", ...({ width: 10, height: 10, borderRadius: 2, backgroundColor: item.color, marginRight: 4 })}}/>
|
|
86
80
|
<label text={item.text} style={{ fontSize: 11 }} />
|
|
87
|
-
</
|
|
81
|
+
</masonview>
|
|
88
82
|
))}
|
|
89
|
-
</
|
|
83
|
+
</masonview>
|
|
90
84
|
}
|
|
91
|
-
<
|
|
92
|
-
ref={measure.ref}
|
|
93
|
-
style={{
|
|
85
|
+
<masonview ref={measure.ref} style={{display: "grid", ...({
|
|
94
86
|
width: props.width,
|
|
95
87
|
height: props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : undefined),
|
|
96
88
|
flexGrow: 1,
|
|
97
|
-
}}
|
|
98
|
-
>
|
|
89
|
+
})}}>
|
|
99
90
|
<image id={props.id ? props.id + '-image' : undefined} src={imageSource} style={{ width: w, height: h }} accessibilityLabel="" />
|
|
100
|
-
<
|
|
101
|
-
<
|
|
102
|
-
id={props.id ? props.id + '-overlay' : undefined}
|
|
103
|
-
style={{ width: w, height: h }}
|
|
104
|
-
>
|
|
91
|
+
<masonview id={props.id ? props.id + '-tap' : undefined} style={{display: "flex", ...({ width: w, height: h })}} onTap={interactive ? onTap : undefined}>
|
|
92
|
+
<masonview id={props.id ? props.id + '-overlay' : undefined} style={{ width: w, height: h }}>
|
|
105
93
|
{scene?.labels.map((l) => (
|
|
106
|
-
<label
|
|
107
|
-
text={l.text}
|
|
108
|
-
{...{ left: l.x, top: l.y }} style={{ width: l.width, fontSize: 10, opacity: 0.7, textAlign: l.align === 'center' ? 'center' : l.align === 'end' ? 'right' : 'left' }}
|
|
109
|
-
/>
|
|
94
|
+
<label text={l.text} {...{ left: l.x, top: l.y }} style={{ width: l.width, fontSize: 10, opacity: 0.7, textAlign: l.align === 'center' ? 'center' : l.align === 'end' ? 'right' : 'left' , position: 'absolute'}} />
|
|
110
95
|
))}
|
|
111
96
|
@if (cursor && props.crosshair && !scene?.pie && plot) {
|
|
112
|
-
<
|
|
97
|
+
<masonview style={{display: "flex", ...({ width: 1, height: plot.height, backgroundColor: '#8a8a8a' , position: 'absolute', left: cursor.px - 0.5, top: plot.y})}}/>
|
|
113
98
|
}
|
|
114
99
|
@if (cursor && (props.crosshair || props.tooltip)) {
|
|
115
|
-
<
|
|
100
|
+
<masonview style={{display: "flex", ...({ width: 8, height: 8, borderRadius: 4, backgroundColor: dotColor ?? '#4e79a7' , position: 'absolute', left: cursor.px - 4, top: cursor.py - 4})}}/>
|
|
116
101
|
}
|
|
117
102
|
@if (cursor && props.tooltip && tipText) {
|
|
118
|
-
<label id={props.id ? props.id + '-tooltip' : undefined} text={tipText} {...{ left: tipLeft, top: tipTop < 0 ? cursor.py + 12 : tipTop }} style={{ width: tipWidth, height: 24, backgroundColor: 'rgba(20,20,20,0.88)', borderRadius: 4, color: '#ffffff', fontSize: 11, textAlign: 'center' }} />
|
|
103
|
+
<label id={props.id ? props.id + '-tooltip' : undefined} text={tipText} {...{ left: tipLeft, top: tipTop < 0 ? cursor.py + 12 : tipTop }} style={{ width: tipWidth, height: 24, backgroundColor: 'rgba(20,20,20,0.88)', borderRadius: 4, color: '#ffffff', fontSize: 11, textAlign: 'center' , position: 'absolute'}} />
|
|
119
104
|
}
|
|
120
|
-
</
|
|
121
|
-
</
|
|
122
|
-
</
|
|
105
|
+
</masonview>
|
|
106
|
+
</masonview>
|
|
107
|
+
</masonview>
|
|
123
108
|
@if (legend === 'bottom' && scene) {
|
|
124
|
-
<
|
|
109
|
+
<masonview style={mergeStyle({flexDirection: "row", flexWrap: "wrap"}, {display: "flex", ...({ paddingTop: 4 })})}>
|
|
125
110
|
{scene.legend.map((item) => (
|
|
126
|
-
<
|
|
127
|
-
<
|
|
111
|
+
<masonview style={mergeStyle({flexDirection: "row", alignItems: "center"}, {display: "flex", ...({ marginRight: 12 })})}>
|
|
112
|
+
<masonview style={{display: "flex", ...({ width: 10, height: 10, borderRadius: 2, backgroundColor: item.color, marginRight: 4 })}}/>
|
|
128
113
|
<label text={item.text} style={{ fontSize: 11 }} />
|
|
129
|
-
</
|
|
114
|
+
</masonview>
|
|
130
115
|
))}
|
|
131
|
-
</
|
|
116
|
+
</masonview>
|
|
132
117
|
}
|
|
133
|
-
</
|
|
118
|
+
</masonview>
|
|
134
119
|
}
|
package/src/Chart.tsrx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @jsxImportSource @nativescript-community/octane */
|
|
2
|
+
import { mergeStyle } from './style-merge'
|
|
2
3
|
import { useMemo, useRef, useState } from 'octane';
|
|
3
4
|
import { AccessibilityRole, Color } from '@nativescript/core';
|
|
4
5
|
import { useMeasure } from '@octane-xplat/ui';
|
|
@@ -104,81 +105,49 @@ export function Chart(props: ChartProps) @{
|
|
|
104
105
|
const tipLeft = cursor && scene ? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth)) : 0;
|
|
105
106
|
const tipTop = cursor ? cursor.py - 30 : 0;
|
|
106
107
|
|
|
107
|
-
<
|
|
108
|
-
id={props.id}
|
|
109
|
-
className={props.className}
|
|
110
|
-
style={{ flexDirection: 'column', ...props.style }}
|
|
111
|
-
accessible={props.accessibilityLabel != null}
|
|
112
|
-
accessibilityRole={AccessibilityRole.Image}
|
|
113
|
-
accessibilityLabel={props.accessibilityLabel}
|
|
114
|
-
>
|
|
108
|
+
<masonview id={props.id} className={props.className} style={{display: "flex", ...({ flexDirection: 'column', ...props.style })}} accessible={props.accessibilityLabel != null} accessibilityRole={AccessibilityRole.Image} accessibilityLabel={props.accessibilityLabel}>
|
|
115
109
|
@if (legend === 'top' && scene) {
|
|
116
|
-
<
|
|
110
|
+
<masonview style={mergeStyle({flexDirection: "row", flexWrap: "wrap"}, {display: "flex", ...({ paddingBottom: 4 })})}>
|
|
117
111
|
{scene.legend.map((item) => (
|
|
118
|
-
<
|
|
112
|
+
<masonview style={mergeStyle({flexDirection: "row", alignItems: "center"}, {display: "flex", ...({ marginRight: 12 })})}>
|
|
119
113
|
<contentview style={{ width: 10, height: 10, borderRadius: 2, backgroundColor: safeColor(item.color, 'transparent'), marginRight: 4 }} />
|
|
120
114
|
<label text={item.text} style={{ fontSize: 11 }} />
|
|
121
|
-
</
|
|
115
|
+
</masonview>
|
|
122
116
|
))}
|
|
123
|
-
</
|
|
117
|
+
</masonview>
|
|
124
118
|
}
|
|
125
|
-
<
|
|
126
|
-
ref={measure.ref}
|
|
127
|
-
style={{
|
|
119
|
+
<masonview ref={measure.ref} style={{display: "grid", ...({
|
|
128
120
|
width: props.width,
|
|
129
121
|
height: props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : undefined),
|
|
130
122
|
flexGrow: 1,
|
|
131
|
-
}}
|
|
132
|
-
>
|
|
123
|
+
})}}>
|
|
133
124
|
<svgview src={scene?.markup ?? EMPTY_SVG} stretch="aspectFit" style={{ width: w, height: h }} />
|
|
134
|
-
<
|
|
135
|
-
id={props.id ? props.id + '-overlay' : undefined}
|
|
136
|
-
style={{ width: w, height: h }}
|
|
137
|
-
isUserInteractionEnabled={interactive}
|
|
138
|
-
onTouch={interactive ? onTouch : undefined}
|
|
139
|
-
onTap={interactive ? onTap : undefined}
|
|
140
|
-
>
|
|
125
|
+
<masonview id={props.id ? props.id + '-overlay' : undefined} style={{ width: w, height: h }} isUserInteractionEnabled={interactive} onTouch={interactive ? onTouch : undefined} onTap={interactive ? onTap : undefined}>
|
|
141
126
|
{scene?.labels.map((l) => (
|
|
142
|
-
<label
|
|
143
|
-
left={l.x}
|
|
144
|
-
top={l.y}
|
|
145
|
-
width={l.width}
|
|
146
|
-
text={l.text}
|
|
147
|
-
textAlignment={l.align === 'center' ? 'center' : l.align === 'end' ? 'right' : 'left'}
|
|
148
|
-
style={{ fontSize: 10, opacity: 0.7 }}
|
|
149
|
-
/>
|
|
127
|
+
<label width={l.width} text={l.text} textAlignment={l.align === 'center' ? 'center' : l.align === 'end' ? 'right' : 'left'} style={{ fontSize: 10, opacity: 0.7 , position: 'absolute', left: l.x, top: l.y}} />
|
|
150
128
|
))}
|
|
151
129
|
@if (cursor && props.crosshair && !scene?.pie && plot) {
|
|
152
|
-
<contentview
|
|
130
|
+
<contentview width={1} height={plot.height} backgroundColor={new Color('#8a8a8a')} style={{position: 'absolute', left: cursor.px - 0.5, top: plot.y}} />
|
|
153
131
|
}
|
|
154
132
|
@if (cursor && (props.crosshair || props.tooltip)) {
|
|
155
|
-
<contentview
|
|
133
|
+
<contentview width={8} height={8} borderRadius={4} backgroundColor={safeColor(dotColor, '#4e79a7')} style={{position: 'absolute', left: cursor.px - 4, top: cursor.py - 4}} />
|
|
156
134
|
}
|
|
157
135
|
@if (cursor && props.tooltip && tipText) {
|
|
158
|
-
<
|
|
159
|
-
left={tipLeft}
|
|
160
|
-
top={tipTop < 0 ? cursor.py + 12 : tipTop}
|
|
161
|
-
backgroundColor={new Color('rgba(20,20,20,0.88)')}
|
|
162
|
-
borderRadius={4}
|
|
163
|
-
paddingTop={2}
|
|
164
|
-
paddingBottom={2}
|
|
165
|
-
paddingLeft={6}
|
|
166
|
-
paddingRight={6}
|
|
167
|
-
>
|
|
136
|
+
<masonview style={{display: "flex", position: 'absolute', left: tipLeft, top: tipTop < 0 ? cursor.py + 12 : tipTop, paddingTop: 2, paddingBottom: 2, paddingLeft: 6, paddingRight: 6}}>
|
|
168
137
|
<label text={tipText} color={new Color('#ffffff')} style={{ fontSize: 11 }} />
|
|
169
|
-
</
|
|
138
|
+
</masonview>
|
|
170
139
|
}
|
|
171
|
-
</
|
|
172
|
-
</
|
|
140
|
+
</masonview>
|
|
141
|
+
</masonview>
|
|
173
142
|
@if (legend === 'bottom' && scene) {
|
|
174
|
-
<
|
|
143
|
+
<masonview style={mergeStyle({flexDirection: "row", flexWrap: "wrap"}, {display: "flex", ...({ paddingTop: 4 })})}>
|
|
175
144
|
{scene.legend.map((item) => (
|
|
176
|
-
<
|
|
145
|
+
<masonview style={mergeStyle({flexDirection: "row", alignItems: "center"}, {display: "flex", ...({ marginRight: 12 })})}>
|
|
177
146
|
<contentview style={{ width: 10, height: 10, borderRadius: 2, backgroundColor: safeColor(item.color, 'transparent'), marginRight: 4 }} />
|
|
178
147
|
<label text={item.text} style={{ fontSize: 11 }} />
|
|
179
|
-
</
|
|
148
|
+
</masonview>
|
|
180
149
|
))}
|
|
181
|
-
</
|
|
150
|
+
</masonview>
|
|
182
151
|
}
|
|
183
|
-
</
|
|
152
|
+
</masonview>
|
|
184
153
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const kebab = (key: string) => key.replace(/[A-Z]/g, (c) => '-' + c.toLowerCase())
|
|
4
|
+
|
|
5
|
+
/** 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[]
|
|
12
|
+
|
|
13
|
+
/** Merge component-emitted style defaults under the authored `style` prop.
|
|
14
|
+
* Authored keys win; array styles fold in order; a string style is appended
|
|
15
|
+
* after the serialized defaults so its declarations override them too. */
|
|
16
|
+
export function mergeStyle(
|
|
17
|
+
base: Record<string, any>,
|
|
18
|
+
style?: Record<string, any> | readonly (Record<string, any> | null | undefined)[] | null,
|
|
19
|
+
): Record<string, any>
|
|
20
|
+
export function mergeStyle(
|
|
21
|
+
base: Record<string, any>,
|
|
22
|
+
style?: StyleInput,
|
|
23
|
+
): string | Record<string, any>
|
|
24
|
+
export function mergeStyle(
|
|
25
|
+
base: Record<string, any>,
|
|
26
|
+
style?: StyleInput,
|
|
27
|
+
): string | Record<string, any> {
|
|
28
|
+
if (style == null) {
|
|
29
|
+
return base
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let obj: Record<string, any> = { ...base }
|
|
33
|
+
const strings: string[] = []
|
|
34
|
+
const add = (s: StyleInput) => {
|
|
35
|
+
if (s == null) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
if (typeof s === 'string') {
|
|
39
|
+
strings.push(s)
|
|
40
|
+
} else if (Array.isArray(s)) {
|
|
41
|
+
for (const part of s) {
|
|
42
|
+
add(part)
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
obj = { ...obj, ...s }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
add(style)
|
|
49
|
+
|
|
50
|
+
if (strings.length === 0) {
|
|
51
|
+
return obj
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const prefix = Object.entries(obj)
|
|
55
|
+
.filter(([, v]) => v != null)
|
|
56
|
+
.map(([k, v]) => `${kebab(k)}:${v}`)
|
|
57
|
+
.join(';')
|
|
58
|
+
return [prefix, ...strings].filter(Boolean).join(';')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type StyleProp = string | Record<string, any> | readonly StyleProp[] | null | undefined
|