tools.js
2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* @Description:
* @Date: 2021-07-02 10:57:34
*/
import { base } from '../chart-type/common';
const dealStr = (str, unit = '') => {
const length = unit.length;
if (`${str}`.slice(0 - length) === unit) {
return str;
} else {
return `${str}${unit}`;
}
};
export const dealAxis = (arr = [], unit = '', lastUnit = '') => {
return arr.map((item, index) => {
const isLast = index === arr.length - 1;
const xName = item.genderType || item.xTopicName || item.optionName;
return {
x: xName ? dealStr(xName, isLast ? lastUnit : unit) : '-',
y: item.yTopicName,
value: item.num || item.countNum || 0
};
});
};
export const dealLegends = (arr = [], unit = '', lastUnit = '') => {
const total = arr.reduce((pre, cur) => {
return pre + (cur.num || cur.countNum || 0);
}, 0);
return arr.reduce((pre, cur, index) => {
pre.push(
`${dealStr(
cur.genderType || cur.xTopicName,
index === arr.length - 1 ? lastUnit : unit
)}${cur.num || cur.countNum || 0}人,占比${base.numberFormat(
total ? (cur.num || cur.countNum || 0) / total : 0,
0.01
)}%`
);
return pre;
}, []);
};
export const randomType = (arr = []) => {
return arr[Math.ceil(Math.random() * arr.length)] || arr[0];
};
export const chartConfigToSetInfo = (chartConfigs, biInfoId) => {
return chartConfigs.map((item, index) => {
const { baseInfo, desc, analysisDesc, analysis, isDelete, chart } = item;
const { id, type } = baseInfo;
const { customText = '', setShow } = desc;
return {
biInfoId: biInfoId,
id: id,
groupDetailId: id,
topicDetailId: id,
fixedId: id,
type: type,
chartType: +chart.type,
customTitle: item.title.name,
customGroupTitle: item.title.customGroupTitle,
colourGroup: Array.isArray(chart.colors)
? chart.colors.join(',')
: chart.colors,
showSort: +index + 1,
isDelete: isDelete,
resultUser: customText,
znResultUser: analysisDesc.customText,
resultIsShow: setShow ? 1 : 0,
znResultIsShow: analysisDesc.setShow ? 1 : 0,
znTableIsShow: analysis.setShow ? 1 : 0
};
});
};