向 Raphael 圆添加 ID

发布于 2024-12-06 11:56:52 字数 3473 浏览 1 评论 0原文

我正在尝试与 Raphael 一起制作一个阻力曲线器。

请查找以下内容:

 r.circle(x, y, 6).attr({
                fill: "#ff0000",
                stroke: "none",
                id: "cir1"
            }),

这是我的代码:

$(document).ready(function() {
var r = Raphael("holder", 1583, 600),
    discattr = {
        fill: "#ff0000",
        stroke: "none"
    };
r.rect(9950, 9990, 6199, 4199, 9910, 777777777777).attr({
    stroke: "#000000"
});
r.text(310, 20, "").attr({
    fill: "#fff",
    "font-size": 16
});

function curve(x, y, ax, ay, bx, by, zx, zy, color) {
    var path = [["M", x, y], ["C", ax, ay, bx, by, zx, zy]],
        path2 = [["M", x, y], ["L", ax, ay], ["M", bx, by], ["L", zx, zy]],
        curve = r.path(path).attr({
            stroke: color || Raphael.getColor(),
            "stroke-width": 4,
            "id": "path"
        }),
        controls = r.set(
        r.path(path2).attr({
            stroke: "#000000",
            id: 'path'
        }), r.circle(x, y, 6).attr({
            fill: "#ff0000",
            stroke: "none",
            id: "cir1"
        }), r.circle(ax, ay, 6).attr({
            fill: '#ff0000',
            stroke: 'none',
            'id': 'cir2'
        }), r.circle(bx, by, 6).attr({
            fill: "#ff0000",
            stroke: "none",
            id: "cir3"
        }), r.circle(zx, zy, 6).attr({
            fill: "#ff0000",
            stroke: "none",
            id: "cir4"
        }));
    t = false;
    controls[1].update = function(x, y) {
        var X = this.attr("cx") + x,
            Y = this.attr("cy") + y;
        this.attr({
            cx: X,
            cy: Y
        });
        path[0][1] = X;
        path[0][2] = Y;
        path2[0][1] = X;
        path2[0][2] = Y;
        t = false;
        controls[2].update(x, y);
    };
    controls[2].update = function(x, y) {
        var X = this.attr("cx") + x,
            Y = this.attr("cy") + y;
        this.attr({
            cx: X,
            cy: Y
        });
        path[1][1] = X;
        path[1][2] = Y;
        path2[1][1] = X;
        path2[1][2] = Y;
        t = false;
        curve.attr({
            path: path
        });
        controls[0].attr({
            path: path2
        });
    };
    controls[3].update = function(x, y) {
        var X = this.attr("cx") + x,
            Y = this.attr("cy") + y;
        this.attr({
            cx: X,
            cy: Y
        });
        path[1][3] = X;
        path[1][4] = Y;
        path2[2][1] = X;
        path2[2][2] = Y;
        t = false;
        curve.attr({
            path: path
        });
        controls[0].attr({
            path: path2
        });
    };
    controls[4].update = function(x, y) {
        var X = this.attr("cx") + x,
            Y = this.attr("cy") + y;
        this.attr({
            cx: X,
            cy: Y
        });
        path[1][5] = X;
        path[1][6] = Y;
        t = false;
        path2[3][1] = X;
        path2[3][2] = Y;
        controls[3].update(x, y);
    };
    controls.drag(move, up);
    t = false;
}

function move(dx, dy) {
    this.update(dx - (this.dx || 0), dy - (this.dy || 0));
    this.dx = dx;
    this.dy = dy;
    t = false;
}

function up() {
    this.dx = this.dy = 0;
    t = false;
}
// curve(70, 100, 80, 100, 130, 154, 170, 200, "hsb(0, .75, .75)");
curve(100, 100, 100, 100, 100, 100, 100, 100, "#ff0000");
});

我正在尝试向每个圆圈添加一个id,但由于某种原因它不起作用。

I'm trying to make a drag curver with Raphael.

Please look for this:

 r.circle(x, y, 6).attr({
                fill: "#ff0000",
                stroke: "none",
                id: "cir1"
            }),

