|
|
|
|
@ -216,7 +216,7 @@ export default { |
|
|
|
|
// 中文字符宽度≈fontSize,英文字符≈fontSize/2,加额外内边距 |
|
|
|
|
const cnChar = text.replace(/[a-zA-Z0-9]/g, '').length; |
|
|
|
|
const enChar = text.length - cnChar; |
|
|
|
|
return cnChar * fontSize + enChar * (fontSize / 2) + 10; // +20 内边距 |
|
|
|
|
return cnChar * fontSize + enChar * (fontSize / 2) + 20; // +20 内边距 |
|
|
|
|
}, |
|
|
|
|
// 图表 |
|
|
|
|
createBarChart(value) { |
|
|
|
|
@ -228,7 +228,9 @@ export default { |
|
|
|
|
|
|
|
|
|
this.$nextTick(() => { |
|
|
|
|
if (!this.$refs.lineChart) return; |
|
|
|
|
|
|
|
|
|
const chartWidth = this.calculateChartWidth(value); |
|
|
|
|
this.$refs.lineChart.style.width = chartWidth + 'px'; |
|
|
|
|
console.log(98989898989, chartWidth); |
|
|
|
|
const mapBoxEchart = this.$echarts.init(this.$refs.lineChart); |
|
|
|
|
this.mapBoxEchart = mapBoxEchart; |
|
|
|
|
|
|
|
|
|
@ -327,6 +329,38 @@ export default { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
// 计算图表所需宽度 |
|
|
|
|
calculateChartWidth(data) { |
|
|
|
|
if (!data || data.length === 0) return 1000; |
|
|
|
|
|
|
|
|
|
let maxChildren = 0; |
|
|
|
|
let maxDepth = 0; |
|
|
|
|
|
|
|
|
|
const traverse = (nodes, depth = 0) => { |
|
|
|
|
if (!nodes || nodes.length === 0) return; |
|
|
|
|
maxDepth = Math.max(maxDepth, depth); |
|
|
|
|
|
|
|
|
|
nodes.forEach(node => { |
|
|
|
|
if (node.children && node.children.length > 0) { |
|
|
|
|
maxChildren = Math.max(maxChildren, node.children.length); |
|
|
|
|
traverse(node.children, depth + 1); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
traverse(data); |
|
|
|
|
|
|
|
|
|
// 根据子节点数量和层级计算宽度 |
|
|
|
|
// 每个节点约 200px,每层约 150px |
|
|
|
|
const width = Math.max( |
|
|
|
|
maxChildren * 200, |
|
|
|
|
maxDepth * 150, |
|
|
|
|
1000 // 最小宽度 1000px |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
console.log('图表宽度计算:', { maxChildren, maxDepth, width }); |
|
|
|
|
return width; |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
</script> |
|
|
|
|
|