antvis/G6

【v5】根据节点的画布坐标,获取画布上节点的浏览器坐标数值不对 #5959

Nancy2013 posted onGitHub

Describe the bug / 问题描述

【实现】 // 通过id获取节点位置 const position = graph.getElementPosition(id); 返回结果:[-108, -48, 0]

// 将节点位置,转换为浏览器坐标 const clientPosition = graph.getClientByCanvas(position); 返回结果:[-108.00000762939453, -47.999996185302734]

【问题】 1、getElementPosition获取的节点位置,是视口坐标还是画布坐标; 2、获取的节点位置,转换为浏览器坐标数值不对; 3、如何获取节点的视口位置,并转换为浏览器坐标;

G6 Version / G6 版本

🆕 5.x

Operating System / 操作系统

Windows

Browser / 浏览器

Chrome


  1. getElementPosition 获取的是画布坐标
  2. 你提到的情况是由于转换过程中的精度问题导致的
  3. 获取视口位置 getViewportByCanvas 获取浏览器坐标:getClientByCanvas
posted by Aarebecca 10 months ago

Fund this Issue

$0.00
Funded

Pull requests