@amcharts/amcharts5-react-native 0.0.0-stage → 5.0.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/CHANGELOG.md +20 -0
- package/LICENSE +35 -0
- package/README.md +193 -2
- package/dist/AmChart.d.ts +102 -0
- package/dist/AmChart.js +188 -0
- package/dist/AmChart.js.map +1 -0
- package/dist/generated.d.ts +2 -0
- package/dist/generated.js +7 -0
- package/dist/generated.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# amCharts 5 for React Native Changelog
|
|
2
|
+
|
|
3
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
|
|
4
|
+
|
|
5
|
+
Please note, that this project, while following numbering syntax, it DOES NOT
|
|
6
|
+
adhere to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) rules.
|
|
7
|
+
|
|
8
|
+
## [5.0.1] - 2026-10-23
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- `themes`: a theme can come with its settings, e.g. `["Adaptive", { baseColor: "#4150a0" }]`.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- Loads amCharts 5.21.4.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [5.0.0] - 2026-10-22
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
- First release: `<AmChart>`, a chart in a WebView, from a JSON config or chart code. Loads amCharts 5.21.3.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
## Free amCharts license
|
|
2
|
+
|
|
3
|
+
This amCharts software is copyrighted by Antanas Marcelionis.
|
|
4
|
+
|
|
5
|
+
This amCharts software is provided under linkware license, conditions of which are outlined below.
|
|
6
|
+
|
|
7
|
+
### You can
|
|
8
|
+
|
|
9
|
+
* Use amCharts software in any of your projects, including commercial.
|
|
10
|
+
* Modify amCharts software to suit your needs (source code is available at [here](https://github.com/amcharts/amcharts5)).
|
|
11
|
+
* Bundle amCharts software with your own projects (free, open source, or commercial).
|
|
12
|
+
|
|
13
|
+
### If the following conditions are met
|
|
14
|
+
|
|
15
|
+
* You do not disable, hide or alter the branding link which is displayed on all the content generated by amCharts software.
|
|
16
|
+
* You include this original LICENSE file together with original (or modified) files from amCharts software.
|
|
17
|
+
* Your own personal license does not supersede or in any way negate the effect of this LICENSE, or make the impression of doing so.
|
|
18
|
+
|
|
19
|
+
### You can't
|
|
20
|
+
|
|
21
|
+
* Remove or alter this LICENSE file.
|
|
22
|
+
* Remove any of the amCharts copyright notices from any of the files of amCharts software.
|
|
23
|
+
* Use amCharts software without built-in attribution (logo). Please see note about commercial amCharts licenses below.
|
|
24
|
+
* Sell or receive any compensation for amCharts software.
|
|
25
|
+
* Distribute amCharts software on its own, not as part of other application.
|
|
26
|
+
|
|
27
|
+
### The above does not suit you?
|
|
28
|
+
|
|
29
|
+
amCharts provides commercial licenses for purchase for various usage scenarios that are not covered by the above conditions.
|
|
30
|
+
|
|
31
|
+
Please refer to [this web page](https://www.amcharts.com/online-store/) or [contact amCharts support](mailto:contact@amcharts.com) for further information.
|
|
32
|
+
|
|
33
|
+
### In doubt?
|
|
34
|
+
|
|
35
|
+
[Contact amCharts](mailto:contact@amcharts.com). We'll be happy to sort you out.
|
package/README.md
CHANGED
|
@@ -1,3 +1,194 @@
|
|
|
1
|
-
#
|
|
1
|
+
# amCharts 5 for React Native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A React Native component for [amCharts 5](https://www.amcharts.com/docs/v5/).
|
|
4
|
+
The chart is drawn by the library itself, in a WebView, so every chart type,
|
|
5
|
+
theme and feature works as it does on the web, on canvas or as SVG.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install @amcharts/amcharts5-react-native react-native-webview
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
With Expo, `npx expo install react-native-webview`, then install this package.
|
|
12
|
+
It works in Expo Go.
|
|
13
|
+
|
|
14
|
+
It needs React Native 0.72 or later and react-native-webview 13 or later.
|
|
15
|
+
`@amcharts/amcharts5` does not have to be installed: the WebView loads the
|
|
16
|
+
library's script files, by default from the amCharts CDN. Each release of
|
|
17
|
+
this package loads the latest library version at the time, listed in its
|
|
18
|
+
CHANGELOG.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## A chart from a JSON config
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { AmChart } from "@amcharts/amcharts5-react-native";
|
|
25
|
+
|
|
26
|
+
<AmChart config={config} themes={["Animated"]} style={{ height: 300 }} />
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The config is a [JSON config](https://www.amcharts.com/docs/v5/concepts/serializing/),
|
|
30
|
+
as an object or a string. The chart types it uses are loaded for it, and so
|
|
31
|
+
is map geodata it names by its global name (`"geoJSON": "am5geodata_worldLow"`).
|
|
32
|
+
A config with different content makes the chart again; the same content
|
|
33
|
+
written inline on every render does not.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## A chart written in code
|
|
37
|
+
|
|
38
|
+
The code is a string, because it runs in the WebView, where the library is: a
|
|
39
|
+
function cannot be passed into a WebView. Write it as in any amCharts example
|
|
40
|
+
for script tags.
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
const code = `
|
|
44
|
+
const chart = root.container.children.push(am5xy.XYChart.new(root, {}));
|
|
45
|
+
|
|
46
|
+
const xAxis = chart.xAxes.push(am5xy.CategoryAxis.new(root, {
|
|
47
|
+
categoryField: "country",
|
|
48
|
+
renderer: am5xy.AxisRendererX.new(root, {})
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
const yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
|
|
52
|
+
renderer: am5xy.AxisRendererY.new(root, {})
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
const series = chart.series.push(am5xy.ColumnSeries.new(root, {
|
|
56
|
+
xAxis: xAxis,
|
|
57
|
+
yAxis: yAxis,
|
|
58
|
+
categoryXField: "country",
|
|
59
|
+
valueYField: "visits"
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
xAxis.data.setAll(data);
|
|
63
|
+
series.data.setAll(data);
|
|
64
|
+
|
|
65
|
+
// New data, without making the chart again
|
|
66
|
+
return (newData) => {
|
|
67
|
+
xAxis.data.setAll(newData);
|
|
68
|
+
series.data.setAll(newData);
|
|
69
|
+
};
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
<AmChart code={code} data={visits} themes={["Animated"]} style={{ height: 300 }} />
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- The code gets `root`, `data` and `post`, and the library's globals: `am5`,
|
|
76
|
+
`am5xy`, `am5themes_Animated` and so on. The files it uses are loaded for it.
|
|
77
|
+
It may declare its own `data`, as many examples do.
|
|
78
|
+
- When `data` changes, by content, the function the code returned gets it.
|
|
79
|
+
Without one, the chart is made again. If the code returns a promise,
|
|
80
|
+
`onReady` waits for it.
|
|
81
|
+
- A different `code` makes the chart again.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
## Events from the chart
|
|
85
|
+
|
|
86
|
+
`post(name, value)` in the chart's code calls `onMessage` in the app. The value
|
|
87
|
+
must be JSON.
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
const code = `
|
|
91
|
+
...
|
|
92
|
+
series.columns.template.events.on("click", (event) => {
|
|
93
|
+
post("tap", event.target.dataItem.dataContext.country);
|
|
94
|
+
});
|
|
95
|
+
`;
|
|
96
|
+
|
|
97
|
+
<AmChart code={code} data={visits} onMessage={(name, value) => {
|
|
98
|
+
if (name === "tap") {
|
|
99
|
+
navigation.navigate("Country", { country: value });
|
|
100
|
+
}
|
|
101
|
+
}} />
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
A ref gives `run(code)`, which runs code in the chart's page with `root`,
|
|
105
|
+
`chart` (the chart a config made), `result` (what the code returned), `data`
|
|
106
|
+
and `post`. Called before the chart is ready, it waits for it.
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
const chartView = useRef<AmChartHandle>(null);
|
|
110
|
+
...
|
|
111
|
+
<AmChart ref={chartView} config={config} />
|
|
112
|
+
...
|
|
113
|
+
// Hide the first series of the chart the config made
|
|
114
|
+
chartView.current?.run("chart.series.getIndex(0).hide()");
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## Props
|
|
119
|
+
|
|
120
|
+
| Prop | What it is |
|
|
121
|
+
|---|---|
|
|
122
|
+
| `config` | The chart as a JSON config: an object or a JSON string. |
|
|
123
|
+
| `code` | The chart as code, used when there is no `config`. |
|
|
124
|
+
| `data` | Data for `code`, as `data`. It must be JSON. With a `config`, it is only there for `run()`. |
|
|
125
|
+
| `themes` | Theme names, e.g. `["Animated", "Dark"]`: the files in the library's `themes/` folder. A theme with settings is a pair: `["Adaptive", { baseColor: "#4150a0" }]`. |
|
|
126
|
+
| `renderer` | `"svg"` draws the chart as SVG; the default is canvas. SVG needs amCharts 5.21.0 or later. |
|
|
127
|
+
| `licenses` | amCharts license keys, which remove the logo: see [License](#license). |
|
|
128
|
+
| `modules` | More script files to load before the chart is built, e.g. `"locales/de_DE"` for a locale named only in a config, or full URLs. Chart types, themes, plugins, locales, fonts and geodata named by their global (`am5fonts_notosans_jp`) are loaded without this. |
|
|
129
|
+
| `libraryUrl` | Where the library's script files are. The default is the amCharts CDN's folder for the library version this package was released with. |
|
|
130
|
+
| `geodataUrl` | Where the geodata files are. The default is `https://cdn.amcharts.com/lib/5/geodata/`, or the `geodata/` folder of a `libraryUrl` that is not on the amCharts CDN. Fonts come from the same place. |
|
|
131
|
+
| `onReady` | Called when the chart is built. |
|
|
132
|
+
| `onError` | Called with a message when the chart could not be built or its code failed. Without it, the message goes to `console.warn`. |
|
|
133
|
+
| `onMessage` | Called with `(name, value)` when the chart's code calls `post`. |
|
|
134
|
+
| `style` | For the view the chart is in. Give it a height, or `flex: 1`; without one it is 400 high. |
|
|
135
|
+
| `webViewProps` | Props for the WebView, e.g. `{ androidLayerType: "hardware" }`, except the ones the chart needs: `source`, `onMessage`, `onShouldStartLoadWithRequest`, `onContentProcessDidTerminate`, `onRenderProcessGone`. |
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## Where the library comes from
|
|
139
|
+
|
|
140
|
+
By default the WebView loads the library from the amCharts CDN, in the
|
|
141
|
+
version this package was released with, so updating the package updates the
|
|
142
|
+
library. The device
|
|
143
|
+
needs a connection the first time; after that the WebView caches the files
|
|
144
|
+
as a browser does.
|
|
145
|
+
|
|
146
|
+
To serve the files yourself, point `libraryUrl` at a folder with the
|
|
147
|
+
library's script files: the contents of the amCharts download, the same files
|
|
148
|
+
that are on the CDN. Shipping them inside the app, so that charts work
|
|
149
|
+
offline, needs a `file://` address the WebView is allowed to read. That
|
|
150
|
+
differs between iOS and Android, and is not covered here yet.
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
## Good to know
|
|
154
|
+
|
|
155
|
+
- Each chart is a WebView. A screen with many charts uses more memory, and a
|
|
156
|
+
chart takes a moment to appear while its page loads.
|
|
157
|
+
- Chart code is a string, so your editor does not check it. Errors in it come
|
|
158
|
+
to `onError`.
|
|
159
|
+
- What goes between the app and the chart (`config`, `data`, `post`) is JSON.
|
|
160
|
+
A `Date` arrives as a string: give dates as timestamps (`date.getTime()`).
|
|
161
|
+
- `code` runs as code in the chart's page. Never build it from text a user
|
|
162
|
+
typed or a server sent; pass such values in `data`.
|
|
163
|
+
- Links in the chart, such as the amCharts logo or a data item's `url`, open
|
|
164
|
+
in the browser, not over the chart.
|
|
165
|
+
- Android's font size setting does not change the chart's text (`textZoom` is
|
|
166
|
+
100); set `webViewProps={{ textZoom: ... }}` to change that.
|
|
167
|
+
- If the system ends the WebView's process, the chart's page is loaded again
|
|
168
|
+
and the chart made again.
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
Without a commercial amCharts license, the charts show a small amCharts logo:
|
|
174
|
+
that is the free license, in the LICENSE file. A commercial license removes
|
|
175
|
+
the logo. Give its keys with `licenses`, on each chart:
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
<AmChart licenses={["AM5C-..."]} config={config} />
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
They are added before the chart is made. Calling `am5.addLicense()` in `code`
|
|
182
|
+
would be too late: a chart decides on the logo when its root is made.
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
## Example
|
|
186
|
+
|
|
187
|
+
[`examples/expo`](examples/expo/), for Expo Go: a chart in code whose data
|
|
188
|
+
changes without making it again and that sends taps to the app, a chart from a
|
|
189
|
+
JSON config with `run()`, and a map.
|
|
190
|
+
|
|
191
|
+
## More
|
|
192
|
+
|
|
193
|
+
- [amCharts 5 documentation](https://www.amcharts.com/docs/v5/) and [demos](https://www.amcharts.com/demos/)
|
|
194
|
+
- License: see [License](#license) above.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle } from "react-native";
|
|
2
|
+
import type { WebViewProps } from "react-native-webview";
|
|
3
|
+
/**
|
|
4
|
+
* Props of `<AmChart>`.
|
|
5
|
+
*/
|
|
6
|
+
export interface AmChartProps {
|
|
7
|
+
/**
|
|
8
|
+
* The chart as a JSON config: an object, or a JSON string. A config with
|
|
9
|
+
* different content makes the chart again.
|
|
10
|
+
*/
|
|
11
|
+
config?: object | string;
|
|
12
|
+
/**
|
|
13
|
+
* The chart as code, used when there is no `config`. It runs in the chart's
|
|
14
|
+
* page with `root`, `data` and `post`, and the library's globals (`am5`,
|
|
15
|
+
* `am5xy`...). A different string makes the chart again. Return a function
|
|
16
|
+
* to get new `data` without making the chart again, or a promise for
|
|
17
|
+
* `onReady` to wait for.
|
|
18
|
+
*/
|
|
19
|
+
code?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Data for `code`, as `data`. It must be JSON. New content goes to the
|
|
22
|
+
* function `code` returned, or makes the chart again. With a `config` it
|
|
23
|
+
* is only there for `run()`.
|
|
24
|
+
*/
|
|
25
|
+
data?: unknown;
|
|
26
|
+
/**
|
|
27
|
+
* Theme names, e.g. `["Animated", "Dark"]`, or a name with the theme's
|
|
28
|
+
* settings: `["Adaptive", { baseColor: "#4150a0" }]`. Settings must be JSON.
|
|
29
|
+
*/
|
|
30
|
+
themes?: Array<string | [string, object]>;
|
|
31
|
+
/**
|
|
32
|
+
* Draws the chart as SVG instead of canvas.
|
|
33
|
+
*
|
|
34
|
+
* @default "canvas"
|
|
35
|
+
*/
|
|
36
|
+
renderer?: "canvas" | "svg";
|
|
37
|
+
/**
|
|
38
|
+
* amCharts license keys, which remove the amCharts logo. They are added
|
|
39
|
+
* before the chart is made: calling `am5.addLicense()` in `code` would be
|
|
40
|
+
* too late.
|
|
41
|
+
*/
|
|
42
|
+
licenses?: Array<string>;
|
|
43
|
+
/**
|
|
44
|
+
* More script files to load, e.g. `"locales/de_DE"`, or a full URL. Chart
|
|
45
|
+
* types, themes, plugins and geodata named by their global are loaded
|
|
46
|
+
* without this.
|
|
47
|
+
*/
|
|
48
|
+
modules?: Array<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Where the library's script files are.
|
|
51
|
+
*
|
|
52
|
+
* @default "https://cdn.amcharts.com/lib/version/<the library version this package was released with>/"
|
|
53
|
+
*/
|
|
54
|
+
libraryUrl?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Where the geodata files are.
|
|
57
|
+
*
|
|
58
|
+
* @default "https://cdn.amcharts.com/lib/5/geodata/", or the `geodata/` folder of a `libraryUrl` that is not on the amCharts CDN
|
|
59
|
+
*/
|
|
60
|
+
geodataUrl?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Called when the chart is built.
|
|
63
|
+
*/
|
|
64
|
+
onReady?: () => void;
|
|
65
|
+
/**
|
|
66
|
+
* Called when the chart could not be built, or its code failed. Without it
|
|
67
|
+
* the error goes to `console.warn`.
|
|
68
|
+
*/
|
|
69
|
+
onError?: (message: string) => void;
|
|
70
|
+
/**
|
|
71
|
+
* Called when the chart's code calls `post(name, value)`.
|
|
72
|
+
*/
|
|
73
|
+
onMessage?: (name: string, value: unknown) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Give the chart a height, or `flex: 1`; without one it is 400 high.
|
|
76
|
+
*/
|
|
77
|
+
style?: StyleProp<ViewStyle>;
|
|
78
|
+
/**
|
|
79
|
+
* Props for the WebView the chart is drawn in, except the ones the chart
|
|
80
|
+
* needs for itself.
|
|
81
|
+
*/
|
|
82
|
+
webViewProps?: Partial<Omit<WebViewProps, "source" | "onMessage" | "onShouldStartLoadWithRequest" | "onContentProcessDidTerminate" | "onRenderProcessGone">>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* What a ref on `<AmChart>` gives.
|
|
86
|
+
*/
|
|
87
|
+
export interface AmChartHandle {
|
|
88
|
+
/**
|
|
89
|
+
* Runs code in the chart's page, with `root`, `chart` (from a config),
|
|
90
|
+
* `result` (what `code` returned), `data` and `post`. Before the chart is
|
|
91
|
+
* ready, it waits for it.
|
|
92
|
+
*/
|
|
93
|
+
run(code: string): void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* An amCharts 5 chart in a WebView, from a JSON config or from chart code.
|
|
97
|
+
*
|
|
98
|
+
* ```tsx
|
|
99
|
+
* <AmChart config={config} themes={["Animated"]} style={{ height: 300 }} />
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare const AmChart: import("react").ForwardRefExoticComponent<AmChartProps & import("react").RefAttributes<AmChartHandle>>;
|
package/dist/AmChart.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AmChart = void 0;
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const react_native_1 = require("react-native");
|
|
9
|
+
const react_native_webview_1 = __importDefault(require("react-native-webview"));
|
|
10
|
+
const generated_1 = require("./generated");
|
|
11
|
+
function folder(url) {
|
|
12
|
+
return /\/$/.test(url) ? url : url + "/";
|
|
13
|
+
}
|
|
14
|
+
// Line separators end a line in older engines, even inside a string
|
|
15
|
+
const separators = new RegExp("[" + String.fromCharCode(0x2028, 0x2029) + "]", "g");
|
|
16
|
+
// Script for injectJavaScript, with a value that may hold any text
|
|
17
|
+
function call(name, value) {
|
|
18
|
+
const text = JSON.stringify(value);
|
|
19
|
+
const json = text === undefined ? "undefined" : text.replace(separators, (c) => "\\u" + c.charCodeAt(0).toString(16));
|
|
20
|
+
return "window.amChartPage && window.amChartPage." + name + "(" + json + "); true;";
|
|
21
|
+
}
|
|
22
|
+
function hasHeight(style) {
|
|
23
|
+
const flat = react_native_1.StyleSheet.flatten(style) || {};
|
|
24
|
+
return flat.height != null || flat.minHeight != null || flat.flex != null || flat.flexGrow != null || flat.aspectRatio != null || flat.bottom != null;
|
|
25
|
+
}
|
|
26
|
+
const webViewStyle = { flex: 1, backgroundColor: "transparent" };
|
|
27
|
+
const CDN = "https://cdn.amcharts.com/lib/";
|
|
28
|
+
/**
|
|
29
|
+
* An amCharts 5 chart in a WebView, from a JSON config or from chart code.
|
|
30
|
+
*
|
|
31
|
+
* ```tsx
|
|
32
|
+
* <AmChart config={config} themes={["Animated"]} style={{ height: 300 }} />
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
exports.AmChart = (0, react_1.forwardRef)(function AmChart(props, ref) {
|
|
36
|
+
const webView = (0, react_1.useRef)(null);
|
|
37
|
+
// A new page after the old one's process was lost
|
|
38
|
+
const [page, setPage] = (0, react_1.useState)(0);
|
|
39
|
+
// The page that has loaded, with the library address it was given
|
|
40
|
+
const [loaded, setLoaded] = (0, react_1.useState)(undefined);
|
|
41
|
+
const shown = (0, react_1.useRef)(loaded);
|
|
42
|
+
shown.current = loaded;
|
|
43
|
+
// The latest callbacks: new ones on every render do not make the chart again
|
|
44
|
+
const latest = (0, react_1.useRef)(props);
|
|
45
|
+
latest.current = props;
|
|
46
|
+
const libraryUrl = folder(props.libraryUrl || CDN + "version/" + generated_1.libraryVersion + "/");
|
|
47
|
+
// Geodata and fonts are not in the CDN's version folders
|
|
48
|
+
const sharedUrl = libraryUrl.indexOf(CDN) === 0 ? CDN + "5/" : libraryUrl;
|
|
49
|
+
const geodataUrl = folder(props.geodataUrl || sharedUrl + "geodata/");
|
|
50
|
+
const currentUrl = (0, react_1.useRef)(libraryUrl);
|
|
51
|
+
currentUrl.current = libraryUrl;
|
|
52
|
+
// Compared by content: a config or data written inline is a new object on every render
|
|
53
|
+
const config = typeof props.config === "string" ? props.config : JSON.stringify(props.config);
|
|
54
|
+
const buildKey = JSON.stringify([config, props.code, props.themes, props.renderer, props.modules, props.licenses, geodataUrl]);
|
|
55
|
+
const dataKey = String(JSON.stringify(props.data));
|
|
56
|
+
const sent = (0, react_1.useRef)({});
|
|
57
|
+
// run() waits for the chart that is being built
|
|
58
|
+
const ready = (0, react_1.useRef)(false);
|
|
59
|
+
const queue = (0, react_1.useRef)([]);
|
|
60
|
+
(0, react_1.useEffect)(() => {
|
|
61
|
+
const target = webView.current;
|
|
62
|
+
if (!loaded || loaded.url !== libraryUrl || !target) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const current = latest.current;
|
|
66
|
+
if (sent.current.build !== buildKey) {
|
|
67
|
+
let parsed;
|
|
68
|
+
try {
|
|
69
|
+
parsed = typeof current.config === "string" ? JSON.parse(current.config) : current.config;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
report("config: " + error.message);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
ready.current = false;
|
|
76
|
+
target.injectJavaScript(call("build", {
|
|
77
|
+
config: parsed,
|
|
78
|
+
code: current.code,
|
|
79
|
+
data: current.data,
|
|
80
|
+
themes: current.themes || [],
|
|
81
|
+
renderer: current.renderer || "canvas",
|
|
82
|
+
licenses: current.licenses || [],
|
|
83
|
+
modules: current.modules || [],
|
|
84
|
+
libraryUrl: libraryUrl,
|
|
85
|
+
geodataUrl: geodataUrl,
|
|
86
|
+
fontsUrl: sharedUrl + "fonts/",
|
|
87
|
+
}));
|
|
88
|
+
sent.current = { build: buildKey, data: dataKey };
|
|
89
|
+
}
|
|
90
|
+
else if (sent.current.data !== dataKey) {
|
|
91
|
+
target.injectJavaScript(call("data", current.data));
|
|
92
|
+
sent.current.data = dataKey;
|
|
93
|
+
}
|
|
94
|
+
}, [loaded, libraryUrl, buildKey, dataKey]);
|
|
95
|
+
function report(message) {
|
|
96
|
+
const callback = latest.current.onError;
|
|
97
|
+
if (callback) {
|
|
98
|
+
callback(message);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
console.warn("AmChart: " + message);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const onMessage = (0, react_1.useCallback)((event) => {
|
|
105
|
+
let message;
|
|
106
|
+
try {
|
|
107
|
+
message = JSON.parse(event.nativeEvent.data);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const current = latest.current;
|
|
113
|
+
if (message.type === "loaded") {
|
|
114
|
+
sent.current = {};
|
|
115
|
+
ready.current = false;
|
|
116
|
+
setLoaded({ url: currentUrl.current });
|
|
117
|
+
}
|
|
118
|
+
else if (message.type === "ready") {
|
|
119
|
+
ready.current = true;
|
|
120
|
+
const target = webView.current;
|
|
121
|
+
queue.current.splice(0).forEach((code) => {
|
|
122
|
+
if (target) {
|
|
123
|
+
target.injectJavaScript(call("run", code));
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
if (current.onReady) {
|
|
127
|
+
current.onReady();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else if (message.type === "error") {
|
|
131
|
+
report(message.message || "");
|
|
132
|
+
}
|
|
133
|
+
else if (message.type === "message") {
|
|
134
|
+
if (current.onMessage) {
|
|
135
|
+
current.onMessage(message.name || "", message.value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}, []);
|
|
139
|
+
// Links in the chart (its logo, a data item's url) open in the browser
|
|
140
|
+
// instead of replacing the chart. Until the page has loaded, it may load
|
|
141
|
+
const onShouldStartLoadWithRequest = (0, react_1.useCallback)((request) => {
|
|
142
|
+
const page = shown.current;
|
|
143
|
+
if (!page || page.url !== currentUrl.current || request.isTopFrame === false || request.url === "about:blank") {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
if (/^(https?|mailto|tel):/i.test(request.url)) {
|
|
147
|
+
react_native_1.Linking.openURL(request.url).catch(() => undefined);
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
}, []);
|
|
151
|
+
const restart = (0, react_1.useCallback)(() => {
|
|
152
|
+
ready.current = false;
|
|
153
|
+
setLoaded(undefined);
|
|
154
|
+
setPage((count) => count + 1);
|
|
155
|
+
}, []);
|
|
156
|
+
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
157
|
+
run(code) {
|
|
158
|
+
if (ready.current && webView.current) {
|
|
159
|
+
webView.current.injectJavaScript(call("run", code));
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
queue.current.push(code);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
}), []);
|
|
166
|
+
// A new base URL loads the page again
|
|
167
|
+
const source = (0, react_1.useMemo)(() => ({ html: generated_1.pageHtml, baseUrl: libraryUrl }), [libraryUrl]);
|
|
168
|
+
return (0, react_1.createElement)(react_native_1.View, { style: hasHeight(props.style) ? props.style : [{ height: 400 }, props.style] }, (0, react_1.createElement)(react_native_webview_1.default, {
|
|
169
|
+
originWhitelist: ["*"],
|
|
170
|
+
scrollEnabled: false,
|
|
171
|
+
bounces: false,
|
|
172
|
+
overScrollMode: "never",
|
|
173
|
+
showsHorizontalScrollIndicator: false,
|
|
174
|
+
showsVerticalScrollIndicator: false,
|
|
175
|
+
setSupportMultipleWindows: false,
|
|
176
|
+
textZoom: 100,
|
|
177
|
+
...props.webViewProps,
|
|
178
|
+
key: page,
|
|
179
|
+
ref: webView,
|
|
180
|
+
source: source,
|
|
181
|
+
style: [webViewStyle, props.webViewProps ? props.webViewProps.style : undefined],
|
|
182
|
+
onMessage: onMessage,
|
|
183
|
+
onShouldStartLoadWithRequest: onShouldStartLoadWithRequest,
|
|
184
|
+
onContentProcessDidTerminate: restart,
|
|
185
|
+
onRenderProcessGone: restart,
|
|
186
|
+
}));
|
|
187
|
+
});
|
|
188
|
+
//# sourceMappingURL=AmChart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AmChart.js","sourceRoot":"","sources":["../src/AmChart.ts"],"names":[],"mappings":";;;;;;AAAA,iCAA0H;AAE1H,+CAAyD;AAEzD,gFAA2C;AAE3C,2CAAuD;AAwHvD,SAAS,MAAM,CAAC,GAAW;IAC1B,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;AAC1C,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;AAEpF,mEAAmE;AACnE,SAAS,IAAI,CAAC,IAAY,EAAE,KAAc;IACzC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,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,KAAK;QACd,cAAc,EAAE,OAAO;QACvB,8BAA8B,EAAE,KAAK;QACrC,4BAA4B,EAAE,KAAK;QACnC,yBAAyB,EAAE,KAAK;QAChC,QAAQ,EAAE,GAAG;QACb,GAAG,KAAK,CAAC,YAAY;QACrB,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,OAAO;QACZ,MAAM,EAAE,MAAM;QACd,KAAK,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;QAChF,SAAS,EAAE,SAAS;QACpB,4BAA4B,EAAE,4BAA4B;QAC1D,4BAA4B,EAAE,OAAO;QACrC,mBAAmB,EAAE,OAAO;KAC5B,CAAC,CACF,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { createElement, forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from \"react\";\nimport type { ForwardedRef } from \"react\";\nimport { Linking, StyleSheet, View } from \"react-native\";\nimport type { StyleProp, ViewStyle } from \"react-native\";\nimport WebView from \"react-native-webview\";\nimport type { WebViewMessageEvent, WebViewProps } from \"react-native-webview\";\nimport { libraryVersion, pageHtml } from \"./generated\";\n\n/**\n * Props of `<AmChart>`.\n */\nexport interface AmChartProps {\n\n\t/**\n\t * The chart as a JSON config: an object, or a JSON string. A config with\n\t * different content makes the chart again.\n\t */\n\tconfig?: object | string;\n\n\t/**\n\t * The chart as code, used when there is no `config`. It runs in the chart's\n\t * page with `root`, `data` and `post`, and the library's globals (`am5`,\n\t * `am5xy`...). A different string makes the chart again. Return a function\n\t * to get new `data` without making the chart again, or a promise for\n\t * `onReady` to wait for.\n\t */\n\tcode?: string;\n\n\t/**\n\t * Data for `code`, as `data`. It must be JSON. New content goes to the\n\t * function `code` returned, or makes the chart again. With a `config` it\n\t * is only there for `run()`.\n\t */\n\tdata?: unknown;\n\n\t/**\n\t * Theme names, e.g. `[\"Animated\", \"Dark\"]`, or a name with the theme's\n\t * settings: `[\"Adaptive\", { baseColor: \"#4150a0\" }]`. Settings must be JSON.\n\t */\n\tthemes?: Array<string | [string, object]>;\n\n\t/**\n\t * Draws the chart as SVG instead of canvas.\n\t *\n\t * @default \"canvas\"\n\t */\n\trenderer?: \"canvas\" | \"svg\";\n\n\t/**\n\t * amCharts license keys, which remove the amCharts logo. They are added\n\t * before the chart is made: calling `am5.addLicense()` in `code` would be\n\t * too late.\n\t */\n\tlicenses?: Array<string>;\n\n\t/**\n\t * More script files to load, e.g. `\"locales/de_DE\"`, or a full URL. Chart\n\t * types, themes, plugins and geodata named by their global are loaded\n\t * without this.\n\t */\n\tmodules?: Array<string>;\n\n\t/**\n\t * Where the library's script files are.\n\t *\n\t * @default \"https://cdn.amcharts.com/lib/version/<the library version this package was released with>/\"\n\t */\n\tlibraryUrl?: string;\n\n\t/**\n\t * Where the geodata files are.\n\t *\n\t * @default \"https://cdn.amcharts.com/lib/5/geodata/\", or the `geodata/` folder of a `libraryUrl` that is not on the amCharts CDN\n\t */\n\tgeodataUrl?: string;\n\n\t/**\n\t * Called when the chart is built.\n\t */\n\tonReady?: () => void;\n\n\t/**\n\t * Called when the chart could not be built, or its code failed. Without it\n\t * the error goes to `console.warn`.\n\t */\n\tonError?: (message: string) => void;\n\n\t/**\n\t * Called when the chart's code calls `post(name, value)`.\n\t */\n\tonMessage?: (name: string, value: unknown) => void;\n\n\t/**\n\t * Give the chart a height, or `flex: 1`; without one it is 400 high.\n\t */\n\tstyle?: StyleProp<ViewStyle>;\n\n\t/**\n\t * Props for the WebView the chart is drawn in, except the ones the chart\n\t * needs for itself.\n\t */\n\twebViewProps?: Partial<Omit<WebViewProps, \"source\" | \"onMessage\" | \"onShouldStartLoadWithRequest\" | \"onContentProcessDidTerminate\" | \"onRenderProcessGone\">>;\n\n}\n\n/**\n * What a ref on `<AmChart>` gives.\n */\nexport interface AmChartHandle {\n\n\t/**\n\t * Runs code in the chart's page, with `root`, `chart` (from a config),\n\t * `result` (what `code` returned), `data` and `post`. Before the chart is\n\t * ready, it waits for it.\n\t */\n\trun(code: string): void;\n\n}\n\ninterface Message {\n\ttype: \"loaded\" | \"ready\" | \"error\" | \"message\";\n\tmessage?: string;\n\tname?: string;\n\tvalue?: unknown;\n}\n\nfunction folder(url: string): string {\n\treturn /\\/$/.test(url) ? url : url + \"/\";\n}\n\n// Line separators end a line in older engines, even inside a string\nconst separators = new RegExp(\"[\" + String.fromCharCode(0x2028, 0x2029) + \"]\", \"g\");\n\n// Script for injectJavaScript, with a value that may hold any text\nfunction call(name: string, value: unknown): string {\n\tconst text = JSON.stringify(value);\n\tconst json = text === undefined ? \"undefined\" : text.replace(separators, (c) => \"\\\\u\" + c.charCodeAt(0).toString(16));\n\treturn \"window.amChartPage && window.amChartPage.\" + name + \"(\" + json + \"); true;\";\n}\n\nfunction hasHeight(style: StyleProp<ViewStyle>): boolean {\n\tconst flat = StyleSheet.flatten(style) || {};\n\treturn flat.height != null || flat.minHeight != null || flat.flex != null || flat.flexGrow != null || flat.aspectRatio != null || flat.bottom != null;\n}\n\nconst webViewStyle = { flex: 1, backgroundColor: \"transparent\" };\n\nconst CDN = \"https://cdn.amcharts.com/lib/\";\n\n/**\n * An amCharts 5 chart in a WebView, from a JSON config or from chart code.\n *\n * ```tsx\n * <AmChart config={config} themes={[\"Animated\"]} style={{ height: 300 }} />\n * ```\n */\nexport const AmChart = forwardRef(function AmChart(props: AmChartProps, ref: ForwardedRef<AmChartHandle>) {\n\tconst webView = useRef<WebView>(null);\n\n\t// A new page after the old one's process was lost\n\tconst [page, setPage] = useState(0);\n\n\t// The page that has loaded, with the library address it was given\n\tconst [loaded, setLoaded] = useState<{ url: string } | undefined>(undefined);\n\tconst shown = useRef(loaded);\n\tshown.current = loaded;\n\n\t// The latest callbacks: new ones on every render do not make the chart again\n\tconst latest = useRef(props);\n\tlatest.current = props;\n\n\tconst libraryUrl = folder(props.libraryUrl || CDN + \"version/\" + libraryVersion + \"/\");\n\n\t// Geodata and fonts are not in the CDN's version folders\n\tconst sharedUrl = libraryUrl.indexOf(CDN) === 0 ? CDN + \"5/\" : libraryUrl;\n\tconst geodataUrl = folder(props.geodataUrl || sharedUrl + \"geodata/\");\n\tconst currentUrl = useRef(libraryUrl);\n\tcurrentUrl.current = libraryUrl;\n\n\t// Compared by content: a config or data written inline is a new object on every render\n\tconst config = typeof props.config === \"string\" ? props.config : JSON.stringify(props.config);\n\tconst buildKey = JSON.stringify([config, props.code, props.themes, props.renderer, props.modules, props.licenses, geodataUrl]);\n\tconst dataKey = String(JSON.stringify(props.data));\n\n\tconst sent = useRef<{ build?: string, data?: string }>({});\n\n\t// run() waits for the chart that is being built\n\tconst ready = useRef(false);\n\tconst queue = useRef<Array<string>>([]);\n\n\tuseEffect(() => {\n\t\tconst target = webView.current;\n\t\tif (!loaded || loaded.url !== libraryUrl || !target) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst current = latest.current;\n\n\t\tif (sent.current.build !== buildKey) {\n\t\t\tlet parsed: unknown;\n\t\t\ttry {\n\t\t\t\tparsed = typeof current.config === \"string\" ? JSON.parse(current.config) : current.config;\n\t\t\t}\n\t\t\tcatch (error) {\n\t\t\t\treport(\"config: \" + (error as Error).message);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tready.current = false;\n\t\t\ttarget.injectJavaScript(call(\"build\", {\n\t\t\t\tconfig: parsed,\n\t\t\t\tcode: current.code,\n\t\t\t\tdata: current.data,\n\t\t\t\tthemes: current.themes || [],\n\t\t\t\trenderer: current.renderer || \"canvas\",\n\t\t\t\tlicenses: current.licenses || [],\n\t\t\t\tmodules: current.modules || [],\n\t\t\t\tlibraryUrl: libraryUrl,\n\t\t\t\tgeodataUrl: geodataUrl,\n\t\t\t\tfontsUrl: sharedUrl + \"fonts/\",\n\t\t\t}));\n\t\t\tsent.current = { build: buildKey, data: dataKey };\n\t\t}\n\t\telse if (sent.current.data !== dataKey) {\n\t\t\ttarget.injectJavaScript(call(\"data\", current.data));\n\t\t\tsent.current.data = dataKey;\n\t\t}\n\t}, [loaded, libraryUrl, buildKey, dataKey]);\n\n\tfunction report(message: string): void {\n\t\tconst callback = latest.current.onError;\n\t\tif (callback) {\n\t\t\tcallback(message);\n\t\t}\n\t\telse {\n\t\t\tconsole.warn(\"AmChart: \" + message);\n\t\t}\n\t}\n\n\tconst onMessage = useCallback((event: WebViewMessageEvent) => {\n\t\tlet message: Message;\n\t\ttry {\n\t\t\tmessage = JSON.parse(event.nativeEvent.data);\n\t\t}\n\t\tcatch (error) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst current = latest.current;\n\n\t\tif (message.type === \"loaded\") {\n\t\t\tsent.current = {};\n\t\t\tready.current = false;\n\t\t\tsetLoaded({ url: currentUrl.current });\n\t\t}\n\t\telse if (message.type === \"ready\") {\n\t\t\tready.current = true;\n\t\t\tconst target = webView.current;\n\t\t\tqueue.current.splice(0).forEach((code) => {\n\t\t\t\tif (target) {\n\t\t\t\t\ttarget.injectJavaScript(call(\"run\", code));\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (current.onReady) {\n\t\t\t\tcurrent.onReady();\n\t\t\t}\n\t\t}\n\t\telse if (message.type === \"error\") {\n\t\t\treport(message.message || \"\");\n\t\t}\n\t\telse if (message.type === \"message\") {\n\t\t\tif (current.onMessage) {\n\t\t\t\tcurrent.onMessage(message.name || \"\", message.value);\n\t\t\t}\n\t\t}\n\t}, []);\n\n\t// Links in the chart (its logo, a data item's url) open in the browser\n\t// instead of replacing the chart. Until the page has loaded, it may load\n\tconst onShouldStartLoadWithRequest = useCallback((request: { url: string, isTopFrame?: boolean }) => {\n\t\tconst page = shown.current;\n\t\tif (!page || page.url !== currentUrl.current || request.isTopFrame === false || request.url === \"about:blank\") {\n\t\t\treturn true;\n\t\t}\n\t\tif (/^(https?|mailto|tel):/i.test(request.url)) {\n\t\t\tLinking.openURL(request.url).catch(() => undefined);\n\t\t}\n\t\treturn false;\n\t}, []);\n\n\tconst restart = useCallback(() => {\n\t\tready.current = false;\n\t\tsetLoaded(undefined);\n\t\tsetPage((count) => count + 1);\n\t}, []);\n\n\tuseImperativeHandle(ref, () => ({\n\t\trun(code: string) {\n\t\t\tif (ready.current && webView.current) {\n\t\t\t\twebView.current.injectJavaScript(call(\"run\", code));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tqueue.current.push(code);\n\t\t\t}\n\t\t},\n\t}), []);\n\n\t// A new base URL loads the page again\n\tconst source = useMemo(() => ({ html: pageHtml, baseUrl: libraryUrl }), [libraryUrl]);\n\n\treturn createElement(View, { style: hasHeight(props.style) ? props.style : [{ height: 400 }, props.style] },\n\t\tcreateElement(WebView, {\n\t\t\toriginWhitelist: [\"*\"],\n\t\t\tscrollEnabled: false,\n\t\t\tbounces: false,\n\t\t\toverScrollMode: \"never\",\n\t\t\tshowsHorizontalScrollIndicator: false,\n\t\t\tshowsVerticalScrollIndicator: false,\n\t\t\tsetSupportMultipleWindows: false,\n\t\t\ttextZoom: 100,\n\t\t\t...props.webViewProps,\n\t\t\tkey: page,\n\t\t\tref: webView,\n\t\t\tsource: source,\n\t\t\tstyle: [webViewStyle, props.webViewProps ? props.webViewProps.style : undefined],\n\t\t\tonMessage: onMessage,\n\t\t\tonShouldStartLoadWithRequest: onShouldStartLoadWithRequest,\n\t\t\tonContentProcessDidTerminate: restart,\n\t\t\tonRenderProcessGone: restart,\n\t\t}),\n\t);\n});\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pageHtml = exports.libraryVersion = void 0;
|
|
4
|
+
// Written by scripts/generate.cjs
|
|
5
|
+
exports.libraryVersion = "5.21.4";
|
|
6
|
+
exports.pageHtml = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n<style>\nhtml, body, #chart {\n\tmargin: 0;\n\tpadding: 0;\n\twidth: 100%;\n\theight: 100%;\n\toverflow: hidden;\n\tbackground: transparent;\n}\nbody {\n\t-webkit-tap-highlight-color: transparent;\n\t-webkit-touch-callout: none;\n\t-webkit-user-select: none;\n\tuser-select: none;\n}\n</style>\n</head>\n<body>\n<div id=\"chart\"></div>\n<script>\n(function () {\n\t\"use strict\";\n\n\t// Which script file has each class, and which files a file needs first\n\tvar classModules = {\"AccelerationBands\":\"stock\",\"AccumulationDistribution\":\"stock\",\"AccumulativeSwingIndex\":\"stock\",\"Annotator\":\"plugins/exporting\",\"ArcDiagram\":\"flow\",\"ArcDiagramLink\":\"flow\",\"ArcDiagramNodes\":\"flow\",\"Aroon\":\"stock\",\"AverageSeries\":\"stock\",\"AverageTrueRange\":\"stock\",\"AwesomeOscillator\":\"stock\",\"Axis\":\"xy\",\"AxisBullet\":\"xy\",\"AxisLabel\":\"xy\",\"AxisLabelRadial\":\"xy\",\"AxisRenderer\":\"xy\",\"AxisRendererCircular\":\"radar\",\"AxisRendererCurveX\":\"timeline\",\"AxisRendererCurveY\":\"timeline\",\"AxisRendererRadial\":\"radar\",\"AxisRendererX\":\"xy\",\"AxisRendererY\":\"xy\",\"AxisTick\":\"xy\",\"BaseColumnSeries\":\"xy\",\"BollingerBands\":\"stock\",\"BreadcrumbBar\":\"hierarchy\",\"BullBearPower\":\"stock\",\"CalloutSeries\":\"stock\",\"Candlestick\":\"xy\",\"CandlestickSeries\":\"xy\",\"CategoryAxis\":\"xy\",\"CategoryDateAxis\":\"xy\",\"ChaikinMoneyFlow\":\"stock\",\"ChaikinOscillator\":\"stock\",\"ChartIndicator\":\"stock\",\"ChartSerializer\":\"plugins/json\",\"Chord\":\"flow\",\"ChordDirected\":\"flow\",\"ChordLink\":\"flow\",\"ChordLinkDirected\":\"flow\",\"ChordNodes\":\"flow\",\"ChordNonRibbon\":\"flow\",\"ClockHand\":\"radar\",\"ClusteredPointSeries\":\"map\",\"ColorControl\":\"stock\",\"ColorPicker\":\"plugins/colorPicker\",\"ColorPickerButton\":\"plugins/colorPicker\",\"ColumnSeries\":\"xy\",\"CommodityChannelIndex\":\"stock\",\"ComparisonControl\":\"stock\",\"CurveChart\":\"timeline\",\"CurveColumnSeries\":\"timeline\",\"CurveCursor\":\"timeline\",\"CurveLineSeries\":\"timeline\",\"DataSaveControl\":\"stock\",\"DateAxis\":\"xy\",\"DateRangeSelector\":\"stock\",\"DisparityIndex\":\"stock\",\"DoodleSeries\":\"stock\",\"DrawingControl\":\"stock\",\"DrawingSeries\":\"stock\",\"DrawingToolControl\":\"stock\",\"Dropdown\":\"stock\",\"DropdownColors\":\"stock\",\"DropdownControl\":\"stock\",\"DropdownList\":\"stock\",\"DropdownListControl\":\"stock\",\"DurationAxis\":\"xy\",\"EditableAxisLabel\":\"xy\",\"EllipseSeries\":\"stock\",\"Exporting\":\"plugins/exporting\",\"ExportingMenu\":\"plugins/exporting\",\"FibonacciSeries\":\"stock\",\"FibonacciTimezoneSeries\":\"stock\",\"Flow\":\"flow\",\"FlowLink\":\"flow\",\"FlowNode\":\"flow\",\"FlowNodes\":\"flow\",\"ForceDirected\":\"hierarchy\",\"FunnelSeries\":\"percent\",\"FunnelSlice\":\"percent\",\"Gantt\":\"gantt\",\"GanttCategoryAxis\":\"gantt\",\"GanttCategoryAxisRenderer\":\"gantt\",\"GanttDateAxis\":\"gantt\",\"GanttDateAxisRenderer\":\"gantt\",\"GanttSeries\":\"gantt\",\"GaplessDateAxis\":\"xy\",\"GraticuleSeries\":\"map\",\"Grid\":\"xy\",\"HeikinAshi\":\"stock\",\"Hierarchy\":\"hierarchy\",\"HierarchyLink\":\"hierarchy\",\"HierarchyNode\":\"hierarchy\",\"HorizontalLineSeries\":\"stock\",\"HorizontalRaySeries\":\"stock\",\"IconControl\":\"stock\",\"IconSeries\":\"stock\",\"Indicator\":\"stock\",\"IndicatorControl\":\"stock\",\"IntervalControl\":\"stock\",\"LabelSeries\":\"stock\",\"LineArrowSeries\":\"stock\",\"LineSeries\":\"xy\",\"LinkedHierarchy\":\"hierarchy\",\"LinkedHierarchyNode\":\"hierarchy\",\"MACD\":\"stock\",\"MACross\":\"stock\",\"MapChart\":\"map\",\"MapLine\":\"map\",\"MapLineSeries\":\"map\",\"MapPointSeries\":\"map\",\"MapPolygon\":\"map\",\"MapPolygonSeries\":\"map\",\"MapRasterSeries\":\"map\",\"MapSankeyNodes\":\"map\",\"MapSankeySeries\":\"map\",\"MapSeries\":\"map\",\"Measure\":\"stock\",\"MedianPrice\":\"stock\",\"Momentum\":\"stock\",\"MovingAverage\":\"stock\",\"MovingAverageDeviation\":\"stock\",\"MovingAverageEnvelope\":\"stock\",\"NightSeries\":\"map\",\"OHLC\":\"xy\",\"OHLCSeries\":\"xy\",\"OnBalanceVolume\":\"stock\",\"OverboughtOversold\":\"stock\",\"PVT\":\"stock\",\"Pack\":\"hierarchy\",\"PanelControls\":\"stock\",\"ParallelChannelSeries\":\"stock\",\"Partition\":\"hierarchy\",\"PercentChart\":\"percent\",\"PercentSeries\":\"percent\",\"PeriodSelector\":\"stock\",\"PictorialStackedSeries\":\"percent\",\"PieChart\":\"percent\",\"PieSeries\":\"percent\",\"PixelMapSeries\":\"map\",\"PolylineSeries\":\"stock\",\"PyramidSeries\":\"percent\",\"QuadrantLineSeries\":\"stock\",\"RadarChart\":\"radar\",\"RadarColumnSeries\":\"radar\",\"RadarCursor\":\"radar\",\"RadarLineSeries\":\"radar\",\"RectangleSeries\":\"stock\",\"RegressionSeries\":\"stock\",\"RelativeStrengthIndex\":\"stock\",\"ResetControl\":\"stock\",\"Sankey\":\"flow\",\"SankeyLink\":\"flow\",\"SankeyNodes\":\"flow\",\"Serializer\":\"plugins/json\",\"SeriesTypeControl\":\"stock\",\"SerpentineChart\":\"timeline\",\"SettingsControl\":\"stock\",\"SettingsModal\":\"stock\",\"SimpleLineSeries\":\"stock\",\"SliceGrouper\":\"plugins/sliceGrouper\",\"SlicedChart\":\"percent\",\"SmoothedRadarLineSeries\":\"radar\",\"SmoothedXLineSeries\":\"xy\",\"SmoothedXYLineSeries\":\"xy\",\"SmoothedYLineSeries\":\"xy\",\"SpiralChart\":\"timeline\",\"StandardDeviation\":\"stock\",\"StepLineSeries\":\"xy\",\"StochasticMomentumIndex\":\"stock\",\"StochasticOscillator\":\"stock\",\"StockChart\":\"stock\",\"StockControl\":\"stock\",\"StockLegend\":\"stock\",\"StockPanel\":\"stock\",\"StockToolbar\":\"stock\",\"Sunburst\":\"hierarchy\",\"SuperTrend\":\"stock\",\"Tree\":\"hierarchy\",\"Treemap\":\"hierarchy\",\"TrendLineSeries\":\"stock\",\"Trix\":\"stock\",\"TypicalPrice\":\"stock\",\"VWAP\":\"stock\",\"ValueAxis\":\"xy\",\"Venn\":\"venn\",\"VerticalLineSeries\":\"stock\",\"Volume\":\"stock\",\"VolumeProfile\":\"stock\",\"VoronoiTreemap\":\"hierarchy\",\"WilliamsR\":\"stock\",\"WordCloud\":\"wc\",\"XYChart\":\"xy\",\"XYChartScrollbar\":\"xy\",\"XYCursor\":\"xy\",\"XYSeries\":\"xy\",\"ZigZag\":\"stock\",\"ZoomControl\":\"map\"};\n\tvar scriptDependencies = {\"pie\":[\"percent\"],\"funnel\":[\"percent\"],\"radar\":[\"xy\"],\"gantt\":[\"xy\",\"plugins/colorPicker\"],\"stock\":[\"xy\"],\"timeline\":[\"xy\"],\"element\":[\"index\",\"plugins/json\"]};\n\tvar modules = {};\n\tObject.keys(classModules).forEach(function (name) {\n\t\tmodules[classModules[name]] = true;\n\t});\n\n\tvar current = 0;\n\tvar options;\n\tvar root;\n\tvar chart;\n\tvar result;\n\tvar update;\n\tvar scripts = {};\n\n\tfunction send(message) {\n\t\tvar text;\n\t\ttry {\n\t\t\ttext = JSON.stringify(message);\n\t\t} catch (error) {\n\t\t\ttext = JSON.stringify({ type: \"error\", message: \"Could not send \" + message.name + \": \" + error.message });\n\t\t}\n\t\twindow.ReactNativeWebView.postMessage(text);\n\t}\n\n\tfunction post(name, value) {\n\t\tsend({ type: \"message\", name: String(name), value: value });\n\t}\n\n\tfunction fail(error) {\n\t\tsend({ type: \"error\", message: String(error && error.message ? error.message : error) });\n\t}\n\n\twindow.addEventListener(\"error\", function (event) {\n\t\tfail(event.error || event.message);\n\t});\n\n\twindow.addEventListener(\"unhandledrejection\", function (event) {\n\t\tfail(event.reason);\n\t});\n\n\t// A geodata global's file: am5geodata_region_world_europeLow > geodata/region/world/europeLow\n\tfunction geodataModule(name) {\n\t\treturn \"geodata/\" + (/^lang_/.test(name) ? \"lang/\" + name.slice(5) : name.replace(/_/g, \"/\"));\n\t}\n\n\t// A global's file: am5xy > xy, am5plugins_exporting > plugins/exporting,\n\t// am5fonts_notosans_sc > fonts/notosans-sc\n\tfunction globalModule(name) {\n\t\tvar rest = name.slice(3);\n\t\tvar match = /^(themes|plugins|locales)_(.+)$/.exec(rest);\n\t\tif (match) {\n\t\t\treturn match[1] + \"/\" + match[2];\n\t\t}\n\t\tif (/^fonts_./.test(rest)) {\n\t\t\treturn \"fonts/\" + rest.slice(6).replace(/_/g, \"-\");\n\t\t}\n\t\tif (/^geodata_./.test(rest)) {\n\t\t\treturn geodataModule(rest.slice(8));\n\t\t}\n\t\treturn modules[rest] ? rest : undefined;\n\t}\n\n\t// A theme is a name, or [name, settings]\n\tfunction themeName(theme) {\n\t\treturn Array.isArray(theme) ? theme[0] : theme;\n\t}\n\n\tfunction add(list, name) {\n\t\tif (!name || name === \"index\" || list.indexOf(name) !== -1) {\n\t\t\treturn;\n\t\t}\n\t\t(scriptDependencies[name] || []).forEach(function (dependency) {\n\t\t\tadd(list, dependency);\n\t\t});\n\t\tlist.push(name);\n\t}\n\n\t// The files a config needs: its classes, and geodata named by its global\n\tfunction addConfig(list, value) {\n\t\tif (typeof value === \"string\") {\n\t\t\tif (/^am5geodata_[A-Za-z0-9_]+$/.test(value)) {\n\t\t\t\tadd(list, geodataModule(value.slice(11)));\n\t\t\t}\n\t\t}\n\t\telse if (Array.isArray(value)) {\n\t\t\tvalue.forEach(function (item) {\n\t\t\t\taddConfig(list, item);\n\t\t\t});\n\t\t}\n\t\telse if (value && typeof value === \"object\") {\n\t\t\tif (typeof value.type === \"string\") {\n\t\t\t\tadd(list, classModules[value.type]);\n\t\t\t}\n\t\t\tObject.keys(value).forEach(function (key) {\n\t\t\t\taddConfig(list, value[key]);\n\t\t\t});\n\t\t}\n\t}\n\n\t// The files code needs, from the globals it uses, and the classes of a\n\t// config it gives the JSON parser\n\tfunction addCode(list, code) {\n\t\t(code.match(/\\bam5[A-Za-z0-9_]*/g) || []).forEach(function (name) {\n\t\t\tadd(list, globalModule(name));\n\t\t});\n\t\tif (code.indexOf(\"am5plugins_json\") !== -1) {\n\t\t\t(code.match(/\\btype[\"']?\\s*:\\s*[\"'][A-Za-z0-9_]+[\"']/g) || []).forEach(function (match) {\n\t\t\t\tadd(list, classModules[/[\"']([A-Za-z0-9_]+)[\"']$/.exec(match)[1]]);\n\t\t\t});\n\t\t}\n\t}\n\n\t// Its own scope, so that it may declare `data` or `root` itself\n\tfunction compile(names, code) {\n\t\treturn new Function(names.join(\",\"), \"return (function () {\\n\" + code + \"\\n})();\");\n\t}\n\n\tfunction url(name) {\n\t\tif (/^[a-z]+:/i.test(name)) {\n\t\t\treturn name;\n\t\t}\n\t\tif (name.indexOf(\"geodata/\") === 0) {\n\t\t\treturn options.geodataUrl + name.slice(8) + \".js\";\n\t\t}\n\t\tif (name.indexOf(\"fonts/\") === 0) {\n\t\t\treturn options.fontsUrl + name.slice(6) + \".js\";\n\t\t}\n\t\treturn options.libraryUrl + name + \".js\";\n\t}\n\n\t// Downloaded side by side, run in order\n\tfunction load(src) {\n\t\tif (!scripts[src]) {\n\t\t\tscripts[src] = new Promise(function (resolve, reject) {\n\t\t\t\tvar script = document.createElement(\"script\");\n\t\t\t\tscript.src = src;\n\t\t\t\tscript.async = false;\n\t\t\t\tscript.onload = function () {\n\t\t\t\t\tresolve();\n\t\t\t\t};\n\t\t\t\tscript.onerror = function () {\n\t\t\t\t\tdelete scripts[src];\n\t\t\t\t\treject(new Error(\"Could not load \" + src));\n\t\t\t\t};\n\t\t\t\tdocument.head.appendChild(script);\n\t\t\t});\n\t\t}\n\t\treturn scripts[src];\n\t}\n\n\tfunction dispose() {\n\t\tif (root) {\n\t\t\troot.dispose();\n\t\t}\n\t\troot = undefined;\n\t\tchart = undefined;\n\t\tresult = undefined;\n\t\tupdate = undefined;\n\t}\n\n\tfunction build(next) {\n\t\tvar id = ++current;\n\t\toptions = next;\n\t\tdispose();\n\n\t\tvar list = [];\n\t\tif (next.config !== undefined) {\n\t\t\tadd(list, \"plugins/json\");\n\t\t\taddConfig(list, next.config);\n\t\t}\n\t\telse {\n\t\t\taddCode(list, next.code || \"\");\n\t\t}\n\t\tnext.themes.forEach(function (theme) {\n\t\t\tadd(list, \"themes/\" + themeName(theme));\n\t\t});\n\t\tnext.modules.forEach(function (name) {\n\t\t\tadd(list, name);\n\t\t});\n\n\t\treturn Promise.all([\"index\"].concat(list).map(function (name) {\n\t\t\treturn load(url(name));\n\t\t})).then(function () {\n\t\t\tif (id !== current) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tvar am5 = window.am5;\n\t\t\tvar settings = {};\n\t\t\tif (next.renderer === \"svg\") {\n\t\t\t\tif (!am5.SVGRenderer) {\n\t\t\t\t\tthrow new Error(\"renderer=\\\"svg\\\" needs amCharts 5.21.0 or later\");\n\t\t\t\t}\n\t\t\t\tsettings.renderer = am5.SVGRenderer;\n\t\t\t}\n\n\t\t\tvar themes = next.themes.map(function (entry) {\n\t\t\t\tvar name = themeName(entry);\n\t\t\t\tvar theme = window[\"am5themes_\" + name];\n\t\t\t\tif (!theme) {\n\t\t\t\t\tthrow new Error(\"No theme \" + name);\n\t\t\t\t}\n\t\t\t\treturn { theme: theme, settings: Array.isArray(entry) ? entry[1] : undefined };\n\t\t\t});\n\n\t\t\t// Before the root: it decides on the logo when it is made\n\t\t\t(next.licenses || []).forEach(function (license) {\n\t\t\t\tif (am5.registry.licenses.indexOf(license) === -1) {\n\t\t\t\t\tam5.addLicense(license);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\troot = am5.Root.new(\"chart\", settings);\n\t\t\troot.setThemes(themes.map(function (entry) {\n\t\t\t\treturn entry.settings ? entry.theme.new(root, entry.settings) : entry.theme.new(root);\n\t\t\t}));\n\n\t\t\tif (next.config !== undefined) {\n\t\t\t\treturn window.am5plugins_json.JsonParser.new(root).parse(next.config, { parent: root.container }).then(function (parsed) {\n\t\t\t\t\tif (id === current) {\n\t\t\t\t\t\tchart = parsed;\n\t\t\t\t\t\tsend({ type: \"ready\" });\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// A promise it returns is waited for\n\t\t\treturn Promise.resolve(compile([\"root\", \"data\", \"post\"], next.code || \"\")(root, next.data, post)).then(function (value) {\n\t\t\t\tif (id === current) {\n\t\t\t\t\tresult = value;\n\t\t\t\t\tif (typeof value === \"function\") {\n\t\t\t\t\t\tupdate = value;\n\t\t\t\t\t}\n\t\t\t\t\tsend({ type: \"ready\" });\n\t\t\t\t}\n\t\t\t});\n\n\t\t}).catch(function (error) {\n\t\t\tif (id === current) {\n\t\t\t\tdispose();\n\t\t\t\tfail(error);\n\t\t\t}\n\t\t});\n\t}\n\n\twindow.amChartPage = {\n\t\tbuild: build,\n\n\t\t// New data: to the function the code returned, or the chart is made\n\t\t// again. A config chart only keeps it, for run()\n\t\tdata: function (data) {\n\t\t\tif (!options) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\toptions.data = data;\n\t\t\tif (options.config !== undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (update) {\n\t\t\t\ttry {\n\t\t\t\t\tupdate(data);\n\t\t\t\t}\n\t\t\t\tcatch (error) {\n\t\t\t\t\tfail(error);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tbuild(options);\n\t\t\t}\n\t\t},\n\n\t\trun: function (code) {\n\t\t\ttry {\n\t\t\t\tcompile([\"root\", \"chart\", \"result\", \"data\", \"post\"], code)(root, chart, result, options ? options.data : undefined, post);\n\t\t\t}\n\t\t\tcatch (error) {\n\t\t\t\tfail(error);\n\t\t\t}\n\t\t}\n\t};\n\n\tsend({ type: \"loaded\" });\n})();\n</script>\n</body>\n</html>\n";
|
|
7
|
+
//# sourceMappingURL=generated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated.js","sourceRoot":"","sources":["../src/generated.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AACrB,QAAA,cAAc,GAAW,QAAQ,CAAC;AAClC,QAAA,QAAQ,GAAW,yycAAyyc,CAAC","sourcesContent":["// Written by scripts/generate.cjs\nexport const libraryVersion: string = \"5.21.4\";\nexport const pageHtml: string = \"<!DOCTYPE html>\\n<html>\\n<head>\\n<meta charset=\\\"utf-8\\\">\\n<meta name=\\\"viewport\\\" content=\\\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\\\">\\n<style>\\nhtml, body, #chart {\\n\\tmargin: 0;\\n\\tpadding: 0;\\n\\twidth: 100%;\\n\\theight: 100%;\\n\\toverflow: hidden;\\n\\tbackground: transparent;\\n}\\nbody {\\n\\t-webkit-tap-highlight-color: transparent;\\n\\t-webkit-touch-callout: none;\\n\\t-webkit-user-select: none;\\n\\tuser-select: none;\\n}\\n</style>\\n</head>\\n<body>\\n<div id=\\\"chart\\\"></div>\\n<script>\\n(function () {\\n\\t\\\"use strict\\\";\\n\\n\\t// Which script file has each class, and which files a file needs first\\n\\tvar classModules = {\\\"AccelerationBands\\\":\\\"stock\\\",\\\"AccumulationDistribution\\\":\\\"stock\\\",\\\"AccumulativeSwingIndex\\\":\\\"stock\\\",\\\"Annotator\\\":\\\"plugins/exporting\\\",\\\"ArcDiagram\\\":\\\"flow\\\",\\\"ArcDiagramLink\\\":\\\"flow\\\",\\\"ArcDiagramNodes\\\":\\\"flow\\\",\\\"Aroon\\\":\\\"stock\\\",\\\"AverageSeries\\\":\\\"stock\\\",\\\"AverageTrueRange\\\":\\\"stock\\\",\\\"AwesomeOscillator\\\":\\\"stock\\\",\\\"Axis\\\":\\\"xy\\\",\\\"AxisBullet\\\":\\\"xy\\\",\\\"AxisLabel\\\":\\\"xy\\\",\\\"AxisLabelRadial\\\":\\\"xy\\\",\\\"AxisRenderer\\\":\\\"xy\\\",\\\"AxisRendererCircular\\\":\\\"radar\\\",\\\"AxisRendererCurveX\\\":\\\"timeline\\\",\\\"AxisRendererCurveY\\\":\\\"timeline\\\",\\\"AxisRendererRadial\\\":\\\"radar\\\",\\\"AxisRendererX\\\":\\\"xy\\\",\\\"AxisRendererY\\\":\\\"xy\\\",\\\"AxisTick\\\":\\\"xy\\\",\\\"BaseColumnSeries\\\":\\\"xy\\\",\\\"BollingerBands\\\":\\\"stock\\\",\\\"BreadcrumbBar\\\":\\\"hierarchy\\\",\\\"BullBearPower\\\":\\\"stock\\\",\\\"CalloutSeries\\\":\\\"stock\\\",\\\"Candlestick\\\":\\\"xy\\\",\\\"CandlestickSeries\\\":\\\"xy\\\",\\\"CategoryAxis\\\":\\\"xy\\\",\\\"CategoryDateAxis\\\":\\\"xy\\\",\\\"ChaikinMoneyFlow\\\":\\\"stock\\\",\\\"ChaikinOscillator\\\":\\\"stock\\\",\\\"ChartIndicator\\\":\\\"stock\\\",\\\"ChartSerializer\\\":\\\"plugins/json\\\",\\\"Chord\\\":\\\"flow\\\",\\\"ChordDirected\\\":\\\"flow\\\",\\\"ChordLink\\\":\\\"flow\\\",\\\"ChordLinkDirected\\\":\\\"flow\\\",\\\"ChordNodes\\\":\\\"flow\\\",\\\"ChordNonRibbon\\\":\\\"flow\\\",\\\"ClockHand\\\":\\\"radar\\\",\\\"ClusteredPointSeries\\\":\\\"map\\\",\\\"ColorControl\\\":\\\"stock\\\",\\\"ColorPicker\\\":\\\"plugins/colorPicker\\\",\\\"ColorPickerButton\\\":\\\"plugins/colorPicker\\\",\\\"ColumnSeries\\\":\\\"xy\\\",\\\"CommodityChannelIndex\\\":\\\"stock\\\",\\\"ComparisonControl\\\":\\\"stock\\\",\\\"CurveChart\\\":\\\"timeline\\\",\\\"CurveColumnSeries\\\":\\\"timeline\\\",\\\"CurveCursor\\\":\\\"timeline\\\",\\\"CurveLineSeries\\\":\\\"timeline\\\",\\\"DataSaveControl\\\":\\\"stock\\\",\\\"DateAxis\\\":\\\"xy\\\",\\\"DateRangeSelector\\\":\\\"stock\\\",\\\"DisparityIndex\\\":\\\"stock\\\",\\\"DoodleSeries\\\":\\\"stock\\\",\\\"DrawingControl\\\":\\\"stock\\\",\\\"DrawingSeries\\\":\\\"stock\\\",\\\"DrawingToolControl\\\":\\\"stock\\\",\\\"Dropdown\\\":\\\"stock\\\",\\\"DropdownColors\\\":\\\"stock\\\",\\\"DropdownControl\\\":\\\"stock\\\",\\\"DropdownList\\\":\\\"stock\\\",\\\"DropdownListControl\\\":\\\"stock\\\",\\\"DurationAxis\\\":\\\"xy\\\",\\\"EditableAxisLabel\\\":\\\"xy\\\",\\\"EllipseSeries\\\":\\\"stock\\\",\\\"Exporting\\\":\\\"plugins/exporting\\\",\\\"ExportingMenu\\\":\\\"plugins/exporting\\\",\\\"FibonacciSeries\\\":\\\"stock\\\",\\\"FibonacciTimezoneSeries\\\":\\\"stock\\\",\\\"Flow\\\":\\\"flow\\\",\\\"FlowLink\\\":\\\"flow\\\",\\\"FlowNode\\\":\\\"flow\\\",\\\"FlowNodes\\\":\\\"flow\\\",\\\"ForceDirected\\\":\\\"hierarchy\\\",\\\"FunnelSeries\\\":\\\"percent\\\",\\\"FunnelSlice\\\":\\\"percent\\\",\\\"Gantt\\\":\\\"gantt\\\",\\\"GanttCategoryAxis\\\":\\\"gantt\\\",\\\"GanttCategoryAxisRenderer\\\":\\\"gantt\\\",\\\"GanttDateAxis\\\":\\\"gantt\\\",\\\"GanttDateAxisRenderer\\\":\\\"gantt\\\",\\\"GanttSeries\\\":\\\"gantt\\\",\\\"GaplessDateAxis\\\":\\\"xy\\\",\\\"GraticuleSeries\\\":\\\"map\\\",\\\"Grid\\\":\\\"xy\\\",\\\"HeikinAshi\\\":\\\"stock\\\",\\\"Hierarchy\\\":\\\"hierarchy\\\",\\\"HierarchyLink\\\":\\\"hierarchy\\\",\\\"HierarchyNode\\\":\\\"hierarchy\\\",\\\"HorizontalLineSeries\\\":\\\"stock\\\",\\\"HorizontalRaySeries\\\":\\\"stock\\\",\\\"IconControl\\\":\\\"stock\\\",\\\"IconSeries\\\":\\\"stock\\\",\\\"Indicator\\\":\\\"stock\\\",\\\"IndicatorControl\\\":\\\"stock\\\",\\\"IntervalControl\\\":\\\"stock\\\",\\\"LabelSeries\\\":\\\"stock\\\",\\\"LineArrowSeries\\\":\\\"stock\\\",\\\"LineSeries\\\":\\\"xy\\\",\\\"LinkedHierarchy\\\":\\\"hierarchy\\\",\\\"LinkedHierarchyNode\\\":\\\"hierarchy\\\",\\\"MACD\\\":\\\"stock\\\",\\\"MACross\\\":\\\"stock\\\",\\\"MapChart\\\":\\\"map\\\",\\\"MapLine\\\":\\\"map\\\",\\\"MapLineSeries\\\":\\\"map\\\",\\\"MapPointSeries\\\":\\\"map\\\",\\\"MapPolygon\\\":\\\"map\\\",\\\"MapPolygonSeries\\\":\\\"map\\\",\\\"MapRasterSeries\\\":\\\"map\\\",\\\"MapSankeyNodes\\\":\\\"map\\\",\\\"MapSankeySeries\\\":\\\"map\\\",\\\"MapSeries\\\":\\\"map\\\",\\\"Measure\\\":\\\"stock\\\",\\\"MedianPrice\\\":\\\"stock\\\",\\\"Momentum\\\":\\\"stock\\\",\\\"MovingAverage\\\":\\\"stock\\\",\\\"MovingAverageDeviation\\\":\\\"stock\\\",\\\"MovingAverageEnvelope\\\":\\\"stock\\\",\\\"NightSeries\\\":\\\"map\\\",\\\"OHLC\\\":\\\"xy\\\",\\\"OHLCSeries\\\":\\\"xy\\\",\\\"OnBalanceVolume\\\":\\\"stock\\\",\\\"OverboughtOversold\\\":\\\"stock\\\",\\\"PVT\\\":\\\"stock\\\",\\\"Pack\\\":\\\"hierarchy\\\",\\\"PanelControls\\\":\\\"stock\\\",\\\"ParallelChannelSeries\\\":\\\"stock\\\",\\\"Partition\\\":\\\"hierarchy\\\",\\\"PercentChart\\\":\\\"percent\\\",\\\"PercentSeries\\\":\\\"percent\\\",\\\"PeriodSelector\\\":\\\"stock\\\",\\\"PictorialStackedSeries\\\":\\\"percent\\\",\\\"PieChart\\\":\\\"percent\\\",\\\"PieSeries\\\":\\\"percent\\\",\\\"PixelMapSeries\\\":\\\"map\\\",\\\"PolylineSeries\\\":\\\"stock\\\",\\\"PyramidSeries\\\":\\\"percent\\\",\\\"QuadrantLineSeries\\\":\\\"stock\\\",\\\"RadarChart\\\":\\\"radar\\\",\\\"RadarColumnSeries\\\":\\\"radar\\\",\\\"RadarCursor\\\":\\\"radar\\\",\\\"RadarLineSeries\\\":\\\"radar\\\",\\\"RectangleSeries\\\":\\\"stock\\\",\\\"RegressionSeries\\\":\\\"stock\\\",\\\"RelativeStrengthIndex\\\":\\\"stock\\\",\\\"ResetControl\\\":\\\"stock\\\",\\\"Sankey\\\":\\\"flow\\\",\\\"SankeyLink\\\":\\\"flow\\\",\\\"SankeyNodes\\\":\\\"flow\\\",\\\"Serializer\\\":\\\"plugins/json\\\",\\\"SeriesTypeControl\\\":\\\"stock\\\",\\\"SerpentineChart\\\":\\\"timeline\\\",\\\"SettingsControl\\\":\\\"stock\\\",\\\"SettingsModal\\\":\\\"stock\\\",\\\"SimpleLineSeries\\\":\\\"stock\\\",\\\"SliceGrouper\\\":\\\"plugins/sliceGrouper\\\",\\\"SlicedChart\\\":\\\"percent\\\",\\\"SmoothedRadarLineSeries\\\":\\\"radar\\\",\\\"SmoothedXLineSeries\\\":\\\"xy\\\",\\\"SmoothedXYLineSeries\\\":\\\"xy\\\",\\\"SmoothedYLineSeries\\\":\\\"xy\\\",\\\"SpiralChart\\\":\\\"timeline\\\",\\\"StandardDeviation\\\":\\\"stock\\\",\\\"StepLineSeries\\\":\\\"xy\\\",\\\"StochasticMomentumIndex\\\":\\\"stock\\\",\\\"StochasticOscillator\\\":\\\"stock\\\",\\\"StockChart\\\":\\\"stock\\\",\\\"StockControl\\\":\\\"stock\\\",\\\"StockLegend\\\":\\\"stock\\\",\\\"StockPanel\\\":\\\"stock\\\",\\\"StockToolbar\\\":\\\"stock\\\",\\\"Sunburst\\\":\\\"hierarchy\\\",\\\"SuperTrend\\\":\\\"stock\\\",\\\"Tree\\\":\\\"hierarchy\\\",\\\"Treemap\\\":\\\"hierarchy\\\",\\\"TrendLineSeries\\\":\\\"stock\\\",\\\"Trix\\\":\\\"stock\\\",\\\"TypicalPrice\\\":\\\"stock\\\",\\\"VWAP\\\":\\\"stock\\\",\\\"ValueAxis\\\":\\\"xy\\\",\\\"Venn\\\":\\\"venn\\\",\\\"VerticalLineSeries\\\":\\\"stock\\\",\\\"Volume\\\":\\\"stock\\\",\\\"VolumeProfile\\\":\\\"stock\\\",\\\"VoronoiTreemap\\\":\\\"hierarchy\\\",\\\"WilliamsR\\\":\\\"stock\\\",\\\"WordCloud\\\":\\\"wc\\\",\\\"XYChart\\\":\\\"xy\\\",\\\"XYChartScrollbar\\\":\\\"xy\\\",\\\"XYCursor\\\":\\\"xy\\\",\\\"XYSeries\\\":\\\"xy\\\",\\\"ZigZag\\\":\\\"stock\\\",\\\"ZoomControl\\\":\\\"map\\\"};\\n\\tvar scriptDependencies = {\\\"pie\\\":[\\\"percent\\\"],\\\"funnel\\\":[\\\"percent\\\"],\\\"radar\\\":[\\\"xy\\\"],\\\"gantt\\\":[\\\"xy\\\",\\\"plugins/colorPicker\\\"],\\\"stock\\\":[\\\"xy\\\"],\\\"timeline\\\":[\\\"xy\\\"],\\\"element\\\":[\\\"index\\\",\\\"plugins/json\\\"]};\\n\\tvar modules = {};\\n\\tObject.keys(classModules).forEach(function (name) {\\n\\t\\tmodules[classModules[name]] = true;\\n\\t});\\n\\n\\tvar current = 0;\\n\\tvar options;\\n\\tvar root;\\n\\tvar chart;\\n\\tvar result;\\n\\tvar update;\\n\\tvar scripts = {};\\n\\n\\tfunction send(message) {\\n\\t\\tvar text;\\n\\t\\ttry {\\n\\t\\t\\ttext = JSON.stringify(message);\\n\\t\\t} catch (error) {\\n\\t\\t\\ttext = JSON.stringify({ type: \\\"error\\\", message: \\\"Could not send \\\" + message.name + \\\": \\\" + error.message });\\n\\t\\t}\\n\\t\\twindow.ReactNativeWebView.postMessage(text);\\n\\t}\\n\\n\\tfunction post(name, value) {\\n\\t\\tsend({ type: \\\"message\\\", name: String(name), value: value });\\n\\t}\\n\\n\\tfunction fail(error) {\\n\\t\\tsend({ type: \\\"error\\\", message: String(error && error.message ? error.message : error) });\\n\\t}\\n\\n\\twindow.addEventListener(\\\"error\\\", function (event) {\\n\\t\\tfail(event.error || event.message);\\n\\t});\\n\\n\\twindow.addEventListener(\\\"unhandledrejection\\\", function (event) {\\n\\t\\tfail(event.reason);\\n\\t});\\n\\n\\t// A geodata global's file: am5geodata_region_world_europeLow > geodata/region/world/europeLow\\n\\tfunction geodataModule(name) {\\n\\t\\treturn \\\"geodata/\\\" + (/^lang_/.test(name) ? \\\"lang/\\\" + name.slice(5) : name.replace(/_/g, \\\"/\\\"));\\n\\t}\\n\\n\\t// A global's file: am5xy > xy, am5plugins_exporting > plugins/exporting,\\n\\t// am5fonts_notosans_sc > fonts/notosans-sc\\n\\tfunction globalModule(name) {\\n\\t\\tvar rest = name.slice(3);\\n\\t\\tvar match = /^(themes|plugins|locales)_(.+)$/.exec(rest);\\n\\t\\tif (match) {\\n\\t\\t\\treturn match[1] + \\\"/\\\" + match[2];\\n\\t\\t}\\n\\t\\tif (/^fonts_./.test(rest)) {\\n\\t\\t\\treturn \\\"fonts/\\\" + rest.slice(6).replace(/_/g, \\\"-\\\");\\n\\t\\t}\\n\\t\\tif (/^geodata_./.test(rest)) {\\n\\t\\t\\treturn geodataModule(rest.slice(8));\\n\\t\\t}\\n\\t\\treturn modules[rest] ? rest : undefined;\\n\\t}\\n\\n\\t// A theme is a name, or [name, settings]\\n\\tfunction themeName(theme) {\\n\\t\\treturn Array.isArray(theme) ? theme[0] : theme;\\n\\t}\\n\\n\\tfunction add(list, name) {\\n\\t\\tif (!name || name === \\\"index\\\" || list.indexOf(name) !== -1) {\\n\\t\\t\\treturn;\\n\\t\\t}\\n\\t\\t(scriptDependencies[name] || []).forEach(function (dependency) {\\n\\t\\t\\tadd(list, dependency);\\n\\t\\t});\\n\\t\\tlist.push(name);\\n\\t}\\n\\n\\t// The files a config needs: its classes, and geodata named by its global\\n\\tfunction addConfig(list, value) {\\n\\t\\tif (typeof value === \\\"string\\\") {\\n\\t\\t\\tif (/^am5geodata_[A-Za-z0-9_]+$/.test(value)) {\\n\\t\\t\\t\\tadd(list, geodataModule(value.slice(11)));\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\telse if (Array.isArray(value)) {\\n\\t\\t\\tvalue.forEach(function (item) {\\n\\t\\t\\t\\taddConfig(list, item);\\n\\t\\t\\t});\\n\\t\\t}\\n\\t\\telse if (value && typeof value === \\\"object\\\") {\\n\\t\\t\\tif (typeof value.type === \\\"string\\\") {\\n\\t\\t\\t\\tadd(list, classModules[value.type]);\\n\\t\\t\\t}\\n\\t\\t\\tObject.keys(value).forEach(function (key) {\\n\\t\\t\\t\\taddConfig(list, value[key]);\\n\\t\\t\\t});\\n\\t\\t}\\n\\t}\\n\\n\\t// The files code needs, from the globals it uses, and the classes of a\\n\\t// config it gives the JSON parser\\n\\tfunction addCode(list, code) {\\n\\t\\t(code.match(/\\\\bam5[A-Za-z0-9_]*/g) || []).forEach(function (name) {\\n\\t\\t\\tadd(list, globalModule(name));\\n\\t\\t});\\n\\t\\tif (code.indexOf(\\\"am5plugins_json\\\") !== -1) {\\n\\t\\t\\t(code.match(/\\\\btype[\\\"']?\\\\s*:\\\\s*[\\\"'][A-Za-z0-9_]+[\\\"']/g) || []).forEach(function (match) {\\n\\t\\t\\t\\tadd(list, classModules[/[\\\"']([A-Za-z0-9_]+)[\\\"']$/.exec(match)[1]]);\\n\\t\\t\\t});\\n\\t\\t}\\n\\t}\\n\\n\\t// Its own scope, so that it may declare `data` or `root` itself\\n\\tfunction compile(names, code) {\\n\\t\\treturn new Function(names.join(\\\",\\\"), \\\"return (function () {\\\\n\\\" + code + \\\"\\\\n})();\\\");\\n\\t}\\n\\n\\tfunction url(name) {\\n\\t\\tif (/^[a-z]+:/i.test(name)) {\\n\\t\\t\\treturn name;\\n\\t\\t}\\n\\t\\tif (name.indexOf(\\\"geodata/\\\") === 0) {\\n\\t\\t\\treturn options.geodataUrl + name.slice(8) + \\\".js\\\";\\n\\t\\t}\\n\\t\\tif (name.indexOf(\\\"fonts/\\\") === 0) {\\n\\t\\t\\treturn options.fontsUrl + name.slice(6) + \\\".js\\\";\\n\\t\\t}\\n\\t\\treturn options.libraryUrl + name + \\\".js\\\";\\n\\t}\\n\\n\\t// Downloaded side by side, run in order\\n\\tfunction load(src) {\\n\\t\\tif (!scripts[src]) {\\n\\t\\t\\tscripts[src] = new Promise(function (resolve, reject) {\\n\\t\\t\\t\\tvar script = document.createElement(\\\"script\\\");\\n\\t\\t\\t\\tscript.src = src;\\n\\t\\t\\t\\tscript.async = false;\\n\\t\\t\\t\\tscript.onload = function () {\\n\\t\\t\\t\\t\\tresolve();\\n\\t\\t\\t\\t};\\n\\t\\t\\t\\tscript.onerror = function () {\\n\\t\\t\\t\\t\\tdelete scripts[src];\\n\\t\\t\\t\\t\\treject(new Error(\\\"Could not load \\\" + src));\\n\\t\\t\\t\\t};\\n\\t\\t\\t\\tdocument.head.appendChild(script);\\n\\t\\t\\t});\\n\\t\\t}\\n\\t\\treturn scripts[src];\\n\\t}\\n\\n\\tfunction dispose() {\\n\\t\\tif (root) {\\n\\t\\t\\troot.dispose();\\n\\t\\t}\\n\\t\\troot = undefined;\\n\\t\\tchart = undefined;\\n\\t\\tresult = undefined;\\n\\t\\tupdate = undefined;\\n\\t}\\n\\n\\tfunction build(next) {\\n\\t\\tvar id = ++current;\\n\\t\\toptions = next;\\n\\t\\tdispose();\\n\\n\\t\\tvar list = [];\\n\\t\\tif (next.config !== undefined) {\\n\\t\\t\\tadd(list, \\\"plugins/json\\\");\\n\\t\\t\\taddConfig(list, next.config);\\n\\t\\t}\\n\\t\\telse {\\n\\t\\t\\taddCode(list, next.code || \\\"\\\");\\n\\t\\t}\\n\\t\\tnext.themes.forEach(function (theme) {\\n\\t\\t\\tadd(list, \\\"themes/\\\" + themeName(theme));\\n\\t\\t});\\n\\t\\tnext.modules.forEach(function (name) {\\n\\t\\t\\tadd(list, name);\\n\\t\\t});\\n\\n\\t\\treturn Promise.all([\\\"index\\\"].concat(list).map(function (name) {\\n\\t\\t\\treturn load(url(name));\\n\\t\\t})).then(function () {\\n\\t\\t\\tif (id !== current) {\\n\\t\\t\\t\\treturn;\\n\\t\\t\\t}\\n\\n\\t\\t\\tvar am5 = window.am5;\\n\\t\\t\\tvar settings = {};\\n\\t\\t\\tif (next.renderer === \\\"svg\\\") {\\n\\t\\t\\t\\tif (!am5.SVGRenderer) {\\n\\t\\t\\t\\t\\tthrow new Error(\\\"renderer=\\\\\\\"svg\\\\\\\" needs amCharts 5.21.0 or later\\\");\\n\\t\\t\\t\\t}\\n\\t\\t\\t\\tsettings.renderer = am5.SVGRenderer;\\n\\t\\t\\t}\\n\\n\\t\\t\\tvar themes = next.themes.map(function (entry) {\\n\\t\\t\\t\\tvar name = themeName(entry);\\n\\t\\t\\t\\tvar theme = window[\\\"am5themes_\\\" + name];\\n\\t\\t\\t\\tif (!theme) {\\n\\t\\t\\t\\t\\tthrow new Error(\\\"No theme \\\" + name);\\n\\t\\t\\t\\t}\\n\\t\\t\\t\\treturn { theme: theme, settings: Array.isArray(entry) ? entry[1] : undefined };\\n\\t\\t\\t});\\n\\n\\t\\t\\t// Before the root: it decides on the logo when it is made\\n\\t\\t\\t(next.licenses || []).forEach(function (license) {\\n\\t\\t\\t\\tif (am5.registry.licenses.indexOf(license) === -1) {\\n\\t\\t\\t\\t\\tam5.addLicense(license);\\n\\t\\t\\t\\t}\\n\\t\\t\\t});\\n\\n\\t\\t\\troot = am5.Root.new(\\\"chart\\\", settings);\\n\\t\\t\\troot.setThemes(themes.map(function (entry) {\\n\\t\\t\\t\\treturn entry.settings ? entry.theme.new(root, entry.settings) : entry.theme.new(root);\\n\\t\\t\\t}));\\n\\n\\t\\t\\tif (next.config !== undefined) {\\n\\t\\t\\t\\treturn window.am5plugins_json.JsonParser.new(root).parse(next.config, { parent: root.container }).then(function (parsed) {\\n\\t\\t\\t\\t\\tif (id === current) {\\n\\t\\t\\t\\t\\t\\tchart = parsed;\\n\\t\\t\\t\\t\\t\\tsend({ type: \\\"ready\\\" });\\n\\t\\t\\t\\t\\t}\\n\\t\\t\\t\\t});\\n\\t\\t\\t}\\n\\n\\t\\t\\t// A promise it returns is waited for\\n\\t\\t\\treturn Promise.resolve(compile([\\\"root\\\", \\\"data\\\", \\\"post\\\"], next.code || \\\"\\\")(root, next.data, post)).then(function (value) {\\n\\t\\t\\t\\tif (id === current) {\\n\\t\\t\\t\\t\\tresult = value;\\n\\t\\t\\t\\t\\tif (typeof value === \\\"function\\\") {\\n\\t\\t\\t\\t\\t\\tupdate = value;\\n\\t\\t\\t\\t\\t}\\n\\t\\t\\t\\t\\tsend({ type: \\\"ready\\\" });\\n\\t\\t\\t\\t}\\n\\t\\t\\t});\\n\\n\\t\\t}).catch(function (error) {\\n\\t\\t\\tif (id === current) {\\n\\t\\t\\t\\tdispose();\\n\\t\\t\\t\\tfail(error);\\n\\t\\t\\t}\\n\\t\\t});\\n\\t}\\n\\n\\twindow.amChartPage = {\\n\\t\\tbuild: build,\\n\\n\\t\\t// New data: to the function the code returned, or the chart is made\\n\\t\\t// again. A config chart only keeps it, for run()\\n\\t\\tdata: function (data) {\\n\\t\\t\\tif (!options) {\\n\\t\\t\\t\\treturn;\\n\\t\\t\\t}\\n\\t\\t\\toptions.data = data;\\n\\t\\t\\tif (options.config !== undefined) {\\n\\t\\t\\t\\treturn;\\n\\t\\t\\t}\\n\\t\\t\\tif (update) {\\n\\t\\t\\t\\ttry {\\n\\t\\t\\t\\t\\tupdate(data);\\n\\t\\t\\t\\t}\\n\\t\\t\\t\\tcatch (error) {\\n\\t\\t\\t\\t\\tfail(error);\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t\\telse {\\n\\t\\t\\t\\tbuild(options);\\n\\t\\t\\t}\\n\\t\\t},\\n\\n\\t\\trun: function (code) {\\n\\t\\t\\ttry {\\n\\t\\t\\t\\tcompile([\\\"root\\\", \\\"chart\\\", \\\"result\\\", \\\"data\\\", \\\"post\\\"], code)(root, chart, result, options ? options.data : undefined, post);\\n\\t\\t\\t}\\n\\t\\t\\tcatch (error) {\\n\\t\\t\\t\\tfail(error);\\n\\t\\t\\t}\\n\\t\\t}\\n\\t};\\n\\n\\tsend({ type: \\\"loaded\\\" });\\n})();\\n</script>\\n</body>\\n</html>\\n\";\n"]}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmChart = void 0;
|
|
4
|
+
var AmChart_1 = require("./AmChart");
|
|
5
|
+
Object.defineProperty(exports, "AmChart", { enumerable: true, get: function () { return AmChart_1.AmChart; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAA3B,kGAAA,OAAO,OAAA","sourcesContent":["export { AmChart } from \"./AmChart\";\nexport type { AmChartProps, AmChartHandle } from \"./AmChart\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amcharts/amcharts5-react-native",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "5.0.1",
|
|
4
|
+
"libraryVersion": "5.21.4",
|
|
5
|
+
"description": "A React Native component for amCharts 5: charts from a JSON config or from chart code, drawn in a WebView",
|
|
6
|
+
"author": "amCharts <contact@amcharts.com> (https://www.amcharts.com/)",
|
|
7
|
+
"homepage": "https://github.com/amcharts/amcharts5/tree/master/integrations/react-native#readme",
|
|
8
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/amcharts/amcharts5/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/amcharts/amcharts5.git",
|
|
15
|
+
"directory": "integrations/react-native"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"amcharts",
|
|
19
|
+
"amcharts5",
|
|
20
|
+
"react-native",
|
|
21
|
+
"expo",
|
|
22
|
+
"charts",
|
|
23
|
+
"chart",
|
|
24
|
+
"data-visualization",
|
|
25
|
+
"maps"
|
|
26
|
+
],
|
|
27
|
+
"main": "dist/index.js",
|
|
28
|
+
"react-native": "dist/index.js",
|
|
29
|
+
"types": "dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md",
|
|
41
|
+
"CHANGELOG.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "node scripts/generate.cjs && tsc -p .",
|
|
46
|
+
"prepack": "npm run build && node -e \"require('fs').copyFileSync('../../packages/shared/LICENSE', 'LICENSE')\""
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=18",
|
|
50
|
+
"react-native": ">=0.72",
|
|
51
|
+
"react-native-webview": ">=13"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/react": "^19.3.0",
|
|
55
|
+
"react": "^19.3.0",
|
|
56
|
+
"react-native": "^0.87.1",
|
|
57
|
+
"react-native-webview": "^14.0.1",
|
|
58
|
+
"typescript": "^5.9.3"
|
|
59
|
+
}
|
|
60
|
+
}
|