├── docs ├── .nojekyll ├── demos │ ├── 07.html │ ├── 01.html │ ├── 02.html │ ├── 03.html │ ├── 04.html │ ├── 18.html │ ├── 08.html │ ├── 05.html │ ├── 10.html │ ├── 06.html │ ├── 11.html │ ├── 14.html │ ├── 16.html │ ├── 15.html │ ├── 13.html │ ├── 12.html │ ├── 09.html │ ├── 19.html │ └── 17.html ├── index.html └── README.md ├── images ├── Jietu20181226-123854.jpg ├── Jietu20190620-133950.jpg ├── 20180227163310_1bVYeW_grid.jpeg ├── 20180626102701_S66sli_petrol.jpeg ├── 20180626102715_wPb7pW_dfd2.jpeg ├── 20180626102608_hCABQQ_summary.jpeg ├── 20180626102646_RPHmnl_example5.jpeg ├── 20180713133303_xif4MK_Screenshot.jpeg ├── 20180227191655_GOJLi1_Jietu20180227-191647.jpeg ├── 20180227192135_1AWJH6_Jietu20180227-192120.jpeg ├── 20180227192811_AA9fXd_Jietu20180227-192758.jpeg ├── 20180227193308_wYaELY_Jietu20180227-193254.jpeg ├── 20180227193546_yg6Z4L_Jietu20180227-193527.jpeg ├── 20180227193801_OejsPz_Jietu20180227-193752.jpeg ├── 20180227194136_zIlkwP_Jietu20180227-194127.jpeg ├── 20180227195351_B18Pal_Jietu20180227-195338.jpeg ├── 20180227195859_fFawMs_Jietu20180227-195844.jpeg ├── 20180227200100_wEX1FU_Jietu20180227-200047.jpeg ├── 20180414105705_PbucQp_Jietu20180414-105646.jpeg ├── 20180415224517_SK0PUc_Jietu20180415-224454.jpeg ├── 20180425224658_pFg6BG_Jietu20180425-224640.jpeg ├── 20180509225507_aRk1UV_Jietu20180509-225433.jpeg ├── 20180611171125_1LBQdG_Jietu20180611-171117.jpeg ├── 20180611171213_XS3vL4_Jietu20180611-171206.jpeg ├── 20180611171335_XWq41h_Jietu20180611-171327.jpeg ├── 20180611171745_mwZc75_Jietu20180611-171731.jpeg ├── 20180626102133_EAJjjY_Jietu20180626-102115.jpeg ├── 20180628154158_hryb52_Jietu20180628-153918.jpeg ├── 20180713130405_UnzvUT_Jietu20180713-130335.jpeg ├── 20180713131254_dLSYLW_Jietu20180713-131238.jpeg ├── 20180713132452_xkiWxs_Jietu20180713-132430.jpeg ├── 20180816163348_S3yJbT_Jietu20180816-163228.jpeg ├── 20181015195143_kNd9Sd_Jietu20181015-194116.jpeg ├── 20181023204322_QVz4Cm_Jietu20181023-204022.jpeg ├── 20181023204336_p2KxaX_Jietu20181023-204054.jpeg ├── 20181023210318_r0MaTA_Jietu20181023-210309.jpeg ├── 20180227184229_wKfyUd_jsPlumb_Diagram_Example.jpeg └── 20180227151857_Pu4O9c_jsPlumb-Connector-Components.jpeg ├── api ├── anchors.js └── overlays-api.js └── README.md /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /images/Jietu20181226-123854.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/Jietu20181226-123854.jpg -------------------------------------------------------------------------------- /images/Jietu20190620-133950.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/Jietu20190620-133950.jpg -------------------------------------------------------------------------------- /images/20180227163310_1bVYeW_grid.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227163310_1bVYeW_grid.jpeg -------------------------------------------------------------------------------- /images/20180626102701_S66sli_petrol.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180626102701_S66sli_petrol.jpeg -------------------------------------------------------------------------------- /images/20180626102715_wPb7pW_dfd2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180626102715_wPb7pW_dfd2.jpeg -------------------------------------------------------------------------------- /images/20180626102608_hCABQQ_summary.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180626102608_hCABQQ_summary.jpeg -------------------------------------------------------------------------------- /images/20180626102646_RPHmnl_example5.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180626102646_RPHmnl_example5.jpeg -------------------------------------------------------------------------------- /images/20180713133303_xif4MK_Screenshot.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180713133303_xif4MK_Screenshot.jpeg -------------------------------------------------------------------------------- /images/20180227191655_GOJLi1_Jietu20180227-191647.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227191655_GOJLi1_Jietu20180227-191647.jpeg -------------------------------------------------------------------------------- /images/20180227192135_1AWJH6_Jietu20180227-192120.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227192135_1AWJH6_Jietu20180227-192120.jpeg -------------------------------------------------------------------------------- /images/20180227192811_AA9fXd_Jietu20180227-192758.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227192811_AA9fXd_Jietu20180227-192758.jpeg -------------------------------------------------------------------------------- /images/20180227193308_wYaELY_Jietu20180227-193254.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227193308_wYaELY_Jietu20180227-193254.jpeg -------------------------------------------------------------------------------- /images/20180227193546_yg6Z4L_Jietu20180227-193527.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227193546_yg6Z4L_Jietu20180227-193527.jpeg -------------------------------------------------------------------------------- /images/20180227193801_OejsPz_Jietu20180227-193752.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227193801_OejsPz_Jietu20180227-193752.jpeg -------------------------------------------------------------------------------- /images/20180227194136_zIlkwP_Jietu20180227-194127.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227194136_zIlkwP_Jietu20180227-194127.jpeg -------------------------------------------------------------------------------- /images/20180227195351_B18Pal_Jietu20180227-195338.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227195351_B18Pal_Jietu20180227-195338.jpeg -------------------------------------------------------------------------------- /images/20180227195859_fFawMs_Jietu20180227-195844.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227195859_fFawMs_Jietu20180227-195844.jpeg -------------------------------------------------------------------------------- /images/20180227200100_wEX1FU_Jietu20180227-200047.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227200100_wEX1FU_Jietu20180227-200047.jpeg -------------------------------------------------------------------------------- /images/20180414105705_PbucQp_Jietu20180414-105646.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180414105705_PbucQp_Jietu20180414-105646.jpeg -------------------------------------------------------------------------------- /images/20180415224517_SK0PUc_Jietu20180415-224454.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180415224517_SK0PUc_Jietu20180415-224454.jpeg -------------------------------------------------------------------------------- /images/20180425224658_pFg6BG_Jietu20180425-224640.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180425224658_pFg6BG_Jietu20180425-224640.jpeg -------------------------------------------------------------------------------- /images/20180509225507_aRk1UV_Jietu20180509-225433.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180509225507_aRk1UV_Jietu20180509-225433.jpeg -------------------------------------------------------------------------------- /images/20180611171125_1LBQdG_Jietu20180611-171117.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180611171125_1LBQdG_Jietu20180611-171117.jpeg -------------------------------------------------------------------------------- /images/20180611171213_XS3vL4_Jietu20180611-171206.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180611171213_XS3vL4_Jietu20180611-171206.jpeg -------------------------------------------------------------------------------- /images/20180611171335_XWq41h_Jietu20180611-171327.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180611171335_XWq41h_Jietu20180611-171327.jpeg -------------------------------------------------------------------------------- /images/20180611171745_mwZc75_Jietu20180611-171731.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180611171745_mwZc75_Jietu20180611-171731.jpeg -------------------------------------------------------------------------------- /images/20180626102133_EAJjjY_Jietu20180626-102115.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180626102133_EAJjjY_Jietu20180626-102115.jpeg -------------------------------------------------------------------------------- /images/20180628154158_hryb52_Jietu20180628-153918.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180628154158_hryb52_Jietu20180628-153918.jpeg -------------------------------------------------------------------------------- /images/20180713130405_UnzvUT_Jietu20180713-130335.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180713130405_UnzvUT_Jietu20180713-130335.jpeg -------------------------------------------------------------------------------- /images/20180713131254_dLSYLW_Jietu20180713-131238.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180713131254_dLSYLW_Jietu20180713-131238.jpeg -------------------------------------------------------------------------------- /images/20180713132452_xkiWxs_Jietu20180713-132430.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180713132452_xkiWxs_Jietu20180713-132430.jpeg -------------------------------------------------------------------------------- /images/20180816163348_S3yJbT_Jietu20180816-163228.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180816163348_S3yJbT_Jietu20180816-163228.jpeg -------------------------------------------------------------------------------- /images/20181015195143_kNd9Sd_Jietu20181015-194116.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20181015195143_kNd9Sd_Jietu20181015-194116.jpeg -------------------------------------------------------------------------------- /images/20181023204322_QVz4Cm_Jietu20181023-204022.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20181023204322_QVz4Cm_Jietu20181023-204022.jpeg -------------------------------------------------------------------------------- /images/20181023204336_p2KxaX_Jietu20181023-204054.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20181023204336_p2KxaX_Jietu20181023-204054.jpeg -------------------------------------------------------------------------------- /images/20181023210318_r0MaTA_Jietu20181023-210309.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20181023210318_r0MaTA_Jietu20181023-210309.jpeg -------------------------------------------------------------------------------- /images/20180227184229_wKfyUd_jsPlumb_Diagram_Example.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227184229_wKfyUd_jsPlumb_Diagram_Example.jpeg -------------------------------------------------------------------------------- /images/20180227151857_Pu4O9c_jsPlumb-Connector-Components.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangduanduan/jsplumb-chinese-tutorial/HEAD/images/20180227151857_Pu4O9c_jsPlumb-Connector-Components.jpeg -------------------------------------------------------------------------------- /docs/demos/07.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 24 | 25 | 26 | 27 |
28 |
29 |
30 |
31 | 32 | 33 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | jsplumb 中文基础教程 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /docs/demos/01.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 24 | 25 | 26 | 27 |
28 |
29 |
30 |
31 | 32 | 33 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /docs/demos/02.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 24 | 25 | 26 | 27 |
28 |
29 |
30 |
31 | 32 | 33 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /docs/demos/03.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 24 | 25 | 26 | 27 |
28 |
29 |
30 |
31 | 32 | 33 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /docs/demos/04.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 24 | 25 | 26 | 27 |
28 |
29 |
30 |
31 | 32 | 33 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /docs/demos/18.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 25 | 26 | 27 | 28 |
29 |
A
30 |
B
31 |
32 | 33 | 34 | 35 | 36 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /docs/demos/08.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 24 | 25 | 26 | 27 |
28 |
29 |
30 |
31 | 32 | 33 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /docs/demos/05.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 24 | 25 | 26 | 27 |
28 |
29 |
30 |
31 | 32 | 33 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /docs/demos/10.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 25 | 26 | 27 | 28 |
29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /docs/demos/06.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 24 | 25 | 26 | 27 |
28 |
29 |
30 |
31 | 32 | 33 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /docs/demos/11.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 25 | 26 | 27 | 28 |
29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /docs/demos/14.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 25 | 26 | 27 | 28 |
29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /docs/demos/16.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 24 | 25 | 26 | 27 |
28 |
29 |
30 |
31 | 32 | 33 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /docs/demos/15.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 25 | 26 | 27 | 28 |
29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /docs/demos/13.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 25 | 26 | 27 | 28 |
29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /docs/demos/12.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 27 | 28 | 29 | 30 |
31 |
32 |
33 |
34 | 35 | 36 | 37 | 38 | 39 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /docs/demos/09.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 24 | 25 | 26 | 27 |
28 |
29 |
30 |
31 | 32 | 33 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /docs/demos/19.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 25 | 26 | 27 | 28 |
29 |
A
30 |
B
31 |
32 | 33 | 34 | 35 | 36 | 37 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /api/anchors.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * An Anchor that is located at the top center of the element. 4 | * @class Anchors.Top 5 | */ 6 | /** 7 | * An Anchor that is located at the top center of the element. 8 | * @class Anchors.TopCenter 9 | * @deprecated Use `Top` instead. 10 | */ 11 | /** 12 | * An Anchor that is located at the bottom center of the element. 13 | * @class Anchors.Bottom 14 | */ 15 | /** 16 | * An Anchor that is located at the bottom center of the element. 17 | * @class Anchors.BottomCenter 18 | * @deprecated Use `Bottom` instead. 19 | */ 20 | /** 21 | * An Anchor that is located at the left middle of the element. 22 | * @class Anchors.Left 23 | */ 24 | /** 25 | * An Anchor that is located at the left middle of the element. 26 | * @class Anchors.LeftMiddle 27 | * @deprecated Use `Left` instead. 28 | */ 29 | /** 30 | * An Anchor that is located at the right middle of the element. 31 | * @class Anchors.Right 32 | */ 33 | /** 34 | * An Anchor that is located at the right middle of the element. 35 | * @class Anchors.RightMiddle 36 | * @deprecated Use `Right` instead. 37 | */ 38 | /** 39 | * An Anchor that is located at the center of the element. 40 | * @class Anchors.Center 41 | */ 42 | /** 43 | * An Anchor that is located at the top right corner of the element. 44 | * @class Anchors.TopRight 45 | */ 46 | /** 47 | * An Anchor that is located at the bottom right corner of the element. 48 | * @class Anchors.BottomRight 49 | */ 50 | /** 51 | * An Anchor that is located at the top left corner of the element. 52 | * @class Anchors.TopLeft 53 | */ 54 | /** 55 | * An Anchor that is located at the bottom left corner of the element. 56 | * @class Anchors.BottomLeft 57 | */ 58 | /** 59 | * Default DynamicAnchors - chooses from Top, Right, Bottom, Left. 60 | * @class Anchors.AutoDefault 61 | */ 62 | /** 63 | * An Anchor whose location is assigned at connection time, through an AnchorPositionFinder. Used in conjunction 64 | * with the `makeTarget` function. jsPlumb has two of these - `Fixed` and `Grid`, and you can also write your own. 65 | * @class Anchors.Assign 66 | */ 67 | 68 | /** 69 | * A continuous anchor that uses only the left edge of the element. 70 | * @class Anchors.ContinuousLeft 71 | */ 72 | /** 73 | * A continuous anchor that uses only the top edge of the element. 74 | * @class Anchors.ContinuousTop 75 | */ 76 | /** 77 | * A continuous anchor that uses only the bottom edge of the element. 78 | * @class Anchors.ContinuousBottom 79 | */ 80 | /** 81 | * A continuous anchor that uses only the right edge of the element. 82 | * @class Anchors.ContinuousRight 83 | */ 84 | 85 | /** 86 | * An Anchor that tracks the other element in the connection, choosing the closest face. 87 | * @class Anchors.Continuous 88 | * @constructor 89 | * @param {Object} [params] Constructor parameters 90 | * @param {String[]} [params.faces] Optional array of faces for the anchor. Valid values are `"top"`, `"left"`, `"bottom"` and `"right"`. 91 | */ 92 | 93 | /** 94 | * An Anchor that tracks the perimeter of some shape, approximating it with a given number of dynamically 95 | * positioned locations. 96 | * @class Anchors.Perimeter 97 | * @constructor 98 | * @param {Object} params Constructor parameters 99 | * @param {Integer} [params.anchorCount=60] Optional number of anchors to use to approximate the perimeter. default is 60. 100 | * @param {String} params.shape Required. the name of the shape. Valid values are 'rectangle', 'square', 'ellipse', 'circle', 'triangle' and 'diamond' 101 | * @param {Number} [params.rotation] Optional rotation, in degrees, to apply. 102 | */ -------------------------------------------------------------------------------- /docs/demos/17.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 24 | 25 | 26 | 27 |
28 |
29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # 1. jsplumb 中文基础教程 2 | 3 | 后续更新会在仓库:https://github.com/wangduanduan/jsplumb-chinese-tutorial.git 4 | 5 | 本文的图片是托管于七牛云的,由于使用的是测试域名,可能不知道哪天,图片就无法显示了。不过每个例子都有简单的在线demo, demo剩千图,还是能看懂的。 6 | 7 | ## 1.1. 什么是jsplumb? 8 | 你有没有想过在你的网站上展示图表或者甚至在浏览器应用程序中使用它?用jsPlumb你可以!它是完全免费的,并根据MIT许可证提供。您可以直接从jsPlumb github网站下载框架。 9 | 10 | 该项目主要由Simon Porritt开发,他在澳大利亚西德尼担任网络开发人员。 jsPlumb由他积极开发。作为许多优秀的开发人员,他似乎更喜欢开发代码而不是编写教程,这就是为什么我提供一个简单的入门教程。 11 | 12 | ![](http://p3alsaatj.bkt.clouddn.com/20180227184229_wKfyUd_jsPlumb_Diagram_Example.jpeg) 13 | 14 | 15 | ## 1.2. jsplumb能干什么? 16 | 17 | 那么如果你应该使用它取决于你想用jsPlumb做什么。该框架适用于必须绘制图表的Web应用程序,例如类似于Visio的应用程序或工作流程设计器等。由于图表项目和连接的所有参数都是非常精细可控的,因此您可以绘制您可以想到的任何类型的图表的! 18 | 19 | ## 1.3. 基本概念 20 | 21 | - Souce 源节点 22 | - Target 目标节点 23 | - Anchor 锚点 24 | - Endpoint 端点 25 | - Connector 连接 26 | 27 | ![](http://p3alsaatj.bkt.clouddn.com/20180227151857_Pu4O9c_jsPlumb-Connector-Components.jpeg) 28 | 29 | 30 | # 2. 基础demos 31 | 32 | ## 2.1. 连接两个节点 33 | 34 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/01.html 35 | 36 | jsPlumb.ready方法和jquery的ready方法差不多的功能,jsPlumb.connect用于建立连线 37 | 38 | ![](http://p3alsaatj.bkt.clouddn.com/20180415224517_SK0PUc_Jietu20180415-224454.jpeg) 39 | 40 | 41 | ``` 42 |
43 |
44 |
45 |
46 | 47 | 48 | 58 | ``` 59 | 60 | 61 | 参数说明: 62 | jsPlumb.connect(config) return connection 63 | 64 | 参数 | 参数类型 | 是否必须 | 说明 65 | ---|---|---|--- 66 | source | String,Object,Endpoint | 是 | 连线源的标识,可以是id, element, 或者Endpoint 67 | target | String,Object,Endpoint | 是 | 连线目标的标识,可以是id, element, 或者Endpoint 68 | endpoint | String | 可选 | 端点类型,形状 69 | 70 | [>>> connect方法详情](https://jsplumbtoolkit.com/community/apidocs/classes/jsPlumbInstance.html#method_connect) 71 | 72 | 73 | ## 2.2. 可拖动节点 74 | 75 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/02.html 76 | 77 | 使用draggable可以让节点被拖动,[draggable方法参考](https://jsplumbtoolkit.com/community/apidocs/classes/jsPlumbInstance.html#method_draggable) 78 | 79 | ![](http://p3alsaatj.bkt.clouddn.com/20180227191655_GOJLi1_Jietu20180227-191647.jpeg) 80 | 81 | ``` 82 |
83 |
84 |
85 |
86 | 87 | 88 | 101 | ``` 102 | 103 | 104 | 105 | ## 2.3. 连接的其他参数 106 | 107 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/03.html 108 | 109 | 可以通过connector去设置链接线的形状,如直线或者曲线之类的。anchor可以去设置锚点的位置。 110 | 111 | jsplumb连线的样式有四种 112 | 113 | - `Bezier`: 贝塞尔曲线 114 | - `Flowchart`: 具有90度转折点的流程线 115 | - `StateMachine`: 状态机 116 | - `Straight`: 直线 117 | 118 | ![](http://p3alsaatj.bkt.clouddn.com/20180227192135_1AWJH6_Jietu20180227-192120.jpeg) 119 | 120 | ``` 121 |
122 |
123 |
124 |
125 | 126 | 127 | 142 | ``` 143 | 144 | ## 2.4. 设置连接的默认值 145 | 146 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/04.html 147 | 148 | 很多连线都是相同设置的情况下,可以将配置抽离出来,作为一个单独的变量,作为connect的第二个参数传入。实际上connect的第二个参数会和第一个参数merge,作为一个整体。 149 | 150 | ``` 151 | 169 | ``` 170 | 171 | ## 2.5. 给连接加上样式 172 | 173 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/05.html 174 | 175 | 例如给连线设置不同的颜色,设置不同的粗细之类的。 176 | 177 | ![](http://p3alsaatj.bkt.clouddn.com/20180227192811_AA9fXd_Jietu20180227-192758.jpeg) 178 | 179 | ``` 180 | jsPlumb.connect({ 181 | source: 'item_left', 182 | target: 'item_right', 183 | paintStyle: { stroke: 'lightgray', strokeWidth: 3 }, 184 | endpointStyle: { fill: 'lightgray', outlineStroke: 'darkgray', outlineWidth: 2 } 185 | }, common) 186 | ``` 187 | 188 | ## 2.6. 给连接加上箭头 189 | 190 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/06.html 191 | 192 | 箭头实际上是通过设置`overlays`去设置的,可以设置箭头的长宽以及箭头的位置,location 0.5表示箭头位于中间,location 1表示箭头设置在连线末端。 一根连线是可以添加多个箭头的。 193 | 194 | `overlays`也是一个比较重要的概念,overlays可以理解为遮罩层。遮罩层不仅仅可以设置箭头,也可以设置其他内容。 195 | 196 | overlays有五种类型,下面给出简介。具体使用方法参见 https://jsplumbtoolkit.com/community/doc/overlays.html 197 | 198 | - `Arrow` 一个可配置的箭头 199 | - `Label` 标签,可以在链接上显示文字信息 200 | - `PlainArrow` 原始类型的箭头 201 | - `Diamond` 菱形箭头 202 | - `Custom` 自定义类型 203 | 204 | ![](http://p3alsaatj.bkt.clouddn.com/20180227193801_OejsPz_Jietu20180227-193752.jpeg) 205 | 206 | ``` 207 | jsPlumb.connect({ 208 | source: 'item_left', 209 | target: 'item_right', 210 | paintStyle: { stroke: 'lightgray', strokeWidth: 3 }, 211 | endpointStyle: { fill: 'lightgray', outlineStroke: 'darkgray', outlineWidth: 2 }, 212 | overlays: [ ['Arrow', { width: 12, length: 12, location: 0.5 }] ] 213 | }, common) 214 | ``` 215 | 216 | ## 2.7. 增加一个端点 217 | 218 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/07.html 219 | 220 | addEndpoint方法可以用来增加端点,[具体使用请看](https://jsplumbtoolkit.com/community/apidocs/classes/jsPlumbInstance.html#method_addEndpoint) 221 | 222 | ![](http://p3alsaatj.bkt.clouddn.com/20180227193308_wYaELY_Jietu20180227-193254.jpeg) 223 | 224 | ``` 225 | jsPlumb.ready(function () { 226 | jsPlumb.addEndpoint('item_left', { 227 | anchors: ['Right'] 228 | }) 229 | }) 230 | ``` 231 | 232 | ## 2.8. 拖动创建连接 233 | 234 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/08.html 235 | 236 | 如果你将`isSource`和`isTarget`设置成true,那么久可以用户在拖动时,自动创建链接。 237 | 238 | ![](http://p3alsaatj.bkt.clouddn.com/20180227193546_yg6Z4L_Jietu20180227-193527.jpeg) 239 | 240 | ``` 241 | jsPlumb.ready(function () { 242 | jsPlumb.setContainer('diagramContainer') 243 | 244 | var common = { 245 | isSource: true, 246 | isTarget: true, 247 | connector: ['Straight'] 248 | } 249 | 250 | jsPlumb.addEndpoint('item_left', { 251 | anchors: ['Right'] 252 | }, common) 253 | 254 | jsPlumb.addEndpoint('item_right', { 255 | anchor: 'Left' 256 | }, common) 257 | 258 | jsPlumb.addEndpoint('item_right', { 259 | anchor: 'Right' 260 | }, common) 261 | }) 262 | ``` 263 | 264 | `一般来说拖动创建的链接,可以再次拖动,让链接断开。如果不想触发这种行为,可以设置。` 265 | 266 | ``` 267 | jsPlumb.importDefaults({ 268 | ConnectionsDetachable: false 269 | }) 270 | ``` 271 | 272 | ## 2.9. 给端点增加样式 273 | 274 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/09.html 275 | 276 | 通过设置各种 `*Style`来改变链接或者端点的样式。 277 | 278 | 279 | ![](http://p3alsaatj.bkt.clouddn.com/20180227194136_zIlkwP_Jietu20180227-194127.jpeg) 280 | 281 | ``` 282 | jsPlumb.ready(function () { 283 | jsPlumb.setContainer('diagramContainer') 284 | 285 | var common = { 286 | isSource: true, 287 | isTarget: true, 288 | connector: 'Straight', 289 | endpoint: 'Dot', 290 | paintStyle: { 291 | fill: 'white', 292 | outlineStroke: 'blue', 293 | strokeWidth: 3 294 | }, 295 | hoverPaintStyle: { 296 | outlineStroke: 'lightblue' 297 | }, 298 | connectorStyle: { 299 | outlineStroke: 'green', 300 | strokeWidth: 1 301 | }, 302 | connectorHoverStyle: { 303 | strokeWidth: 2 304 | } 305 | } 306 | 307 | jsPlumb.addEndpoint('item_left', { 308 | anchors: ['Right'] 309 | }, common) 310 | 311 | jsPlumb.addEndpoint('item_right', { 312 | anchor: 'Left' 313 | }, common) 314 | 315 | jsPlumb.addEndpoint('item_right', { 316 | anchor: 'Right' 317 | }, common) 318 | }) 319 | ``` 320 | 321 | ## 2.10. 节点改变尺寸 322 | 323 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/10.html 324 | 325 | jsplumb实际上不支持改变节点大小,实际上只能通过jquery ui resizable 方法去改变。 326 | 327 | ![](http://p3alsaatj.bkt.clouddn.com/20180227195351_B18Pal_Jietu20180227-195338.jpeg) 328 | 329 | ``` 330 |
331 |
332 |
333 |
334 | 335 | 336 | 337 | 338 | 357 | ``` 358 | 359 | ## 2.11. 限制节点拖动区域 360 | 361 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/11.html 362 | 363 | 默认情况下,节点可以被拖动到区域外边,如果想只能在区域内拖动,需要设置containment,这样节点只能在固定区域内移动。 364 | 365 | 366 | ![](http://p3alsaatj.bkt.clouddn.com/20180227195859_fFawMs_Jietu20180227-195844.jpeg) 367 | 368 | ``` 369 | jsPlumb.setContainer('area-id') 370 | ``` 371 | 372 | ## 2.12. 节点网格对齐 373 | 374 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/12.html 375 | 网格对齐实际上是设置了`grid`属性,使移动只能按照固定的尺寸移动。然后用一张图作为背景铺开作为网格来实现的。 376 | 377 | ![](http://p3alsaatj.bkt.clouddn.com/20180227200100_wEX1FU_Jietu20180227-200047.jpeg) 378 | 379 | ``` 380 | #diagramContainer { 381 | padding: 20px; 382 | width: 80%; 383 | height: 400px; 384 | border: 1px solid gray; 385 | background-image: url(http://p3alsaatj.bkt.clouddn.com/20180227163310_1bVYeW_grid.jpeg); 386 | background-repeat: repeat; 387 | } 388 | 389 | jsPlumb.draggable('item_left', { 390 | containment: 'parent', 391 | grid: [10, 10] 392 | }) 393 | ``` 394 | 395 | ## 2.13. 给链接添加点击事件:点击删除连线 396 | 397 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/13.html 398 | 399 | ![](http://p3alsaatj.bkt.clouddn.com/20180713130405_UnzvUT_Jietu20180713-130335.jpeg) 400 | 401 | ``` 402 | // 请单点击一下连接线, 403 | jsPlumb.bind('click', function (conn, originalEvent) { 404 | if (window.prompt('确定删除所点击的链接吗? 输入1确定') === '1') { 405 | jsPlumb.detach(conn) 406 | } 407 | }) 408 | ``` 409 | 410 | jsPlumb支持许多事件 411 | 412 | `jsPlumb Events列表` 413 | 414 | - connection 415 | - connectionDetached 416 | - connectionMoved 417 | - click 418 | - dblclick 419 | - endpointClick 420 | - endpointDblClick 421 | - contextmenu 422 | - beforeDrop 423 | - beforeDetach 424 | - zoom 425 | - Connection Events 426 | - Endpoint Events 427 | - Overlay Events 428 | - Unbinding Events 429 | 430 | 参考用法参考:https://jsplumbtoolkit.com/community/doc/events.html#jsPlumbEvents 431 | 432 | ## 2.14. 删除节点,包括节点相关的连接 433 | 434 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/14.html 435 | 436 | ![](http://p3alsaatj.bkt.clouddn.com/20180713131254_dLSYLW_Jietu20180713-131238.jpeg) 437 | 438 | ``` 439 | // nodeId为节点id, remove方法可以删除节点以及和节点相关的连线 440 | console.log('3 秒后移除左边节点包括它的连线') 441 | setTimeout(function () { 442 | jsPlumb.remove('item_left') 443 | }, 3000) 444 | ``` 445 | 446 | 注意remove方法有些情况下是无法删除干净连线的,[详情](https://jsplumbtoolkit.com/community/doc/removing.html) 447 | 448 | ## 2.15. 通过编码连接endPoint 449 | 450 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/15.html 451 | 452 | ![](http://p3alsaatj.bkt.clouddn.com/20180713132452_xkiWxs_Jietu20180713-132430.jpeg) 453 | 454 | 初始化数据后,给节点加上了endPoint, 如果想编码让endPoint链接上。需要在addEndpoint时,就给该断点加上一个uuid, 然后通过connect()方法,将两个断点链接上。建议使用[node-uuid](https://github.com/kelektiv/node-uuid)给每个断点都加上唯一的uuid, 这样以后链接就方便多了。 455 | 456 | ``` 457 | jsPlumb.addEndpoint('item_left', { 458 | anchors: ['Right'], 459 | uuid: 'fromId' 460 | }) 461 | 462 | jsPlumb.addEndpoint('item_right', { 463 | anchors: ['Left'], 464 | uuid: 'toId' 465 | }) 466 | 467 | console.log('3 秒后建立连线') 468 | setTimeout(function () { 469 | jsPlumb.connect({ uuids: ['fromId', 'toId'] }) 470 | }, 3000) 471 | ``` 472 | 473 | ## 2.16. 连接前的检查,判断是否建立连接 474 | 475 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/16.html 476 | 477 | ![](http://p3alsaatj.bkt.clouddn.com/20180713133303_xif4MK_Screenshot.jpeg) 478 | 479 | 有时候当用户从A端点链接到B端点时,需要做一些检查,如果不符合条件,就不让链接建立。 480 | 481 | ``` 482 | // 当链接建立前 483 | jsPlumb.bind('beforeDrop', function (info) { 484 | var a = 10 485 | var b = 2 486 | if (a < b) { 487 | console.log('链接会自动建立') 488 | return true // 链接会自动建立 489 | } else { 490 | console.log('链接取消') 491 | return false // 链接不会建立,注意,必须是false 492 | } 493 | }) 494 | ``` 495 | 496 | ## 2.17. 一个端点如何拖拽出多条连线 497 | 498 | 默认情况下,`maxConnections`的值是1,也就是一个端点最多只能拉出一条连线。 499 | 500 | 你也可以设置成其他值,例如5,表示最多可以有5条连线。 501 | 502 | 如果你想不限制连线的数量,那么可以将该值设置为`-1` 503 | 504 | ``` 505 | var common = { 506 | isSource: true, 507 | isTarget: true, 508 | connector: ['Straight'], 509 | maxConnections: -1 510 | } 511 | 512 | jsPlumb.addEndpoint('item_left', { 513 | anchors: ['Right'] 514 | }, common) 515 | ``` 516 | 517 | ## 2.18. 整个节点作为source或者target 518 | 519 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/18.html 520 | 521 | 整个节点作为source或者target, 并且将锚点设置成Continuous,那么锚点就会随着节点的位置改变而改变自己的位置。 522 | 523 | jsPlumb的锚点分为四类 524 | 525 | - `Static` 静态 固定位置的锚点 526 | - `Dynamic` jsPlumb自动选择合适的锚点,动态锚点 527 | - `Perimeter` 边缘锚点,会根据节点形状去改变位置 528 | - `Continuous` 根据节点位置,自动调整位置的锚点 529 | 530 | 详情:https://jsplumbtoolkit.com/community/doc/anchors.html 531 | 532 | ``` 533 | window.jsPlumb.ready(function () { 534 | var jsPlumb = window.jsPlumb 535 | 536 | jsPlumb.makeSource('A', { 537 | endpoint:"Dot", 538 | anchor: "Continuous" 539 | }) 540 | 541 | jsPlumb.makeTarget('B', { 542 | endpoint:"Dot", 543 | anchor: "Continuous" 544 | }) 545 | 546 | jsPlumb.draggable('A') 547 | jsPlumb.draggable('B') 548 | }) 549 | ``` 550 | 551 | ![](http://p3alsaatj.bkt.clouddn.com/20181023204322_QVz4Cm_Jietu20181023-204022.jpeg) 552 | 553 | ![](http://p3alsaatj.bkt.clouddn.com/20181023204336_p2KxaX_Jietu20181023-204054.jpeg) 554 | 555 | ## 2.19. 节点缩放 556 | 557 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/19.html 558 | 559 | ``` 560 | window.jsPlumb.ready(function () { 561 | var jsPlumb = window.jsPlumb 562 | jsPlumb.setContainer("diagramContainer") 563 | 564 | jsPlumb.connect({ 565 | source: 'A', 566 | target: 'B', 567 | endpoint: 'Dot' 568 | }) 569 | 570 | var baseZoom = 1 571 | setInterval(() => { 572 | baseZoom -= 0.1 573 | if (baseZoom < 0.5) { 574 | baseZoom = 1 575 | } 576 | zoom(baseZoom) 577 | }, 1000) 578 | }) 579 | 580 | function zoom (scale) { 581 | $("#diagramContainer").css({ 582 | "-webkit-transform": `scale(${scale})`, 583 | "-moz-transform": `scale(${scale})`, 584 | "-ms-transform": `scale(${scale})`, 585 | "-o-transform": `scale(${scale})`, 586 | "transform": `scale(${scale})` 587 | }) 588 | jsPlumb.setZoom(0.75); 589 | } 590 | ``` 591 | 592 | ![](http://p3alsaatj.bkt.clouddn.com/20181023210318_r0MaTA_Jietu20181023-210309.jpeg) 593 | 594 | # 3. jsPlumb默认配置简介 595 | 596 | 参考地址: https://jsplumbtoolkit.com/community/doc/defaults.html 597 | 598 | jsPlumb的配置项有很多,如果你不主动去设置,那么jsPlumb就使用默认的配置。 599 | 600 | 另外建议你不要修改默认的配置,而是使用自定义的方式。 601 | 602 | 另外一点要注意,如果你想修改默认配置,那么使用importDefaults方法,并且属性的首字母要大写。如果你用addEndpoint, 并使用类似maxConnections的属性,那么首字母要小写。 603 | 604 | 参见demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/17.html demo上需要你自己手动拖动创建链接。 605 | 606 | ![](http://p3alsaatj.bkt.clouddn.com/20181015195143_kNd9Sd_Jietu20181015-194116.jpeg) 607 | 608 | ``` 609 | var common = { 610 | isSource: true, 611 | isTarget: true, 612 | connector: ['Straight'], 613 | maxConnections: -1 614 | } 615 | 616 | jsPlumb.addEndpoint('item_left', { 617 | anchors: ['Right'] 618 | }, common) 619 | ``` 620 | 621 | ``` 622 | Anchor : "BottomCenter", 623 | Anchors : [ null, null ], 624 | ConnectionsDetachable : true, 625 | ConnectionOverlays : [], 626 | Connector : "Bezier", 627 | Container : null, 628 | DoNotThrowErrors : false, 629 | DragOptions : { }, 630 | DropOptions : { }, 631 | Endpoint : "Dot", 632 | Endpoints : [ null, null ], 633 | EndpointOverlays : [ ], 634 | EndpointStyle : { fill : "#456" }, 635 | EndpointStyles : [ null, null ], 636 | EndpointHoverStyle : null, 637 | EndpointHoverStyles : [ null, null ], 638 | HoverPaintStyle : null, 639 | LabelStyle : { color : "black" }, 640 | LogEnabled : false, 641 | Overlays : [ ], 642 | MaxConnections : 1, 643 | PaintStyle : { strokeWidth : 8, stroke : "#456" }, 644 | ReattachConnections : false, 645 | RenderMode : "svg", 646 | Scope : "jsPlumb_DefaultScope" 647 | ``` 648 | 649 | 你也可以从`jsPlumb.Defaults`对象中查看默认的配置。如果你想要更加个性化的设置连线,那么最好可以了解一下,它的默认设置有哪些,从而方便的来完成自己的设计需求。 650 | 651 | ![](http://p3alsaatj.bkt.clouddn.com/20180509225507_aRk1UV_Jietu20180509-225433.jpeg) 652 | 653 | 654 | 655 | 默认参数的简介: 656 | 657 | - `Anchor` 锚点,即端点链接的位置 658 | - `Anchors` 多个锚点 [源锚点,目标锚点]. 659 | - `Connector` 链接 660 | - `ConnectionsDetachable` 节点是否可以用鼠标拖动使其断开,默认为true。即用鼠标链接上的连线,也可以使用鼠标拖动让其断开。设置成false,可以让其拖动也不会自动断开。 661 | - `Container` 连线的容器 662 | - `DoNotThrowErrors` 是否抛出错误 663 | - `ConnectionOverlays` 链接遮罩层 664 | - `DragOptions` 拖动设置 665 | - `DropOptions` 拖放设置 666 | - `Endpoint` 端点 667 | - `Endpoints` 数组形式的,[源端点,目标端点] 668 | - `EndpointOverlays` 端点遮罩层 669 | - `EndpointStyle` 端点样式 670 | - `EndpointStyles` [源端点样式,目标端点样式] 671 | - `EndpointHoverStyle` 端点鼠标经过的样式 672 | - `EndpointHoverStyles` [源端点鼠标经过样式,目标端点鼠标经过样式] 673 | - `HoverPaintStyle` 鼠标经过链接线时的样式 674 | - `LabelStyle` 标签样式 675 | - `LogEnabled` 是否启用日志 676 | - `Overlays` 连接线和端点的遮罩层样式 677 | - `MaxConnections` 端点最大连接线数量默认为1, 设置成-1可以表示无数个链接 678 | - `PaintStyle` 连线样式 679 | - `ReattachConnections` 端点是否可以再次重新链接 680 | - `RenderMode` 渲染模式,默认是svg 681 | - `Scope` 作用域,用来区分哪些端点可以链接,作用域相同的可以链接 682 | 683 | 684 | ``` 685 | // 可以使用importDefaults,来重写某些默认设置 686 | jsPlumb.importDefaults({ 687 | PaintStyle : { 688 | strokeWidth:13, 689 | stroke: 'rgba(200,0,0,0.5)' 690 | }, 691 | DragOptions : { cursor: "crosshair" }, 692 | Endpoints : [ [ "Dot", { radius:7 } ], [ "Dot", { radius:11 } ] ], 693 | EndpointStyles : [{ fill:"#225588" }, { fill:"#558822" }] 694 | }); 695 | ``` 696 | 697 | # 4. 有没有稍微复杂一点,带有拖放的栗子? 698 | 项目地址:https://github.com/wangduanduan/visual-ivr ,将views目录下的drag-drop-demo.html拖放到浏览器中,就可以愉快的玩耍了。 699 | 700 | 从该demo中除了可以学到基本的jsplumb的api, 也可以学到其他的关于拖放的知识点。其中目前只做了语音节点的拖放,其他的还时间做。该demo没有使用webpack打包,代码写的有点乱,大家凑合着看,有问题可以提issue, 或者评论。 701 | 702 | ![](http://p3alsaatj.bkt.clouddn.com/20180425224658_pFg6BG_Jietu20180425-224640.jpeg) 703 | 704 | 705 | # 5. 实战项目 一个可视化IVR编辑器 706 | 707 | 项目地址:https://github.com/wangduanduan/visual-ivr 该项目还在开发完善中,不过已经具备基本功能。 708 | 709 | 该项目是用webpack打包的项目,所有文件都在src目录下。 710 | 711 | 图1是基于jsplumb做的最基础的版本,图2是最近优化后的版本,该版本未开源。 712 | 713 | ![](http://p3alsaatj.bkt.clouddn.com/20180414105705_PbucQp_Jietu20180414-105646.jpeg) 714 | 715 | 【图1】 716 | 717 | 718 | ![](http://p3alsaatj.bkt.clouddn.com/20180628154158_hryb52_Jietu20180628-153918.jpeg) 719 | 【图2】 720 | 721 | # 6. 还有哪些类似的图形连线可视化项目 722 | 723 | ## 6.1. G6 AntV 724 | 725 | https://github.com/antvis/g6 726 | 727 | ![](http://p3alsaatj.bkt.clouddn.com/20180611171335_XWq41h_Jietu20180611-171327.jpeg) 728 | 729 | ## 6.2. VivaGraphJS 730 | 731 | https://github.com/anvaka/VivaGraphJS 732 | 733 | ![](http://p3alsaatj.bkt.clouddn.com/20180611171125_1LBQdG_Jietu20180611-171117.jpeg) 734 | 735 | ![](http://p3alsaatj.bkt.clouddn.com/20180611171745_mwZc75_Jietu20180611-171731.jpeg) 736 | 737 | ## 6.3. springy 738 | 739 | https://github.com/dhotson/springy 740 | 741 | ![](http://p3alsaatj.bkt.clouddn.com/20180611171213_XS3vL4_Jietu20180611-171206.jpeg) 742 | 743 | ## 6.4. graphviz 744 | 745 | https://www.graphviz.org/about/ 746 | 747 | 中文有个基本的介绍文档写的不错,参考:https://casatwy.com/shi-yong-dotyu-yan-he-graphvizhui-tu-fan-yi.html 748 | 749 | graphviz可以把你写的.dot文件渲染成一张图。 750 | 751 | mac上首先要安装:`brew install graphviz` 752 | 753 | 然后如果你用vscode的话,vscode上又graphviz的扩展插件,可以预览你的dot文件。 754 | 755 | 总体来说,graphviz的功能十分强大,同时它也提供了其他语言的脚本api来方便绘图。总之,如果你不想通过拖拉拽来绘制一些流程图,又对图形布局不是很感兴趣的话,`graphviz是一个免费而且效率高而且能装逼的工具` 756 | 757 | ![](http://p3alsaatj.bkt.clouddn.com/20180626102133_EAJjjY_Jietu20180626-102115.jpeg) 758 | 759 | 再贴几张graphviz的绘图 760 | 761 | ![](http://p3alsaatj.bkt.clouddn.com/20180626102608_hCABQQ_summary.jpeg) 762 | 763 | ![](http://p3alsaatj.bkt.clouddn.com/20180626102646_RPHmnl_example5.jpeg) 764 | 765 | ![](http://p3alsaatj.bkt.clouddn.com/20180626102701_S66sli_petrol.jpeg) 766 | 767 | ![](http://p3alsaatj.bkt.clouddn.com/20180626102715_wPb7pW_dfd2.jpeg) 768 | 769 | 770 | ## 6.5. visjs 771 | 772 | http://visjs.org/index.html 773 | 774 | 该项目看起来不错,github上将近有7000 star, 但是它的开发者似乎没时间维护该项目了,正在给该项目找下家。 775 | 776 | ![](http://p3alsaatj.bkt.clouddn.com/20180816163348_S3yJbT_Jietu20180816-163228.jpeg) 777 | 778 | 779 | 780 | 781 | 782 | # 7. 参考资源 783 | - [jsPlumb Class](https://jsplumbtoolkit.com/community/apidocs/classes/jsPlumb.html) 784 | - [freedevelopertutorials jsplumb-tutorial](http://www.freedevelopertutorials.com/jsplumb-tutorial/) 785 | 786 | 787 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 在2024年这个时间点,流程图框架选型有太多可选择的框架了,没必要选择jsplumb。 2 | 3 | 1. jsplumb本身就是10年前开发,用的技术栈可能比较老旧 4 | 2. jsplumb的开源协议并不太友好 5 | 6 | 你可以访问:https://github.com/topics/flowchart 在这个话题下,有很多的框架可以选择。 7 | 8 | 例如: 9 | 10 | - https://github.com/xyflow/xyflow 11 | - https://github.com/didi/LogicFlow 12 | - https://github.com/alyssaxuu/flowy 13 | - https://github.com/antvis/X6 14 | - https://github.com/bcakmakoglu/vue-flow 15 | 16 | ---- 17 | 18 | 19 | 20 | 21 | 22 | - [1. jsplumb 中文基础教程](#1-jsplumb-中文基础教程) 23 | - [1.1. 什么是jsplumb?](#11-什么是jsplumb) 24 | - [1.2. jsplumb能干什么?](#12-jsplumb能干什么) 25 | - [1.3. 基本概念](#13-基本概念) 26 | - [1.3.1. Anchors [todo]](#131-anchors-todo) 27 | - [1.3.2. Connectors [todo]](#132-connectors-todo) 28 | - [1.3.3. Endpoints [todo]](#133-endpoints-todo) 29 | - [1.3.4. Overlays [todo]](#134-overlays-todo) 30 | - [1.3.5. Groups [todo]](#135-groups-todo) 31 | - [1.4. 样式设置 [todo]](#14-样式设置-todo) 32 | - [2. 基础demos](#2-基础demos) 33 | - [2.1. 连接两个节点](#21-连接两个节点) 34 | - [2.2. 可拖动节点](#22-可拖动节点) 35 | - [2.3. 连接的其他参数](#23-连接的其他参数) 36 | - [2.4. 设置连接的默认值](#24-设置连接的默认值) 37 | - [2.5. 给连接加上样式](#25-给连接加上样式) 38 | - [2.6. 给连接加上箭头](#26-给连接加上箭头) 39 | - [2.7. 增加一个端点](#27-增加一个端点) 40 | - [2.8. 拖动创建连接](#28-拖动创建连接) 41 | - [2.9. 给端点增加样式](#29-给端点增加样式) 42 | - [2.10. 节点改变尺寸](#210-节点改变尺寸) 43 | - [2.11. 限制节点拖动区域](#211-限制节点拖动区域) 44 | - [2.12. 节点网格对齐](#212-节点网格对齐) 45 | - [2.13. 给连接添加点击事件:点击删除连线](#213-给连接添加点击事件点击删除连线) 46 | - [2.14. 删除节点,包括节点相关的连接](#214-删除节点包括节点相关的连接) 47 | - [2.15. 通过编码连接endPoint](#215-通过编码连接endpoint) 48 | - [2.16. 连接前的检查,判断是否建立连接](#216-连接前的检查判断是否建立连接) 49 | - [2.17. 一个端点如何拖拽出多条连线](#217-一个端点如何拖拽出多条连线) 50 | - [2.18. 整个节点作为source或者target](#218-整个节点作为source或者target) 51 | - [2.19. 节点缩放](#219-节点缩放) 52 | - [3. jsPlumb事件列表](#3-jsplumb事件列表) 53 | - [3.1. 常用事件](#31-常用事件) 54 | - [3.1.1. connection 连接建立时触发](#311-connection-连接建立时触发) 55 | - [3.1.2. connectionDetached 连接断开时触发](#312-connectiondetached-连接断开时触发) 56 | - [3.1.3. connectionMoved 连接移动事件](#313-connectionmoved-连接移动事件) 57 | - [3.1.4. connectionAborted 连接取消事件](#314-connectionaborted-连接取消事件) 58 | - [3.1.5. click 连接点击事件](#315-click-连接点击事件) 59 | - [3.1.6. dblclick 连接双击事件](#316-dblclick-连接双击事件) 60 | - [3.1.7. connectionDrag 连接拖动事件](#317-connectiondrag-连接拖动事件) 61 | - [3.1.8. connectionDragStop 连接停止拖动事件](#318-connectiondragstop-连接停止拖动事件) 62 | - [3.1.9. endpointClick 端点单击事件](#319-endpointclick-端点单击事件) 63 | - [3.1.10. endpointDblClick 端点双击事件](#3110-endpointdblclick-端点双击事件) 64 | - [3.1.11. contextmenu 鼠标右键事件](#3111-contextmenu-鼠标右键事件) 65 | - [3.1.12. beforeDrop 连接建立前事件](#3112-beforedrop-连接建立前事件) 66 | - [3.1.13. beforeDetach 连接断开前事件](#3113-beforedetach-连接断开前事件) 67 | - [3.1.14. zoom 缩放事件](#3114-zoom-缩放事件) 68 | - [3.2. 其他事件](#32-其他事件) 69 | - [3.2.1. Connection Events](#321-connection-events) 70 | - [3.2.2. Endpoint Events](#322-endpoint-events) 71 | - [3.2.3. Overlay Events](#323-overlay-events) 72 | - [4. jsPlumb默认配置简介](#4-jsplumb默认配置简介) 73 | - [5. 工具函数](#5-工具函数) 74 | - [5.1. 重绘某个元素 jsPlumb.revalidate](#51-重绘某个元素-jsplumbrevalidate) 75 | - [5.2. 重绘所有元素 jsPlumb.repaintEverything](#52-重绘所有元素-jsplumbrepainteverything) 76 | - [5.3. 重设节点ID jsPlumb.setId](#53-重设节点id-jsplumbsetid) 77 | - [5.4. 删除节点 jsPlumb.remove](#54-删除节点-jsplumbremove) 78 | - [5.5. 清空所有节点连接和端点 jsPlumb.empty](#55-清空所有节点连接和端点-jsplumbempty) 79 | - [5.6. 移除连线 jsPlumb.detach](#56-移除连线-jsplumbdetach) 80 | - [5.7. 移除某个节点上的所有连线 jsPlumb.deleteConnectionsForElement](#57-移除某个节点上的所有连线-jsplumbdeleteconnectionsforelement) 81 | - [5.8. 移除所有节点上的连线 jsPlumb.deleteEveryConnection()](#58-移除所有节点上的连线-jsplumbdeleteeveryconnection) 82 | - [5.9. 移除某个节点上的端点](#59-移除某个节点上的端点) 83 | - [5.10. 移除所有节点上的端点](#510-移除所有节点上的端点) 84 | - [5.11. 元素的显示与隐藏](#511-元素的显示与隐藏) 85 | - [6. 样式修改](#6-样式修改) 86 | - [6.1. 通过css添加样式](#61-通过css添加样式) 87 | - [6.2. paintStyle属性添加](#62-paintstyle属性添加) 88 | - [7. 查询 [todo]](#7-查询-todo) 89 | - [8. 视图与数据结构同步](#8-视图与数据结构同步) 90 | - [9. 有没有稍微复杂一点,带有拖放的栗子?](#9-有没有稍微复杂一点带有拖放的栗子) 91 | - [10. 还有哪些类似的图形连线可视化项目](#10-还有哪些类似的图形连线可视化项目) 92 | - [10.1. G6 AntV](#101-g6-antv) 93 | - [10.2. VivaGraphJS](#102-vivagraphjs) 94 | - [10.3. springy](#103-springy) 95 | - [10.4. graphviz](#104-graphviz) 96 | - [10.5. visjs](#105-visjs) 97 | - [11. 参考资源](#11-参考资源) 98 | 99 | 100 | 101 | # 1. jsplumb 中文基础教程 102 | 103 | 后续更新会在仓库:https://github.com/wangduanduan/jsplumb-chinese-tutorial.git 104 | 105 | > 阅读建议:由于本教程目录太多,建议安装谷歌浏览器插件[Smart TOC](https://chrome.google.com/webstore/detail/smart-toc/lifgeihcfpkmmlfjbailfpfhbahhibba),方便目录按照目录跳转查看。 106 | 107 | ## 1.1. 什么是jsplumb? 108 | 你有没有想过在你的网站上展示图表或者甚至在浏览器应用程序中使用它?用jsPlumb你可以!它是完全免费的,并根据MIT许可证提供。您可以直接从jsPlumb github网站下载框架。 109 | 110 | 该项目主要由Simon Porritt开发,他在澳大利亚西德尼担任网络开发人员。 jsPlumb由他积极开发。作为许多优秀的开发人员,他似乎更喜欢开发代码而不是编写教程,这就是为什么我提供一个简单的入门教程。 111 | 112 | ![](./images/20180227184229_wKfyUd_jsPlumb_Diagram_Example.jpeg) 113 | 114 | 115 | ## 1.2. jsplumb能干什么? 116 | 117 | 那么如果你应该使用它取决于你想用jsPlumb做什么。该框架适用于必须绘制图表的Web应用程序,例如类似于Visio的应用程序或工作流程设计器等。由于图表项目和连接的所有参数都是非常精细可控的,因此您可以绘制您可以想到的任何类型的图表的! 118 | 119 | ## 1.3. 基本概念 120 | 121 | - Souce 源节点 122 | - Target 目标节点 123 | - Anchor 锚点 锚点位于源节点或者目标节点上 124 | - Endpoint 端点 端点位于连线上 125 | - Connector 连接 或者也可以理解是连接线 126 | - Overlays 可以理解为在连接线上的文字或者箭头之类的东东 127 | 128 | ![](./images/20180227151857_Pu4O9c_jsPlumb-Connector-Components.jpeg) 129 | 130 | ### 1.3.1. Anchors [todo] 131 | 锚点类型: 132 | - 静态锚点 133 | - 动态锚点 134 | - 边缘锚点 135 | - 固定锚点 136 | 137 | ### 1.3.2. Connectors [todo] 138 | 连线类型: 139 | - Bezier 贝塞尔曲线 140 | - Straight 直线 141 | - Flowchart 90度转角线 142 | - State Machine 状态机 143 | 144 | ### 1.3.3. Endpoints [todo] 145 | 端点类型: 146 | - Dot 圆点 147 | - Rectangle 矩形 148 | - Image 图像 149 | - Blank 空白 150 | 151 | ### 1.3.4. Overlays [todo] 152 | 153 | Overlays可以理解为在连接线上的文字或者箭头之类的东东 154 | 155 | Overlays类型 156 | - Arrow 157 | - Label 158 | - PlainArrow 159 | - Diamond 160 | - Custom 161 | 162 | ```js 163 | // 连线上overlay可以多个, 164 | // 每个overlay可以指定相对位置 165 | // label类型的overlay实际上可以在里面直接写html 166 | // 167 | jsPlumb.connect({ 168 | ... 169 | connectorOverlays: [ 170 | ['Arrow', { 171 | width: 10, 172 | length: 10, 173 | location: 1 174 | }], 175 | ['Label', { 176 | label: '', 177 | cssClass: '', 178 | labelStyle: { 179 | color: 'red' 180 | }, 181 | events: { 182 | click: function (labelOverlay, originalEvent) { 183 | console.log('click on label overlay for :' + labelOverlay.component) 184 | console.log(labelOverlay) 185 | console.log(originalEvent) 186 | } 187 | } 188 | }] 189 | ] 190 | }); 191 | ``` 192 | 193 | ### 1.3.5. Groups [todo] 194 | 195 | ## 1.4. 样式设置 [todo] 196 | 197 | # 2. 基础demos 198 | 199 | ## 2.1. 连接两个节点 200 | 201 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/01.html 202 | 203 | jsPlumb.ready方法和jquery的ready方法差不多的功能,jsPlumb.connect用于建立连线 204 | 205 | ![](./images/20180415224517_SK0PUc_Jietu20180415-224454.jpeg) 206 | 207 | 208 | ``` 209 |
210 |
211 |
212 |
213 | 214 | 215 | 225 | ``` 226 | 227 | 228 | 参数说明: 229 | jsPlumb.connect(config) return connection 230 | 231 | 参数 | 参数类型 | 是否必须 | 说明 232 | ---|---|---|--- 233 | source | String,Object,Endpoint | 是 | 连线源的标识,可以是id, element, 或者Endpoint 234 | target | String,Object,Endpoint | 是 | 连线目标的标识,可以是id, element, 或者Endpoint 235 | endpoint | String | 可选 | 端点类型,形状 236 | 237 | [>>> connect方法详情](https://github.com/jsplumb/jsplumb/blob/da6688b86fbfba621bf3685e4431a4d9be7213b4/doc/api/jsplumb-api.js#L76) 238 | 239 | 240 | ## 2.2. 可拖动节点 241 | 242 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/02.html 243 | 244 | 使用draggable可以让节点被拖动,[draggable方法参考](https://github.com/jsplumb/jsplumb/blob/da6688b86fbfba621bf3685e4431a4d9be7213b4/doc/api/jsplumb-api.js#L690) 245 | 246 | ![](./images/20180227191655_GOJLi1_Jietu20180227-191647.jpeg) 247 | 248 | ``` 249 |
250 |
251 |
252 |
253 | 254 | 255 | 268 | ``` 269 | 270 | 271 | 272 | ## 2.3. 连接的其他参数 273 | 274 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/03.html 275 | 276 | 可以通过connector去设置连接线的形状,如直线或者曲线之类的。anchor可以去设置锚点的位置。 277 | 278 | jsplumb连线的样式有四种 279 | 280 | - `Bezier`: 贝塞尔曲线 281 | - `Flowchart`: 具有90度转折点的流程线 282 | - `StateMachine`: 状态机 283 | - `Straight`: 直线 284 | 285 | ![](./images/20180227192135_1AWJH6_Jietu20180227-192120.jpeg) 286 | 287 | ``` 288 |
289 |
290 |
291 |
292 | 293 | 294 | 309 | ``` 310 | 311 | ## 2.4. 设置连接的默认值 312 | 313 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/04.html 314 | 315 | 很多连线都是相同设置的情况下,可以将配置抽离出来,作为一个单独的变量,作为connect的第二个参数传入。实际上connect的第二个参数会和第一个参数merge,作为一个整体。 316 | 317 | ``` 318 | 336 | ``` 337 | 338 | ## 2.5. 给连接加上样式 339 | 340 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/05.html 341 | 342 | 例如给连线设置不同的颜色,设置不同的粗细之类的。 343 | 344 | ![](./images/20180227192811_AA9fXd_Jietu20180227-192758.jpeg) 345 | 346 | ``` 347 | jsPlumb.connect({ 348 | source: 'item_left', 349 | target: 'item_right', 350 | paintStyle: { stroke: 'lightgray', strokeWidth: 3 }, 351 | endpointStyle: { fill: 'lightgray', outlineStroke: 'darkgray', outlineWidth: 2 } 352 | }, common) 353 | ``` 354 | 355 | ## 2.6. 给连接加上箭头 356 | 357 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/06.html 358 | 359 | 箭头实际上是通过设置`overlays`去设置的,可以设置箭头的长宽以及箭头的位置,location 0.5表示箭头位于中间,location 1表示箭头设置在连线末端。 一根连线是可以添加多个箭头的。 360 | 361 | `overlays`也是一个比较重要的概念,overlays可以理解为遮罩层。遮罩层不仅仅可以设置箭头,也可以设置其他内容。 362 | 363 | overlays有五种类型,下面给出简介。具体使用方法参见 http://jsplumb.github.io/jsplumb/overlays.html 364 | 365 | - `Arrow` 一个可配置的箭头 366 | - `Label` 标签,可以在连接上显示文字信息 367 | - `PlainArrow` 原始类型的箭头 368 | - `Diamond` 菱形箭头 369 | - `Custom` 自定义类型 370 | 371 | ![](./images/20180227193801_OejsPz_Jietu20180227-193752.jpeg) 372 | 373 | ``` 374 | jsPlumb.connect({ 375 | source: 'item_left', 376 | target: 'item_right', 377 | paintStyle: { stroke: 'lightgray', strokeWidth: 3 }, 378 | endpointStyle: { fill: 'lightgray', outlineStroke: 'darkgray', outlineWidth: 2 }, 379 | overlays: [ ['Arrow', { width: 12, length: 12, location: 0.5 }] ] 380 | }, common) 381 | ``` 382 | 383 | ## 2.7. 增加一个端点 384 | 385 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/07.html 386 | 387 | addEndpoint方法可以用来增加端点,[具体使用请看](https://github.com/jsplumb/jsplumb/blob/da6688b86fbfba621bf3685e4431a4d9be7213b4/doc/api/jsplumb-api.js#L57) 388 | 389 | ![](./images/20180227193308_wYaELY_Jietu20180227-193254.jpeg) 390 | 391 | ``` 392 | jsPlumb.ready(function () { 393 | jsPlumb.addEndpoint('item_left', { 394 | anchors: ['Right'] 395 | }) 396 | }) 397 | ``` 398 | 399 | ## 2.8. 拖动创建连接 400 | 401 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/08.html 402 | 403 | 如果你将`isSource`和`isTarget`设置成true,那么久可以用户在拖动时,自动创建连接。 404 | 405 | ![](./images/20180227193546_yg6Z4L_Jietu20180227-193527.jpeg) 406 | 407 | ``` 408 | jsPlumb.ready(function () { 409 | jsPlumb.setContainer('diagramContainer') 410 | 411 | var common = { 412 | isSource: true, 413 | isTarget: true, 414 | connector: ['Straight'] 415 | } 416 | 417 | jsPlumb.addEndpoint('item_left', { 418 | anchors: ['Right'] 419 | }, common) 420 | 421 | jsPlumb.addEndpoint('item_right', { 422 | anchor: 'Left' 423 | }, common) 424 | 425 | jsPlumb.addEndpoint('item_right', { 426 | anchor: 'Right' 427 | }, common) 428 | }) 429 | ``` 430 | 431 | `一般来说拖动创建的连接,可以再次拖动,让连接断开。如果不想触发这种行为,可以设置。` 432 | 433 | ```js 434 | jsPlumb.importDefaults({ 435 | ConnectionsDetachable: false 436 | }) 437 | ``` 438 | 439 | `如果你需要在连接被拖动建立后,更新数据模型,则需要订阅connection事件`, 回调函数的info对象里,有你所需的任何数据。比如说从哪个节点拖动到哪个节点的。 440 | 441 | 关于事件,可以参考事件章节。 442 | 443 | ```js 444 | jsPlumb.bind("connection", function(info, originalEvent) { 445 | .. update your model in here, maybe. 446 | }); 447 | ``` 448 | 449 | ## 2.9. 给端点增加样式 450 | 451 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/09.html 452 | 453 | 通过设置各种 `*Style`来改变连接或者端点的样式。 454 | 455 | 456 | ![](./images/20180227194136_zIlkwP_Jietu20180227-194127.jpeg) 457 | 458 | ``` 459 | jsPlumb.ready(function () { 460 | jsPlumb.setContainer('diagramContainer') 461 | 462 | var common = { 463 | isSource: true, 464 | isTarget: true, 465 | connector: 'Straight', 466 | endpoint: 'Dot', 467 | paintStyle: { 468 | fill: 'white', 469 | outlineStroke: 'blue', 470 | strokeWidth: 3 471 | }, 472 | hoverPaintStyle: { 473 | outlineStroke: 'lightblue' 474 | }, 475 | connectorStyle: { 476 | outlineStroke: 'green', 477 | strokeWidth: 1 478 | }, 479 | connectorHoverStyle: { 480 | strokeWidth: 2 481 | } 482 | } 483 | 484 | jsPlumb.addEndpoint('item_left', { 485 | anchors: ['Right'] 486 | }, common) 487 | 488 | jsPlumb.addEndpoint('item_right', { 489 | anchor: 'Left' 490 | }, common) 491 | 492 | jsPlumb.addEndpoint('item_right', { 493 | anchor: 'Right' 494 | }, common) 495 | }) 496 | ``` 497 | 498 | ## 2.10. 节点改变尺寸 499 | 500 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/10.html 501 | 502 | jsplumb实际上不支持改变节点大小,实际上只能通过jquery ui resizable 方法去改变。 503 | 504 | ![](./images/20180227195351_B18Pal_Jietu20180227-195338.jpeg) 505 | 506 | ``` 507 |
508 |
509 |
510 |
511 | 512 | 513 | 514 | 515 | 534 | ``` 535 | 536 | ## 2.11. 限制节点拖动区域 537 | 538 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/11.html 539 | 540 | 默认情况下,节点可以被拖动到区域外边,如果想只能在区域内拖动,需要设置containment,这样节点只能在固定区域内移动。 541 | 542 | 实际上上这个功能是使用jQueryUI的功能,所以函数的使用可以参考jQueryUI的文档。https://jqueryui.com/draggable/#constrain-movement 543 | 544 | ![](./images/20180227195859_fFawMs_Jietu20180227-195844.jpeg) 545 | 546 | ``` 547 | jsPlumb.draggable('item_left', {containment: 'parent'}) 548 | jsPlumb.draggable('item_right', {containment: 'parent'}) 549 | jsPlumb.draggable('some-id', {containment: "#containment-wrapper"}) 550 | ``` 551 | 552 | ## 2.12. 节点网格对齐 553 | 554 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/12.html 555 | 网格对齐实际上是设置了`grid`属性,使移动只能按照固定的尺寸移动。然后用一张图作为背景铺开作为网格来实现的。 556 | 557 | ![](./images/20180227200100_wEX1FU_Jietu20180227-200047.jpeg) 558 | 559 | ``` 560 | #diagramContainer { 561 | padding: 20px; 562 | width: 80%; 563 | height: 400px; 564 | border: 1px solid gray; 565 | background-image: url(./images/20180227163310_1bVYeW_grid.jpeg); 566 | background-repeat: repeat; 567 | } 568 | 569 | jsPlumb.draggable('item_left', { 570 | containment: 'parent', 571 | grid: [10, 10] 572 | }) 573 | ``` 574 | 575 | ## 2.13. 给连接添加点击事件:点击删除连线 576 | 577 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/13.html 578 | 579 | ![](./images/20180713130405_UnzvUT_Jietu20180713-130335.jpeg) 580 | 581 | ``` 582 | // 请单点击一下连接线, 583 | jsPlumb.bind('click', function (conn, originalEvent) { 584 | if (window.prompt('确定删除所点击的连接吗? 输入1确定') === '1') { 585 | jsPlumb.detach(conn) 586 | } 587 | }) 588 | ``` 589 | 590 | jsPlumb支持许多事件 591 | 592 | `jsPlumb Events列表` 593 | 594 | - connection 595 | - connectionDetached 596 | - connectionMoved 597 | - click 598 | - dblclick 599 | - endpointClick 600 | - endpointDblClick 601 | - contextmenu 602 | - beforeDrop 603 | - beforeDetach 604 | - zoom 605 | - Connection Events 606 | - Endpoint Events 607 | - Overlay Events 608 | - Unbinding Events 609 | 610 | 参考用法参考:https://github.com/jsplumb/jsplumb/blob/da6688b86f/doc/wiki/events.md 611 | 612 | ## 2.14. 删除节点,包括节点相关的连接 613 | 614 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/14.html 615 | 616 | ![](./images/20180713131254_dLSYLW_Jietu20180713-131238.jpeg) 617 | 618 | ``` 619 | // nodeId为节点id, remove方法可以删除节点以及和节点相关的连线 620 | console.log('3 秒后移除左边节点包括它的连线') 621 | setTimeout(function () { 622 | jsPlumb.remove('item_left') 623 | }, 3000) 624 | ``` 625 | 626 | 注意remove方法有些情况下是无法删除干净连线的,[详情](https://github.com/jsplumb/jsplumb/blob/da6688b86fbfba621bf3685e4431a4d9be7213b4/doc/api/jsplumb-api.js#L648) 627 | 628 | ## 2.15. 通过编码连接endPoint 629 | 630 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/15.html 631 | 632 | ![](./images/20180713132452_xkiWxs_Jietu20180713-132430.jpeg) 633 | 634 | 初始化数据后,给节点加上了endPoint, 如果想编码让endPoint连接上。需要在addEndpoint时,就给该断点加上一个uuid, 然后通过connect()方法,将两个断点连接上。建议使用[node-uuid](https://github.com/kelektiv/node-uuid)给每个断点都加上唯一的uuid, 这样以后连接就方便多了。 635 | 636 | ``` 637 | jsPlumb.addEndpoint('item_left', { 638 | anchors: ['Right'], 639 | uuid: 'fromId' 640 | }) 641 | 642 | jsPlumb.addEndpoint('item_right', { 643 | anchors: ['Left'], 644 | uuid: 'toId' 645 | }) 646 | 647 | console.log('3 秒后建立连线') 648 | setTimeout(function () { 649 | jsPlumb.connect({ uuids: ['fromId', 'toId'] }) 650 | }, 3000) 651 | ``` 652 | 653 | ## 2.16. 连接前的检查,判断是否建立连接 654 | 655 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/16.html 656 | 657 | ![](./images/20180713133303_xif4MK_Screenshot.jpeg) 658 | 659 | 有时候当用户从A端点连接到B端点时,需要做一些检查,如果不符合条件,就不让连接建立。 660 | 661 | ``` 662 | // 当连接建立前 663 | jsPlumb.bind('beforeDrop', function (info) { 664 | var a = 10 665 | var b = 2 666 | if (a < b) { 667 | console.log('连接会自动建立') 668 | return true // 连接会自动建立 669 | } else { 670 | console.log('连接取消') 671 | return false // 连接不会建立,注意,必须是false 672 | } 673 | }) 674 | ``` 675 | 676 | ## 2.17. 一个端点如何拖拽出多条连线 677 | 678 | demo https://wdd.js.org/jsplumb-chinese-tutorial/demos/17.html 679 | 680 | 默认情况下,`maxConnections`的值是1,也就是一个端点最多只能拉出一条连线。 681 | 682 | 你也可以设置成其他值,例如5,表示最多可以有5条连线。 683 | 684 | 如果你想不限制连线的数量,那么可以将该值设置为`-1` 685 | 686 | ``` 687 | var common = { 688 | isSource: true, 689 | isTarget: true, 690 | connector: ['Straight'], 691 | maxConnections: -1 692 | } 693 | 694 | jsPlumb.addEndpoint('item_left', { 695 | anchors: ['Right'] 696 | }, common) 697 | ``` 698 | 699 | ## 2.18. 整个节点作为source或者target 700 | 701 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/18.html 702 | 703 | 整个节点作为source或者target, 并且将锚点设置成Continuous,那么锚点就会随着节点的位置改变而改变自己的位置。 704 | 705 | jsPlumb的锚点分为四类 706 | 707 | - `Static` 静态 固定位置的锚点 708 | - `Dynamic` jsPlumb自动选择合适的锚点,动态锚点 709 | - `Perimeter` 边缘锚点,会根据节点形状去改变位置 710 | - `Continuous` 根据节点位置,自动调整位置的锚点 711 | 712 | 详情:https://github.com/jsplumb/jsplumb/blob/da6688b86f/doc/wiki/anchors.md 713 | 714 | ``` 715 | window.jsPlumb.ready(function () { 716 | var jsPlumb = window.jsPlumb 717 | 718 | jsPlumb.makeSource('A', { 719 | endpoint:"Dot", 720 | anchor: "Continuous" 721 | }) 722 | 723 | jsPlumb.makeTarget('B', { 724 | endpoint:"Dot", 725 | anchor: "Continuous" 726 | }) 727 | 728 | jsPlumb.draggable('A') 729 | jsPlumb.draggable('B') 730 | }) 731 | ``` 732 | 733 | ![](./images/20181023204322_QVz4Cm_Jietu20181023-204022.jpeg) 734 | 735 | ![](./images/20181023204336_p2KxaX_Jietu20181023-204054.jpeg) 736 | 737 | ## 2.19. 节点缩放 738 | 739 | demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/19.html 740 | 741 | ``` 742 | window.jsPlumb.ready(function () { 743 | var jsPlumb = window.jsPlumb 744 | jsPlumb.setContainer("diagramContainer") 745 | 746 | jsPlumb.connect({ 747 | source: 'A', 748 | target: 'B', 749 | endpoint: 'Dot' 750 | }) 751 | 752 | var baseZoom = 1 753 | setInterval(() => { 754 | baseZoom -= 0.1 755 | if (baseZoom < 0.5) { 756 | baseZoom = 1 757 | } 758 | zoom(baseZoom) 759 | }, 1000) 760 | }) 761 | 762 | function zoom (scale) { 763 | $("#diagramContainer").css({ 764 | "-webkit-transform": `scale(${scale})`, 765 | "-moz-transform": `scale(${scale})`, 766 | "-ms-transform": `scale(${scale})`, 767 | "-o-transform": `scale(${scale})`, 768 | "transform": `scale(${scale})` 769 | }) 770 | jsPlumb.setZoom(0.75); 771 | } 772 | ``` 773 | 774 | ![](./images/20181023210318_r0MaTA_Jietu20181023-210309.jpeg) 775 | 776 | # 3. jsPlumb事件列表 777 | 778 | ## 3.1. 常用事件 779 | 780 | 具体事件中回调函数中参数的字段含义,参见 781 | 绑定事件的方式, 以connection事件为例子 782 | 783 | ```js 784 | jsPlumb.bind("connection", function(info) { 785 | .. update your model in here, maybe. 786 | }); 787 | ``` 788 | 789 | 790 | ### 3.1.1. connection 连接建立时触发 791 | 792 | `connection(info, originalEvent)` 793 | 794 | - info.connection 795 | - info.sourceId 796 | - info.targetId 797 | - info.source 798 | - info.target 799 | - info.sourceEndpoint 800 | - info.targetEndpoint 801 | - originalEvent: 原始事件。只有用户拖动创建的连接,originalEvent才存在。 802 | 803 | **注意事项**:通过编码连接节点,也会触发connection事件,如果只想处理用户拖动创建建立的连接,可以判断第二个参数originalEvent是否存在。 804 | 805 | ### 3.1.2. connectionDetached 连接断开时触发 806 | 807 | `connectionDetached(info, originalEvent)` 808 | 809 | - info.connection 810 | - info.sourceId 811 | - info.targetId 812 | - info.source 813 | - info.target 814 | - info.sourceEndpoint 815 | - info.targetEndpoint 816 | - originalEvent 817 | 818 | **注意事项**:当拖动一个连线出现后,却没有连接到目标端点就放弃时,不会触发connectionDetached事件,会触发connectionAborted事件 819 | 820 | ### 3.1.3. connectionMoved 连接移动事件 821 | `connectionMoved(info, originalEvent)` 822 | ### 3.1.4. connectionAborted 连接取消事件 823 | `connectionAborted(connection, originalEvent)` 824 | ### 3.1.5. click 连接点击事件 825 | `click(connection, originalEvent)` 826 | ### 3.1.6. dblclick 连接双击事件 827 | `dblclick(connection, originalEvent)` 828 | ### 3.1.7. connectionDrag 连接拖动事件 829 | `connectionDrag(connection)` 830 | ### 3.1.8. connectionDragStop 连接停止拖动事件 831 | `connectionDragStop(connection)` 832 | ### 3.1.9. endpointClick 端点单击事件 833 | `endpointClick(endpoint, originalEvent)` 834 | ### 3.1.10. endpointDblClick 端点双击事件 835 | `endpointDblClick(endpoint, originalEvent)` 836 | ### 3.1.11. contextmenu 鼠标右键事件 837 | `contextmenu(component, originalEvent)` 838 | ### 3.1.12. beforeDrop 连接建立前事件 839 | `beforeDrop(info)` 注意如果这个回调函数返回false, 那么连接将不会被建立,可以用来连接建立的拦截 840 | ### 3.1.13. beforeDetach 连接断开前事件 841 | `beforeDetach(connection)` 842 | ### 3.1.14. zoom 缩放事件 843 | `zoom(value)` 844 | 845 | ## 3.2. 其他事件 846 | ### 3.2.1. Connection Events 847 | 848 | 在获得一个连接后,可以单独给某个连接绑定事件 849 | 850 | ```js 851 | var connection = jsPlumb.connect({source:"d1", target:"d2"}); 852 | connection.bind("click", function(conn) { 853 | console.log("you clicked on ", conn); 854 | }); 855 | ``` 856 | 857 | 当获取到连接后,连接还可以绑定其他事件 858 | 859 | - click(connection, originalEvent) - notification a Connection was clicked. 860 | - dblclick(connection, originalEvent) - notification a Connection was double-clicked. 861 | - contextmenu(connection, originalEvent) - a right-click on the Connection. 862 | - mouseover(connection, originalEvent) - notification the mouse is over the Connection's path. 863 | - mouseout(connection, originalEvent) - notification the mouse has exited the Connection's path. 864 | - mousedown(connection, originalEvent) - notification the mouse button was pressed on the Connection's path. 865 | - mouseup(connection, originalEvent) - notification the mouse button was released on the Connection's path. 866 | 867 | ### 3.2.2. Endpoint Events 868 | 869 | ```js 870 | var endpoint = jsPlumb.addEndpoint("d1", { someOptions } ); 871 | endpoint.bind("click", function(endpoint) { 872 | console.log("you clicked on ", endpoint); 873 | }); 874 | ``` 875 | 876 | - click(endpoint, originalEvent) - notification an Endpoint was clicked. 877 | - dblclick(endpoint, originalEvent) - notification an Endpoint was double-clicked. 878 | - contextmenu(endpoint, originalEvent) - a right-click on the Endpoint. 879 | - mouseover(endpoint, originalEvent) - notification the mouse is over the Endpoint. 880 | - mouseout(endpoint, originalEvent) - notification the mouse has exited the Endpoint. 881 | - mousedown(endpoint, originalEvent) - notification the mouse button was pressed on the Endpoint. 882 | - mouseup(endpoint, originalEvent) - notification the mouse button was released on the Endpoint. 883 | - maxConnections(info, originalEvent) - notification the user tried to drop a Connection on an Endpoint that already has the maximum number of Connections. info is an object literal containing these values: 884 | - info.endpoint : Endpoint on which the Connection was dropped 885 | - info.connection : The Connection the user tried to drop 886 | - info.maxConnections : The value of maxConnections for the Endpoint 887 | 888 | ### 3.2.3. Overlay Events 889 | 890 | 可以把Overlay理解为连线上的文字或者图标,可以给这些overlays单独绑定事件。 891 | 892 | ``` 893 | jsPlumb.connect({ 894 | source:"el1", 895 | target:"el2", 896 | overlays:[ 897 | [ "Label", { 898 | events:{ 899 | click:function(labelOverlay, originalEvent) { 900 | console.log("click on label overlay for :" + labelOverlay.component); 901 | } 902 | } 903 | }], 904 | [ "Diamond", { 905 | events:{ 906 | dblclick:function(diamondOverlay, originalEvent) { 907 | console.log("double click on diamond overlay for : " + diamondOverlay.component); 908 | } 909 | } 910 | }] 911 | ] 912 | }); 913 | ``` 914 | 915 | 916 | # 4. jsPlumb默认配置简介 917 | 918 | 参考地址: https://github.com/jsplumb/jsplumb/blob/da6688b86f/doc/wiki/defaults.md 919 | 920 | jsPlumb的配置项有很多,如果你不主动去设置,那么jsPlumb就使用默认的配置。 921 | 922 | 另外建议你不要修改默认的配置,而是使用自定义的方式。 923 | 924 | 另外一点要注意,如果你想修改默认配置,那么使用importDefaults方法,并且属性的首字母要大写。如果你用addEndpoint, 并使用类似maxConnections的属性,那么首字母要小写。 925 | 926 | 参见demo: https://wdd.js.org/jsplumb-chinese-tutorial/demos/17.html demo上需要你自己手动拖动创建连接。 927 | 928 | ![](./images/20181015195143_kNd9Sd_Jietu20181015-194116.jpeg) 929 | 930 | ``` 931 | var common = { 932 | isSource: true, 933 | isTarget: true, 934 | connector: ['Straight'], 935 | maxConnections: -1 936 | } 937 | 938 | jsPlumb.addEndpoint('item_left', { 939 | anchors: ['Right'] 940 | }, common) 941 | ``` 942 | 943 | ``` 944 | Anchor : "BottomCenter", 945 | Anchors : [ null, null ], 946 | ConnectionsDetachable : true, 947 | ConnectionOverlays : [], 948 | Connector : "Bezier", 949 | Container : null, 950 | DoNotThrowErrors : false, 951 | DragOptions : { }, 952 | DropOptions : { }, 953 | Endpoint : "Dot", 954 | Endpoints : [ null, null ], 955 | EndpointOverlays : [ ], 956 | EndpointStyle : { fill : "#456" }, 957 | EndpointStyles : [ null, null ], 958 | EndpointHoverStyle : null, 959 | EndpointHoverStyles : [ null, null ], 960 | HoverPaintStyle : null, 961 | LabelStyle : { color : "black" }, 962 | LogEnabled : false, 963 | Overlays : [ ], 964 | MaxConnections : 1, 965 | PaintStyle : { strokeWidth : 8, stroke : "#456" }, 966 | ReattachConnections : false, 967 | RenderMode : "svg", 968 | Scope : "jsPlumb_DefaultScope" 969 | ``` 970 | 971 | 你也可以从`jsPlumb.Defaults`对象中查看默认的配置。如果你想要更加个性化的设置连线,那么最好可以了解一下,它的默认设置有哪些,从而方便的来完成自己的设计需求。 972 | 973 | ![](./images/20180509225507_aRk1UV_Jietu20180509-225433.jpeg) 974 | 975 | 976 | 977 | 默认参数的简介: 978 | 979 | - `Anchor` 锚点,即端点连接的位置 980 | - `Anchors` 多个锚点 [源锚点,目标锚点]. 981 | - `Connector` 连接 982 | - `ConnectionsDetachable` 节点是否可以用鼠标拖动使其断开,默认为true。即用鼠标连接上的连线,也可以使用鼠标拖动让其断开。设置成false,可以让其拖动也不会自动断开。 983 | - `Container` 连线的容器 984 | - `DoNotThrowErrors` 是否抛出错误 985 | - `ConnectionOverlays` 连接遮罩层 986 | - `DragOptions` 拖动设置 987 | - `DropOptions` 拖放设置 988 | - `Endpoint` 端点 989 | - `Endpoints` 数组形式的,[源端点,目标端点] 990 | - `EndpointOverlays` 端点遮罩层 991 | - `EndpointStyle` 端点样式 992 | - `EndpointStyles` [源端点样式,目标端点样式] 993 | - `EndpointHoverStyle` 端点鼠标经过的样式 994 | - `EndpointHoverStyles` [源端点鼠标经过样式,目标端点鼠标经过样式] 995 | - `HoverPaintStyle` 鼠标经过连接线时的样式 996 | - `LabelStyle` 标签样式 997 | - `LogEnabled` 是否启用日志 998 | - `Overlays` 连接线和端点的遮罩层样式 999 | - `MaxConnections` 端点最大连接线数量默认为1, 设置成-1可以表示无数个连接 1000 | - `PaintStyle` 连线样式 1001 | - `ReattachConnections` 端点是否可以再次重新连接 1002 | - `RenderMode` 渲染模式,默认是svg 1003 | - `Scope` 作用域,用来区分哪些端点可以连接,作用域相同的可以连接 1004 | 1005 | 1006 | ``` 1007 | // 可以使用importDefaults,来重写某些默认设置 1008 | jsPlumb.importDefaults({ 1009 | PaintStyle : { 1010 | strokeWidth:13, 1011 | stroke: 'rgba(200,0,0,0.5)' 1012 | }, 1013 | DragOptions : { cursor: "crosshair" }, 1014 | Endpoints : [ [ "Dot", { radius:7 } ], [ "Dot", { radius:11 } ] ], 1015 | EndpointStyles : [{ fill:"#225588" }, { fill:"#558822" }] 1016 | }); 1017 | ``` 1018 | 1019 | # 5. 工具函数 1020 | ## 5.1. 重绘某个元素 jsPlumb.revalidate 1021 | 1022 | ```js 1023 | jsPlumb.revalidate(el) 1024 | ``` 1025 | 1026 | 关于 el: 1027 | 1028 | - a string, representing the id of some element 1029 | - a list of strings, representing the ids of some elements 1030 | - a DOM element 1031 | - a list of DOM elements 1032 | - a selector from your underlying library 1033 | 1034 | 1035 | ## 5.2. 重绘所有元素 jsPlumb.repaintEverything 1036 | 1037 | ```js 1038 | jsPlumb.repaintEverything() 1039 | ``` 1040 | 1041 | ## 5.3. 重设节点ID jsPlumb.setId 1042 | 1043 | 节点的ID对jsPlumb的重要性不言而喻,有时候我们需要改变节点的id, 那么需要显式的告诉jsPlumb节点id改变了。 1044 | 1045 | ```js 1046 | jsPlumb.setId(el, newId); 1047 | // 或者 1048 | jsPlumb.setIdChanged(oldId, newId); 1049 | ``` 1050 | 1051 | ## 5.4. 删除节点 jsPlumb.remove 1052 | 1053 | ```js 1054 | var conn = jsPlumb.connect({source:"element1", target:"element2"}); 1055 | ... 1056 | jsPlumb.remove("element1"); 1057 | ``` 1058 | 1059 | ## 5.5. 清空所有节点连接和端点 jsPlumb.empty 1060 | 1061 | ```js 1062 | var conn = jsPlumb.connect({source:"one", target:"someOtherElement"}); 1063 | ... 1064 | jsPlumb.empty("list"); 1065 | ``` 1066 | 1067 | ## 5.6. 移除连线 jsPlumb.detach 1068 | 1069 | ```js 1070 | var conn = jsPlumb.connect({ some params}); 1071 | ... 1072 | jsPlumb.detach(conn); 1073 | ``` 1074 | 1075 | ## 5.7. 移除某个节点上的所有连线 jsPlumb.deleteConnectionsForElement 1076 | 1077 | ```js 1078 | jsPlumb.deleteConnectionsForElement(el, [params]) 1079 | ``` 1080 | 1081 | ## 5.8. 移除所有节点上的连线 jsPlumb.deleteEveryConnection() 1082 | 1083 | ```js 1084 | jsPlumb.deleteEveryConnection() 1085 | ``` 1086 | 1087 | ## 5.9. 移除某个节点上的端点 1088 | 1089 | ```js 1090 | var ep = jsPlumb.addEndpoint(someElement, { ... }); 1091 | ... 1092 | jsPlumb.deleteEndpoint(ep); 1093 | ``` 1094 | 1095 | ## 5.10. 移除所有节点上的端点 1096 | 1097 | ```js 1098 | jsPlumb.deleteEveryEndpoint(); 1099 | ``` 1100 | 1101 | ## 5.11. 元素的显示与隐藏 1102 | 1103 | ```js 1104 | jsPlumb.hide("window5"); // 隐藏节点的所有连线 1105 | jsPlumb.hide("window5", true); // 隐藏节点的所有端点 1106 | jsPlumb.show("window5"); // 显示节点的所有连线 1107 | jsPlumb.toggleVisible("window5"); // 反转显示节点的连线 1108 | jsPlumb.show("window5", true); // 显示节点的所有连线和端点 1109 | ``` 1110 | 1111 | 1112 | # 6. 样式修改 1113 | ## 6.1. 通过css添加样式 1114 | 1115 | 参考:http://jsplumb.github.io/jsplumb/styling-via-css.html 1116 | 1117 | 1118 | ## 6.2. paintStyle属性添加 1119 | 1120 | 参考:http://jsplumb.github.io/jsplumb/paint-styles.html 1121 | 1122 | ```js 1123 | jsPlumb.connect({ 1124 | source:"el1", 1125 | target:"el2", 1126 | paintStyle:{ stroke:"blue", strokeWidth:10 } 1127 | }); 1128 | ``` 1129 | 1130 | # 7. 查询 [todo] 1131 | 1132 | # 8. 视图与数据结构同步 1133 | 1134 | **首先,jsplumb并不维护你的数据结构。** 你的数据结构你自己维护,如果页面发生改变,jsplumb会通过事件通知你。你通过事件去改变你的数据。 1135 | 1136 | 熟悉react或者vue的,会有点熟悉,这不就是单向数据流吗? 1137 | 1138 | 1. 通过渲染逻辑将基本数据结构渲染成连线图 1139 | 2. 连线图发生改变,如发生连线之类的,jsplumb会通过事件告诉你 1140 | 3. 你需要处理jsplumb给你的事件,然后修改你的基本数据 1141 | 1142 | ![](./images/Jietu20190620-133950.jpg) 1143 | 1144 | ```js 1145 | [ 1146 | { 1147 | id: 1, 1148 | link: '' 1149 | }, 1150 | { 1151 | id: 2, 1152 | link: '' 1153 | }] 1154 | ``` 1155 | 1156 | 当你收到连接建立事件后,例如1连接到了2, 你需要修改这个数据结构。 1157 | 1158 | ```js 1159 | [ 1160 | { 1161 | id: 1, 1162 | link: '2' 1163 | }, 1164 | { 1165 | id: 2, 1166 | link: '' 1167 | }] 1168 | ``` 1169 | 1170 | 1171 | # 9. 有没有稍微复杂一点,带有拖放的栗子? 1172 | 项目地址:https://github.com/wangduanduan/visual-ivr 1173 | 在线demo: https://wdd.js.org/visual-ivr/ 1174 | 1175 | ![](./images/Jietu20181226-123854.jpg) 1176 | 1177 | 上图是基于jsplumb做的最基础的demo版本。 1178 | 1179 | 下图是是最近优化后的版本 1180 | 1181 | ![](./images/20180628154158_hryb52_Jietu20180628-153918.jpeg) 1182 | ****** 1183 | 模仿官网database-visualizer实现sqlflow数据血缘流程图的demo 1184 | 1185 | 项目地址:https://github.com/mizuhokaga/jsplumb-dataLineage 1186 | 1187 | ![](https://github.com/mizuhokaga/jsplumb-dataLineage/raw/master/imgs/myflow.png) 1188 | # 10. 还有哪些类似的图形连线可视化项目 1189 | 1190 | ## 10.1. G6 AntV 1191 | 1192 | https://github.com/antvis/g6 1193 | 1194 | ![](./images/20180611171335_XWq41h_Jietu20180611-171327.jpeg) 1195 | 1196 | ## 10.2. VivaGraphJS 1197 | 1198 | https://github.com/anvaka/VivaGraphJS 1199 | 1200 | ![](./images/20180611171125_1LBQdG_Jietu20180611-171117.jpeg) 1201 | 1202 | ![](./images/20180611171745_mwZc75_Jietu20180611-171731.jpeg) 1203 | 1204 | ## 10.3. springy 1205 | 1206 | https://github.com/dhotson/springy 1207 | 1208 | ![](./images/20180611171213_XS3vL4_Jietu20180611-171206.jpeg) 1209 | 1210 | ## 10.4. graphviz 1211 | 1212 | https://www.graphviz.org/about/ 1213 | 1214 | 中文有个基本的介绍文档写的不错,参考:https://casatwy.com/shi-yong-dotyu-yan-he-graphvizhui-tu-fan-yi.html 1215 | 1216 | graphviz可以把你写的.dot文件渲染成一张图。 1217 | 1218 | mac上首先要安装:`brew install graphviz` 1219 | 1220 | 然后如果你用vscode的话,vscode上又graphviz的扩展插件,可以预览你的dot文件。 1221 | 1222 | 总体来说,graphviz的功能十分强大,同时它也提供了其他语言的脚本api来方便绘图。总之,如果你不想通过拖拉拽来绘制一些流程图,又对图形布局不是很感兴趣的话,`graphviz是一个免费而且效率高而且能装逼的工具` 1223 | 1224 | ![](./images/20180626102133_EAJjjY_Jietu20180626-102115.jpeg) 1225 | 1226 | 再贴几张graphviz的绘图 1227 | 1228 | ![](./images/20180626102608_hCABQQ_summary.jpeg) 1229 | 1230 | ![](./images/20180626102646_RPHmnl_example5.jpeg) 1231 | 1232 | ![](./images/20180626102701_S66sli_petrol.jpeg) 1233 | 1234 | ![](./images/20180626102715_wPb7pW_dfd2.jpeg) 1235 | 1236 | 1237 | ## 10.5. visjs 1238 | 1239 | http://visjs.org/index.html 1240 | 1241 | 该项目看起来不错,github上将近有7000 star, 但是它的开发者似乎没时间维护该项目了,正在给该项目找下家。 1242 | 1243 | ![](./images/20180816163348_S3yJbT_Jietu20180816-163228.jpeg) 1244 | 1245 | 1246 | 1247 | 1248 | 1249 | # 11. 参考资源 1250 | 1251 | - [官方文档](http://jsplumb.github.io/jsplumb/home.html) 1252 | 1253 | 1254 | [![Powered by DartNode](https://dartnode.com/branding/DN-Open-Source-sm.png)](https://dartnode.com "Powered by DartNode - Free VPS for Open Source") -------------------------------------------------------------------------------- /api/overlays-api.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | jsplumb/overlays-api.js at master · jsplumb/jsplumb · GitHub 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 |
112 | Skip to content 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 425 | 426 |
427 | 428 |
429 | 430 | 431 |
432 | 433 |
434 | 435 | 436 | 437 |
438 |
439 |
440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 |
458 |
459 | 460 | 500 | 501 |