This is my code:

$(document).ready(function() {
var r = Raphael("holder", 1583, 600),
    discattr = {
        fill: "#ff0000",
        stroke: "none"
    };
r.rect(9950, 9990, 6199, 4199, 9910, 777777777777).attr({
    stroke: "#000000"
});
r.text(310, 20, "").attr({
    fill: "#fff",
    "font-size": 16
});

function curve(x, y, ax, ay, bx, by, zx, zy, color) {
    var path = [["M", x, y], ["C", ax, ay, bx, by, zx, zy]],
        path2 = [["M", x, y], ["L", ax, ay], ["M", bx, by], ["L", zx, zy]],
        curve = r.path(path).attr({
            stroke: color || Raphael.getColor(),
            "stroke-width": 4,
            "id": "path"
        }),
        controls = r.set(
        r.path(path2).attr({
            stroke: "#000000",
            id: 'path'
        }), r.circle(x, y, 6).attr({
            fill: "#ff0000",
            stroke: "none",
            id: "cir1"
        }), r.circle(ax, ay, 6).attr({
            fill: '#ff0000',
            stroke: 'none',
            'id': 'cir2'
        }), r.circle(bx, by, 6).attr({
            fill: "#ff0000",
            stroke: "none",
            id: "cir3"
        }), r.circle(zx, zy, 6).attr({
            fill: "#ff0000",
            stroke: "none",
            id: "cir4"
        }));
    t = false;
    controls[1].update = function(x, y) {
        var X = this.attr("cx") + x,
            Y = this.attr("cy") + y;
        this.attr({
            cx: X,
            cy: Y
        });
        path[0][1] = X;
        path[0][2] = Y;
        path2[0][1] = X;
        path2[0][2] = Y;
        t = false;
        controls[2].update(x, y);
    };
    controls[2].update = function(x, y) {
        var X = this.attr("cx") + x,
            Y = this.attr("cy") + y;
        this.attr({
            cx: X,
            cy: Y
        });
        path[1][1] = X;
        path[1][2] = Y;
        path2[1][1] = X;
        path2[1][2] = Y;
        t = false;
        curve.attr({
            path: path
        });
        controls[0].attr({
            path: path2
        });
    };
    controls[3].update = function(x, y) {
        var X = this.attr("cx") + x,
            Y = this.attr("cy") + y;
        this.attr({
            cx: X,
            cy: Y
        });
        path[1][3] = X;
        path[1][4] = Y;
        path2[2][1] = X;
        path2[2][2] = Y;
        t = false;
        curve.attr({
            path: path
        });
        controls[0].attr({
            path: path2
        });
    };
    controls[4].update = function(x, y) {
        var X = this.attr("cx") + x,
            Y = this.attr("cy") + y;
        this.attr({
            cx: X,
            cy: Y
        });
        path[1][5] = X;
        path[1][6] = Y;
        t = false;
        path2[3][1] = X;
        path2[3][2] = Y;
        controls[3].update(x, y);
    };
    controls.drag(move, up);
    t = false;
}

function move(dx, dy) {
    this.update(dx - (this.dx || 0), dy - (this.dy || 0));
    this.dx = dx;
    this.dy = dy;
    t = false;
}

function up() {
    this.dx = this.dy = 0;
    t = false;
}
// curve(70, 100, 80, 100, 130, 154, 170, 200, "hsb(0, .75, .75)");
curve(100, 100, 100, 100, 100, 100, 100, 100, "#ff0000");
});

I am trying to add an id to each circle, but it is not working for some reason.

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

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

发布评论

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

评论(1

从来不烧饼 2024-12-13 11:56:52

您可以使用 element.data() 添加其他数据,例如自定义 ID函数。您的圈子代码片段可能如下:

r.circle(x, y, 6).attr({
    fill: "#ff0000",
    stroke: "none"
}).data("id", "cir1"),

You can add miscellaneous data, like a custom ID, using the element.data() function. Your circle code snippet could be the following:

r.circle(x, y, 6).attr({
    fill: "#ff0000",
    stroke: "none"
}).data("id", "cir1"),
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文