@eohjsc/react-native-smart-city 0.3.63 → 0.3.64
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
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { memo, useCallback } from 'react';
|
|
2
|
-
import Svg, { Path, Text,
|
|
2
|
+
import Svg, { Path, Text, Circle } from 'react-native-svg';
|
|
3
3
|
import { View, StyleSheet } from 'react-native';
|
|
4
4
|
|
|
5
5
|
import {
|
|
@@ -28,6 +28,8 @@ const Anemometer = memo(
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const value = data.length ? data[0].value : 0;
|
|
31
|
+
const measure = data.length ? data[0].measure : 'm/s';
|
|
32
|
+
|
|
31
33
|
const radius = (size - strokeWidth) / 2;
|
|
32
34
|
const viewBox = `0 0 ${width} ${width}`;
|
|
33
35
|
const d = drawArc(center.x, center.y, radius, startAngle, endAngle);
|
|
@@ -35,8 +37,6 @@ const Anemometer = memo(
|
|
|
35
37
|
const strokeAngle = (endAngle - startAngle) / numberOfSection;
|
|
36
38
|
const strokeLength = (strokeAngle * circumference) / 360 - 1;
|
|
37
39
|
const strokeDasharrayBg = `${strokeLength} 1`;
|
|
38
|
-
const totalAngle = (3 * PI) / 2;
|
|
39
|
-
const alpha = (value * totalAngle) / maxValue;
|
|
40
40
|
const arc = circumference * 0.75;
|
|
41
41
|
const offset = arc - (value / maxValue) * arc;
|
|
42
42
|
|
|
@@ -116,7 +116,6 @@ const Anemometer = memo(
|
|
|
116
116
|
maxValue,
|
|
117
117
|
txtColor,
|
|
118
118
|
]);
|
|
119
|
-
const needleAngle = -21 + (alpha / PI) * 180;
|
|
120
119
|
|
|
121
120
|
return (
|
|
122
121
|
<View style={styles.standard}>
|
|
@@ -145,10 +144,11 @@ const Anemometer = memo(
|
|
|
145
144
|
/>
|
|
146
145
|
{textAngles()}
|
|
147
146
|
<Text
|
|
148
|
-
fill={Colors.
|
|
149
|
-
fontSize=
|
|
147
|
+
fill={Colors.Lime6}
|
|
148
|
+
fontSize={48}
|
|
149
|
+
fontWeight="bold"
|
|
150
150
|
x={width / 2}
|
|
151
|
-
y={width / 2 +
|
|
151
|
+
y={width / 2 + 16}
|
|
152
152
|
textAnchor="middle"
|
|
153
153
|
fontFamily={Fonts.Regular}
|
|
154
154
|
>
|
|
@@ -156,30 +156,14 @@ const Anemometer = memo(
|
|
|
156
156
|
</Text>
|
|
157
157
|
<Text
|
|
158
158
|
fill={Colors.Gray8}
|
|
159
|
-
fontSize=
|
|
159
|
+
fontSize={16}
|
|
160
160
|
x={width / 2}
|
|
161
|
-
y={width / 2 +
|
|
161
|
+
y={width / 2 + 64}
|
|
162
162
|
textAnchor="middle"
|
|
163
163
|
fontFamily={Fonts.Regular}
|
|
164
164
|
>
|
|
165
|
-
|
|
165
|
+
{measure}
|
|
166
166
|
</Text>
|
|
167
|
-
|
|
168
|
-
<G
|
|
169
|
-
x={width / 2 - 50}
|
|
170
|
-
y={width / 2 - 12}
|
|
171
|
-
rotation={needleAngle}
|
|
172
|
-
origin="50,10."
|
|
173
|
-
>
|
|
174
|
-
<Path
|
|
175
|
-
fillRule="evenodd"
|
|
176
|
-
clipRule="evenodd"
|
|
177
|
-
// eslint-disable-next-line max-len
|
|
178
|
-
d="M6.75518 30.5986L46.6732 5.59447C49.7242 3.68338 53.7596 4.87054 55.2897 8.12934C56.8321 11.4146 55.1275 15.3065 51.667 16.4005L6.75518 30.5986Z"
|
|
179
|
-
fill="#595959"
|
|
180
|
-
/>
|
|
181
|
-
<Circle cx={49.5} cy={10.5762} r={3.5} fill="white" />
|
|
182
|
-
</G>
|
|
183
167
|
</Svg>
|
|
184
168
|
</View>
|
|
185
169
|
);
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import renderer, { act } from 'react-test-renderer';
|
|
3
|
+
import MockAdapter from 'axios-mock-adapter';
|
|
4
|
+
|
|
3
5
|
import { DetailHistoryChart } from '../components/DetailHistoryChart';
|
|
4
6
|
import { SCProvider } from '../../../context';
|
|
5
7
|
import { mockSCStore } from '../../../context/mockStore';
|
|
6
8
|
import HistoryChart from '../../../commons/Device/HistoryChart';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
useState: jest.fn((init) => [init, mockSetState]),
|
|
13
|
-
};
|
|
14
|
-
});
|
|
9
|
+
import api from '../../../utils/Apis/axios';
|
|
10
|
+
import { API } from '../../../configs';
|
|
11
|
+
|
|
12
|
+
const mock = new MockAdapter(api.axiosInstance);
|
|
13
|
+
|
|
15
14
|
const wrapComponent = (item, sensor) => (
|
|
16
15
|
<SCProvider initState={mockSCStore({})}>
|
|
17
16
|
<DetailHistoryChart item={item} sensor={sensor} />
|
|
@@ -20,12 +19,28 @@ const wrapComponent = (item, sensor) => (
|
|
|
20
19
|
describe('Test DetailHistoryChart', () => {
|
|
21
20
|
let tree;
|
|
22
21
|
it('create DetailHistoryChart', async () => {
|
|
22
|
+
mock
|
|
23
|
+
.onGet(API.VALUE_CONSUME.DISPLAY_HISTORY())
|
|
24
|
+
.reply(200, [{ data: [1, 2, 3] }]);
|
|
23
25
|
const item = {
|
|
26
|
+
id: 10452,
|
|
27
|
+
order: 0,
|
|
28
|
+
template: 'history',
|
|
29
|
+
type: 'history',
|
|
24
30
|
configuration: {
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
type: 'horizontal_bar_chart',
|
|
32
|
+
date_format: 'DD.MM',
|
|
33
|
+
configs: [
|
|
34
|
+
{
|
|
35
|
+
id: 9848,
|
|
36
|
+
title: 'horizontal',
|
|
37
|
+
color: 'blue',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
27
40
|
},
|
|
41
|
+
is_configuration_ready: true,
|
|
28
42
|
};
|
|
43
|
+
|
|
29
44
|
const sensor = {
|
|
30
45
|
name: 'Sensor name',
|
|
31
46
|
is_managed_by_backend: false,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
3
3
|
import { StyleSheet } from 'react-native';
|
|
4
4
|
import HistoryChart from '../../../commons/Device/HistoryChart';
|
|
5
5
|
import { API } from '../../../configs';
|
|
@@ -7,20 +7,40 @@ import { axiosGet } from '../../../utils/Apis/axios';
|
|
|
7
7
|
|
|
8
8
|
export const DetailHistoryChart = ({ item = {}, sensor = {} }) => {
|
|
9
9
|
const { configuration = {} } = item;
|
|
10
|
-
const { configs = [] } = configuration;
|
|
11
|
-
const [
|
|
10
|
+
const { configs = [], type = '' } = configuration;
|
|
11
|
+
const [lineChartData, setLineChartData] = useState(configs);
|
|
12
|
+
const [horizontalChartData, setHorizontalChartData] = useState([]);
|
|
13
|
+
const [groupBy, setGroupBy] = useState('date');
|
|
12
14
|
const [startDate, setStartDate] = useState(
|
|
13
|
-
|
|
15
|
+
type === 'line_chart'
|
|
16
|
+
? moment().subtract(1, 'days').valueOf()
|
|
17
|
+
: moment().subtract(6, 'days')
|
|
14
18
|
);
|
|
15
|
-
const [endDate, setEndDate] = useState(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const [endDate, setEndDate] = useState(
|
|
20
|
+
type === 'line_chart' ? moment().valueOf() : moment()
|
|
21
|
+
);
|
|
22
|
+
const [chartConfig, setChartConfig] = useState({
|
|
23
|
+
unit: '',
|
|
24
|
+
});
|
|
25
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
26
|
+
|
|
27
|
+
const fetchData = useCallback(async () => {
|
|
28
|
+
let params = new URLSearchParams();
|
|
29
|
+
configs.map((config) => {
|
|
30
|
+
params.append('config', config.id);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (type !== 'line_chart') {
|
|
34
|
+
params.append('group_by', groupBy);
|
|
35
|
+
if (groupBy === 'date') {
|
|
36
|
+
params.append('date_from', moment(startDate).format('YYYY-MM-DD'));
|
|
37
|
+
params.append('date_to', moment(endDate).format('YYYY-MM-DD'));
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
22
40
|
params.append('date_from', startDate / 1000);
|
|
23
41
|
params.append('date_to', endDate / 1000);
|
|
42
|
+
}
|
|
43
|
+
if (type === 'line_chart') {
|
|
24
44
|
const { success, data } = await axiosGet(
|
|
25
45
|
API.DEVICE.DISPLAY_HISTORY(sensor.id),
|
|
26
46
|
{ params }
|
|
@@ -38,23 +58,53 @@ export const DetailHistoryChart = ({ item = {}, sensor = {} }) => {
|
|
|
38
58
|
};
|
|
39
59
|
return { ...config, data: dataChart.data };
|
|
40
60
|
});
|
|
41
|
-
|
|
61
|
+
setLineChartData(formatData);
|
|
62
|
+
setIsLoading(true);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (type === 'horizontal_bar_chart') {
|
|
66
|
+
const { success, data } = await axiosGet(
|
|
67
|
+
API.VALUE_CONSUME.DISPLAY_HISTORY(),
|
|
68
|
+
{
|
|
69
|
+
params,
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
if (success) {
|
|
73
|
+
setHorizontalChartData(data);
|
|
74
|
+
if (data[0]?.data) {
|
|
75
|
+
setIsLoading(true);
|
|
76
|
+
}
|
|
42
77
|
}
|
|
43
|
-
}
|
|
78
|
+
}
|
|
79
|
+
}, [configs, endDate, groupBy, sensor.id, startDate, type]);
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
44
82
|
fetchData();
|
|
45
|
-
}, [
|
|
46
|
-
|
|
83
|
+
}, [fetchData]);
|
|
84
|
+
|
|
85
|
+
if (!lineChartData?.length) {
|
|
47
86
|
return false;
|
|
48
87
|
}
|
|
49
88
|
|
|
50
89
|
return (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
90
|
+
<>
|
|
91
|
+
{isLoading && (
|
|
92
|
+
<HistoryChart
|
|
93
|
+
configuration={item.configuration}
|
|
94
|
+
datas={type === 'line_chart' ? lineChartData : horizontalChartData}
|
|
95
|
+
setStartDate={setStartDate}
|
|
96
|
+
startDate={startDate}
|
|
97
|
+
setEndDate={setEndDate}
|
|
98
|
+
endDate={endDate}
|
|
99
|
+
groupBy={groupBy}
|
|
100
|
+
setGroupBy={setGroupBy}
|
|
101
|
+
chartConfig={chartConfig}
|
|
102
|
+
setChartConfig={setChartConfig}
|
|
103
|
+
formatType={type !== 'line_chart' && 'date'}
|
|
104
|
+
style={styles.chartStyle}
|
|
105
|
+
/>
|
|
106
|
+
)}
|
|
107
|
+
</>
|
|
58
108
|
);
|
|
59
109
|
};
|
|
60
110
|
|