1
|
/**
|
2
|
* Class representing a floating point connecting a node present in the viewport with a node excluded to the sidebar. Position
|
3
|
* of a floating point is changed every time when graph is moved or zoomed, node is moved in viewport or sidebar is scrolled.
|
4
|
* @constructor
|
5
|
*/
|
6
|
function FloatingPoint() {
|
7
|
var rootElement;
|
8
|
|
9
|
var node;
|
10
|
var position = new Coordinates(0, 0);
|
11
|
|
12
|
var inEdgeList = [];
|
13
|
var outEdgeList = [];
|
14
|
|
15
|
/**
|
16
|
* Sets a DOM element in sidebar that this floating point is bound to. It is used to calculate floating point position
|
17
|
* when sidebar is scrolled.
|
18
|
* @param {Element} newValue DOM element in sidebar the floating point is bound to.
|
19
|
*/
|
20
|
this.setElement = function(newValue) {
|
21
|
rootElement = newValue;
|
22
|
};
|
23
|
|
24
|
/**
|
25
|
* Sets a graph node (vertex or group) that this floating point is bound to. This node is then highlighted when the other
|
26
|
* node of the edge is clicked.
|
27
|
* @param {(Vertex|Group)} newValue Graph node the floating point is bound to.
|
28
|
*/
|
29
|
this.setNode = function(newValue) {
|
30
|
node = newValue;
|
31
|
};
|
32
|
|
33
|
/**
|
34
|
* Adds a new edge ending in this floating point. Its ending point is moved to the current position of the floating point.
|
35
|
* @param {Edge} edge Edge going to the floating point.
|
36
|
*/
|
37
|
this.addInEdge = function(edge) {
|
38
|
if (!(edge instanceof Edge)) {
|
39
|
throw new TypeError(edge.toString() + 'is not instance of Edge');
|
40
|
}
|
41
|
|
42
|
edge.moveEnd(this.getPosition());
|
43
|
|
44
|
inEdgeList.push(edge);
|
45
|
};
|
46
|
|
47
|
/**
|
48
|
* Adds a new edge starting in this floating point. Its starting point is moved to the current position of the floating point.
|
49
|
* @param {Edge} edge Edge going from the floating point.
|
50
|
*/
|
51
|
this.addOutEdge = function(edge) {
|
52
|
if (!(edge instanceof Edge)) {
|
53
|
throw new TypeError(edge.toString() + 'is not instance of Edge');
|
54
|
}
|
55
|
|
56
|
edge.moveStart(this.getPosition());
|
57
|
|
58
|
outEdgeList.push(edge);
|
59
|
};
|
60
|
|
61
|
/**
|
62
|
* @returns {array<Edge>} Array of edges going to the floating point.
|
63
|
*/
|
64
|
this.getInEdgeList = function() {
|
65
|
return inEdgeList;
|
66
|
};
|
67
|
|
68
|
/**
|
69
|
* @returns {array<Edge>} Array of edges going from the floating point.
|
70
|
*/
|
71
|
this.getOutEdgeList = function() {
|
72
|
return outEdgeList;
|
73
|
};
|
74
|
|
75
|
/**
|
76
|
* @returns {Coordinates} Current position of the floating point.
|
77
|
*/
|
78
|
this.getPosition = function() {
|
79
|
return position;
|
80
|
};
|
81
|
|
82
|
/**
|
83
|
* Updates the current position of vertices related to the floating point.
|
84
|
*/
|
85
|
this.setPosition = function() {
|
86
|
var bbox = rootElement.getBoundingClientRect();
|
87
|
var viewportPosition = app.viewportComponent.getPosition();
|
88
|
|
89
|
position.x = (bbox.left - viewportPosition.x);
|
90
|
position.y = (bbox.top - viewportPosition.y - app.headerHeight);
|
91
|
|
92
|
if (node instanceof Vertex) {
|
93
|
var inEdgeOffsetY = 15;
|
94
|
var outEdgeOffsetY = 45;
|
95
|
} else if (node instanceof Group) {
|
96
|
var inEdgeOffsetY = 40;
|
97
|
var outEdgeOffsetY = 70;
|
98
|
}
|
99
|
|
100
|
// redraw dependent edges
|
101
|
inEdgeList.forEach(function(edge) {
|
102
|
edge.moveEnd(new Coordinates(
|
103
|
position.x / app.zoom.scale,
|
104
|
(position.y + inEdgeOffsetY) / app.zoom.scale,
|
105
|
));
|
106
|
}, this);
|
107
|
|
108
|
outEdgeList.forEach(function(edge) {
|
109
|
edge.moveStart(new Coordinates(
|
110
|
position.x / app.zoom.scale,
|
111
|
(position.y + outEdgeOffsetY) / app.zoom.scale,
|
112
|
));
|
113
|
}, this);
|
114
|
};
|
115
|
|
116
|
/**
|
117
|
* @returns {Coordinates} Centre of this floating point.
|
118
|
*/
|
119
|
this.getCenter = function() {
|
120
|
return position;
|
121
|
};
|
122
|
|
123
|
/**
|
124
|
* Always returns false as floating points may never be excluded. It is here for FloatingPoint to be compatible with API of Vertex.
|
125
|
* @see Vertex
|
126
|
* @returns {boolean} Always false.
|
127
|
*/
|
128
|
this.isExcluded = function() {
|
129
|
return false;
|
130
|
};
|
131
|
|
132
|
/**
|
133
|
* Does nothing as floating points may never be dimmed. It is here for FloatingPoint to be compatible with API of Vertex.
|
134
|
* @see Vertex
|
135
|
* @param {boolean} newValue Anything.
|
136
|
*/
|
137
|
this.setDimmed = function(newValue) {
|
138
|
// do nothing
|
139
|
};
|
140
|
|
141
|
/**
|
142
|
* Toggles highlighting of the depedent node.
|
143
|
* @param {boolean} newValue True to highlight the node as required, otherwise false.
|
144
|
*/
|
145
|
this.setHighlightedRequired = function(newValue) {
|
146
|
node.setHighlightedRequired(newValue);
|
147
|
};
|
148
|
|
149
|
/**
|
150
|
* Toggles highlighting of the depedent node.
|
151
|
* @param {boolean} newValue True to highlight the node as provided, otherwise false.
|
152
|
*/
|
153
|
this.setHighlightedProvided = function(newValue) {
|
154
|
node.setHighlightedProvided(newValue);
|
155
|
};
|
156
|
}
|