502 | 503 | /jsplumb 506 | 507 | 508 |

509 | 510 |
511 | 512 | 562 | 563 | 611 | 612 | 613 |
614 |
615 |
616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | Permalink 625 | 626 | 627 | 640 | 641 | 642 |
643 | 644 | 645 |
646 | 649 | Branch: 650 | master 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 |
659 | 660 |
661 | 665 | Find file 666 | 667 | 668 | Copy path 669 | 670 |
671 |
672 | 675 | 676 |
677 | 681 | Find file 682 | 683 | 684 | Copy path 685 | 686 |
687 |
688 | 689 | 690 | 691 | 692 |
693 | Fetching contributors… 694 |
695 | 696 |
697 | 698 | Cannot retrieve contributors at this time 699 |
700 |
701 | 702 | 703 | 704 | 705 |
706 | 707 |
708 |
709 | 710 | 71 lines (66 sloc) 711 | 712 | 4.93 KB 713 |
714 | 715 |
716 | 717 |
718 | Raw 719 | Blame 720 | History 721 |
722 | 723 | 724 |
725 | 726 | 730 | 734 |
735 |
736 |
737 | 738 | 739 | 740 | 741 | 742 | 743 |
744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 1029 | 1030 |
/**
* Parent for all Overlay types. The core concept with an Overlay is that of its `location`, which is specified
* as follows:
*
* ###### Connectors
* - a value between 0 and 1 inclusive is a proportional value, relative to the length of the Connector's path.
* - a value greater than 1 or less than 0 is an absolute value (travel along the path inscribed by the Connector)
*
* For Connectors, the default value is `0.5`.
*
* ###### Endpoints
* - An array of two values which are proportional to the width and height of the Endpoint.
*
* For Endpoints, the default value is `[0.5, 0.5]`.
* @class Overlay
*/
813 |
/**
* Draws an arrow, using four points: the head and two tail points, and a `foldback` point, which permits the tail of the arrow to be indented.
* @class Overlays.Arrow
* @constructor
* @param {Object} params Constructor parameters
* @param {Integer} [params.width=20] Width of the tail of the arrow
* @param {Integer} [params.length=20] Distance from the tail of the arrow to the head
* @param {Float} [params.location=0.5] Where, either as a proportional value from 0 to 1 inclusive, or as an absolute value (negative values mean distance from target; positive values greater than 1 mean distance from source) the Arrow should appear on the Connector
* @param {Integer} [params.direction=1] Which way to point. Allowed values are 1 (the default, meaning forwards) and -1, meaning backwards
* @param {Float} [params.foldback=0.623] How far along the axis of the arrow the tail points foldback in to.
* @param {Object} [params.paintStyle] A style object in the form used for paintStyle values for Endpoints and Connectors.
*/
866 |
/**
* This is just a specialized instance of Arrow in which jsPlumb hardcodes `foldback` to 1, meaning the tail of the Arrow is a flat edge
* @class Overlays.PlainArrow
* @constructor
* @param {Object} params Constructor parameters
* @param {Integer} [params.width=20] Width of the tail of the arrow
* @param {Integer} [params.length=20] Distance from the tail of the arrow to the head
* @param {Float} [params.location=0.5] Where, either as a proportional value from 0 to 1 inclusive, or as an absolute value (negative values mean distance from target; positive values greater than 1 mean distance from source) the PlainArrow should appear on the Connector
* @param {Integer} [params.direction=1] Which way to point. Allowed values are 1 (the default, meaning forwards) and -1, meaning backwards
* @param {Object} [params.paintStyle] A style object in the form used for paintStyle values for Endpoints and Connectors.
*/
915 |
/**
* This is a specialized instance of Arrow in which jsPlumb hardcodes `foldback` to 2, meaning the Arrow turns into a Diamond
* @class Overlays.Diamond
* @param {Object} params Constructor parameters
* @param {Integer} [params.width=20] Width of the diamond.
* @param {Integer} [params.length=20] Length of the diamond.
* @param {Float} [params.location=0.5] Where, either as a proportional value from 0 to 1 inclusive, or as an absolute value (negative values mean distance from target; positive values greater than 1 mean distance from source) the Diamond should appear on the Connector
* @param {Object} [params.paintStyle] A style object in the form used for paintStyle values for Endpoints and Connectors.
*/
956 |
/**
* Provides a text label with which to decorate Connectors or Endpoints. jsPlumb draws a Label overlay as a styled DIV. You can style a Label
* using the `cssClass` parameter, or - if you need to programmatically generate the appearance - the `labelStyle` parameter.
* @class Overlays.Label
* @constructor
* @param {Object} params Constructor parameters
* @param {String|Function} label - The text to display. You can provide a function here instead of plain text: it is passed the component as an argument, and it should return a String.
* @param {String} [cssClass] Optional css class to use for the Label.
* @param {Float} [location=0.5] Where, either as a proportional value from 0 to 1 inclusive, or as an absolute value (negative values mean distance from target; positive values greater than 1 mean distance from source) the Label should appear on the Connector
* @param {Object} [labelStyle] Optional object containing properties for the label's style. Use this if you need to prgrammatically generate the label's appearance.
* @param {String} [labelStyle.cssClass] css class for the label (you can also use the `cssClass` parameter on the label; this exists for historical reasons)
* @param {String} [labelStyle.font] A string specifying a font to use, in valid CSS format.
* @param {String} [labelStyle.color] A string specifying a font color to use, in valid CSS format.
* @param {String} [labelStyle.fill] A string specifying the background for the label, in valid CSS format.
* @param {String} [labelStyle.borderStyle] A string specifying the border color for the label, in valid CSS format.
* @param {Integer} [labelStyle.borderWidth] Width of the border's label
* @param {Integer} [labelStyle.padding] Padding for the label.
*/
1031 | 1032 | 1053 | 1054 |
1055 | 1056 |
1057 | 1058 | 1059 | 1060 |
1061 | 1062 | 1063 |
1064 | 1065 | 1066 |
1067 |
1068 | 1069 | 1070 | 1071 |
1072 |
1073 | 1074 |
1075 |
1076 | 1077 | 1078 |
1079 | 1080 | 1081 | 1109 | 1110 | 1111 | 1112 |
1113 | 1114 | 1117 | You can’t perform that action at this time. 1118 |
1119 | 1120 | 1121 | 1122 | 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | 1134 | 1145 | 1146 | 1150 | 1151 |
1152 | 1153 | 1154 | 1155 | 1156 | --------------------------------------------------------------------------------