in src/common/checkFunctions.ts [573:626]
export function checkSizeConfig(
chartType: string,
config: any,
width: number | null,
height: number | null,
) {
if (chartType === 'G2Scatter') {
const { size = [4, 20] } = config;
if ((Array.isArray(size) && size[0] < 4) || (typeof size === 'number' && size < 4)) {
warn('Scatter', '检测出散点图配置项中size过小,建议不小于4,否则会影响图表的展示效果');
}
if ((Array.isArray(size) && size[1] > 20) || (typeof size === 'number' && size > 4)) {
warn('Scatter', '检测出散点图配置项中size过大,建议不大于20,否则会影响图表的展示效果');
}
} else if (chartType === 'G2Pie' && config?.cycle) {
const { padding = [0, 0, 0, 0], innerRadius = 0.8, outerRadius = 0.8, legend } = config;
// 根据图表的宽高、legend及padding计算饼图的直径
let pieWidth = width;
if (pieWidth) {
pieWidth -= padding[1] + padding[3];
if (
legend &&
legend?.visible !== false &&
(legend.position === 'left' || legend.position === 'right')
) {
// 此处legend宽度设为1/2
pieWidth /= 2;
}
}
let pieHeight = height || 200;
if (pieHeight) {
pieHeight -= padding[0] + padding[2];
if (
legend &&
legend?.visible !== false &&
(legend.position === 'top' || legend.position === 'bottom')
) {
// 此处legend高度设为30
pieWidth -= 30;
}
}
const pieD = width && height ? Math.min(pieWidth, pieHeight) : width ? pieWidth : pieHeight;
const outerR = (pieD / 2) * outerRadius;
const innerR = outerR * innerRadius;
const cycleWidth = outerR - innerR;
if (cycleWidth > 24) {
warn('Pie', '检测出圆环图的环宽过大,建议不超过24,否则会影响图表的展示效果');
}
}
}