@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/dist/macos/core/scene.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { buildXScale, buildYScale, inferXKind, yDomain } from "./scales.js";
|
|
2
|
-
import { xAxisModel, yAxisModel } from "./axes.js";
|
|
3
|
-
import { buildMarks } from "./marks.js";
|
|
4
|
-
import { svgDocument } from "./svg.js";
|
|
5
|
-
//#region src/core/scene.ts
|
|
6
|
-
/** Default categorical palette — Tableau 10, embedded so the leaf stays free
|
|
7
|
-
* of d3-scale-chromatic. */
|
|
8
|
-
var PALETTE = [
|
|
9
|
-
"#4e79a7",
|
|
10
|
-
"#f28e2b",
|
|
11
|
-
"#e15759",
|
|
12
|
-
"#76b7b2",
|
|
13
|
-
"#59a14f",
|
|
14
|
-
"#edc948",
|
|
15
|
-
"#b07aa1",
|
|
16
|
-
"#ff9da7",
|
|
17
|
-
"#9c755f",
|
|
18
|
-
"#bab0ac"
|
|
19
|
-
];
|
|
20
|
-
function computeScene(props, width, height) {
|
|
21
|
-
if (!(width > 0) || !(height > 0) || !props.data?.length) return null;
|
|
22
|
-
const pie = props.type === "pie";
|
|
23
|
-
const xLabels = !pie && props.xAxis?.labels !== false;
|
|
24
|
-
const yLabels = !pie && props.yAxis?.labels !== false;
|
|
25
|
-
const margin = {
|
|
26
|
-
top: 8,
|
|
27
|
-
right: 10,
|
|
28
|
-
bottom: pie ? 8 : xLabels ? 26 : 10,
|
|
29
|
-
left: pie ? 8 : yLabels ? 46 : 10,
|
|
30
|
-
...props.margin
|
|
31
|
-
};
|
|
32
|
-
const plot = {
|
|
33
|
-
x: margin.left,
|
|
34
|
-
y: margin.top,
|
|
35
|
-
width: Math.max(0, width - margin.left - margin.right),
|
|
36
|
-
height: Math.max(0, height - margin.top - margin.bottom)
|
|
37
|
-
};
|
|
38
|
-
if (!(plot.width > 0) || !(plot.height > 0)) return null;
|
|
39
|
-
const series = props.data.map((s, i) => ({
|
|
40
|
-
name: s.name,
|
|
41
|
-
color: s.color ?? PALETTE[i % PALETTE.length],
|
|
42
|
-
values: s.values
|
|
43
|
-
}));
|
|
44
|
-
let marks;
|
|
45
|
-
let points;
|
|
46
|
-
let pieScene = null;
|
|
47
|
-
let labels = [];
|
|
48
|
-
let grid = [];
|
|
49
|
-
let frame = [];
|
|
50
|
-
if (pie) {
|
|
51
|
-
const built = buildMarks("pie", {
|
|
52
|
-
plot,
|
|
53
|
-
xKind: "band",
|
|
54
|
-
x: buildXScale("band", [], 0),
|
|
55
|
-
y: buildYScale([0, 1], 1)
|
|
56
|
-
}, series, {
|
|
57
|
-
innerRadiusRatio: props.innerRadiusRatio,
|
|
58
|
-
palette: PALETTE
|
|
59
|
-
});
|
|
60
|
-
marks = built.marks;
|
|
61
|
-
points = [];
|
|
62
|
-
const center = {
|
|
63
|
-
cx: built.pie.cx + plot.x,
|
|
64
|
-
cy: built.pie.cy + plot.y
|
|
65
|
-
};
|
|
66
|
-
pieScene = {
|
|
67
|
-
...built.pie,
|
|
68
|
-
...center,
|
|
69
|
-
slices: built.pie.slices.map((s) => ({
|
|
70
|
-
...s,
|
|
71
|
-
cx: s.cx + center.cx,
|
|
72
|
-
cy: s.cy + center.cy
|
|
73
|
-
}))
|
|
74
|
-
};
|
|
75
|
-
} else {
|
|
76
|
-
const xKind = inferXKind(props.type, props.data);
|
|
77
|
-
const layout = {
|
|
78
|
-
plot,
|
|
79
|
-
xKind,
|
|
80
|
-
x: buildXScale(xKind, props.data, plot.width),
|
|
81
|
-
y: buildYScale(yDomain(props.data, props.type, props.stacked === true), plot.height)
|
|
82
|
-
};
|
|
83
|
-
const built = buildMarks(props.type, layout, series, {
|
|
84
|
-
stacked: props.stacked,
|
|
85
|
-
palette: PALETTE
|
|
86
|
-
});
|
|
87
|
-
marks = built.marks;
|
|
88
|
-
points = built.points.map((p) => ({
|
|
89
|
-
...p,
|
|
90
|
-
cx: p.cx + plot.x,
|
|
91
|
-
cy: p.cy + plot.y
|
|
92
|
-
}));
|
|
93
|
-
const xAxis = xAxisModel(xKind, layout.x, props.xAxis, plot);
|
|
94
|
-
const yAxis = yAxisModel(layout.y, props.yAxis, plot);
|
|
95
|
-
labels = [...xAxis.labels, ...yAxis.labels];
|
|
96
|
-
grid = [...xAxis.grid, ...yAxis.grid];
|
|
97
|
-
frame = [...xAxis.frame, ...yAxis.frame];
|
|
98
|
-
}
|
|
99
|
-
const legend = pieScene ? pieScene.slices.map((s) => ({
|
|
100
|
-
color: s.color,
|
|
101
|
-
text: s.label
|
|
102
|
-
})) : series.map((s) => ({
|
|
103
|
-
color: s.color,
|
|
104
|
-
text: s.name
|
|
105
|
-
}));
|
|
106
|
-
return {
|
|
107
|
-
type: props.type,
|
|
108
|
-
width,
|
|
109
|
-
height,
|
|
110
|
-
plot,
|
|
111
|
-
markup: svgDocument(marks, grid, frame, plot, width, height),
|
|
112
|
-
labels,
|
|
113
|
-
legend,
|
|
114
|
-
series,
|
|
115
|
-
points,
|
|
116
|
-
pie: pieScene
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
//#endregion
|
|
120
|
-
export { PALETTE, computeScene };
|
package/dist/macos/core/svg.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
//#region src/core/svg.ts
|
|
2
|
-
/** Mark[] → one `<svg>` markup string. Emits only the androidsvg ∩ SVGKit
|
|
3
|
-
* subset: `<svg>`/`<g>` structure, path/rect/circle/line shapes, solid fills
|
|
4
|
-
* and strokes, `translate` transforms, opacity attributes. Never `<text>`,
|
|
5
|
-
* filters, masks, patterns, or gradients — labels are real elements in the
|
|
6
|
-
* leaf overlay (docs/notes/primitive-notes.md). */
|
|
7
|
-
function num(v) {
|
|
8
|
-
if (!Number.isFinite(v)) return "0";
|
|
9
|
-
return Number.isInteger(v) ? String(v) : String(+v.toFixed(2));
|
|
10
|
-
}
|
|
11
|
-
function esc(v) {
|
|
12
|
-
return v.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<").replaceAll(">", ">");
|
|
13
|
-
}
|
|
14
|
-
function paintAttrs(m) {
|
|
15
|
-
let out = "";
|
|
16
|
-
if (m.fill !== void 0) out += ` fill="${esc(m.fill)}"`;
|
|
17
|
-
if (m.fillOpacity !== void 0) out += ` fill-opacity="${num(m.fillOpacity)}"`;
|
|
18
|
-
if (m.stroke !== void 0) out += ` stroke="${esc(m.stroke)}"`;
|
|
19
|
-
if (m.strokeOpacity !== void 0) out += ` stroke-opacity="${num(m.strokeOpacity)}"`;
|
|
20
|
-
if (m.strokeWidth !== void 0) out += ` stroke-width="${num(m.strokeWidth)}"`;
|
|
21
|
-
if (m.strokeLinecap !== void 0) out += ` stroke-linecap="${m.strokeLinecap}"`;
|
|
22
|
-
if (m.transform !== void 0) out += ` transform="${esc(m.transform)}"`;
|
|
23
|
-
return out;
|
|
24
|
-
}
|
|
25
|
-
function markXml(m) {
|
|
26
|
-
switch (m.kind) {
|
|
27
|
-
case "path": return `<path d="${esc(m.d)}"${paintAttrs(m)}/>`;
|
|
28
|
-
case "rect": return `<rect x="${num(m.x)}" y="${num(m.y)}" width="${num(m.width)}" height="${num(m.height)}"${paintAttrs(m)}/>`;
|
|
29
|
-
case "circle": return `<circle cx="${num(m.cx)}" cy="${num(m.cy)}" r="${num(m.r)}"${paintAttrs(m)}/>`;
|
|
30
|
-
case "line": return `<line x1="${num(m.x1)}" y1="${num(m.y1)}" x2="${num(m.x2)}" y2="${num(m.y2)}"${paintAttrs(m)}/>`;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/** Chart marks are plot-space; axis rules are chart-space. Paint order:
|
|
34
|
-
* gridlines under the translated marks group, frame (spine + stubs) over. */
|
|
35
|
-
function svgDocument(marks, grid, frame, plot, width, height) {
|
|
36
|
-
const body = `${grid.map(markXml).join("")}<g transform="translate(${num(plot.x)} ${num(plot.y)})">${marks.map(markXml).join("")}</g>${frame.map(markXml).join("")}`;
|
|
37
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${num(width)} ${num(height)}" width="${num(width)}" height="${num(height)}">${body}</svg>`;
|
|
38
|
-
}
|
|
39
|
-
//#endregion
|
|
40
|
-
export { svgDocument };
|
package/dist/macos/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
//#region src/svg-image.macos.ts
|
|
2
|
-
function svgDataUri(markup) {
|
|
3
|
-
const data = NSString.stringWithString(markup).dataUsingEncoding(4);
|
|
4
|
-
if (!data) throw new Error("Unable to encode SVG as UTF-8");
|
|
5
|
-
return `data:image/svg+xml;base64,${data.base64EncodedStringWithOptions(0)}`;
|
|
6
|
-
}
|
|
7
|
-
/** Normalize bundled markup and SVG data URIs for AppKit's image host. */
|
|
8
|
-
function appKitImageSource(src) {
|
|
9
|
-
if (src.trimStart().startsWith("<svg") || src.trimStart().startsWith("<?xml")) return svgDataUri(src);
|
|
10
|
-
if (/^data:image\/svg\+xml[;,]/i.test(src) && !src.slice(0, src.indexOf(",")).endsWith(";base64")) return svgDataUri(decodeURIComponent(src.slice(src.indexOf(",") + 1)));
|
|
11
|
-
return src;
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
export { appKitImageSource, svgDataUri };
|
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import { computeScene } from "./core/scene.js";
|
|
2
|
-
import { createScrub, hitLabel } from "./core/hit.js";
|
|
3
|
-
import { defineUniversalComponent, hookSlots, universalIf, universalPlan, universalValue, useMemo, useRef, useState, withSlot } from "@nativescript-community/octane";
|
|
4
|
-
import { AccessibilityRole, Color } from "@nativescript/core";
|
|
5
|
-
import { useMeasure } from "@octane-xplat/ui";
|
|
6
|
-
//#region src/Chart.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("nativescript", {
|
|
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": "contentview",
|
|
26
|
-
"bindings": [["style", 1]]
|
|
27
|
-
}, {
|
|
28
|
-
"kind": "host",
|
|
29
|
-
"type": "label",
|
|
30
|
-
"bindings": [["text", 2], ["style", 3]]
|
|
31
|
-
}]
|
|
32
|
-
});
|
|
33
|
-
var __octaneUniversalPlan1 = universalPlan("nativescript", {
|
|
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("nativescript", {
|
|
47
|
-
"kind": "host",
|
|
48
|
-
"type": "label",
|
|
49
|
-
"bindings": [
|
|
50
|
-
["left", 0],
|
|
51
|
-
["top", 1],
|
|
52
|
-
["width", 2],
|
|
53
|
-
["text", 3],
|
|
54
|
-
["textAlignment", 4],
|
|
55
|
-
["style", 5]
|
|
56
|
-
]
|
|
57
|
-
});
|
|
58
|
-
var __octaneUniversalPlan3 = universalPlan("nativescript", {
|
|
59
|
-
"kind": "host",
|
|
60
|
-
"type": "contentview",
|
|
61
|
-
"props": { "width": 1 },
|
|
62
|
-
"bindings": [
|
|
63
|
-
["left", 0],
|
|
64
|
-
["top", 1],
|
|
65
|
-
["height", 2],
|
|
66
|
-
["backgroundColor", 3]
|
|
67
|
-
]
|
|
68
|
-
});
|
|
69
|
-
var __octaneUniversalPlan4 = universalPlan("nativescript", {
|
|
70
|
-
"kind": "host",
|
|
71
|
-
"type": "contentview",
|
|
72
|
-
"props": {
|
|
73
|
-
"width": 8,
|
|
74
|
-
"height": 8,
|
|
75
|
-
"borderRadius": 4
|
|
76
|
-
},
|
|
77
|
-
"bindings": [
|
|
78
|
-
["left", 0],
|
|
79
|
-
["top", 1],
|
|
80
|
-
["backgroundColor", 2]
|
|
81
|
-
]
|
|
82
|
-
});
|
|
83
|
-
var __octaneUniversalPlan5 = universalPlan("nativescript", {
|
|
84
|
-
"kind": "host",
|
|
85
|
-
"type": "flexboxlayout",
|
|
86
|
-
"props": {
|
|
87
|
-
"borderRadius": 4,
|
|
88
|
-
"paddingTop": 2,
|
|
89
|
-
"paddingBottom": 2,
|
|
90
|
-
"paddingLeft": 6,
|
|
91
|
-
"paddingRight": 6
|
|
92
|
-
},
|
|
93
|
-
"bindings": [
|
|
94
|
-
["left", 0],
|
|
95
|
-
["top", 1],
|
|
96
|
-
["backgroundColor", 2]
|
|
97
|
-
],
|
|
98
|
-
"children": [{
|
|
99
|
-
"kind": "host",
|
|
100
|
-
"type": "label",
|
|
101
|
-
"bindings": [
|
|
102
|
-
["text", 3],
|
|
103
|
-
["color", 4],
|
|
104
|
-
["style", 5]
|
|
105
|
-
]
|
|
106
|
-
}]
|
|
107
|
-
});
|
|
108
|
-
var __octaneUniversalPlan6 = universalPlan("nativescript", {
|
|
109
|
-
"kind": "host",
|
|
110
|
-
"type": "flexboxlayout",
|
|
111
|
-
"props": {
|
|
112
|
-
"flexDirection": "row",
|
|
113
|
-
"alignItems": "center"
|
|
114
|
-
},
|
|
115
|
-
"bindings": [["style", 0]],
|
|
116
|
-
"children": [{
|
|
117
|
-
"kind": "host",
|
|
118
|
-
"type": "contentview",
|
|
119
|
-
"bindings": [["style", 1]]
|
|
120
|
-
}, {
|
|
121
|
-
"kind": "host",
|
|
122
|
-
"type": "label",
|
|
123
|
-
"bindings": [["text", 2], ["style", 3]]
|
|
124
|
-
}]
|
|
125
|
-
});
|
|
126
|
-
var __octaneUniversalPlan7 = universalPlan("nativescript", {
|
|
127
|
-
"kind": "host",
|
|
128
|
-
"type": "flexboxlayout",
|
|
129
|
-
"props": {
|
|
130
|
-
"flexDirection": "row",
|
|
131
|
-
"flexWrap": "wrap"
|
|
132
|
-
},
|
|
133
|
-
"bindings": [["style", 0]],
|
|
134
|
-
"children": [{
|
|
135
|
-
"kind": "slot",
|
|
136
|
-
"slot": 1
|
|
137
|
-
}]
|
|
138
|
-
});
|
|
139
|
-
var __octaneUniversalPlan8 = universalPlan("nativescript", {
|
|
140
|
-
"kind": "host",
|
|
141
|
-
"type": "flexboxlayout",
|
|
142
|
-
"bindings": [
|
|
143
|
-
["id", 0],
|
|
144
|
-
["className", 1],
|
|
145
|
-
["style", 2],
|
|
146
|
-
["accessible", 3],
|
|
147
|
-
["accessibilityRole", 4],
|
|
148
|
-
["accessibilityLabel", 5]
|
|
149
|
-
],
|
|
150
|
-
"children": [
|
|
151
|
-
{
|
|
152
|
-
"kind": "slot",
|
|
153
|
-
"slot": 6
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
"kind": "host",
|
|
157
|
-
"type": "gridlayout",
|
|
158
|
-
"bindings": [["ref", 7], ["style", 8]],
|
|
159
|
-
"children": [{
|
|
160
|
-
"kind": "host",
|
|
161
|
-
"type": "svgview",
|
|
162
|
-
"props": { "stretch": "aspectFit" },
|
|
163
|
-
"bindings": [["src", 9], ["style", 10]]
|
|
164
|
-
}, {
|
|
165
|
-
"kind": "host",
|
|
166
|
-
"type": "absolutelayout",
|
|
167
|
-
"bindings": [
|
|
168
|
-
["id", 11],
|
|
169
|
-
["style", 12],
|
|
170
|
-
["isUserInteractionEnabled", 13],
|
|
171
|
-
["onTouch", 14],
|
|
172
|
-
["onTap", 15]
|
|
173
|
-
],
|
|
174
|
-
"children": [
|
|
175
|
-
{
|
|
176
|
-
"kind": "slot",
|
|
177
|
-
"slot": 16
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
"kind": "slot",
|
|
181
|
-
"slot": 17
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
"kind": "slot",
|
|
185
|
-
"slot": 18
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
"kind": "slot",
|
|
189
|
-
"slot": 19
|
|
190
|
-
}
|
|
191
|
-
]
|
|
192
|
-
}]
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
"kind": "slot",
|
|
196
|
-
"slot": 20
|
|
197
|
-
}
|
|
198
|
-
]
|
|
199
|
-
});
|
|
200
|
-
var EMPTY_SVG = "<svg xmlns=\"http://www.w3.org/2000/svg\"/>";
|
|
201
|
-
var TIP_ESTIMATE_CHAR = 6.2;
|
|
202
|
-
var Chart = defineUniversalComponent("nativescript", function Chart(props) {
|
|
203
|
-
const measure = withSlot(_h$0, useMeasure);
|
|
204
|
-
const [cursor, setCursor] = useState(null, _h$1);
|
|
205
|
-
const sceneRef = useRef(null, _h$2);
|
|
206
|
-
const propsRef = useRef(props, _h$3);
|
|
207
|
-
propsRef.current = props;
|
|
208
|
-
const bounds = measure.bounds;
|
|
209
|
-
const w = props.width ?? bounds?.width ?? 0;
|
|
210
|
-
const h = props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : bounds?.height && bounds.height > 0 ? bounds.height : w > 0 ? w / 1.6 : 0);
|
|
211
|
-
const scene = useMemo(() => w > 0 && h > 0 ? computeScene(propsRef.current, w, h) : null, [
|
|
212
|
-
props.type,
|
|
213
|
-
props.data,
|
|
214
|
-
props.margin,
|
|
215
|
-
props.stacked,
|
|
216
|
-
props.innerRadiusRatio,
|
|
217
|
-
props.xAxis,
|
|
218
|
-
props.yAxis,
|
|
219
|
-
w,
|
|
220
|
-
h
|
|
221
|
-
], _h$4);
|
|
222
|
-
sceneRef.current = scene;
|
|
223
|
-
const interactive = !!(props.onPress || props.onScrub || props.tooltip || props.crosshair);
|
|
224
|
-
const onTouch = useMemo(() => {
|
|
225
|
-
const scrub = createScrub(() => sceneRef.current, () => propsRef.current, setCursor);
|
|
226
|
-
return (e) => {
|
|
227
|
-
scrub(e.action, e.getX(), e.getY());
|
|
228
|
-
};
|
|
229
|
-
}, [], _h$5);
|
|
230
|
-
const onTap = useMemo(() => {
|
|
231
|
-
const scrub = createScrub(() => sceneRef.current, () => propsRef.current, setCursor);
|
|
232
|
-
return (e) => {
|
|
233
|
-
const size = e.object?.getActualSize?.();
|
|
234
|
-
scrub("tap", e.getX?.() ?? (size ? size.width / 2 : 0), e.getY?.() ?? (size ? size.height / 2 : 0));
|
|
235
|
-
};
|
|
236
|
-
}, [], _h$6);
|
|
237
|
-
const legend = props.legend === true ? "bottom" : props.legend;
|
|
238
|
-
const plot = scene?.plot;
|
|
239
|
-
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;
|
|
240
|
-
const tipText = cursor && scene ? hitLabel(scene, cursor) : null;
|
|
241
|
-
const tipWidth = tipText ? tipText.length * TIP_ESTIMATE_CHAR + 14 : 0;
|
|
242
|
-
const tipLeft = cursor && scene ? Math.min(Math.max(0, cursor.px - tipWidth / 2), Math.max(0, scene.width - tipWidth)) : 0;
|
|
243
|
-
const tipTop = cursor ? cursor.py - 30 : 0;
|
|
244
|
-
return universalValue(__octaneUniversalPlan8, [
|
|
245
|
-
props.id,
|
|
246
|
-
props.className,
|
|
247
|
-
{
|
|
248
|
-
flexDirection: "column",
|
|
249
|
-
...props.style
|
|
250
|
-
},
|
|
251
|
-
props.accessibilityLabel != null,
|
|
252
|
-
AccessibilityRole.Image,
|
|
253
|
-
props.accessibilityLabel,
|
|
254
|
-
universalIf(legend === "top" && scene, () => {
|
|
255
|
-
return universalValue(__octaneUniversalPlan1, [{ paddingBottom: 4 }, scene.legend.map((item) => universalValue(__octaneUniversalPlan0, [
|
|
256
|
-
{ marginRight: 12 },
|
|
257
|
-
{
|
|
258
|
-
width: 10,
|
|
259
|
-
height: 10,
|
|
260
|
-
borderRadius: 2,
|
|
261
|
-
backgroundColor: new Color(item.color),
|
|
262
|
-
marginRight: 4
|
|
263
|
-
},
|
|
264
|
-
item.text,
|
|
265
|
-
{ fontSize: 11 }
|
|
266
|
-
]))]);
|
|
267
|
-
}),
|
|
268
|
-
measure.ref,
|
|
269
|
-
{
|
|
270
|
-
width: props.width,
|
|
271
|
-
height: props.height ?? (props.aspectRatio && w > 0 ? w / props.aspectRatio : void 0),
|
|
272
|
-
flexGrow: 1
|
|
273
|
-
},
|
|
274
|
-
scene?.markup ?? EMPTY_SVG,
|
|
275
|
-
{
|
|
276
|
-
width: w,
|
|
277
|
-
height: h
|
|
278
|
-
},
|
|
279
|
-
props.id ? props.id + "-overlay" : void 0,
|
|
280
|
-
{
|
|
281
|
-
width: w,
|
|
282
|
-
height: h
|
|
283
|
-
},
|
|
284
|
-
interactive,
|
|
285
|
-
interactive ? onTouch : void 0,
|
|
286
|
-
interactive ? onTap : void 0,
|
|
287
|
-
scene?.labels.map((l) => universalValue(__octaneUniversalPlan2, [
|
|
288
|
-
l.x,
|
|
289
|
-
l.y,
|
|
290
|
-
l.width,
|
|
291
|
-
l.text,
|
|
292
|
-
l.align === "center" ? "center" : l.align === "end" ? "right" : "left",
|
|
293
|
-
{
|
|
294
|
-
fontSize: 10,
|
|
295
|
-
opacity: .7
|
|
296
|
-
}
|
|
297
|
-
])),
|
|
298
|
-
universalIf(cursor && props.crosshair && !scene?.pie && plot, () => {
|
|
299
|
-
return universalValue(__octaneUniversalPlan3, [
|
|
300
|
-
cursor.px - .5,
|
|
301
|
-
plot.y,
|
|
302
|
-
plot.height,
|
|
303
|
-
new Color("#8a8a8a")
|
|
304
|
-
]);
|
|
305
|
-
}),
|
|
306
|
-
universalIf(cursor && (props.crosshair || props.tooltip), () => {
|
|
307
|
-
return universalValue(__octaneUniversalPlan4, [
|
|
308
|
-
cursor.px - 4,
|
|
309
|
-
cursor.py - 4,
|
|
310
|
-
new Color(dotColor ?? "#4e79a7")
|
|
311
|
-
]);
|
|
312
|
-
}),
|
|
313
|
-
universalIf(cursor && props.tooltip && tipText, () => {
|
|
314
|
-
return universalValue(__octaneUniversalPlan5, [
|
|
315
|
-
tipLeft,
|
|
316
|
-
tipTop < 0 ? cursor.py + 12 : tipTop,
|
|
317
|
-
new Color("rgba(20,20,20,0.88)"),
|
|
318
|
-
tipText,
|
|
319
|
-
new Color("#ffffff"),
|
|
320
|
-
{ fontSize: 11 }
|
|
321
|
-
]);
|
|
322
|
-
}),
|
|
323
|
-
universalIf(legend === "bottom" && scene, () => {
|
|
324
|
-
return universalValue(__octaneUniversalPlan7, [{ paddingTop: 4 }, scene.legend.map((item) => universalValue(__octaneUniversalPlan6, [
|
|
325
|
-
{ marginRight: 12 },
|
|
326
|
-
{
|
|
327
|
-
width: 10,
|
|
328
|
-
height: 10,
|
|
329
|
-
borderRadius: 2,
|
|
330
|
-
backgroundColor: new Color(item.color),
|
|
331
|
-
marginRight: 4
|
|
332
|
-
},
|
|
333
|
-
item.text,
|
|
334
|
-
{ fontSize: 11 }
|
|
335
|
-
]))]);
|
|
336
|
-
})
|
|
337
|
-
]);
|
|
338
|
-
}, { "module": "@nativescript-community/octane" });
|
|
339
|
-
//#endregion
|
|
340
|
-
export { Chart };
|
package/dist/native/core/axes.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { xCenter } from "./scales.js";
|
|
2
|
-
import { format } from "d3-format";
|
|
3
|
-
import { timeFormat } from "d3-time-format";
|
|
4
|
-
//#region src/core/axes.ts
|
|
5
|
-
var AXIS_COLOR = "#9aa3ad";
|
|
6
|
-
var GRID_COLOR = "#9aa3ad";
|
|
7
|
-
var GRID_OPACITY = .22;
|
|
8
|
-
var si = format("~s");
|
|
9
|
-
var plain = format("~g");
|
|
10
|
-
var day = timeFormat("%b %d");
|
|
11
|
-
/** Default tick label formatting — SI suffixes for big magnitudes, plain
|
|
12
|
-
* significant digits otherwise, short month-day for dates. */
|
|
13
|
-
function defaultFormat(value) {
|
|
14
|
-
if (value instanceof Date) return day(value);
|
|
15
|
-
if (typeof value === "number") return Math.abs(value) >= 1e3 ? si(value) : plain(value);
|
|
16
|
-
return String(value);
|
|
17
|
-
}
|
|
18
|
-
/** Cap categorical label count so boxes don't collide — keep every nth. */
|
|
19
|
-
function thinDomain(domain, plotWidth) {
|
|
20
|
-
const maxLabels = Math.max(2, Math.floor(plotWidth / 56));
|
|
21
|
-
if (domain.length <= maxLabels) return domain;
|
|
22
|
-
const step = Math.ceil(domain.length / maxLabels);
|
|
23
|
-
return domain.filter((_, i) => i % step === 0);
|
|
24
|
-
}
|
|
25
|
-
function xAxisModel(kind, scale, spec, plot) {
|
|
26
|
-
const labels = spec?.labels !== false;
|
|
27
|
-
const stubs = spec?.ticks !== false;
|
|
28
|
-
const grid = spec?.grid === true;
|
|
29
|
-
const fmt = spec?.format ?? defaultFormat;
|
|
30
|
-
const frame = [{
|
|
31
|
-
kind: "line",
|
|
32
|
-
x1: plot.x,
|
|
33
|
-
y1: plot.y + plot.height,
|
|
34
|
-
x2: plot.x + plot.width,
|
|
35
|
-
y2: plot.y + plot.height,
|
|
36
|
-
stroke: AXIS_COLOR,
|
|
37
|
-
strokeWidth: 1
|
|
38
|
-
}];
|
|
39
|
-
const gridMarks = [];
|
|
40
|
-
const out = [];
|
|
41
|
-
let values;
|
|
42
|
-
let format = fmt;
|
|
43
|
-
if (kind === "band" || kind === "point") values = thinDomain(scale.domain(), plot.width);
|
|
44
|
-
else {
|
|
45
|
-
const continuous = scale;
|
|
46
|
-
const count = spec?.tickCount ?? 6;
|
|
47
|
-
values = continuous.ticks(count);
|
|
48
|
-
if (!spec?.format && kind === "time") {
|
|
49
|
-
const tf = continuous.tickFormat(count);
|
|
50
|
-
format = (v) => tf(v);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
for (const v of values) {
|
|
54
|
-
const px = plot.x + xCenter(kind, scale, v);
|
|
55
|
-
if (stubs) frame.push({
|
|
56
|
-
kind: "line",
|
|
57
|
-
x1: px,
|
|
58
|
-
y1: plot.y + plot.height,
|
|
59
|
-
x2: px,
|
|
60
|
-
y2: plot.y + plot.height + 4,
|
|
61
|
-
stroke: AXIS_COLOR,
|
|
62
|
-
strokeWidth: 1
|
|
63
|
-
});
|
|
64
|
-
if (grid) gridMarks.push({
|
|
65
|
-
kind: "line",
|
|
66
|
-
x1: px,
|
|
67
|
-
y1: plot.y,
|
|
68
|
-
x2: px,
|
|
69
|
-
y2: plot.y + plot.height,
|
|
70
|
-
stroke: GRID_COLOR,
|
|
71
|
-
strokeOpacity: GRID_OPACITY,
|
|
72
|
-
strokeWidth: 1
|
|
73
|
-
});
|
|
74
|
-
if (labels) {
|
|
75
|
-
const width = Math.min(72, plot.width / Math.max(1, values.length));
|
|
76
|
-
const boxX = Math.min(Math.max(0, px - width / 2), Math.max(0, plot.x + plot.width + 8 - width));
|
|
77
|
-
out.push({
|
|
78
|
-
x: boxX,
|
|
79
|
-
y: plot.y + plot.height + 6,
|
|
80
|
-
width,
|
|
81
|
-
align: "center",
|
|
82
|
-
text: format(v),
|
|
83
|
-
axis: "x"
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
labels: out,
|
|
89
|
-
frame,
|
|
90
|
-
grid: gridMarks
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
function yAxisModel(scale, spec, plot) {
|
|
94
|
-
const labels = spec?.labels !== false;
|
|
95
|
-
const stubs = spec?.ticks !== false;
|
|
96
|
-
const grid = spec?.grid === true;
|
|
97
|
-
const fmt = spec?.format ?? defaultFormat;
|
|
98
|
-
const frame = [{
|
|
99
|
-
kind: "line",
|
|
100
|
-
x1: plot.x,
|
|
101
|
-
y1: plot.y,
|
|
102
|
-
x2: plot.x,
|
|
103
|
-
y2: plot.y + plot.height,
|
|
104
|
-
stroke: AXIS_COLOR,
|
|
105
|
-
strokeWidth: 1
|
|
106
|
-
}];
|
|
107
|
-
const gridMarks = [];
|
|
108
|
-
const out = [];
|
|
109
|
-
for (const v of scale.ticks(spec?.tickCount ?? 5)) {
|
|
110
|
-
const py = plot.y + scale(v);
|
|
111
|
-
if (stubs) frame.push({
|
|
112
|
-
kind: "line",
|
|
113
|
-
x1: plot.x - 4,
|
|
114
|
-
y1: py,
|
|
115
|
-
x2: plot.x,
|
|
116
|
-
y2: py,
|
|
117
|
-
stroke: AXIS_COLOR,
|
|
118
|
-
strokeWidth: 1
|
|
119
|
-
});
|
|
120
|
-
if (grid) gridMarks.push({
|
|
121
|
-
kind: "line",
|
|
122
|
-
x1: plot.x,
|
|
123
|
-
y1: py,
|
|
124
|
-
x2: plot.x + plot.width,
|
|
125
|
-
y2: py,
|
|
126
|
-
stroke: GRID_COLOR,
|
|
127
|
-
strokeOpacity: GRID_OPACITY,
|
|
128
|
-
strokeWidth: 1
|
|
129
|
-
});
|
|
130
|
-
if (labels) out.push({
|
|
131
|
-
x: 0,
|
|
132
|
-
y: py - 6,
|
|
133
|
-
width: Math.max(0, plot.x - 8),
|
|
134
|
-
align: "end",
|
|
135
|
-
text: fmt(v),
|
|
136
|
-
axis: "y"
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
labels: out,
|
|
141
|
-
frame,
|
|
142
|
-
grid: gridMarks
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
//#endregion
|
|
146
|
-
export { defaultFormat, xAxisModel, yAxisModel };
|