tw5-vis-network 10.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +10 -0
- package/README.md +37 -0
- package/package.json +37 -0
- package/plugins/vis-network/DefaultColourMappings.multids +7 -0
- package/plugins/vis-network/Stylesheet.tid +39 -0
- package/plugins/vis-network/adapter.js +179 -0
- package/plugins/vis-network/felixhayashi_vis_vis.js +36 -0
- package/plugins/vis-network/lib/icon.svg +2 -0
- package/plugins/vis-network/lib/tiddlywiki.files +27 -0
- package/plugins/vis-network/lib/vis-network.min.js +48 -0
- package/plugins/vis-network/license.tid +29 -0
- package/plugins/vis-network/messages/graph-center-node.js +19 -0
- package/plugins/vis-network/messages/graph-export-png.js +28 -0
- package/plugins/vis-network/messages/graph-move-view.js +52 -0
- package/plugins/vis-network/messages/tiddlywiki.files +17 -0
- package/plugins/vis-network/plugin.info +13 -0
- package/plugins/vis-network/properties/background.js +51 -0
- package/plugins/vis-network/properties/canvas.js +79 -0
- package/plugins/vis-network/properties/color.js +104 -0
- package/plugins/vis-network/properties/defaults.js +42 -0
- package/plugins/vis-network/properties/edges.js +87 -0
- package/plugins/vis-network/properties/events.js +127 -0
- package/plugins/vis-network/properties/id.js +24 -0
- package/plugins/vis-network/properties/image.js +35 -0
- package/plugins/vis-network/properties/interaction.js +48 -0
- package/plugins/vis-network/properties/layout.js +55 -0
- package/plugins/vis-network/properties/manipulation.js +181 -0
- package/plugins/vis-network/properties/nodes.js +42 -0
- package/plugins/vis-network/properties/physics.js +110 -0
- package/plugins/vis-network/properties/position.js +60 -0
- package/plugins/vis-network/properties/tiddlywiki.files +17 -0
- package/plugins/vis-network/readme.tid +8 -0
- package/plugins/vis-network/vis.js +59 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
title: $:/plugins/flibbles/vis-network/license
|
|
2
|
+
|
|
3
|
+
\rules except wikilink
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025, [[Cameron Fischer|https://github.com/flibbles/tw5-vis-network?tab=BSD-2-Clause-1-ov-file]]
|
|
6
|
+
|
|
7
|
+
!! The ''vis-network'' license
|
|
8
|
+
|
|
9
|
+
The MIT License (MIT)
|
|
10
|
+
|
|
11
|
+
Copyright © 2014-2018 [[Almende B.V.|https://github.com/vis/vis-network]]
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.name = "graph-center-node";
|
|
4
|
+
|
|
5
|
+
exports.parameters = {
|
|
6
|
+
tiddler: {type: "string"},
|
|
7
|
+
scale: {type: "number"}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
exports.handle = function(message, params) {
|
|
11
|
+
if (params.tiddler) {
|
|
12
|
+
var settings = {}
|
|
13
|
+
if (params.scale !== undefined) {
|
|
14
|
+
settings.scale = params.scale;
|
|
15
|
+
}
|
|
16
|
+
settings.animation = true;
|
|
17
|
+
this.vis.focus(params.tiddler, settings);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var preamble = "data:image/png;base64,";
|
|
4
|
+
|
|
5
|
+
exports.name = "graph-export-png";
|
|
6
|
+
|
|
7
|
+
exports.parameters = {
|
|
8
|
+
targetTiddler: {type: "string"},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
exports.handle = function(message, params) {
|
|
12
|
+
if (params.targetTiddler) {
|
|
13
|
+
this.wiki.addTiddler({
|
|
14
|
+
title: params.targetTiddler,
|
|
15
|
+
type: "image/png",
|
|
16
|
+
text: getCanvas(this.canvasElement)
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
function getCanvas(canvas) {
|
|
23
|
+
var data = canvas.toDataURL('image/png');
|
|
24
|
+
if ($tw.utils.startsWith(data, preamble)) {
|
|
25
|
+
data = data.substr(preamble.length);
|
|
26
|
+
}
|
|
27
|
+
return data;
|
|
28
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.name = "graph-move-view";
|
|
4
|
+
|
|
5
|
+
exports.parameters = {
|
|
6
|
+
x: {type: "number"},
|
|
7
|
+
y: {type: "number"},
|
|
8
|
+
// Only scale or scaleBy should be supplied
|
|
9
|
+
scale: {type: "number"},
|
|
10
|
+
scaleBy: {type: "number"},
|
|
11
|
+
/* For now, we're not going to expose the animation features.
|
|
12
|
+
* It's easier to add them later than to remove them
|
|
13
|
+
ms: {type: "number"},
|
|
14
|
+
easingFunction: {type: "enum", default: "linear", values: [
|
|
15
|
+
"linear",
|
|
16
|
+
"easeInQuad",
|
|
17
|
+
"easeOutQuad",
|
|
18
|
+
"easeInOutQuad",
|
|
19
|
+
"easeInCubic",
|
|
20
|
+
"easeOutCubic",
|
|
21
|
+
"easeInOutCubic",
|
|
22
|
+
"easeInQuart",
|
|
23
|
+
"easeOutQuart",
|
|
24
|
+
"easeInOutQuart",
|
|
25
|
+
"easeInQuint",
|
|
26
|
+
"easeOutQuint",
|
|
27
|
+
"easeInOutQuint"
|
|
28
|
+
]}
|
|
29
|
+
*/
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.handle = function(message, params) {
|
|
33
|
+
var settings = {}
|
|
34
|
+
if (params.x !== undefined && params.y !== undefined) {
|
|
35
|
+
settings.position = { x: params.x, y: params.y };
|
|
36
|
+
}
|
|
37
|
+
if (params.scale !== undefined) {
|
|
38
|
+
settings.scale = params.scale;
|
|
39
|
+
} else if (params.scaleBy !== undefined) {
|
|
40
|
+
var scale = this.vis.getScale();
|
|
41
|
+
settings.scale = scale * params.scaleBy;
|
|
42
|
+
}
|
|
43
|
+
/*
|
|
44
|
+
if (params.ms !== undefined) {
|
|
45
|
+
settings.animation = {
|
|
46
|
+
duration: params.time || 0,
|
|
47
|
+
easingFunction: params.easeFunction || "linear"};
|
|
48
|
+
}
|
|
49
|
+
*/
|
|
50
|
+
settings.animation = true;
|
|
51
|
+
this.vis.moveTo(settings);
|
|
52
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"directories": [
|
|
3
|
+
{
|
|
4
|
+
"path": ".",
|
|
5
|
+
"filesRegExp": "^.*\\.js$",
|
|
6
|
+
"isTiddlerFile": false,
|
|
7
|
+
"fields": {
|
|
8
|
+
"title": {
|
|
9
|
+
"source": "filename",
|
|
10
|
+
"prefix": "$:/plugins/flibbles/vis-network/messages/"
|
|
11
|
+
},
|
|
12
|
+
"type": "application/javascript",
|
|
13
|
+
"module-type": "vis-message"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Vis-Network",
|
|
3
|
+
"title": "$:/plugins/flibbles/vis-network",
|
|
4
|
+
"description": "TiddlyWiki5 plugin for the vis-network library",
|
|
5
|
+
"author": "Cameron Fischer",
|
|
6
|
+
"version": "10.5.5",
|
|
7
|
+
"stability": "STABILITY_2_STABLE",
|
|
8
|
+
"core-version": ">=5.3.0",
|
|
9
|
+
"source": "https://github.com/flibbles/tw5-vis-network",
|
|
10
|
+
"type": "application/json",
|
|
11
|
+
"plugin-type": "plugin",
|
|
12
|
+
"list": "readme license"
|
|
13
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Manages images in nodes.
|
|
4
|
+
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
exports.name = "background";
|
|
10
|
+
|
|
11
|
+
exports.properties = {
|
|
12
|
+
graph: {
|
|
13
|
+
background: {type: "image"}
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.init = function(visNetwork) {
|
|
18
|
+
var self = this;
|
|
19
|
+
visNetwork.on("beforeDrawing", function(canvas) {
|
|
20
|
+
if (self.backgroundImage) {
|
|
21
|
+
var image = self.backgroundImage;
|
|
22
|
+
canvas.drawImage(image, -image.width/2, -image.height/2);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.process = function(objects, changes) {
|
|
28
|
+
var self = this;
|
|
29
|
+
if (changes.graph) {
|
|
30
|
+
if (changes.graph.background) {
|
|
31
|
+
if (!this.backgroundImage || (this.backgroundImage.src !== changes.graph.background)) {
|
|
32
|
+
var window = this.window();
|
|
33
|
+
var image = new window.Image();
|
|
34
|
+
// We don't actually set the image as our background until after
|
|
35
|
+
// it's had a chance to load. Not a big deal for tiddler images
|
|
36
|
+
// but remote ones need this, and we can't tell the difference
|
|
37
|
+
// from here.
|
|
38
|
+
image.onload = function() {
|
|
39
|
+
self.backgroundImage = image;
|
|
40
|
+
// I don't think I need to redraw, but I might be wrong.
|
|
41
|
+
self.vis.redraw();
|
|
42
|
+
};
|
|
43
|
+
image.src = changes.graph.background;
|
|
44
|
+
this.backgroundImage = undefined;
|
|
45
|
+
}
|
|
46
|
+
changes.graph.background = undefined;
|
|
47
|
+
} else {
|
|
48
|
+
this.backgroundImage = undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Handles the focusing, blurring, and dropping of the graph canvas.
|
|
4
|
+
|
|
5
|
+
Not actually a vis thing. We put this behavior in ourselves.
|
|
6
|
+
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
"use strict";
|
|
10
|
+
|
|
11
|
+
exports.name = "canvas";
|
|
12
|
+
|
|
13
|
+
exports.properties = {
|
|
14
|
+
graph: {
|
|
15
|
+
focus: {type: "actions"},
|
|
16
|
+
blur: {type: "actions"},
|
|
17
|
+
drop: {type: "actions", variables: ["dropTiddler"]}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.init = function(visNetwork) {
|
|
22
|
+
visNetwork.canvas.frame.addEventListener("focus", this);
|
|
23
|
+
visNetwork.canvas.frame.addEventListener("blur", this);
|
|
24
|
+
visNetwork.canvas.frame.addEventListener("drop", this);
|
|
25
|
+
visNetwork.canvas.frame.addEventListener("dragover", this);
|
|
26
|
+
|
|
27
|
+
// handles both focus and blur events that occur to the canvas frame
|
|
28
|
+
this.handleEvent = handleEvent;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.destroy = function(visNetwork) {
|
|
32
|
+
this.vis.canvas.frame.removeEventListener("focus", this);
|
|
33
|
+
this.vis.canvas.frame.removeEventListener("blur", this);
|
|
34
|
+
this.vis.canvas.frame.removeEventListener("drop", this);
|
|
35
|
+
this.vis.canvas.frame.removeEventListener("dragover", this);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.process = function(objects, changes) {
|
|
39
|
+
if (changes.graph) {
|
|
40
|
+
changes.graph.focus = undefined;
|
|
41
|
+
changes.graph.blur = undefined;
|
|
42
|
+
changes.graph.drop = undefined;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
function handleEvent(event) {
|
|
47
|
+
var self = this;
|
|
48
|
+
switch (event.type) {
|
|
49
|
+
case "drop":
|
|
50
|
+
// Warning: Stopping before this line in the debugger causes
|
|
51
|
+
// event.dataTransfer to be null in Firefox.
|
|
52
|
+
var dataTransfer = event.dataTransfer;
|
|
53
|
+
$tw.utils.importDataTransfer(event.dataTransfer, null, function(fieldsArray) {
|
|
54
|
+
fieldsArray.forEach(function(fields) {
|
|
55
|
+
if (fields.title) {
|
|
56
|
+
self.onevent({
|
|
57
|
+
type: "drop",
|
|
58
|
+
objectType: "graph",
|
|
59
|
+
event: event
|
|
60
|
+
}, {dropTiddler: fields.title || fields.text});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
// Without stopPropagation, TW may try to "import" the dragged item
|
|
66
|
+
event.stopPropagation();
|
|
67
|
+
break;
|
|
68
|
+
case "dragover":
|
|
69
|
+
// Apparently this is necessary to make sure drop events trigger.
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
break;
|
|
72
|
+
default: // focus || blur
|
|
73
|
+
this.onevent({
|
|
74
|
+
type: event.type,
|
|
75
|
+
objectType: "graph",
|
|
76
|
+
event: event
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Manages the contrast of font colors when inside its shape.
|
|
4
|
+
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
var shapesWithInternalText = {
|
|
10
|
+
ellipse: true,
|
|
11
|
+
circle: true,
|
|
12
|
+
database: true,
|
|
13
|
+
box: true
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.name = "color";
|
|
17
|
+
|
|
18
|
+
exports.properties = {
|
|
19
|
+
nodes: {
|
|
20
|
+
color: {type: "color", default: "#D2E5FF"},
|
|
21
|
+
fontColor: {type: "color", default: "#343434"},
|
|
22
|
+
borderColor: {type: "color", default: "#2B7CE9"}
|
|
23
|
+
},
|
|
24
|
+
edges: {
|
|
25
|
+
color: {type: "color"}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.process = function(objects, changes) {
|
|
30
|
+
var graph = changes.graph;
|
|
31
|
+
if (graph) {
|
|
32
|
+
if (graph.nodeColor) {
|
|
33
|
+
graph.nodes = graph.nodes || {};
|
|
34
|
+
graph.nodes.color = graph.nodeColor;
|
|
35
|
+
graph.nodeColor = undefined;
|
|
36
|
+
}
|
|
37
|
+
if (graph.fontColor) {
|
|
38
|
+
graph.nodes = graph.nodes || {};
|
|
39
|
+
graph.nodes.font = {
|
|
40
|
+
color: graph.fontColor
|
|
41
|
+
};
|
|
42
|
+
graph.edges = graph.edges || {font: {align: "horizontal"}};
|
|
43
|
+
graph.edges.font.color = graph.fontColor;
|
|
44
|
+
graph.fontColor = undefined;
|
|
45
|
+
}
|
|
46
|
+
if (graph.graphColor) {
|
|
47
|
+
graph.edges = graph.edges || {font: {align: "horizontal"}};
|
|
48
|
+
graph.edges.font.strokeColor = graph.graphColor;
|
|
49
|
+
graph.graphColor = undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (changes.nodes) {
|
|
53
|
+
var globalColor = (changes.graph && changes.graph.nodes && changes.graph.nodes.color) || (objects.graph && objects.graph.nodeColor);
|
|
54
|
+
if (!globalColor && objects.graph) {
|
|
55
|
+
// The color isn't being set. Maybe it was already set.
|
|
56
|
+
globalColor = objects.graph.nodes && objects.graph.nodes.color;
|
|
57
|
+
}
|
|
58
|
+
for (var id in changes.nodes) {
|
|
59
|
+
// Set contrast color for the font, if necessary
|
|
60
|
+
var node = changes.nodes[id];
|
|
61
|
+
if (node) {
|
|
62
|
+
setFontColor(node, globalColor);
|
|
63
|
+
setNodeColor(node, globalColor, objects.nodes && objects.nodes[id]);
|
|
64
|
+
}
|
|
65
|
+
// Set a border color if necessary
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
function setFontColor(node, globalColor) {
|
|
71
|
+
if (node.fontColor) {
|
|
72
|
+
node.font = node.font || {};
|
|
73
|
+
node.font.color = node.fontColor;
|
|
74
|
+
node.fontColor = undefined;
|
|
75
|
+
} else if (shapesWithInternalText[node.shape] === true
|
|
76
|
+
&& node.label
|
|
77
|
+
&& (node.color || globalColor)
|
|
78
|
+
&& (!node.font || !node.font.color)) {
|
|
79
|
+
node.font = node.font || {};
|
|
80
|
+
var fontColor = $tw.macros.contrastcolour.run(
|
|
81
|
+
node.color || "",
|
|
82
|
+
globalColor || "#D2E5FF",
|
|
83
|
+
"#000000", "#ffffff");
|
|
84
|
+
node.font.color = fontColor;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
function setNodeColor(node, globalColor, object) {
|
|
89
|
+
if (node.borderColor) {
|
|
90
|
+
var background = node.color;
|
|
91
|
+
if (!background && object && typeof object.color === "object") {
|
|
92
|
+
// This is a work-around for a vis-network bug where background
|
|
93
|
+
// color cannot be unset while more specific colorings exist.
|
|
94
|
+
background = globalColor;
|
|
95
|
+
}
|
|
96
|
+
node.color = {
|
|
97
|
+
border: node.borderColor,
|
|
98
|
+
highlight: {background: background, border: node.borderColor},
|
|
99
|
+
hover: {background: background, border: node.borderColor},
|
|
100
|
+
background: background
|
|
101
|
+
};
|
|
102
|
+
node.borderColor = undefined;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Installs defaults for first object.
|
|
4
|
+
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
var options = {
|
|
10
|
+
interaction: {
|
|
11
|
+
hover: true
|
|
12
|
+
},
|
|
13
|
+
nodes: {
|
|
14
|
+
shape: "dot",
|
|
15
|
+
font: {}
|
|
16
|
+
},
|
|
17
|
+
edges: {
|
|
18
|
+
arrows: "to"
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.name = "defaults";
|
|
23
|
+
|
|
24
|
+
exports.process = function(objects, changes) {
|
|
25
|
+
if (!objects.graph) {
|
|
26
|
+
if (!changes.graph) {
|
|
27
|
+
changes.graph = {};
|
|
28
|
+
}
|
|
29
|
+
set(changes.graph, options);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function set(target, input) {
|
|
34
|
+
for (var def in input) {
|
|
35
|
+
if (typeof input[def] === "object") {
|
|
36
|
+
target[def] = target[def] || {};
|
|
37
|
+
set(target[def], input[def]);
|
|
38
|
+
} else {
|
|
39
|
+
target[def] = input[def];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Handles a bug in vis-network where edge labels cannot be removed.
|
|
4
|
+
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
var smooths = {};
|
|
10
|
+
var curves = ["dynamic", "continuous", "discrete", "diagonalCross", "straightCross", "horizontal", "vertical", "curvedCW", "curvedCCW", "cubicBezier", "cubicBezierHorizontal", "cubicBezierVertical"];
|
|
11
|
+
|
|
12
|
+
$tw.utils.each(curves, function(type) {
|
|
13
|
+
smooths[type] = {enabled: true, type: type};
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var strokes = {
|
|
17
|
+
solid: false,
|
|
18
|
+
dashed: true, // equivalent of [5,5] I believe
|
|
19
|
+
dotted: [1, 4]
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// We set type to an empty object instead of null, because vis-network
|
|
23
|
+
// will erroneously try to access it in some cases.
|
|
24
|
+
smooths.no = {enabled: false, type: {}};
|
|
25
|
+
smooths.dynamic.roundness = 0.5;
|
|
26
|
+
smooths.cubicBezier.forceDirection = "none";
|
|
27
|
+
smooths.cubicBezierHorizontal.type = "cubicBezier";
|
|
28
|
+
smooths.cubicBezierHorizontal.forceDirection = "horizontal";
|
|
29
|
+
smooths.cubicBezierVertical.type = "cubicBezier";
|
|
30
|
+
smooths.cubicBezierVertical.forceDirection = "vertical";
|
|
31
|
+
|
|
32
|
+
exports.name = "edges";
|
|
33
|
+
|
|
34
|
+
exports.properties = {
|
|
35
|
+
edges: {
|
|
36
|
+
// These two properties don't require special handling
|
|
37
|
+
hidden: {type: "boolean", default: false},
|
|
38
|
+
width: {type: "number", min: 0, default: 1, increment: 0.1},
|
|
39
|
+
// "Arrows" actually accept any combination of those values. Plus this has many more options.
|
|
40
|
+
// For backward compatibility, we accept a hidden " " property,
|
|
41
|
+
// which used to be the old "no", until I realized what bad design
|
|
42
|
+
// that was.
|
|
43
|
+
arrows: {type: "enum", default: "to", values: ["no", "to", "from", "middle"], hidden: ["no"], multiple: true},
|
|
44
|
+
stroke: {type: "enum", values: ["solid", "dashed", "dotted"], default: "solid"},
|
|
45
|
+
roundness: {type: "number", default: 0.5, min: 0, max: 1, increment: 0.01},
|
|
46
|
+
label: {type: "string"},
|
|
47
|
+
smooth: {type: "enum", default: "dynamic", values: ["no"].concat(curves)},
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.process = function(objects, changes) {
|
|
52
|
+
if (changes.edges) {
|
|
53
|
+
var oldEdges = (objects && objects.edges) || {};
|
|
54
|
+
for (var id in changes.edges) {
|
|
55
|
+
var edge = changes.edges[id];
|
|
56
|
+
var old = oldEdges[id] || {};
|
|
57
|
+
if (edge) {
|
|
58
|
+
// fix for vis-network edge label but
|
|
59
|
+
if (!edge.label && old.label) {
|
|
60
|
+
edge.label = "\0";
|
|
61
|
+
}
|
|
62
|
+
// Fix for flibbles/tw5-graph#33 bug
|
|
63
|
+
if (edge.smooth) {
|
|
64
|
+
edge.smooth = Object.assign({}, smooths[edge.smooth]);
|
|
65
|
+
edge.smooth.roundness = (edge.roundness === undefined)?
|
|
66
|
+
0.5: edge.roundness;
|
|
67
|
+
} else if (old.smooth !== undefined) {
|
|
68
|
+
// Once smooth is set, it can never truly be unset without
|
|
69
|
+
// vis-network crashes occurring.
|
|
70
|
+
edge.smooth = smooths.dynamic;
|
|
71
|
+
}
|
|
72
|
+
if (edge.roundness !== undefined) {
|
|
73
|
+
edge.roundness = undefined;
|
|
74
|
+
}
|
|
75
|
+
if (edge.arrows) {
|
|
76
|
+
edge.arrows = edge.arrows.join(",");
|
|
77
|
+
}
|
|
78
|
+
if (edge.stroke) {
|
|
79
|
+
edge.dashes = strokes[edge.stroke] || false;
|
|
80
|
+
edge.stroke = undefined;
|
|
81
|
+
} else if (old.dashes !== undefined) {
|
|
82
|
+
edge.dashes = false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Manages the contrast of font colors when inside its shape.
|
|
4
|
+
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
exports.name = "events";
|
|
10
|
+
|
|
11
|
+
exports.properties = {
|
|
12
|
+
graph: {
|
|
13
|
+
doubleclick: {type: "actions", variables: ["x", "y"]},
|
|
14
|
+
},
|
|
15
|
+
nodes: {
|
|
16
|
+
actions: {type: "actions"},
|
|
17
|
+
hover: {type: "actions"},
|
|
18
|
+
blur: {type: "actions"},
|
|
19
|
+
drag: {type: "actions"},
|
|
20
|
+
free: {type: "actions", variables: ["x", "y"]}
|
|
21
|
+
},
|
|
22
|
+
edges: {
|
|
23
|
+
actions: {type: "actions"},
|
|
24
|
+
hover: {type: "actions"},
|
|
25
|
+
blur: {type: "actions"}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.init = function(visNetwork) {
|
|
30
|
+
var self = this;
|
|
31
|
+
//this.vis.on("click", function(params) { });
|
|
32
|
+
visNetwork.on("doubleClick", function(params) {
|
|
33
|
+
var data = {
|
|
34
|
+
type: "actions",
|
|
35
|
+
event: params.event.pointers[0],
|
|
36
|
+
};
|
|
37
|
+
var variables;
|
|
38
|
+
// TODO: Meta keys
|
|
39
|
+
if (params.nodes.length >= 1) {
|
|
40
|
+
data.id = params.nodes[0];
|
|
41
|
+
data.objectType = "nodes";
|
|
42
|
+
} else if (params.edges.length >= 1) {
|
|
43
|
+
data.id = params.edges[0];
|
|
44
|
+
data.objectType = "edges";
|
|
45
|
+
} else {
|
|
46
|
+
data.type = "doubleclick";
|
|
47
|
+
data.objectType = "graph";
|
|
48
|
+
variables = variablesFromInputParams(params);
|
|
49
|
+
}
|
|
50
|
+
self.onevent(data, variables);
|
|
51
|
+
});
|
|
52
|
+
visNetwork.on("dragStart", function(params) {
|
|
53
|
+
if (params.nodes.length > 0) {
|
|
54
|
+
var data = {
|
|
55
|
+
type: "drag",
|
|
56
|
+
objectType: "nodes",
|
|
57
|
+
id: params.nodes[0],
|
|
58
|
+
event: params.event
|
|
59
|
+
};
|
|
60
|
+
self.onevent(data, {});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
visNetwork.on("dragEnd", function(params) {
|
|
64
|
+
if (params.nodes.length > 0) {
|
|
65
|
+
var data = {
|
|
66
|
+
type: "free",
|
|
67
|
+
objectType: "nodes",
|
|
68
|
+
id: params.nodes[0],
|
|
69
|
+
event: params.event
|
|
70
|
+
};
|
|
71
|
+
var nodePosition = this.getPosition(params.nodes[0]);
|
|
72
|
+
nodePosition.x = round(nodePosition.x);
|
|
73
|
+
nodePosition.y = round(nodePosition.y);
|
|
74
|
+
self.onevent(data, nodePosition);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
visNetwork.on("hoverNode", function(params) {
|
|
78
|
+
self.onevent({
|
|
79
|
+
type: "hover",
|
|
80
|
+
objectType: "nodes",
|
|
81
|
+
id: params.node,
|
|
82
|
+
event: params.event,
|
|
83
|
+
}, {});
|
|
84
|
+
});
|
|
85
|
+
visNetwork.on("blurNode", function(params) {
|
|
86
|
+
self.onevent({
|
|
87
|
+
type: "blur",
|
|
88
|
+
objectType: "nodes",
|
|
89
|
+
id: params.node,
|
|
90
|
+
event: params.event
|
|
91
|
+
}, {});
|
|
92
|
+
});
|
|
93
|
+
visNetwork.on("hoverEdge", function(params) {
|
|
94
|
+
self.onevent({
|
|
95
|
+
type: "hover",
|
|
96
|
+
objectType: "edges",
|
|
97
|
+
id: params.edge,
|
|
98
|
+
event: params.event,
|
|
99
|
+
}, {});
|
|
100
|
+
});
|
|
101
|
+
visNetwork.on("blurEdge", function(params) {
|
|
102
|
+
self.onevent({
|
|
103
|
+
type: "blur",
|
|
104
|
+
objectType: "edges",
|
|
105
|
+
id: params.edge,
|
|
106
|
+
event: params.event
|
|
107
|
+
}, {});
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
exports.process = function(object, changes) {
|
|
112
|
+
if (changes.graph && changes.graph.doubleclick) {
|
|
113
|
+
changes.graph.doubleclick = undefined;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
function round(number) {
|
|
118
|
+
return Math.round(number * 10) / 10;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
function variablesFromInputParams(params) {
|
|
122
|
+
return {
|
|
123
|
+
x: round(params.pointer.canvas.x),
|
|
124
|
+
y: round(params.pointer.canvas.y)};
|
|
125
|
+
//xView: params.pointer.DOM.x,
|
|
126
|
+
//yView: params.pointer.DOM.y};
|
|
127
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Installs the ids into all the objects.
|
|
4
|
+
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
exports.name = "id";
|
|
10
|
+
|
|
11
|
+
exports.process = function(objects, changes) {
|
|
12
|
+
for (var type in changes) {
|
|
13
|
+
// Assign the ids to each non-graph object
|
|
14
|
+
if (type !== "graph") {
|
|
15
|
+
var set = changes[type];
|
|
16
|
+
for (var id in set) {
|
|
17
|
+
var object = set[id];
|
|
18
|
+
if (object !== null) {
|
|
19
|
+
object.id = id;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|