Skip to content

Commit

Permalink
fix: 总览拖拽图表后浮窗位置
Browse files Browse the repository at this point in the history
  • Loading branch information
hanaTsuk1 committed Jul 2, 2024
1 parent cadb8c1 commit da48f87
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/hooks/useEcharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ import type { TooltipComponentPositionCallback } from 'echarts'
export function useEcharts() {
const { bottom, mouseY } = layoutMainInject()
const parentEl = useParentElement()
const { top: parentTop } = useElementBounding(parentEl)

const position: TooltipComponentPositionCallback = (point, _, __, ___, size) => {
if (!parentEl.value)
return [0, 0]

const { top: parentTop } = parentEl.value.getBoundingClientRect()

const [x] = point
const [contentWidth, contentHeight] = size.contentSize
const [viewWidth] = size.viewSize

const offset = 20
let left = x + offset
let top = mouseY.value - parentTop.value
let top = mouseY.value - parentTop

if (x + contentWidth > viewWidth) {
left = x - contentWidth - offset
Expand All @@ -21,7 +25,7 @@ export function useEcharts() {
}

if (mouseY.value + contentHeight > bottom.value)
top = mouseY.value - contentHeight - parentTop.value
top = mouseY.value - contentHeight - parentTop

return [left, top]
}
Expand Down

0 comments on commit da48f87

Please sign in to comment.