树图定向 [英] Tree drawing orientation

查看:100
本文介绍了树图定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用树布局做了一个稍微修改的树。我需要定向树从右到左,而不是从默认的左到右的方向。什么是正确的和适当的d3:ish的方式来做这个?

I've made a slightly modified tree using the tree layout. I needed to orient the tree right-to-left instead of the regular left-to-right orientation that's the default. What is the right and proper d3:ish way to do this?

我最后这样做通过简单地颠倒x坐标创建布局后,但我觉得这是一个黑客。当然有更优雅的东西吗?

I ended up doing this by simply inverting the x coordinate after creating the layout but I feel that this is a hack. Surely there is something more elegant?

我想到了围绕中心做一个SVG旋转,但是我必须旋转标签来得到正确的文本。

I thought about doing an SVG rotation around the center but then I'd have to rotate the labels to get the text right way around. That didn't feel right either.

推荐答案

树布局在宽度的任意坐标空间中计算节点位置 x )和深度( y 。要更改布局的方向,请更改从布局的坐标空间到SVG像素坐标的映射。如果您不想手动进行映射,可以使用

The tree layout computes node positions in an arbitrary coordinate space of breadth (x) and depth (y). To change the orientation of the layout, change the mapping from the layout’s coordinate space to SVG pixel coordinates. If you prefer not to do the mapping manually, you could use quantitative scales to specify a more intuitive (but more verbose) mapping.

这里是一个显示四个不同方向的示例:

Here’s an example showing four different orientations:

  • http://bl.ocks.org/3184089

这篇关于树图定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