是否可以在sigma.js中制作多色高光弧?

发布于 2025-02-07 20:44:55 字数 1781 浏览 0 评论 0 原文

我正在尝试实现自己的 Hoverrenderer 以使高光具有多种颜色。因此,我在 src/rendering/canvas/hover.ts行58

context.arc(data.x, data.y, data.size + PADDING, 0, Math.PI * 2);
context.closePath();
context.fill();

        const [fillStart, fillEnd, fillRadius] = [0, Math.PI * 2, data.size + PADDING];
        // compute segment arc radian
        const arcRadian = (fillEnd - fillStart) / data.highlightColor.length;

        // draw the highlight ring/arc in different colors specified in highlightColor
        for (let index = 0; index < data.highlightColor.length; index++) {
            context.arc(
                data.x,
                data.y,
                fillRadius + 5,
                fillStart,
                fillStart + arcRadian
            );
            context.fillStyle = data.highlightColor[index];
            context.fill();
            fillStart += arcRadian;
        }
        context.closePath();

即使我的 data.highlightcolor 也将 替换为 ['#ff2301','# d53032','#2f4538'] ,我得到的弧仍然是单色的。 此帖子具有类似的实现并实现了效果我想。 Sigma是否施加了任何限制?

I'm trying to implement my own hoverRenderer to make the highlight ring have multiple colors. So I took the drawHover in src/rendering/canvas/hover.ts line 58 and replaced

context.arc(data.x, data.y, data.size + PADDING, 0, Math.PI * 2);
context.closePath();
context.fill();

with

        const [fillStart, fillEnd, fillRadius] = [0, Math.PI * 2, data.size + PADDING];
        // compute segment arc radian
        const arcRadian = (fillEnd - fillStart) / data.highlightColor.length;

        // draw the highlight ring/arc in different colors specified in highlightColor
        for (let index = 0; index < data.highlightColor.length; index++) {
            context.arc(
                data.x,
                data.y,
                fillRadius + 5,
                fillStart,
                fillStart + arcRadian
            );
            context.fillStyle = data.highlightColor[index];
            context.fill();
            fillStart += arcRadian;
        }
        context.closePath();

Even though my data.highlightColor was set to ['#FF2301', '#D53032', '#2F4538'], the arc I got was still single colored. This post has a similar implementation and achieves the effect I want. Is there any restriction imposed by Sigma that prevents this?

enter image description here

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

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

发布评论

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

评论(1

腻橙味 2025-02-14 20:44:55

事实证明,在每个图纸中需要 beginpath 。以下应该有效

        for (let index = 0; index < data.highlightColor.length; index++) {
            context.beginPath();
            context.arc(
                data.x,
                data.y,
                fillRadius + 5,
                fillStart,
                fillStart + arcRadian
            );
            context.fillStyle = data.highlightColor[index];
            context.fill();
            fillStart += arcRadian;
        }

It turns out beginPath is required in each drawing. The following should work

        for (let index = 0; index < data.highlightColor.length; index++) {
            context.beginPath();
            context.arc(
                data.x,
                data.y,
                fillRadius + 5,
                fillStart,
                fillStart + arcRadian
            );
            context.fillStyle = data.highlightColor[index];
            context.fill();
            fillStart += arcRadian;
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文