fastlion-amis
Version:
一种MIS页面生成工具
393 lines (392 loc) • 16.3 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getChartSchema = void 0;
var helper_1 = require("../../../utils/helper");
var getChartSchema = function (_a) {
var type = _a.type, selectedXAxisData = _a.selectedXAxisData, selectedYAxisData = _a.selectedYAxisData, data = _a.data, columns = _a.columns, primaryField = _a.primaryField, barValue = _a.barValue, chartTitle = _a.chartTitle, tableName = _a.tableName;
var defaultSchame = {};
var name = (tableName || (0, helper_1.uuid)()) + "_chart";
if (['line', 'bar', 'area', 'bar-vertical', 'line-bar'].includes(type)) {
defaultSchame = {
"height": "100%",
"width": "100%",
"type": "chart",
"name": name,
"className": "w-full",
"config": {
"title": [
{
// subtext: chartTitle,
left: "4%",
text: chartTitle
}
],
"legend": {
// "top": "2%",
"bottom": "2%",
"show": true,
"data": ['a']
},
"tooltip": {
"show": true,
"trigger": "axis"
},
"series": [],
"xAxis": {
data: ['1'],
type: 'category'
},
"yAxis": {},
"grid": {
"left": "5%",
"containLabel": true
},
"dataZoom": [],
"toolbox": {
"feature": {
// "saveAsImage": {
// "show": true,
// "type": "png"
// },
// "myExport": {
// "show": true,
// "api": {
// "method": "post",
// "url": "/api/v1/export/PAGE_CHARTS_LINE/download/default_export?keepDataFormat=true&exportType=1&exportFields=REPORT_DATE,CREATE_ORDER_CNT,SENT_ORDER_CNT,COMMIT_ORDER_CNT&dataFilterPageId=PAGE_CHARTS_LINE&p_n=PAGE_CHARTS_LIST,PAGE_CHARTS_LINE"
// },
// "title": chartTitle
// }
}
},
"color": colorList
}
};
var xAxis = data.map(function (item) { return item[selectedXAxisData]; });
var targetCol = columns.find(function (item) { return item.name === selectedXAxisData; });
if (type === 'bar-vertical') {
var targetCol_1 = columns.find(function (item) { return item.name === selectedXAxisData; });
defaultSchame.config.yAxis = {
data: xAxis,
type: 'category',
name: targetCol_1.label || selectedXAxisData,
nameLocation: 'end'
};
defaultSchame.config.xAxis = {};
}
else {
defaultSchame.config.xAxis = {
data: xAxis,
type: 'category',
name: targetCol.label || selectedXAxisData,
nameLocation: 'end'
};
}
defaultSchame.config.legend.data = selectedYAxisData.map(function (item) { var _a; return ((_a = columns.find(function (col) { return col.name === item; })) === null || _a === void 0 ? void 0 : _a.label) || item; });
var series = selectedYAxisData.map(function (yAxisItem, index) {
var _a;
return {
data: data.map(function (item) { return item[yAxisItem]; }),
type: getItemType(type === 'line-bar' ? ((barValue === null || barValue === void 0 ? void 0 : barValue.includes(yAxisItem)) ? 'bar' : 'line') : type),
smooth: type === 'area' ? 0.5 : 0,
name: ((_a = columns.find(function (col) { return col.name === yAxisItem; })) === null || _a === void 0 ? void 0 : _a.label) || yAxisItem,
areaStyle: type === 'area' ? { "color": areaColorList[index] } : null,
label: {
formatter: function (params) {
var findCol = columns.find(function (col) { return col.name === yAxisItem; });
var prefix = findCol.prefix, suffix = findCol.suffix, kilobitSeparator = findCol.kilobitSeparator, precision = findCol.precision, pristine = findCol.pristine;
return (0, helper_1.standardValueText)(params.value, {
prefix: prefix || pristine.prefix,
suffix: suffix || pristine.suffix,
kilobitSeparator: kilobitSeparator || pristine.kilobitSeparator,
precision: precision || pristine.precision
});
},
position: 'top',
show: true
},
tooltip: {
valueFormatter: function (value) {
var _a = formatValue(value, yAxisItem, columns), _ = _a[0], val = _a[1];
return val;
}
}
};
});
defaultSchame.config.series = series;
}
//散点图
if (['scatter', 'scatter-size'].includes(type)) {
defaultSchame = {
"height": "100%",
"width": "100%",
"type": "chart",
"name": name,
"className": "w-full",
config: {
"title": [
{
// subtext: chartTitle,
left: "4%",
text: chartTitle
}
],
"legend": {
"bottom": "2%"
},
"tooltip": {
formatter: function (params) {
var _a = formatValue(params.value[2], primaryField, columns), keyCol = _a[0], keyValue = _a[1];
var _b = formatValue(params.value[0], selectedXAxisData[0], columns), xCol = _b[0], xColValue = _b[1];
var _c = formatValue(params.value[1], selectedXAxisData[1], columns), yCol = _c[0], yColValue = _c[1];
var showValue = '';
var showField = {};
if (selectedYAxisData[0]) {
var _d = formatValue(params.value[3], selectedYAxisData[0], columns), col = _d[0], val = _d[1];
showField = col;
showValue = val;
}
return keyCol.label + ': ' + keyValue + '<br/>' + xCol.label + ': ' + xColValue + '<br/>' + yCol.label + ': ' + yColValue + (showValue ? '<br/>' + showField.label + ': ' + showValue : '');
},
"show": true,
"trigger": "item"
},
"series": [
{
"data": [
[
28604,
77,
"Australia\r"
]
],
"symbolSize": 20,
"type": "scatter"
}
],
"xAxis": {
"type": "value"
},
"yAxis": {
"type": "value"
},
"grid": {
"left": "5%",
"containLabel": true
},
"dataZoom": [],
"toolbox": {}
}
};
var series = data.map(function (item) { return [item[selectedXAxisData[0]], item[selectedXAxisData[1]], item[primaryField || selectedXAxisData[0]], item[selectedYAxisData[0]]]; });
defaultSchame.config.series = [
{
symbolSize: type === 'scatter-size' ? function (data) {
return data[3];
} : 20,
type: "scatter",
data: series
}
];
var xCol = columns.find(function (item) { return item.name === (selectedXAxisData[0]); });
var yCol = columns.find(function (item) { return item.name === (selectedXAxisData[1]); });
defaultSchame.config.xAxis = {
type: "value",
name: (xCol === null || xCol === void 0 ? void 0 : xCol.label) || selectedXAxisData[0],
nameLocation: 'end'
};
defaultSchame.config.yAxis = {
type: "value",
name: (yCol === null || yCol === void 0 ? void 0 : yCol.label) || selectedXAxisData[1],
nameLocation: 'end'
};
}
//饼图,环形图
if (['pie', 'ring'].includes(type)) {
defaultSchame = {
"height": "100%",
"width": "100%",
"type": "chart",
"name": name,
"className": "w-full",
config: {
"title": [
{
// "subtext": chartTitle,
"left": "4%",
"text": chartTitle
}
],
"legend": {
"bottom": "2%"
},
"tooltip": {
"trigger": "item"
},
"series": [
{
"data": [
{
"CREATE_ORDER_CNT": 20,
"REPORT_DATE": "20240102",
"name": "男装",
"value": 20,
"TYPE": "男装"
}
],
"avoidLabelOverlap": true,
"tooltip": {
"valueFormatter": "function (value) { return window._standardValueText(value, {prefix:'',suffix:'',kilobitSeparator:null,precision:0}) }"
},
"label": {
"formatter": "{b} {d}%"
},
"type": "pie",
"radius": "20%"
}
],
"toolbox": {}
}
};
var series = data.map(function (item) { return ({
value: item[selectedYAxisData[0]],
name: item[selectedXAxisData]
}); });
defaultSchame.config.series = [{
"avoidLabelOverlap": true,
"tooltip": {
"valueFormatter": function (value) {
var _a = formatValue(value, selectedYAxisData[0], columns), _ = _a[0], val = _a[1];
return val;
}
},
"label": {
"formatter": "{b} {d}%"
},
"type": getItemType(type),
"radius": type === 'ring' ? ["50%", "70%"] : "40%",
data: series
}];
}
//漏斗图
if (['funnel'].includes(type)) {
defaultSchame = {
"height": "100%",
"width": "100%",
"type": "chart",
"name": name,
"className": "w-full",
config: {
"title": [
{
"subtext": chartTitle,
"left": "4%"
}
],
"legend": {
"bottom": "2%"
},
"tooltip": {
"trigger": "item"
},
"series": [
{
"data": [
{
"name": "确认订单金额",
"tooltip": {
"valueFormatter": "function (value) { return window._standardValueText(value, {prefix:'¥',suffix:'',kilobitSeparator:false,precision:2}) }"
},
"value": 3146
},
{
"name": "发货订单金额",
"tooltip": {
"valueFormatter": "function (value) { return window._standardValueText(value, {prefix:'¥',suffix:'',kilobitSeparator:false,precision:2}) }"
},
"value": 4146
},
{
"name": "创建订单金额",
"tooltip": {
"valueFormatter": "function (value) { return window._standardValueText(value, {prefix:'¥',suffix:'',kilobitSeparator:false,precision:2}) }"
},
"value": 2146.78
}
],
"type": "funnel"
}
],
"toolbox": {},
"color": colorList
}
};
var series = data.map(function (dataItem) {
return {
name: dataItem[selectedXAxisData],
value: dataItem[selectedYAxisData[0]],
tooltip: {
valueFormatter: function (value) {
var _a = formatValue(value, selectedYAxisData[0], columns), _ = _a[0], val = _a[1];
return val;
}
}
};
});
defaultSchame.config.series = [{
data: series,
type: getItemType(type)
}];
}
return defaultSchame;
};
exports.getChartSchema = getChartSchema;
var getItemType = function (type) {
switch (type) {
case 'area':
case 'line':
return 'line';
case 'bar-vertical':
case 'bar':
return 'bar';
case 'scatter':
case 'scatter-size':
return 'scatter';
case 'pie':
case 'ring':
return 'pie';
case 'funnel':
return 'funnel';
default:
return 'line';
}
};
var formatValue = function (value, fieldName, columns) {
var targetCol = columns.find(function (item) { return item.name === fieldName; });
var prefix = targetCol.prefix, suffix = targetCol.suffix, kilobitSeparator = targetCol.kilobitSeparator, precision = targetCol.precision, pristine = targetCol.pristine;
var keyValue = (0, helper_1.standardValueText)(value, {
prefix: prefix || pristine.prefix,
suffix: suffix || pristine.suffix,
kilobitSeparator: kilobitSeparator || pristine.kilobitSeparator,
precision: precision || pristine.precision
});
return [targetCol, keyValue];
};
var colorList = [
"#F5222D",
"#9254DE",
"#0958D9",
"#08979C",
"#EB2F96",
"#FAAD14",
"#ee6666",
"#7CB305",
"#ADC6FF",
"#fc8452",
"#5CDBD3"
];
var areaColorList = [
'rgba(245,34,45, 0.5)', 'rgba(146,84,222, 0.5)', 'rgba(9, 88, 217, 0.5)', 'rgba(8, 151, 156, 0.5)',
'rgba(235,47,150, 0.5)', 'rgba(250,173,20, 0.5)', 'rgba(238,102,102, 0.5)', 'rgba(124,179,5, 0.5)',
'rgba(173, 198, 255, 0.5)', 'rgba(252,132,82, 0.5)', 'rgba(92,219,211, 0.5)'
];
//# sourceMappingURL=./renderers/Table/DataCharts/chartTools.js.map
;