@alicloud/cloud-charts
Version:

185 lines (183 loc) • 4.35 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.EmptyDataProcess = void 0;
exports.isEmptyData = isEmptyData;
exports.processEmptyData = processEmptyData;
var _data = require("./data");
var _index = _interopRequireDefault(require("../themes/index"));
/** 空数据处理的三种类型 */
var EmptyDataProcess = exports.EmptyDataProcess = /*#__PURE__*/function (EmptyDataProcess) {
EmptyDataProcess[EmptyDataProcess["Axis"] = 0] = "Axis";
EmptyDataProcess[EmptyDataProcess["Polar"] = 1] = "Polar";
EmptyDataProcess[EmptyDataProcess["Background"] = 2] = "Background";
return EmptyDataProcess;
}({});
/** 根据数据量判断是否是空数据 */
function isEmptyData(dataSize) {
return dataSize === 0;
}
/** 根据空数据处理类型、数据结构类型进行空数据处理,个别图表需要特殊处理 */
function processEmptyData(emptyType, dataType, chartName) {
if (emptyType === EmptyDataProcess.Axis) {
return {
data: [],
config: {
xAxis: {
min: 0,
max: 100,
label: false
},
yAxis: {
min: 0,
max: 100,
label: false
},
padding: 0,
guide: {
visible: false
},
zoom: false
}
};
} else if (emptyType === EmptyDataProcess.Polar) {
if (chartName === 'G2Radar') {
// 雷达图特殊处理
return {
data: [{
x: 'a',
y: 0
}, {
x: 'b',
y: 0
}, {
x: 'c',
y: 0
}, {
x: 'd',
y: 0
}, {
x: 'e',
y: 0
}, {
x: 'f',
y: 0
}],
config: {
xAxis: {
label: false
},
yAxis: {
min: 0,
max: 100,
label: false
},
legend: false,
tooltip: false,
colors: _index["default"]['widgets-color-layout-background'],
zoom: false,
padding: 0
}
};
} else if (dataType === _data.DataStructure.Common) {
return {
data: [{
x: 'a',
y: 100
}],
config: {
legend: false,
tooltip: false,
colors: _index["default"]['widgets-color-layout-background'],
label: false,
zoom: false,
padding: 0
}
};
} else if (dataType === _data.DataStructure.Tree) {
return {
data: {
children: [{
name: 'root',
value: 100,
empty: true
}]
},
config: {
legend: false,
tooltip: false,
colors: _index["default"]['widgets-color-layout-background'],
label: false,
zoom: false,
padding: 0
}
};
}
} else {
if (dataType === _data.DataStructure.Common) {
// 分箱图特殊处理
if (chartName === 'G2Rectangle') {
return {
data: [{
x: 0,
y: 0
}],
config: {
padding: 0,
xAxis: false,
yAxis: false,
tooltip: false,
legend: false,
zoom: false
}
};
}
return {
data: [],
config: {
padding: 0,
xAxis: false,
yAxis: false,
tooltip: false,
legend: false,
zoom: false
}
};
} else if (dataType === _data.DataStructure.Tree) {
return {
data: {
name: '',
children: []
},
config: {
padding: 0,
xAxis: false,
yAxis: false,
tooltip: false,
legend: false,
colors: _index["default"]['widgets-color-layout-background'],
zoom: false
}
};
} else if (dataType === _data.DataStructure.Graph) {
return {
data: {
nodes: [],
links: []
},
config: {
padding: 0,
xAxis: false,
yAxis: false,
tooltip: false,
legend: false,
zoom: false
}
};
}
}
return {
data: null,
config: null
};
}