在两个raphael对象之间拖动画一条线

时间:2012-06-19 10:17:52

标签: jquery raphael

我试图在两个Raphael对象之间画一条线连接器,但我不能这样做。

我尝试了jsPlumb,但它只适用于div标签。我想在raphael矩形对象上绘制端点。我已经试过了。

我在下面的代码中使用了jsplumb和Raphael对象:

$("#btnAI, #btnDI").live("click", function() {

        if(this.id == "btnAI")
            text = "AI";
        else
            text = "DI";

        var Execount = "#" + (++ecount);
        var SetAI = paper.set().draggable.enable();
        // create a set to store AI

        var outerRect = getRectangle(paper, 30, 40, 120, 120, "white", "Gray", 5);
        // outer Rectangle
        SetAI.push(outerRect);

        var InnerRect = getRectangle(paper, 40, 50, 100, 100, "#5a5a5a", "Gray", 5);
        // inner Rectangle
        SetAI.push(InnerRect);

        SetAI.push(GetText(paper, 90, 70, text + uniqueId("AI")));
        // text to display which contact

        SetAI.push(GetText(paper, 110, 130, Execount));
        // text for unique id

        SetAI.push(GetLine(paper, 40, 80, 100, 0));
        //upper line

        SetAI.push(GetLine(paper, 40, 120, 100, 0));
        //lower line

        SetAI.push(getRectangle(paper, 99, 90, 41, 20, null, "#FFF", 0));
        //rect to display o/p value

        SetAI.push(getRectangle(paper, 40, 85, 48, 30, null, "#FFF", 0));
        //rect to display o/p value

        jsPlumb.setMouseEventsEnabled(true);
                jsPlumb.setRenderMode();
                jsPlumb.Defaults.Container = 'canvasdiv';
                jsPlumb.Defaults.Overlays = [["Arrow", {
                            location : 0.9
                        }], ["Label", {
                            location : 0.1,
                            label : function(label) {
                                return label.connection.labelText || "";
                            },
                            cssClass : "aLabel"
                        }]];
                outerRect.node.setAttribute("class","jsclass");
                var sourceEndpoint = {
                        endpoint : "Rectangle",
                        paintStyle : {
                            fillStyle : "red",
                            width:20,
                            height:15
                        },
                        isSource : true,
                        connector : ["Flowchart", {
                            stub : 40
                        }],
                        connectorStyle : {
                        lineWidth : 3,
                        joinstyle : "round",
                        strokeStyle :"Green",
                    },
                        connectorHoverStyle :{
                        lineWidth : 3,
                        strokeStyle : "#2e2aF8"
                    },
                        dropOptions : {
                            hoverClass : "hover",
                            activeClass : "active",
                            zIndex:1000
                        },
                }

                var targetEndpoint = {
                        endpoint : "Rectangle",
                        paintStyle : {
                            fillStyle : "green",
                            width:20,
                            height:15
                        },
                        isTarget : true,
                        connector : ["Flowchart", {
                            stub : 40
                        }],
                        connectorStyle : {
                        strokeStyle : "#FF3333",
                        lineWidth : 2
                    },
                    dropOptions : {
                            hoverClass : "hover",
                            activeClass : "active"
                        },
                }

                jsPlumb.addEndpoint(outerRect.node, {anchor : "BottomCenter"}, sourceEndpoint);
                //jsPlumb.addEndpoint(outerRect.node, {anchor : "RightMiddle"}, targetEndpoint);
                jsPlumb.draggable($(".jsclass"));

请为此提供帮助。

1 个答案:

答案 0 :(得分:0)

一个好的jQuery线条绘制程序是jsPlumb