@cgeui/utils 0.0.2 → 0.0.3
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/dist/esm/charts/Chart/utils/complementData.js +714 -0
- package/dist/esm/charts/Chart/utils/convertToEchartsConfig/chartsToEchartsConfig.js +99 -0
- package/dist/esm/charts/Chart/utils/convertToEchartsConfig/index.js +2 -0
- package/dist/esm/charts/Chart/utils/convertToEchartsConfig/pieChartToEchartsConfig.js +140 -0
- package/dist/esm/charts/Chart/utils/getOption.js +365 -0
- package/dist/esm/charts/Chart/utils/handleChartConfig.js +279 -0
- package/dist/esm/charts/Chart/utils/index.js +5 -0
- package/dist/esm/charts/Chart/utils/preConfig/index.js +307 -0
- package/dist/esm/charts/Chart/utils/preConfig/type.js +1 -0
- package/dist/esm/charts/PieChart/interface.js +1 -0
- package/dist/esm/charts/PieChart/locales/en-US.js +9 -0
- package/dist/esm/charts/PieChart/locales/index.js +7 -0
- package/dist/esm/charts/PieChart/locales/zh-CN.js +9 -0
- package/dist/esm/charts/PieChart/util.js +434 -0
- package/dist/esm/charts/SuperChart/config/bar.js +39 -0
- package/dist/esm/charts/SuperChart/config/index.js +237 -0
- package/dist/esm/charts/SuperChart/configStyle/color.js +23 -0
- package/dist/esm/charts/SuperChart/configStyle/dataZoom.js +13 -0
- package/dist/esm/charts/SuperChart/configStyle/grid.js +20 -0
- package/dist/esm/charts/SuperChart/configStyle/index.js +10 -0
- package/dist/esm/charts/SuperChart/configStyle/legend.js +68 -0
- package/dist/esm/charts/SuperChart/configStyle/lineStyle.js +80 -0
- package/dist/esm/charts/SuperChart/configStyle/title.js +16 -0
- package/dist/esm/charts/SuperChart/configStyle/tooltip.js +38 -0
- package/dist/esm/charts/SuperChart/configStyle/visualMap.js +18 -0
- package/dist/esm/charts/SuperChart/configStyle/xAxis.js +19 -0
- package/dist/esm/charts/SuperChart/configStyle/yAxis.js +56 -0
- package/dist/esm/charts/SuperChart/interface.js +1 -0
- package/dist/esm/charts/chartTheme/colorUtil.js +22 -0
- package/dist/esm/charts/chartTheme/darkChart.js +508 -0
- package/dist/esm/charts/chartTheme/defaultChart.js +492 -0
- package/dist/esm/charts/chartTheme/index.js +4 -0
- package/dist/esm/charts/chartTheme/themeColor.js +168 -0
- package/dist/esm/charts/index.js +5 -0
- package/dist/esm/charts/utils/charts/hex2Rgb.js +32 -0
- package/dist/esm/charts/utils/constants/env.js +6 -0
- package/dist/esm/charts/utils/constants/helper.js +5 -0
- package/dist/esm/charts/utils/constants/index.js +3 -0
- package/dist/esm/charts/utils/constants/table.js +17 -0
- package/dist/esm/charts/utils/data.js +450 -0
- package/dist/esm/charts/utils/index.js +5 -0
- package/dist/esm/charts/utils/locale.js +7 -0
- package/dist/esm/charts/utils/time/index.js +14 -0
- package/dist/esm/charts/utils/types/action.d.ts +33 -0
- package/dist/esm/charts/utils/types/chart.d.ts +220 -0
- package/dist/esm/charts/utils/types/data.d.ts +51 -0
- package/dist/esm/charts/utils/types/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/lib/charts/Chart/utils/complementData.js +721 -0
- package/dist/lib/charts/Chart/utils/convertToEchartsConfig/chartsToEchartsConfig.js +105 -0
- package/dist/lib/charts/Chart/utils/convertToEchartsConfig/index.js +27 -0
- package/dist/lib/charts/Chart/utils/convertToEchartsConfig/pieChartToEchartsConfig.js +147 -0
- package/dist/lib/charts/Chart/utils/getOption.js +371 -0
- package/dist/lib/charts/Chart/utils/handleChartConfig.js +284 -0
- package/dist/lib/charts/Chart/utils/index.js +60 -0
- package/dist/lib/charts/Chart/utils/preConfig/index.js +313 -0
- package/dist/lib/charts/Chart/utils/preConfig/type.js +5 -0
- package/dist/lib/charts/PieChart/interface.js +5 -0
- package/dist/lib/charts/PieChart/locales/en-US.js +15 -0
- package/dist/lib/charts/PieChart/locales/index.js +14 -0
- package/dist/lib/charts/PieChart/locales/zh-CN.js +15 -0
- package/dist/lib/charts/PieChart/util.js +441 -0
- package/dist/lib/charts/SuperChart/config/bar.js +45 -0
- package/dist/lib/charts/SuperChart/config/index.js +243 -0
- package/dist/lib/charts/SuperChart/configStyle/color.js +29 -0
- package/dist/lib/charts/SuperChart/configStyle/dataZoom.js +19 -0
- package/dist/lib/charts/SuperChart/configStyle/grid.js +26 -0
- package/dist/lib/charts/SuperChart/configStyle/index.js +76 -0
- package/dist/lib/charts/SuperChart/configStyle/legend.js +74 -0
- package/dist/lib/charts/SuperChart/configStyle/lineStyle.js +86 -0
- package/dist/lib/charts/SuperChart/configStyle/title.js +22 -0
- package/dist/lib/charts/SuperChart/configStyle/tooltip.js +44 -0
- package/dist/lib/charts/SuperChart/configStyle/visualMap.js +24 -0
- package/dist/lib/charts/SuperChart/configStyle/xAxis.js +25 -0
- package/dist/lib/charts/SuperChart/configStyle/yAxis.js +62 -0
- package/dist/lib/charts/SuperChart/interface.js +5 -0
- package/dist/lib/charts/chartTheme/colorUtil.js +28 -0
- package/dist/lib/charts/chartTheme/darkChart.js +514 -0
- package/dist/lib/charts/chartTheme/defaultChart.js +498 -0
- package/dist/lib/charts/chartTheme/index.js +49 -0
- package/dist/lib/charts/chartTheme/themeColor.js +174 -0
- package/dist/lib/charts/index.js +60 -0
- package/dist/lib/charts/utils/charts/hex2Rgb.js +38 -0
- package/dist/lib/charts/utils/constants/env.js +12 -0
- package/dist/lib/charts/utils/constants/helper.js +11 -0
- package/dist/lib/charts/utils/constants/index.js +38 -0
- package/dist/lib/charts/utils/constants/table.js +23 -0
- package/dist/lib/charts/utils/data.js +454 -0
- package/dist/lib/charts/utils/index.js +60 -0
- package/dist/lib/charts/utils/locale.js +13 -0
- package/dist/lib/charts/utils/time/index.js +21 -0
- package/dist/lib/charts/utils/types/action.d.ts +33 -0
- package/dist/lib/charts/utils/types/chart.d.ts +220 -0
- package/dist/lib/charts/utils/types/data.d.ts +51 -0
- package/dist/lib/charts/utils/types/index.d.ts +3 -0
- package/dist/lib/index.js +25 -0
- package/package.json +2 -1
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
8
|
+
import { get, isArray } from "lodash";
|
|
9
|
+
export var tooltipICon = function tooltipICon(item, params) {
|
|
10
|
+
var icon = item.icon,
|
|
11
|
+
color = item.color;
|
|
12
|
+
var iconColor = color || (params === null || params === void 0 ? void 0 : params.color);
|
|
13
|
+
if (icon && _typeof(icon) === "object") {
|
|
14
|
+
var _icon$width = icon.width,
|
|
15
|
+
width = _icon$width === void 0 ? "6px" : _icon$width,
|
|
16
|
+
_icon$height = icon.height,
|
|
17
|
+
height = _icon$height === void 0 ? "6px" : _icon$height;
|
|
18
|
+
var path = icon.path.split("path://")[1];
|
|
19
|
+
return "<svg fill=\"currentColor\" style=\"color:".concat(iconColor, "; width:").concat(width, ";height:").concat(height, ";\"><path d=\"").concat(path, "\" ></path></svg>");
|
|
20
|
+
}
|
|
21
|
+
switch (icon) {
|
|
22
|
+
case "circle":
|
|
23
|
+
return "<span class='circle tooltipIcon' style='background: ".concat(iconColor, "'></span>");
|
|
24
|
+
case "diamond":
|
|
25
|
+
return "<span class=\"diamond tooltipIcon\" style='background: ".concat(iconColor, "'></span>");
|
|
26
|
+
case "line":
|
|
27
|
+
return "<span class=\"line tooltipIcon\" style='background-color: ".concat(iconColor, "'></span>");
|
|
28
|
+
case "rect":
|
|
29
|
+
return "<span class=\"react tooltipIcon\" style='background: ".concat(iconColor, "'></span>");
|
|
30
|
+
case "":
|
|
31
|
+
case null:
|
|
32
|
+
return "";
|
|
33
|
+
default:
|
|
34
|
+
return "<span class='circle tooltipIcon' style='background: ".concat(iconColor, "'></span>");
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export var tooltipLabel = function tooltipLabel(item, params, is2Dim) {
|
|
38
|
+
var label = item.label,
|
|
39
|
+
seriesLabel = item.seriesLabel,
|
|
40
|
+
nameExpression = item.nameExpression,
|
|
41
|
+
nameHelper = item.nameHelper;
|
|
42
|
+
if (nameExpression) {
|
|
43
|
+
var leftIndex = nameExpression.indexOf("{");
|
|
44
|
+
var rightIndex = nameExpression.indexOf("}");
|
|
45
|
+
var key = nameExpression.substring(leftIndex + 1, rightIndex);
|
|
46
|
+
var keyStr = nameExpression.substring(leftIndex, rightIndex + 1);
|
|
47
|
+
var value = get(params, "".concat(key)) || "";
|
|
48
|
+
if (nameHelper) {
|
|
49
|
+
value = (nameHelper === null || nameHelper === void 0 ? void 0 : nameHelper["".concat(value)]) || value;
|
|
50
|
+
}
|
|
51
|
+
return nameExpression.replace(keyStr, value) || "";
|
|
52
|
+
}
|
|
53
|
+
if (seriesLabel) {
|
|
54
|
+
return is2Dim ? params.name : params.seriesName;
|
|
55
|
+
}
|
|
56
|
+
if (label) {
|
|
57
|
+
return label;
|
|
58
|
+
}
|
|
59
|
+
return "";
|
|
60
|
+
};
|
|
61
|
+
export var tooltipValue = function tooltipValue(item, params) {
|
|
62
|
+
var value = item.value,
|
|
63
|
+
valueKey = item.valueKey;
|
|
64
|
+
var isShowValue = value || valueKey;
|
|
65
|
+
if (value || value === 0) {
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
var res = isShowValue ? "- " : "";
|
|
69
|
+
if (valueKey) {
|
|
70
|
+
res = get(params, "data.".concat(valueKey));
|
|
71
|
+
if (!res && res !== 0) {
|
|
72
|
+
res = "-";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return res;
|
|
76
|
+
};
|
|
77
|
+
export var periodBasisCompare = function periodBasisCompare(type, number, isGreenUp) {
|
|
78
|
+
if (number === null || number === undefined) {
|
|
79
|
+
return "";
|
|
80
|
+
} else {
|
|
81
|
+
return "<div class=\"period-basis\" data-color=".concat(isGreenUp ? "green-up" : "green-down", ">\n <div class=\"period-basis-title\">").concat(type === "yearToYear" ? "同比" : "环比", "</div>\n <div class=").concat(number >= 0 ? "period-basis-content-up" : "period-basis-content-down", ">\n <div class=\"period-basis-number\">\n ").concat(number >= 0 ? number.toFixed(1) : Math.abs(number).toFixed(1), "%\n </div>\n <div class=\"period-basis-triangle-box\">\n <div class=\"period-basis-triangle\"></div>\n </div>\n </div>\n </div>");
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
export var tooltipPeriodBasisCompare = function tooltipPeriodBasisCompare(isShowPeriodBasisCompare, params, isGreenUp) {
|
|
85
|
+
if (isShowPeriodBasisCompare) {
|
|
86
|
+
var _params$data, _params$data2;
|
|
87
|
+
return "<div>\n ".concat(periodBasisCompare("monthToMonth", params === null || params === void 0 || (_params$data = params.data) === null || _params$data === void 0 ? void 0 : _params$data.monthToMonth, isGreenUp), "\n ").concat(periodBasisCompare("yearToYear", params === null || params === void 0 || (_params$data2 = params.data) === null || _params$data2 === void 0 ? void 0 : _params$data2.yearToYear, isGreenUp), "</div>");
|
|
88
|
+
} else return "";
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
//新增环比
|
|
92
|
+
export var tooltipContent = function tooltipContent(item, params, is2Dim) {
|
|
93
|
+
var unitVal = "";
|
|
94
|
+
var _ref = item || {},
|
|
95
|
+
unit = _ref.unit,
|
|
96
|
+
unitKey = _ref.unitKey;
|
|
97
|
+
if (!unitKey && unit) {
|
|
98
|
+
unitVal = unit;
|
|
99
|
+
}
|
|
100
|
+
if (unitKey) {
|
|
101
|
+
unitVal = get(params, "data.".concat(unitKey));
|
|
102
|
+
}
|
|
103
|
+
return "<div class=\"cell-row\">\n <div class=\"cell-name\">\n <div>".concat(tooltipICon(item, params), "</div>\n <div>").concat(tooltipLabel(item, params, is2Dim), "</div>\n </div>\n <div class=\"cell-value\">").concat(tooltipValue(item, params), "<span class=\"cell-value-unit\">").concat(unitVal, "</span></div></div>");
|
|
104
|
+
};
|
|
105
|
+
export var tooltipTitle = function tooltipTitle(title, params, is2Dim) {
|
|
106
|
+
var label = title.label,
|
|
107
|
+
seriesLabel = title.seriesLabel,
|
|
108
|
+
valueKey = title.valueKey,
|
|
109
|
+
value = title.value,
|
|
110
|
+
show = title.show,
|
|
111
|
+
nameExpression = title.nameExpression,
|
|
112
|
+
formatter = title.formatter;
|
|
113
|
+
var isShowLabel = label || seriesLabel || nameExpression;
|
|
114
|
+
if (formatter) {
|
|
115
|
+
return "<h3>".concat(formatter(params));
|
|
116
|
+
}
|
|
117
|
+
if (isShowLabel) {
|
|
118
|
+
return "<h3>".concat(tooltipLabel(title, params, is2Dim), "<span style='padding-left: 14px'>").concat(tooltipValue(title, params), "</span></h3>");
|
|
119
|
+
}
|
|
120
|
+
if (value || valueKey) {
|
|
121
|
+
return "<h3>".concat(tooltipValue(title, params), "</h3>");
|
|
122
|
+
}
|
|
123
|
+
if (!show || JSON.stringify(JSON.parse(title)) === "{}") return "";
|
|
124
|
+
return "";
|
|
125
|
+
};
|
|
126
|
+
export var getTooltipFormatter = function getTooltipFormatter(params, content, title, is2Dim, index, isShowPeriodBasisCompare, isGreenUp) {
|
|
127
|
+
var getTooltipTitle = function getTooltipTitle() {
|
|
128
|
+
return index === 0 || !index ? "".concat(tooltipTitle(title, params, is2Dim)) : "";
|
|
129
|
+
};
|
|
130
|
+
return '<div class="tooltip-cell-container">' + getTooltipTitle() + content.map(function (item) {
|
|
131
|
+
var excludeSeries = item.excludeSeries,
|
|
132
|
+
includeSeries = item.includeSeries,
|
|
133
|
+
startsWithSeries = item.startsWithSeries,
|
|
134
|
+
showByValueKey = item.showByValueKey,
|
|
135
|
+
valueKey = item.valueKey;
|
|
136
|
+
if (includeSeries) {
|
|
137
|
+
for (var i = 0; i < includeSeries.length; i++) {
|
|
138
|
+
if (params.seriesName.indexOf(includeSeries[i]) > -1) {
|
|
139
|
+
return tooltipContent(item, params, is2Dim);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
if (excludeSeries) {
|
|
145
|
+
for (var _i = 0; _i < excludeSeries.length; _i++) {
|
|
146
|
+
if (params.seriesName.indexOf(excludeSeries[_i]) > -1) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return tooltipContent(item, params, is2Dim);
|
|
151
|
+
}
|
|
152
|
+
if (startsWithSeries) {
|
|
153
|
+
if (params.seriesName.startsWith(startsWithSeries)) {
|
|
154
|
+
return tooltipContent(item, params, is2Dim);
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
if (showByValueKey) {
|
|
159
|
+
if (params.data["".concat(valueKey)]) {
|
|
160
|
+
return tooltipContent(item, params, is2Dim);
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return tooltipContent(item, params, is2Dim);
|
|
165
|
+
}).join("") + "" + tooltipPeriodBasisCompare(isShowPeriodBasisCompare, params, isGreenUp) + "</div>";
|
|
166
|
+
};
|
|
167
|
+
var itemTooltipFormatter = function itemTooltipFormatter(dataConfig, is2Dim) {
|
|
168
|
+
var content = (dataConfig === null || dataConfig === void 0 ? void 0 : dataConfig.content) || [];
|
|
169
|
+
var title = (dataConfig === null || dataConfig === void 0 ? void 0 : dataConfig.title) || {};
|
|
170
|
+
var isShowPeriodBasisCompare = (dataConfig === null || dataConfig === void 0 ? void 0 : dataConfig.isShowPeriodBasisCompare) || false;
|
|
171
|
+
var isGreenUp = dataConfig === null || dataConfig === void 0 ? void 0 : dataConfig.isGreenUp;
|
|
172
|
+
var showMoreSeries = (dataConfig === null || dataConfig === void 0 ? void 0 : dataConfig.showMoreSeries) === undefined ? true : dataConfig === null || dataConfig === void 0 ? void 0 : dataConfig.showMoreSeries;
|
|
173
|
+
return function (params) {
|
|
174
|
+
var formatterContent = "";
|
|
175
|
+
if (showMoreSeries && isArray(params)) {
|
|
176
|
+
params.forEach(function (item, index) {
|
|
177
|
+
formatterContent += getTooltipFormatter(item, content, title, is2Dim, index, isShowPeriodBasisCompare, isGreenUp);
|
|
178
|
+
});
|
|
179
|
+
return formatterContent;
|
|
180
|
+
}
|
|
181
|
+
var hoverData = isArray(params) && params.length >= 1 ? (params === null || params === void 0 ? void 0 : params[0]) || {} : params;
|
|
182
|
+
return getTooltipFormatter(hoverData, content, title, is2Dim, undefined, isShowPeriodBasisCompare, isGreenUp);
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
var handleTooltipConfigData = function handleTooltipConfigData(config, is2Dim) {
|
|
186
|
+
if (config !== null && config !== void 0 && config.dataConfig && !(config !== null && config !== void 0 && config.formatter)) {
|
|
187
|
+
var formatter = itemTooltipFormatter(config === null || config === void 0 ? void 0 : config.dataConfig, is2Dim);
|
|
188
|
+
config.formatter = formatter;
|
|
189
|
+
}
|
|
190
|
+
return config;
|
|
191
|
+
};
|
|
192
|
+
export var defaultLegendIcon = function defaultLegendIcon(type) {
|
|
193
|
+
switch (type) {
|
|
194
|
+
case "bar":
|
|
195
|
+
return "rect";
|
|
196
|
+
case "line":
|
|
197
|
+
return "circle";
|
|
198
|
+
case "pie":
|
|
199
|
+
return "circle";
|
|
200
|
+
case "boxplot":
|
|
201
|
+
return "path://M2.5 0H9.5V1H6.5V11H9.5V12H2.5V11H5.5V1H2.5V0Z";
|
|
202
|
+
default:
|
|
203
|
+
return "circle";
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
export var handleIcon = function handleIcon(icon) {
|
|
207
|
+
switch (icon) {
|
|
208
|
+
case "line":
|
|
209
|
+
return "path://M0 426.666667h1024v170.666666H0z";
|
|
210
|
+
case "dottedLine":
|
|
211
|
+
return "path://M0 426.666667h426.666667v170.666666H0zM597.333333 426.666667h426.666667v170.666666H597.333333z";
|
|
212
|
+
case "boxplot":
|
|
213
|
+
return "path://M2.5 0H9.5V1H6.5V11H9.5V12H2.5V11H5.5V1H2.5V0Z";
|
|
214
|
+
default:
|
|
215
|
+
return icon;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
export var defaultLegendData = function defaultLegendData(config, colorList, series) {
|
|
219
|
+
return series.map(function (item) {
|
|
220
|
+
var name = item.name;
|
|
221
|
+
var obj = {
|
|
222
|
+
name: name,
|
|
223
|
+
icon: "",
|
|
224
|
+
itemStyle: {
|
|
225
|
+
color: ""
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
if (config !== null && config !== void 0 && config.icon) {
|
|
229
|
+
obj.icon = handleIcon(config.icon);
|
|
230
|
+
} else {
|
|
231
|
+
obj.icon = defaultLegendIcon(item === null || item === void 0 ? void 0 : item.type);
|
|
232
|
+
}
|
|
233
|
+
obj.itemStyle.color = (config === null || config === void 0 ? void 0 : config.color) || undefined;
|
|
234
|
+
return obj;
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
export var legendData = function legendData(dataConfig, colorList, series) {
|
|
238
|
+
var _seriesData$;
|
|
239
|
+
var configKeys = Object.keys(dataConfig);
|
|
240
|
+
var data = configKeys.map(function (item) {
|
|
241
|
+
if (item !== "default") {
|
|
242
|
+
var _dataConfig;
|
|
243
|
+
if ((_dataConfig = dataConfig["".concat(item)]) !== null && _dataConfig !== void 0 && _dataConfig.icon) {
|
|
244
|
+
dataConfig["".concat(item)].icon = handleIcon(dataConfig["".concat(item)].icon);
|
|
245
|
+
}
|
|
246
|
+
return dataConfig["".concat(item)];
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}).filter(function (sub) {
|
|
250
|
+
return sub !== null;
|
|
251
|
+
});
|
|
252
|
+
var seriesData = series;
|
|
253
|
+
if (seriesData && seriesData.length > 0 && ((_seriesData$ = seriesData[0]) === null || _seriesData$ === void 0 ? void 0 : _seriesData$.type) === "pie") {
|
|
254
|
+
var _seriesData$2;
|
|
255
|
+
seriesData = (_seriesData$2 = seriesData[0]) === null || _seriesData$2 === void 0 ? void 0 : _seriesData$2.data;
|
|
256
|
+
}
|
|
257
|
+
var defaultSeries = seriesData.map(function (item) {
|
|
258
|
+
var name = item.name;
|
|
259
|
+
if (configKeys.indexOf(name) === -1) {
|
|
260
|
+
return item;
|
|
261
|
+
}
|
|
262
|
+
return null;
|
|
263
|
+
}).filter(function (sub) {
|
|
264
|
+
return sub !== null;
|
|
265
|
+
});
|
|
266
|
+
var defaultData = defaultLegendData(dataConfig === null || dataConfig === void 0 ? void 0 : dataConfig.default, colorList, defaultSeries);
|
|
267
|
+
return [].concat(_toConsumableArray(data), _toConsumableArray(defaultData));
|
|
268
|
+
};
|
|
269
|
+
var handleLegendConfigData = function handleLegendConfigData(config, defaultColorList, series) {
|
|
270
|
+
var legend = config.legend,
|
|
271
|
+
color = config.color;
|
|
272
|
+
var colorList = color ? color : defaultColorList;
|
|
273
|
+
if (legend && legend !== null && legend !== void 0 && legend.dataConfig) {
|
|
274
|
+
var data = legendData(legend === null || legend === void 0 ? void 0 : legend.dataConfig, colorList, series);
|
|
275
|
+
legend.data = data;
|
|
276
|
+
}
|
|
277
|
+
return config;
|
|
278
|
+
};
|
|
279
|
+
export { handleTooltipConfigData, itemTooltipFormatter, handleLegendConfigData };
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
6
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
7
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
import { groupBy, merge } from 'lodash';
|
|
14
|
+
import { itemTooltipFormatter } from "../handleChartConfig";
|
|
15
|
+
var transformDimData = function transformDimData(list, dimensions) {
|
|
16
|
+
if (dimensions && dimensions.length >= 2) {
|
|
17
|
+
return list.map(function (item) {
|
|
18
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
19
|
+
name: item[dimensions[0]],
|
|
20
|
+
value: item[dimensions[1]]
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return list;
|
|
25
|
+
};
|
|
26
|
+
export var indicator2ChartData = function indicator2ChartData(data, is2Dim) {
|
|
27
|
+
if (!data) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (data.list) {
|
|
31
|
+
var list = data.list,
|
|
32
|
+
dimensions = data.dimensions;
|
|
33
|
+
if (!is2Dim) {
|
|
34
|
+
var group = groupBy(list, 'group_name');
|
|
35
|
+
// console.log(res);
|
|
36
|
+
return Object.entries(group).map(function (_ref) {
|
|
37
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
38
|
+
key = _ref2[0],
|
|
39
|
+
items = _ref2[1];
|
|
40
|
+
return {
|
|
41
|
+
groupKey: key,
|
|
42
|
+
groupName: items[0].group_name,
|
|
43
|
+
source: transformDimData(items, dimensions)
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return transformDimData(list, dimensions);
|
|
48
|
+
}
|
|
49
|
+
return [];
|
|
50
|
+
};
|
|
51
|
+
export var modifyIcon = function modifyIcon(chartConfig, type) {
|
|
52
|
+
chartConfig.type = type;
|
|
53
|
+
};
|
|
54
|
+
export var getChartIcon = function getChartIcon(type) {
|
|
55
|
+
var icon = 'circle';
|
|
56
|
+
switch (type) {
|
|
57
|
+
case 'bar':
|
|
58
|
+
icon = 'rect';
|
|
59
|
+
break;
|
|
60
|
+
case 'boxplot':
|
|
61
|
+
case 'line':
|
|
62
|
+
icon = 'circle';
|
|
63
|
+
break;
|
|
64
|
+
case 'pie':
|
|
65
|
+
default:
|
|
66
|
+
icon = type;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
type: type,
|
|
71
|
+
legend: icon,
|
|
72
|
+
series: icon
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export var modifyTitle = function modifyTitle(chartConfig, _ref3) {
|
|
76
|
+
var subtextX = _ref3.subtextX,
|
|
77
|
+
subtextY = _ref3.subtextY,
|
|
78
|
+
positionSubtextY = _ref3.positionSubtextY,
|
|
79
|
+
positionSubtextX = _ref3.positionSubtextX;
|
|
80
|
+
if (!subtextX && !subtextY) return;
|
|
81
|
+
chartConfig.configData.title = [];
|
|
82
|
+
var positionX = [{
|
|
83
|
+
right: -3,
|
|
84
|
+
bottom: 35
|
|
85
|
+
}];
|
|
86
|
+
var positionY = [{
|
|
87
|
+
left: -5,
|
|
88
|
+
top: -10
|
|
89
|
+
}, {
|
|
90
|
+
right: 5,
|
|
91
|
+
top: -10
|
|
92
|
+
}];
|
|
93
|
+
if (subtextX) {
|
|
94
|
+
chartConfig.configData.title.push(_objectSpread(_objectSpread(_objectSpread({
|
|
95
|
+
subtext: subtextX
|
|
96
|
+
}, positionX[0]), positionSubtextX && positionSubtextX[0]), {}, {
|
|
97
|
+
subtextStyle: {
|
|
98
|
+
fontSize: 12,
|
|
99
|
+
fontWeight: 'normal'
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
if (typeof subtextY === 'string') {
|
|
104
|
+
chartConfig.configData.title.push(_objectSpread(_objectSpread(_objectSpread({
|
|
105
|
+
subtext: subtextY
|
|
106
|
+
}, positionY[0]), positionSubtextY && positionSubtextY[0]), {}, {
|
|
107
|
+
subtextStyle: {
|
|
108
|
+
fontSize: 12,
|
|
109
|
+
fontWeight: 'normal'
|
|
110
|
+
}
|
|
111
|
+
}));
|
|
112
|
+
} else if (Array.isArray(subtextY)) {
|
|
113
|
+
subtextY.forEach(function (text, index) {
|
|
114
|
+
chartConfig.configData.title.push(_objectSpread(_objectSpread(_objectSpread({
|
|
115
|
+
subtext: text
|
|
116
|
+
}, positionY[index]), positionSubtextY && positionSubtextY[index]), {}, {
|
|
117
|
+
subtextStyle: {
|
|
118
|
+
fontSize: 12,
|
|
119
|
+
fontWeight: 'normal'
|
|
120
|
+
}
|
|
121
|
+
}));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
export var modifyChartConfig = function modifyChartConfig(chartConfig, preChartConfig) {
|
|
126
|
+
if (!preChartConfig) return;
|
|
127
|
+
// const { type, subtextX, subtextY } = preChartConfig;
|
|
128
|
+
// modifyIcon(chartConfig, type);
|
|
129
|
+
modifyTitle(chartConfig, preChartConfig);
|
|
130
|
+
};
|
|
131
|
+
var isToolTipConfig = function isToolTipConfig(config) {
|
|
132
|
+
return !!(config !== null && config !== void 0 && config.contentFormatter);
|
|
133
|
+
};
|
|
134
|
+
export var createChartConfig = function createChartConfig() {
|
|
135
|
+
var preChartConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
136
|
+
type: 'bar'
|
|
137
|
+
};
|
|
138
|
+
var filter = arguments.length > 1 ? arguments[1] : undefined;
|
|
139
|
+
var isPDF = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
140
|
+
var _preChartConfig$type = preChartConfig.type,
|
|
141
|
+
type = _preChartConfig$type === void 0 ? 'bar' : _preChartConfig$type,
|
|
142
|
+
_preChartConfig$is2Di = preChartConfig.is2Dim,
|
|
143
|
+
is2Dim = _preChartConfig$is2Di === void 0 ? true : _preChartConfig$is2Di,
|
|
144
|
+
title = preChartConfig.title,
|
|
145
|
+
_preChartConfig$color = preChartConfig.color,
|
|
146
|
+
color = _preChartConfig$color === void 0 ? ['#30C147', '#1467FF', '#F5AE59', '#9251DF'] : _preChartConfig$color,
|
|
147
|
+
_preChartConfig$legen = preChartConfig.legend,
|
|
148
|
+
legend = _preChartConfig$legen === void 0 ? {} : _preChartConfig$legen,
|
|
149
|
+
series = preChartConfig.series,
|
|
150
|
+
visualMap = preChartConfig.visualMap,
|
|
151
|
+
xOrder = preChartConfig.xOrder,
|
|
152
|
+
grid = preChartConfig.grid,
|
|
153
|
+
seriesOrder = preChartConfig.seriesOrder,
|
|
154
|
+
subtextY = preChartConfig.subtextY,
|
|
155
|
+
tooltip = preChartConfig.tooltip,
|
|
156
|
+
xAxis = preChartConfig.xAxis,
|
|
157
|
+
yAxis = preChartConfig.yAxis,
|
|
158
|
+
readLegend = preChartConfig.readLegend,
|
|
159
|
+
preTransform = preChartConfig.preTransform,
|
|
160
|
+
preSeries = preChartConfig.preSeries,
|
|
161
|
+
pieTooltipContent = preChartConfig.pieTooltipContent,
|
|
162
|
+
pieTotalToFixedNumber = preChartConfig.pieTotalToFixedNumber,
|
|
163
|
+
dataZoom = preChartConfig.dataZoom;
|
|
164
|
+
var icon = getChartIcon(type);
|
|
165
|
+
// console.log('yAxis', yAxis);
|
|
166
|
+
var chartConfig = {
|
|
167
|
+
type: type,
|
|
168
|
+
title: title,
|
|
169
|
+
configData: {
|
|
170
|
+
color: color,
|
|
171
|
+
legend: is2Dim ? legend : merge({
|
|
172
|
+
type: 'scroll',
|
|
173
|
+
dataConfig: {
|
|
174
|
+
default: {
|
|
175
|
+
icon: icon.legend
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
left: 'center',
|
|
179
|
+
// right: 'middle',
|
|
180
|
+
bottom: 0
|
|
181
|
+
}, legend),
|
|
182
|
+
visualMap: visualMap || false,
|
|
183
|
+
series: merge({}, {
|
|
184
|
+
default: {
|
|
185
|
+
type: type,
|
|
186
|
+
smooth: false,
|
|
187
|
+
animation: !isPDF
|
|
188
|
+
// yAxisIndex: 0,
|
|
189
|
+
// itemStyle: {
|
|
190
|
+
// normal: {
|
|
191
|
+
// opacity: 0,
|
|
192
|
+
// },
|
|
193
|
+
// },
|
|
194
|
+
}
|
|
195
|
+
}, series),
|
|
196
|
+
seriesOrder: seriesOrder,
|
|
197
|
+
xAxis: xAxis || {},
|
|
198
|
+
// formatter: {
|
|
199
|
+
// type: 'time',
|
|
200
|
+
// formatter: 'YYYY-MM',
|
|
201
|
+
// },
|
|
202
|
+
// name: '时间(月)',
|
|
203
|
+
|
|
204
|
+
xOrder: xOrder,
|
|
205
|
+
yAxis: yAxis || {
|
|
206
|
+
splitNumber: 4,
|
|
207
|
+
minInterval: 1,
|
|
208
|
+
scale: false
|
|
209
|
+
},
|
|
210
|
+
grid: grid || {
|
|
211
|
+
top: 40,
|
|
212
|
+
left: 5,
|
|
213
|
+
containLabel: true,
|
|
214
|
+
bottom: 26,
|
|
215
|
+
right: 55
|
|
216
|
+
},
|
|
217
|
+
dataZoom: dataZoom || {},
|
|
218
|
+
tooltip: {
|
|
219
|
+
trigger: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.trigger) || 'axis',
|
|
220
|
+
// axisPointer: {
|
|
221
|
+
// type: 'line',
|
|
222
|
+
// lineStyle: { color: '#1467FF' },
|
|
223
|
+
// },
|
|
224
|
+
axisPointer: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.axisPointer) || {},
|
|
225
|
+
formatter: function formatter(param, ticket, callback) {
|
|
226
|
+
if (tooltip !== null && tooltip !== void 0 && tooltip.tooltipFormatter) {
|
|
227
|
+
return tooltip.tooltipFormatter(param, filter, ticket, callback);
|
|
228
|
+
}
|
|
229
|
+
var content = [];
|
|
230
|
+
if (isToolTipConfig(tooltip === null || tooltip === void 0 ? void 0 : tooltip.content)) {
|
|
231
|
+
content = tooltip.content.contentFormatter(param);
|
|
232
|
+
} else {
|
|
233
|
+
content = param.map(function (item, index) {
|
|
234
|
+
var _tooltip$dataConfig, _tooltip$dataConfig$f;
|
|
235
|
+
var itemConfig;
|
|
236
|
+
if (Array.isArray(tooltip === null || tooltip === void 0 ? void 0 : tooltip.content)) {
|
|
237
|
+
var _tooltip$content;
|
|
238
|
+
itemConfig = (tooltip === null || tooltip === void 0 || (_tooltip$content = tooltip.content) === null || _tooltip$content === void 0 ? void 0 : _tooltip$content[index]) || {};
|
|
239
|
+
} else {
|
|
240
|
+
var _tooltip$content2;
|
|
241
|
+
itemConfig = (tooltip === null || tooltip === void 0 || (_tooltip$content2 = tooltip.content) === null || _tooltip$content2 === void 0 ? void 0 : _tooltip$content2[item.seriesName]) || {};
|
|
242
|
+
}
|
|
243
|
+
var tooltipIcon = getChartIcon(item.seriesType || 'bar');
|
|
244
|
+
var tooltipValue = (tooltip === null || tooltip === void 0 || (_tooltip$dataConfig = tooltip.dataConfig) === null || _tooltip$dataConfig === void 0 || (_tooltip$dataConfig = _tooltip$dataConfig[item.seriesName]) === null || _tooltip$dataConfig === void 0 || (_tooltip$dataConfig$f = _tooltip$dataConfig.formatter) === null || _tooltip$dataConfig$f === void 0 ? void 0 : _tooltip$dataConfig$f.call(_tooltip$dataConfig, item.data.value)) || item.data.value;
|
|
245
|
+
return {
|
|
246
|
+
label: itemConfig.label || is2Dim && (Array.isArray(subtextY) ? subtextY[index] : subtextY) || item.seriesName,
|
|
247
|
+
value: tooltipValue == null || tooltipValue === '' ? '-' : "".concat(tooltipValue).concat(itemConfig.unit || ''),
|
|
248
|
+
icon: tooltipIcon.legend,
|
|
249
|
+
color: item.color,
|
|
250
|
+
unit: (item === null || item === void 0 ? void 0 : item.unit) || ''
|
|
251
|
+
};
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if (tooltip !== null && tooltip !== void 0 && tooltip.totalItem) {
|
|
255
|
+
var totalValue = param.reduce(function (cur, next) {
|
|
256
|
+
var _next$data;
|
|
257
|
+
return cur + ((_next$data = next.data) !== null && _next$data !== void 0 && _next$data.value ? parseFloat(next.data.value) : 0);
|
|
258
|
+
}, 0);
|
|
259
|
+
if (tooltip.totalItem.position === 'bottom') {
|
|
260
|
+
content.push(_objectSpread(_objectSpread({}, tooltip.totalItem), {}, {
|
|
261
|
+
value: parseFloat(totalValue).toFixed(2)
|
|
262
|
+
}));
|
|
263
|
+
} else {
|
|
264
|
+
content.unshift(_objectSpread(_objectSpread({}, tooltip.totalItem), {}, {
|
|
265
|
+
value: parseFloat(totalValue).toFixed(2)
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// console.log('tooltipformatter content', content);
|
|
270
|
+
if (tooltip !== null && tooltip !== void 0 && tooltip.tooltipTitleFormatter && !tooltip.tooltipTitleFormatter(param) && !content) return null;
|
|
271
|
+
return itemTooltipFormatter({
|
|
272
|
+
showMoreSeries: true,
|
|
273
|
+
title: {
|
|
274
|
+
label: tooltip !== null && tooltip !== void 0 && tooltip.tooltipTitleFormatter ? tooltip.tooltipTitleFormatter(param) : '',
|
|
275
|
+
seriesLabel: false,
|
|
276
|
+
valueKey: tooltip !== null && tooltip !== void 0 && tooltip.tooltipTitleFormatter ? '' : 'name',
|
|
277
|
+
show: tooltip !== null && tooltip !== void 0 && tooltip.tooltipTitleFormatter ? tooltip.tooltipTitleFormatter(param) ? true : false : true
|
|
278
|
+
},
|
|
279
|
+
content: content
|
|
280
|
+
}, is2Dim)(param[0]);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
readLegend: readLegend,
|
|
285
|
+
pieTooltipContent: pieTooltipContent,
|
|
286
|
+
pieTotalToFixedNumber: pieTotalToFixedNumber,
|
|
287
|
+
preTransform: preTransform,
|
|
288
|
+
preSeries: preSeries,
|
|
289
|
+
dataFillConfig: {
|
|
290
|
+
dimensions: ['name', 'value']
|
|
291
|
+
//TODO: 填补数据
|
|
292
|
+
// "range": [
|
|
293
|
+
// "2023-02-20",
|
|
294
|
+
// "2023-03-21"
|
|
295
|
+
// ],
|
|
296
|
+
// "interval": [
|
|
297
|
+
// 1,
|
|
298
|
+
// "d"
|
|
299
|
+
// ],
|
|
300
|
+
// "fillWith": "ZERO"
|
|
301
|
+
},
|
|
302
|
+
is2Dim: is2Dim
|
|
303
|
+
};
|
|
304
|
+
modifyChartConfig(chartConfig, preChartConfig);
|
|
305
|
+
// console.log('chartConfig chartConfig11', chartConfig);
|
|
306
|
+
return chartConfig;
|
|
307
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|