`

jsplumb综合记录

阅读更多
var firstInstance = jsPlumb.getInstance();
firstInstance.importDefaults({
  Connector : [ "Bezier", { curviness: 150 } ],
  Anchors : [ "TopCenter", "BottomCenter" ]
});

firstInstance.connect({
  source:"element1", 
  target:"element2", 
  scope:"someScope" 
});

Changing Element Id
jsPlumb.setId(el, newId)
jsPlumb.setIdChanged(oldId, newId)

Component	Class
Endpoint	jsplumb-endpoint
Connector	jsplumb-connector
Overlay	jsplumb-overlay

set container
jsPlumb.Defaults.Container
jsPlumb.setContainer($("body"));
jsPlumb.setContainer(document.getElementById("foo"));
jsPlumb.setContainer("containerId");

Also Important If you happen to be using jsPlumb's draggable method to make other parts of your UI draggable (ie. not just things you're plumbing together), 
be careful not to call draggable on the element that is acting as the Container for the current instance, or you will see some odd situations occur when dragging. 
It is suggested that the best thing to do if you wish to use jsPlumb to enable dragging on non-plumbed elements is to create a new instance:
var nonPlumbing = jsPlumb.getInstance();
nonPlumbing.draggable("some element");


jsPlumb.addEndpoint(someDiv, { endpoint options });
jsPlumb.connect({ source:someDiv, target:someOtherDiv });


//挂起绘图
//默认每调用一次connect or addEndpoint就会引起关联元素的重绘(因为要画出anchor、endpoint、connector、overlay)
//这样如果有多个connect or addEndpoint操作就会引出多次绘图,在一些慢浏览器上会造成bad experience
//因此应该在需要多次connect or addEndpoint操作之前声明阻止绘图,在操作完成之后再一次过把全部图画出来(默认第二个参数为true时会调用repaintEverything方法)
jsPlumb.setSuspendDrawing(true);
...
- load up all your data here -
...
jsPlumb.setSuspendDrawing(false, true);
或者使用函数模版
jsPlumb.batch(fn, [doNotRepaintAfterwards]);	//	第二个参数设置为true时,不会把图画出来

------------------------------------------------
Anchor用来设置position和rotation

模版:
jsPlumb.addEndpoint("someElement", {
  endpoint:"Dot",
  anchor:[ 0.5, 1, 0, 1, 0, 50 ]
});

anchor:[ 0.5, 1, 0, 1, 0, 50 ]	
前两个是设置anchor的x、y坐标的(相对于someElement元素),取值范围为0-1,是一个百分比数值,x表示相对于someElement的宽度,y表示相对于someElement的高度
接着的两个参数是设置曲线的发射方向的,取值范围是1、0、-1,例如[-1,0]表示曲线由端点的左方发出,[0,1]表示曲线由端点的下方发出,[-1,1]表示曲线有端点的左下方发出
最后两个参数是设置端点离端点设定位置(就是最开始的两个参数所设定的位置)的远离距离的,也就是端点最后确定展示的位置

jsPlumb.addEndpoint("someDiv", {
    endpoint:"Dot",
    anchor:[ "Perimeter", { shape:"Square", anchorCount:150 }]
});
//anchor:["Continuous", { faces:[ "top", "left" ] } ]
------------------------------------------------

connector
"Straight", {"stub": 10, "gap": 0}  stub与gap都是设置直线离点的偏移距离

You can specify one or more overlays when making a call to jsPlumb.connect, jsPlumb.addEndpoint or 
jsPlumb.makeSource (but not jsPlumb.makeTarget: overlays are always derived from what the source of a Connection defines) 

------------------------------------------------

addEndpoint与makeSource、makeTarget的区别是前者会在元素上生成端点,而后者不会生成端点,只有在真正连接时才生成端点

Note that this does not affect existing Connections. It affects only Connections that are created after you set the new Type(s) on an Endpoint.
为端点添加type,并不会也作用到已有的connection,只会作用到之后从这端点拖拽出的connection

var endpointOptions = { 
  isTarget:true, 
  uniqueEndpoint:true,	//只产生一个端点
  endpoint:"Rectangle", 
  paintStyle:{ fillStyle:"gray" } 
};

connection很多特性默认来自endpoint的属性,而作为有source,则connection和target的特性默认来自source

------------------------------------------------

var arrowCommon = { foldback: 0.7, fillStyle: color, width: 14 },
	overlays = [
		[ "Arrow", { location: 0.7 }, arrowCommon ],
		[ "Arrow", { location: 0.3, direction: -1 }, arrowCommon ]
	];
instance.connect({source:"chartWindow2", target:"chartWindow5", overlays: overlays});	//这种声明了源和目的的只会展示一个arrow(由源点指向目的点的)
instance.connect({uuids: ["chartWindow3-bottom", "chartWindow6-top" ], overlays: overlays, detachable: true, reattach: true});//这种没有声明源和目的,会生成两个arrow

------------------------------------------------

sample:
jsPlumb.connect({
  ...
  overlays:[ 
    "Arrow", 
      [ "Label", { label:"foo", location:0.25, id:"myLabel" } ]
    ],
  ...
});

var e = jsPlumb.addEndpoint("someElement");
e.addOverlay([ "Arrow", { width:10, height:10, id:"arrow" }]); 

var c = jsPlumb.connect({
  source:"d1", 
  target:"d2", 
  overlays:[
    [ "Label", {label:"FOO", id:"label"}]
  ] 
});
var label = c.getOverlay("label");
/*	显示隐藏overlay的方法
	// now you can hide this label:
	label.setVisible(false);
	// there are also hide/show methods:
	label.show();
	label.hide();
	//或者
	c.hideOverlay("label");
	c.showOverlay("label");
	c.removeOverlay("label");
*/
console.log("Label is currently", label.getLabel());
label.setLabel("BAR");
console.log("Label is now", label.getLabel());

Both Connections and Endpoints support Label Overlays, and because changing labels is quite a common operation, 
setLabel and getLabel methods have been added to these objects:
var conn = jsPlumb.connect({
  source:"d1", 
  target:"d2",
  label:"FOO"
});
console.log("Label is currently", conn.getLabel());
conn.setLabel("BAR");
console.log("Label is now", conn.getLabel());
//setLabel through function
conn.setLabel(function(c) {
  var s = new Date();
  return s.getTime() + "milliseconds have elapsed since 01/01/1970";
});

//自定义overlay
var conn = jsPlumb.connect({
  source:"d1",
  target:"d2",
  paintStyle:{
    strokeStyle:"red",
    lineWidth:3
  },
  overlays:[
    ["Custom", {
      create:function(component) {
        return $("<select id='myDropDown'><option value='foo'>foo</option><option value='bar'>bar</option></select>");                
      },
      location:0.7,
      id:"customOverlay"
    }]
  ]
});

var common = {
    cssClass:"myCssClass"
};
jsPlumb.connect({
  source:"someDiv",
  target:"someOtherDiv",
  anchor:[ "Continuous", { faces:["top","bottom"] }],
  endpoint:[ "Dot", { radius:5, hoverClass:"myEndpointHover" }, common ],
  connector:[ "Bezier", { curviness:100 }, common ],
  overlays: [
        [ "Arrow", { foldback:0.2 }, common ],
        [ "Label", { cssClass:"labelClass" } ]  
    ]
});


 

分享到:
评论

相关推荐

    jsPlumb_demo11.rar

    jsPlumb

    jsplumb和jsplumbtoolkit实例

    画流程图的插件,jsplumbtoolkit实例,网上苦苦找不到示例,以上示例也是根据别人的进行了一下扩展,基本可以使用,希望有人再作下详细的扩展

    jsPlumb-2.2.3.js

    jsPlumb-2.2.3.js

    jsplumb-js包.zip

    jsplumb-js包.zip

    jsplumbtoolkit.rar

    jsplumbtoolkit.rar,里面包含css,js,和layer插件,jsplumb该框架适用于必须绘制图表的Web应用程序,例如类似于Visio的应用程序或工作流程设计器等。由于图表项目和连接的所有参数都是非常精细可控的,因此您可以...

    jsPlumb实例

    jsPlumb实例

    jsPlumb-2.2.8-拖拽

    拖拽连接,拖拽连接,拖拽连接,jsPlumb-2.2.8-拖拽 jsPlumb-2.2.8-拖拽

    使用 jsPlumb 绘制拓扑图的通用方法

    使用 jsPlumb 绘制拓扑图的通用方法

    jsplumb-master_jsplumb_

    jsplumb 画图的一些示例,能拖动,能连线布局

    jsPlumb 完整实例

    完整的jsPlumb流程图案例,实现页面初始化流程图,添加删除移动节点,修改节点属性,添加删除连接线,以及保存所有节点连接线等功能

    jsplumb连线的demo

    jsplumb的简单demo

    jsPlumb完整实例

    完整的jsPlumb流程图案例,实现页面初始化流程图,添加删除移动节点,修改节点属性,添加删除连接线,以及保存所有节点连接线等功能

    jsPlumb社区版+demo

    jsPlumb 社区版本,附加原始demo

    一个JsPlumb demo

    一个简单的关于JsPlumb的demo,jsPlumb是一个强大的JavaScript连线库,它可以将html中的元素用箭头、曲线、直线等连接起来,适用于开发Web上的图表、建模工具等。

    jsplumb实例及API

    jsplumb实例及APIjsplumb实例及APIjsplumb实例及APIjsplumb实例及API

    jsplumbtoolkit.js 彻底破解去除域名验证,支持中文 toolkit版本1.14.7,社区版对应2.93版

    jsplumbtoolkit比开源版的强大很多,不过最便宜要3500刀,对于我们这种报着学习态度同志来说确实有点贵了,我去除了限制仅为了学习。 正式使用请大家使用正式授权的版本。 破解了jsplumbtoolkit的域名验证,不报错,...

    jsPlumb-1.7.4

    jsPlumb-1.7.4

    jsplumb中文API

    Jsplumb是Jquery的一个插件,它能够让你用动态的或静态的链接来连接html界面上行的元素,并且从1.1.0版本开始,提供用鼠标拖动来链接。

    最完整的jsPlumb流程图demo

    史上最完整jsPlumb流程图实例,初始化流程图,添加删除移动节点,修改节点名称,添加删除连接线,以及保存所有节点连接线等功能!

    JsPlumb实践资料大全

    包括01.jsPlumb Toolkit库破解过程分析.docx 02.入门笔记.docx 示例demo代码 demo1groups.rar demo2state.rar topodemo(使用 jsPlumb 绘制拓扑图的通用方法).zip 解压密码1

Global site tag (gtag.js) - Google Analytics