RaphaelJS 似乎缺乏形状层次结构

发布于 2024-11-09 00:33:04 字数 151 浏览 5 评论 0原文

拉斐尔似乎缺乏形状层次?

我无法创建一个较小的圆“附加”到一个较大的圆,并且知道当较大的圆被缩放/平移时它会被缩放/平移。

类似地,如果我将元素放入集合中,拖动处理程序将单独连接到形状,并且在其回调中我没有该集合的句柄。

我是否忽略了什么?

Raphael seems to lack shape hierarchies?

I can't create a smaller circle "attached" to a larger circle, and know that it will be scaled/translated when the larger one is.

Similarly, if i put elements into a set, the drag handler connects to shapes individually and in its callbacks i have no handle on the set.

Am i overlooking something?

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

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

发布评论

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

评论(2

留蓝 2024-11-16 00:33:04

这是当前的行为,因为拉斐尔没有为“集合”创建任何实际元素。

This the current behaviour as Raphael does not create any real element for a "set".

贱贱哒 2024-11-16 00:33:04

如果要在集合上启用 Drag'nDrop,可以使用以下代码:

Raphael.el.set_drag = function (aSet) {
    // Enable drag'n drop in a Set
    var startAll = function () {
        // storing original coordinates
        for (var i in this.set.items) {
            var comp = this.set.items[i];
            try {
                comp.attr({opacity: 0.3});
            } catch (ex) {;}
            if (comp.type == "path") {
                comp.ox = comp.getBBox().x;
                comp.oy = comp.getBBox().y;
            }
            else {
                comp.ox = comp.attrs.cx || comp.attrs.x;
                comp.oy = comp.attrs.cy || comp.attrs.y;
            }
        }
    },

    moveAll = function (dx, dy) {
        for (var i in this.set.items) {
            var comp = this.set.items[i];
            if (comp.attrs.cx)             // ellipse
                comp.attr({cx: comp.ox + dx, cy: comp.oy + dy});
            else if (comp.attrs.x)
                comp.attr({x: comp.ox + dx, y: comp.oy + dy});
            else            // path
                comp.translate(comp.ox - comp.getBBox().x + dx, comp.oy - comp.getBBox().y + dy);
        }
    },

    upAll = function () {
        for (var i in this.set.items) {
            var comp = this.set.items[i];
            if (comp.attrs.cx)             // ellipse
                comp.attr({cx: comp.ox, cy: comp.oy + dy});
            else if (comp.attrs.x)
                comp.attr({x: comp.ox, y: comp.oy + dy});
            else            // path
                comp.translate(comp.ox , comp.oy - comp.getBBox().y + dy);
            this.set.items[i].attr({opacity: 1});
        }
    };

    this.set = aSet; //create a "set" property on the element
    this.drag(moveAll,startAll,upAll);
    return this;    
}


// Create your elements
var first_element = paper.rect(10,10,100,50).attr({fill:'#f00'});
var second_element = paper.rect(30,300,100,50).attr({fill:'#0f0'});

// Add elements to your set
var myset = paper.set();
myset.push(first_element);
myset.push(second_element);

// Add handler on the elements
first_element.set_drag(myset);
second_element.set_drag(book_set);

If you want to enable Drag'nDrop on a set, you can use the following code :

Raphael.el.set_drag = function (aSet) {
    // Enable drag'n drop in a Set
    var startAll = function () {
        // storing original coordinates
        for (var i in this.set.items) {
            var comp = this.set.items[i];
            try {
                comp.attr({opacity: 0.3});
            } catch (ex) {;}
            if (comp.type == "path") {
                comp.ox = comp.getBBox().x;
                comp.oy = comp.getBBox().y;
            }
            else {
                comp.ox = comp.attrs.cx || comp.attrs.x;
                comp.oy = comp.attrs.cy || comp.attrs.y;
            }
        }
    },

    moveAll = function (dx, dy) {
        for (var i in this.set.items) {
            var comp = this.set.items[i];
            if (comp.attrs.cx)             // ellipse
                comp.attr({cx: comp.ox + dx, cy: comp.oy + dy});
            else if (comp.attrs.x)
                comp.attr({x: comp.ox + dx, y: comp.oy + dy});
            else            // path
                comp.translate(comp.ox - comp.getBBox().x + dx, comp.oy - comp.getBBox().y + dy);
        }
    },

    upAll = function () {
        for (var i in this.set.items) {
            var comp = this.set.items[i];
            if (comp.attrs.cx)             // ellipse
                comp.attr({cx: comp.ox, cy: comp.oy + dy});
            else if (comp.attrs.x)
                comp.attr({x: comp.ox, y: comp.oy + dy});
            else            // path
                comp.translate(comp.ox , comp.oy - comp.getBBox().y + dy);
            this.set.items[i].attr({opacity: 1});
        }
    };

    this.set = aSet; //create a "set" property on the element
    this.drag(moveAll,startAll,upAll);
    return this;    
}


// Create your elements
var first_element = paper.rect(10,10,100,50).attr({fill:'#f00'});
var second_element = paper.rect(30,300,100,50).attr({fill:'#0f0'});

// Add elements to your set
var myset = paper.set();
myset.push(first_element);
myset.push(second_element);

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