D3JS:放大在悬停的阳光

发布于 2025-01-29 21:58:47 字数 1574 浏览 6 评论 0 原文

我将D3.HierArchy与D3.分区一起设置阳光图表。我将值和尺寸设置为erSarchy.count()(将孩子计数并将计数设置为每个节点的值),以便在每个级别上同样尺寸的Sunburst图表。

是否可以在悬停(而不改变其位置)上仅扩大朝阳图表的一部分?如果我使用EG变换量表(1.5),则位置也会向朝阳图的外界移动。

编辑://

我使用此代码来生成阳光弧:

const arc = d3.arc<d3.HierarchyRectangularNode<any>>()
            .startAngle(d => d.x0)
            .endAngle(d => d.x1)
            .padAngle(d => Math.min((d.x1 - d.x0) / 2, 0.005))
            .padRadius(width / 4)
            .innerRadius(d => d.y0)
            .outerRadius(d => d.y1 - 1)

如果我在建议的方法中应用值:

                    const ringInnerRadius = i.y0;
                    const ringOuterRadius = i.y1 -1;

                    const ringMidRadius = (ringInnerRadius + ringOuterRadius) / 2;

                    const sectorStartAngle = i.x0;
                    const sectorEndAngle = i.x1;
                    const sectorMidAngle = (sectorStartAngle + sectorEndAngle) / 2;

                    const scale = 1.5;

                    const transX = (1-scale) * ringMidRadius * Math.cos(sectorMidAngle);
                    const transY = (1-scale) * ringMidRadius * Math.sin(sectorMidAngle);

我提出以下问题。在这里,您可以从中心看到第一个级别,该级别被转移并立即远离中心:

“在此处输入图像说明”

I use a d3.hierarchy together with d3.partition to setup a sunburst chart. I set the value and the size with hierarchy.count() (which counts the children and set the count as value for each node) in order to equally size the sunburst chart on each level.

parcel

Is it possible to enlarge only one section of the sunburst chart on hover (without changing its position)? If I use e.g. transform scale(1.5) also the position is shifted towards the outer bounds of the sunburst chart.

Edit://

I used this code to generate the sunburst arcs:

const arc = d3.arc<d3.HierarchyRectangularNode<any>>()
            .startAngle(d => d.x0)
            .endAngle(d => d.x1)
            .padAngle(d => Math.min((d.x1 - d.x0) / 2, 0.005))
            .padRadius(width / 4)
            .innerRadius(d => d.y0)
            .outerRadius(d => d.y1 - 1)

if i apply the values in the suggested method:

                    const ringInnerRadius = i.y0;
                    const ringOuterRadius = i.y1 -1;

                    const ringMidRadius = (ringInnerRadius + ringOuterRadius) / 2;

                    const sectorStartAngle = i.x0;
                    const sectorEndAngle = i.x1;
                    const sectorMidAngle = (sectorStartAngle + sectorEndAngle) / 2;

                    const scale = 1.5;

                    const transX = (1-scale) * ringMidRadius * Math.cos(sectorMidAngle);
                    const transY = (1-scale) * ringMidRadius * Math.sin(sectorMidAngle);

I come up with the following issue. Here you see the first level from the center, which is shifted and turned right away from the center:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笨死的猪 2025-02-05 21:58:47

如果您知道该扇区中心的距离和角度,则可以将扇区缩放1.5,然后将其转换回其所属的位置。

const ringInnerRadius = ...;
const ringOuterRadius = ...;
const ringMidRadius = (ringInnerRadius + ringOuterRadius) / 2;

const sectorStartAngle = ...;
const sectorEndAngle = ...;
const sectorMidAngle = (sectorStartAngle + sectorEndAngle) / 2;

const scale = 1.5;

const transX = (1-scale) * ringMidRadius * Math.cos(sectorMidAngle);
const transY = (1-scale) * ringMidRadius * Math.sin(sectorMidAngle);

sector.attr("transform", `translate(${transX} ${transY}) scale(1.5)`)

If you know the distance and angle of the center of the sector, then you can scale the sector by 1.5 and then translate it back to where it belongs.

const ringInnerRadius = ...;
const ringOuterRadius = ...;
const ringMidRadius = (ringInnerRadius + ringOuterRadius) / 2;

const sectorStartAngle = ...;
const sectorEndAngle = ...;
const sectorMidAngle = (sectorStartAngle + sectorEndAngle) / 2;

const scale = 1.5;

const transX = (1-scale) * ringMidRadius * Math.cos(sectorMidAngle);
const transY = (1-scale) * ringMidRadius * Math.sin(sectorMidAngle);

sector.attr("transform", `translate(${transX} ${transY}) scale(1.5)`)
热血少△年 2025-02-05 21:58:47

这是无法解决的,我也没有工作。现在,我使用了一种名为Sunburst的不同技术,并突出显示不同的部分。我从 D3JS的阳光与扭曲&gt; v4

This is not resolved, and I do not get it working. Now, I use a different technique named sunburst with distortion to highlight different parts. I updated the code from https://bl.ocks.org/mbostock/1306365 (from the all famous Mike Bostock) for d3 v4 and posted the converted code as an answer to my question here: d3js Sunburst with Distortion > v4

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文