fix:调整饼图,气泡图,桑基图的大小位置

This commit is contained in:
zyh
2023-12-20 15:58:01 +08:00
parent a7e177162b
commit 3d9a4c0f44
4 changed files with 13 additions and 11 deletions

View File

@@ -209,7 +209,7 @@ export default {
.attr('height', height)
.attr('viewBox', [-width / 2, -height / 2, width, height])
const outerRadius = (Math.min(width, height) / 2) * 0.6 // outer radius of pie, in pixels
const outerRadius = (Math.min(width, height) / 2) * 0.8 // outer radius of pie, in pixels
const innerRadius = outerRadius * (this.chartInfo.type === 'doughnut' ? 0.67 : 0) // inner radius of pie, in pixels (non-zero for donut)
const padAngle = 0 // angular separation between wedges
const arc = d3.arc().innerRadius(innerRadius).outerRadius(outerRadius)

View File

@@ -153,8 +153,9 @@ export default {
// 计算svg高度
const height = this.rankData.length * (barHeight + margin) + margin
this.svg = d3.select(`#rank-svg-${this.chartId}`).attr('height', height)
const bodyX = 50
const bodyWidth = width - 3 * bodyX
const left = 20
const right = 80
const bodyWidth = width - left - right
// 从大到小排序
let rankData = lodash.cloneDeep(this.rankData)
@@ -176,7 +177,7 @@ export default {
const minWidth = 2
// 渲染柱形
const bars = this.svg.append('g')
.attr('transform', `translate(${bodyX})`)
.attr('transform', `translate(${left})`)
.selectAll()
.data(rankData)
bars.enter()
@@ -200,7 +201,7 @@ export default {
// 文本标签
this.svg.append('g')
.attr('transform', `translate(${bodyX})`)
.attr('transform', `translate(${left})`)
.selectAll()
.data(rankData)
.enter()
@@ -230,7 +231,7 @@ export default {
// 生成标签和矩形
this.svg.append('g')
.attr('transform', `translate(${bodyX})`)
.attr('transform', `translate(${left})`)
.selectAll('text')
.data(rankData)
.enter()

View File

@@ -208,7 +208,7 @@ export default {
.attr('height', height)
.attr('viewBox', [-width / 2, -height / 2, width, height])
const outerRadius = (Math.min(width, height) / 2) * 0.6 // outer radius of pie, in pixels
const outerRadius = (Math.min(width, height) / 2) * 0.8 // outer radius of pie, in pixels
const innerRadius = 20 // inner radius of pie, in pixels (non-zero for donut)
const padAngle = 0 // angular separation between wedges
const radius = 4

View File

@@ -170,17 +170,18 @@ export default {
}
const width = svgDom.getBoundingClientRect().width
const height = svgDom.getBoundingClientRect().height
const margin1 = 100
const margin2 = 50
const vertical = 20
const left = 20
const right = 80
this.svg = d3.select(`#sankey-svg-${this.chartId}`)
const chart = this.svg.append('g').attr('transform', `translate(${margin2}, ${margin2})`)
const chart = this.svg.append('g').attr('transform', `translate(${left}, ${vertical})`)
// 创建桑基图生成器
const sankey = d3Sankey
.sankey()
.nodeWidth(20)
.nodePadding(20)
.size([width - 2 * margin1, height - 2 * margin2])
.size([width - 2 * left - right, height - 2 * vertical])
.nodeId((d) => d.node)
const nodesData = lodash.cloneDeep(this.nodesData)
const linksData = lodash.cloneDeep(this.linksData)