@fto-consult/expo-ui 1.1.39 → 1.1.40
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 +1 -1
- package/src/components/Chart/appexChart/index.html +29 -0
- package/src/components/Chart/appexChart/index.js +26 -0
- package/src/components/Chart/appexChart/index.native.js +62 -0
- package/src/components/Chart/index.js +64 -16
- package/src/components/Chart/utils.js +25 -0
- package/src/components/WebView/index.js +7 -1
- package/src/components/Chart/appexchart.3.5.html +0 -14
- package/src/components/Chart/index.native.js +0 -58
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import ApexChart from 'apexcharts/dist/apexcharts.common';
|
|
2
|
+
import React from "$react";
|
|
3
|
+
import View from "$components/View"
|
|
4
|
+
|
|
5
|
+
const AppexChartComponent = React.forwardRef(({chartContext,options,...props},ref)=>{
|
|
6
|
+
const chartRef = React.useRef(null);
|
|
7
|
+
React.useEffect(()=>{
|
|
8
|
+
chartContext.current = new ApexChart(chartRef.current,options)
|
|
9
|
+
chartContext.current.render();
|
|
10
|
+
return ()=>{
|
|
11
|
+
if (chartContext.current && typeof chartContext.current.destroy === 'function') {
|
|
12
|
+
setTimeout(()=>{
|
|
13
|
+
try {chartContext.current.destroy();} catch{}
|
|
14
|
+
},500);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},[]);
|
|
18
|
+
return <View
|
|
19
|
+
{...props}
|
|
20
|
+
ref = {React.mergeRefs(chartRef,ref)}
|
|
21
|
+
/>
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
AppexChartComponent.displayName = "AppexChartComponent";
|
|
25
|
+
|
|
26
|
+
export default AppexChartComponent;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const htmlTemplate = require("./index.html");
|
|
2
|
+
import React from "$react";
|
|
3
|
+
import WebView from "$ecomponents/WebView";
|
|
4
|
+
import {defaultStr,defaultObj,uniqid} from "$utils";
|
|
5
|
+
import View from "$ecomponents/View";
|
|
6
|
+
|
|
7
|
+
export const ChartComponent = React.forwardRef(({chartContext,testID,webViewProps,options,...props},ref)=>{
|
|
8
|
+
webViewProps = defaultObj(webViewProps);
|
|
9
|
+
const webViewRef = React.useRef(null);
|
|
10
|
+
const chartId = React.useRef(uniqid("chart-webview-id"));
|
|
11
|
+
const jsonOptions = JSON.stringify(options);
|
|
12
|
+
const exec = (method,a)=>{
|
|
13
|
+
if(!webViewRef.current) return;
|
|
14
|
+
webViewRef.current.injectJavaScript(`
|
|
15
|
+
const method = "${method}";
|
|
16
|
+
const chartId = "${chartId}";
|
|
17
|
+
const a = ${typeof a =='string'? '"'+a.replaceAll('"','\"')+'"':typeof a =='boolean'? a : a && typeof a =='object'? JSON.stringify(a):undefined};
|
|
18
|
+
let element = document.getElementById(chartId);
|
|
19
|
+
if(!element){
|
|
20
|
+
element = document.createElement("div");
|
|
21
|
+
document.body.appendChild(element);
|
|
22
|
+
}
|
|
23
|
+
element.id = chartId;
|
|
24
|
+
if(!window.chartInstance || typeof window.chartInstance!='object') {
|
|
25
|
+
window.chartInstance = new ApexChart(element,${jsonOptions});
|
|
26
|
+
}
|
|
27
|
+
if(!window.chartInstance || typeof chartInstance[method] !='function') return;
|
|
28
|
+
try {
|
|
29
|
+
chartInstance[method](a);
|
|
30
|
+
} catch{}
|
|
31
|
+
`);
|
|
32
|
+
};
|
|
33
|
+
testID = defaultStr(testID,"RN_AppexChartComponentNative");
|
|
34
|
+
chartContext.current = React.useRef({});
|
|
35
|
+
chartContext.current.exec = exec;
|
|
36
|
+
["updateOptions","updateSeries","destroy"].map((cb)=>{
|
|
37
|
+
chartContext.current[cb]=(a,b,c)=>{
|
|
38
|
+
return exec(cb,a,b,c);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return <View ref={ref} {...props} testID={testID} style={[{flex:1},props.style]}>
|
|
43
|
+
<WebView.Local
|
|
44
|
+
originWhitelist={["*"]}
|
|
45
|
+
testID = {testID+"_WebView"}
|
|
46
|
+
{...webViewProps}
|
|
47
|
+
file = {htmlTemplate}
|
|
48
|
+
ref = {webViewRef}
|
|
49
|
+
onLoadEnd={(event) => {
|
|
50
|
+
exec();
|
|
51
|
+
if(typeof webViewProps.onLoadEnd =='function'){
|
|
52
|
+
webViewProps.onLoadEnd({event,webViewRef,chartContext});
|
|
53
|
+
}
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
</WebView.Local>
|
|
57
|
+
</View>
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
ChartComponent.displayName = "ChartComponent.Native";
|
|
61
|
+
|
|
62
|
+
export default ChartComponent;
|
|
@@ -1,22 +1,70 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import React from '$react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import {defaultStr} from "$utils";
|
|
4
|
+
import {extend} from "./utils"
|
|
5
|
+
import stableHash from 'stable-hash';
|
|
6
|
+
import Chart from "./appexChart";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
/**** le composant Chart s'appuie sur le composant appexChart : https://apexcharts.com/
|
|
9
|
+
* les props requis duduit composant sont :
|
|
10
|
+
* type {string}, le type de chart
|
|
11
|
+
* series {array} - //les series appexchart
|
|
12
|
+
* width {number} - la largeur du chart
|
|
13
|
+
* height {number} - la longueur du chart
|
|
14
|
+
* options {number} - les options supplémentaires au chart
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
const ChartComponent = React.forwardRef(({type, height, width, series, options,testID,webViewProps, ...props },ref)=>{
|
|
18
|
+
const chartContext = React.useRef(null);
|
|
19
|
+
const config = extend(options,{
|
|
20
|
+
chart: {
|
|
21
|
+
type,
|
|
22
|
+
height,
|
|
23
|
+
width
|
|
24
|
+
},
|
|
25
|
+
series,
|
|
26
|
+
});
|
|
27
|
+
testID = defaultStr(testID,"RN_ChartComponent");
|
|
28
|
+
const prevWidth = React.usePrevious(width), prevHeight = React.usePrevious(height);
|
|
29
|
+
const prevOptions = React.usePrevious(options,stableHash);
|
|
30
|
+
const prevSeries = React.usePrevious(series,JSON.stringify);
|
|
31
|
+
React.useEffect(()=>{
|
|
32
|
+
if(chartContext.current && chartContext.current.updateOptions){
|
|
33
|
+
if((JSON.stringify(prevSeries) == JSON.stringify(series)) || width != prevWidth || height != prevHeight){
|
|
34
|
+
chartContext.current.updateOptions(config);
|
|
35
|
+
} else if(JSON.stringify(prevOptions) != JSON.stringify(options)){
|
|
36
|
+
chartContext.current.updateSeries(series);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},[stableHash({type,options,series,width,height})])
|
|
40
|
+
return <Chart {...props} options={config} chartContext={chartContext} testID={testID} ref={ref}/>
|
|
18
41
|
});
|
|
19
42
|
|
|
43
|
+
|
|
44
|
+
ChartComponent.propTypes = {
|
|
45
|
+
type: PropTypes.string.isRequired,
|
|
46
|
+
width: PropTypes.oneOfType([
|
|
47
|
+
PropTypes.string,
|
|
48
|
+
PropTypes.number,
|
|
49
|
+
]),
|
|
50
|
+
height: PropTypes.oneOfType([
|
|
51
|
+
PropTypes.string,
|
|
52
|
+
PropTypes.number,
|
|
53
|
+
]),
|
|
54
|
+
series: PropTypes.array.isRequired,
|
|
55
|
+
options: PropTypes.shape({
|
|
56
|
+
xaxis : PropTypes.object,
|
|
57
|
+
}).isRequired,
|
|
58
|
+
///lorsque le chart est rendu en environnement native, les props du webView
|
|
59
|
+
webViewProps : PropTypes.object,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ChartComponent.defaultProps = {
|
|
63
|
+
type: 'line',
|
|
64
|
+
width: '100%',
|
|
65
|
+
height: 'auto'
|
|
66
|
+
}
|
|
67
|
+
|
|
20
68
|
ChartComponent.displayName = "ChartComponent";
|
|
21
69
|
|
|
22
70
|
export default ChartComponent;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2022 @fto-consult/Boris Fouomene. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
import {isObj} from "$utils";
|
|
5
|
+
export function extend (target,source){
|
|
6
|
+
const output = Object.assign({}, target);
|
|
7
|
+
if (isObj(target) && isObj(source)) {
|
|
8
|
+
Object.keys(source).forEach((key) => {
|
|
9
|
+
if (isObj(source[key])) {
|
|
10
|
+
if (!(key in target)) {
|
|
11
|
+
Object.assign(output, {
|
|
12
|
+
[key]: source[key]
|
|
13
|
+
})
|
|
14
|
+
} else {
|
|
15
|
+
output[key] = this.extend(target[key], source[key])
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
Object.assign(output, {
|
|
19
|
+
[key]: source[key]
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
return output
|
|
25
|
+
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// Copyright 2022 @fto-consult/Boris Fouomene. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
|
|
1
5
|
import WebView from "./Component";
|
|
2
6
|
import {defaultStr} from "$utils";
|
|
3
7
|
import React from "$react";
|
|
@@ -7,7 +11,9 @@ import FileSystem from "$file-system";
|
|
|
7
11
|
|
|
8
12
|
const WebViewComponent = React.forwardRef(({children,source,style,testID,...props},ref)=>{
|
|
9
13
|
testID = defaultStr(testID,"RN_WebviewComponent");
|
|
10
|
-
return <WebView
|
|
14
|
+
return <WebView
|
|
15
|
+
ref={ref}
|
|
16
|
+
{...props}
|
|
11
17
|
testID = {testID}
|
|
12
18
|
style={[{backgroundColor:'transparent'},style]}
|
|
13
19
|
source = {defaultObj(source)}
|