fix(视图): AntV 饼图导出图片时标签会错位重叠
This commit is contained in:
parent
3b8e30a850
commit
1f2ce26597
@ -32,6 +32,7 @@ export function basePieOptionAntV(container, chart, action) {
|
|||||||
tooltip: tooltip,
|
tooltip: tooltip,
|
||||||
legend: legend,
|
legend: legend,
|
||||||
animation: false,
|
animation: false,
|
||||||
|
autoFit: false,
|
||||||
pieStyle: {
|
pieStyle: {
|
||||||
lineWidth: 0
|
lineWidth: 0
|
||||||
},
|
},
|
||||||
|
|||||||
@ -34,8 +34,8 @@
|
|||||||
<div
|
<div
|
||||||
:id="chartId"
|
:id="chartId"
|
||||||
ref="chart"
|
ref="chart"
|
||||||
style="width: 100%;overflow: hidden;"
|
style="overflow: hidden;"
|
||||||
:style="{height:chartHeight}"
|
:style="{height:chartHeight, width: chartWidth}"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -118,6 +118,7 @@ export default {
|
|||||||
dynamicAreaCode: null,
|
dynamicAreaCode: null,
|
||||||
borderRadius: '0px',
|
borderRadius: '0px',
|
||||||
chartHeight: '100%',
|
chartHeight: '100%',
|
||||||
|
chartWidth: '100%',
|
||||||
title_class: {
|
title_class: {
|
||||||
margin: '0 0',
|
margin: '0 0',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
@ -170,10 +171,11 @@ export default {
|
|||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
if (this.myChart?.container) {
|
if (this.myChart?.container) {
|
||||||
if (typeof this.myChart.container.getAttribute === 'function') {
|
if (this.myChart.container?.getAttribute?.('size-sensor-id')) {
|
||||||
clear(this.myChart.container)
|
clear(this.myChart.container)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.resizeObserver?.disconnect()
|
||||||
this.myChart?.clear?.()
|
this.myChart?.clear?.()
|
||||||
this.myChart?.unbindSizeSensor?.()
|
this.myChart?.unbindSizeSensor?.()
|
||||||
this.myChart?.unbind?.()
|
this.myChart?.unbind?.()
|
||||||
@ -244,6 +246,7 @@ export default {
|
|||||||
this.initTitle()
|
this.initTitle()
|
||||||
this.calcHeightRightNow(this.drawView)
|
this.calcHeightRightNow(this.drawView)
|
||||||
window.addEventListener('resize', this.chartResize)
|
window.addEventListener('resize', this.chartResize)
|
||||||
|
this.initResizeObserver()
|
||||||
},
|
},
|
||||||
async drawView() {
|
async drawView() {
|
||||||
const chart = JSON.parse(JSON.stringify(this.chart))
|
const chart = JSON.parse(JSON.stringify(this.chart))
|
||||||
@ -304,7 +307,7 @@ export default {
|
|||||||
this.myChart = await baseFlowMapOption(this.chartId, chart, this.antVAction)
|
this.myChart = await baseFlowMapOption(this.chartId, chart, this.antVAction)
|
||||||
} else if (chart.type === 'bidirectional-bar') {
|
} else if (chart.type === 'bidirectional-bar') {
|
||||||
this.myChart = baseBidirectionalBarOptionAntV(this.chartId, chart, this.antVAction)
|
this.myChart = baseBidirectionalBarOptionAntV(this.chartId, chart, this.antVAction)
|
||||||
} else if (chart.type === 'stock-line'){
|
} else if (chart.type === 'stock-line') {
|
||||||
this.myChart = stockLineOptionAntV(this.chartId, chart, this.antVAction)
|
this.myChart = stockLineOptionAntV(this.chartId, chart, this.antVAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,11 +392,11 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
chartResize() {
|
chartResize(callback) {
|
||||||
this.resizeTimer && clearTimeout(this.resizeTimer)
|
this.resizeTimer && clearTimeout(this.resizeTimer)
|
||||||
this.resizeTimer = setTimeout(() => {
|
this.resizeTimer = setTimeout(() => {
|
||||||
this.calcHeightRightNow()
|
this.calcHeightRightNow(callback)
|
||||||
}, 100)
|
}, 300)
|
||||||
},
|
},
|
||||||
trackClick(trackAction) {
|
trackClick(trackAction) {
|
||||||
const idTypeMap = this.chart.data.fields.reduce((pre, next) => {
|
const idTypeMap = this.chart.data.fields.reduce((pre, next) => {
|
||||||
@ -503,18 +506,28 @@ export default {
|
|||||||
calcHeightRightNow(callback) {
|
calcHeightRightNow(callback) {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
if (this.$refs.chartContainer) {
|
if (this.$refs.chartContainer) {
|
||||||
const { offsetHeight } = this.$refs.chartContainer
|
const { offsetHeight, offsetWidth } = this.$refs.chartContainer
|
||||||
let titleHeight = 0
|
let titleHeight = 0
|
||||||
if (this.$refs.title) {
|
if (this.$refs.title) {
|
||||||
titleHeight = this.$refs.title.offsetHeight
|
titleHeight = this.$refs.title.offsetHeight
|
||||||
}
|
}
|
||||||
this.chartHeight = (offsetHeight - titleHeight) + 'px'
|
this.chartHeight = (offsetHeight - titleHeight) + 'px'
|
||||||
|
this.chartWidth = offsetWidth + 'px'
|
||||||
this.$nextTick(() => callback?.())
|
this.$nextTick(() => callback?.())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
initRemark() {
|
initRemark() {
|
||||||
this.remarkCfg = getRemark(this.chart)
|
this.remarkCfg = getRemark(this.chart)
|
||||||
|
},
|
||||||
|
initResizeObserver() {
|
||||||
|
const manualResizeCharts = ['pie', 'pie-donut']
|
||||||
|
if (manualResizeCharts.includes(this.chart.type)) {
|
||||||
|
this.resizeObserver = new ResizeObserver(() => {
|
||||||
|
this.chartResize(this.drawView)
|
||||||
|
})
|
||||||
|
this.resizeObserver.observe(this.$refs.chart)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user