Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【V5】坐标系范围 #5400

Closed
BinghuiXie opened this issue Aug 15, 2023 · 2 comments · Fixed by #5447
Closed

【V5】坐标系范围 #5400

BinghuiXie opened this issue Aug 15, 2023 · 2 comments · Fixed by #5447
Assignees
Labels

Comments

@BinghuiXie
Copy link
Contributor

image
坐标系的范围,用上图描述应该是哪一个部分呢?在下图创建坐标系实例的时候,忽略了中间内边距的部分,却把呼吸区域和外边距区域的范围算了进去,没有理解为什么要这样计算
image
或者说:
image
这张图里面的计算逻辑是对的吗?因为很明显可以看出,加了 padding 以后,“坐标系的范围” 和标记绘制区域完全错开了

Originally posted by @BinghuiXie in #5399

@pearmini
Copy link
Member

这里看上去确实有点问题,应该不需要加 margin,我排查一下。

@pearmini
Copy link
Member

坐标系的范围就应该是下图红色区域:

正确创建坐标系应该如下:

 const options = {
    ...layout,
    x: insetLeft,
    y: insetTop,
    width: innerWidth - insetLeft - insetRight,
    height: innerHeight - insetBottom - insetTop,
    transformations: transform.flatMap(useCoordinate),
  };

x 和 y 没有考虑 margin 和 padding 的原因是:在绘制的时候会对 group 进行偏移:

function updateBBox(selection) {
  selection
    .style('x', (d) => d.paddingLeft + d.marginLeft)
    .style('y', (d) => d.paddingTop + d.marginTop)
    .style('width', (d) => d.innerWidth)
    .style('height', (d) => d.innerHeight);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants