fix(视图): AntV 横向柱状图配置多个互动方式顶部会出现遮挡

This commit is contained in:
wisonic-s 2024-04-03 16:55:32 +08:00
parent 1fa3899795
commit b5543222c6
2 changed files with 46 additions and 4 deletions

View File

@ -3936,3 +3936,26 @@ export function parseJson(target) {
}
return JSON.parse(JSON.stringify(target))
}
export function adjustPosition(targetDom, parentDom, clickPosition, offset, initSize) {
const { clientHeight: targetHeight, clientWidth: targetWidth } = targetDom
const { clientHeight: parentHeight, clientWidth: parentWidth } = parentDom
const { x, y } = clickPosition
const { x: offsetX, y: offsetY } = offset
const result = {
x: offsetX ? x + offsetX : x,
y: offsetY ? y + offsetY : y
}
const width = targetWidth ? targetWidth : initSize.width
const height = targetHeight ? targetHeight : initSize.height
if ( result.x + width > parentWidth ) {
result.x = parentWidth - width
}
if (result.y + height > parentHeight) {
result.y = parentHeight - height
}
if (result.y - height < 0) {
result.y = height
}
return result
}

View File

@ -32,6 +32,7 @@
</div>
</span>
<div
ref="chart"
:id="chartId"
style="width: 100%;overflow: hidden;"
:style="{height:chartHeight}"
@ -43,7 +44,7 @@
import { baseLiquid } from '@/views/chart/chart/liquid/liquid'
import { uuid } from 'vue-uuid'
import ViewTrackBar from '@/components/canvas/components/editor/ViewTrackBar'
import { getRemark, hexColorToRGBA } from '@/views/chart/chart/util'
import { adjustPosition, getRemark, hexColorToRGBA } from '@/views/chart/chart/util'
import { baseBarOptionAntV, hBaseBarOptionAntV, baseBidirectionalBarOptionAntV, timeRangeBarOptionAntV } from '@/views/chart/chart/bar/bar_antv'
import { baseAreaOptionAntV, baseLineOptionAntV } from '@/views/chart/chart/line/line_antv'
import { basePieOptionAntV, basePieRoseOptionAntV } from '@/views/chart/chart/pie/pie_antv'
@ -345,9 +346,27 @@ export default {
}
if (this.trackMenu.length < 2) { //
this.trackClick(this.trackMenu[0])
} else { //
this.trackBarStyle.left = param.x + 'px'
this.trackBarStyle.top = (param.y + 10) + 'px'
} else {
//
const menuDom = this.$refs.viewTrack.$el.getElementsByClassName("track-menu")?.[0]
const chartDom = this.$refs.chart
let position = {
x: param.x,
y: param.y
}
const offset = {
x: 0,
y: 10
}
const initSize = {
width: 80,
height: 76
}
if (menuDom && chartDom) {
position = adjustPosition(menuDom, chartDom, param, offset, initSize)
}
this.trackBarStyle.left = position.x + 'px'
this.trackBarStyle.top = position.y + 'px'
this.$refs.viewTrack.trackButtonClick()
}
},