Skip to content

Commit

Permalink
fix(edges): correctly detect self ref edge hover (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
piratuks authored and Thomaash committed Jan 28, 2020
1 parent 0d98fb9 commit 2abf6f4
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 11 deletions.
15 changes: 13 additions & 2 deletions examples/network/edgeStyles/selfReference.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
from: 2, to: 2, label: "Testing", arrows: 'to, middle, from',
selfReference: {
size: 40,
angle: Math.PI / 6,
angle: Math.PI * 7 / 6,
renderBehindTheNode: false
}
},
Expand All @@ -98,7 +98,18 @@
edges: edges
};
var options = {

edges: {
color: {
color: "#2B7CE9",
highlight: "#2B7CE9",
hover: "#2B7CE9"
},
hoverWidth: function (width) { return width + 2; },
shadow: true
},
interaction: {
hover: true,
},
};
var network = new vis.Network(container, data, options);

Expand Down
4 changes: 3 additions & 1 deletion lib/network/modules/components/nodes/shapes/Box.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class Box extends NodeBase {
* @returns {number}
*/
distanceToBorder(ctx, angle) {
this.resize(ctx);
if (ctx) {
this.resize(ctx);
}
let borderWidth = this.options.borderWidth;

return Math.min(
Expand Down
4 changes: 3 additions & 1 deletion lib/network/modules/components/nodes/shapes/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class Circle extends CircleImageBase {
* @returns {number}
*/
distanceToBorder(ctx, angle) { // eslint-disable-line no-unused-vars
this.resize(ctx);
if (ctx) {
this.resize(ctx);
}
return this.width * 0.5;
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/network/modules/components/nodes/shapes/CircularImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ class CircularImage extends CircleImageBase {
* @returns {number}
*/
distanceToBorder(ctx, angle) { // eslint-disable-line no-unused-vars
this.resize(ctx);
if (ctx) {
this.resize(ctx);
}
return this.width * 0.5;
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/network/modules/components/nodes/shapes/Dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class Dot extends ShapeBase {
* @returns {number}
*/
distanceToBorder(ctx, angle) { // eslint-disable-line no-unused-vars
this.resize(ctx);
if (ctx) {
this.resize(ctx);
}
return this.options.size;
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/network/modules/components/nodes/shapes/Ellipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class Ellipse extends NodeBase {
* @returns {number}
*/
distanceToBorder(ctx, angle) {
this.resize(ctx);
if (ctx) {
this.resize(ctx);
}
var a = this.width * 0.5;
var b = this.height * 0.5;
var w = (Math.sin(angle) * a);
Expand Down
4 changes: 3 additions & 1 deletion lib/network/modules/components/nodes/util/NodeBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class NodeBase {
*/
_distanceToBorder(ctx,angle) {
var borderWidth = this.options.borderWidth;
this.resize(ctx);
if (ctx){
this.resize(ctx);
}
return Math.min(
Math.abs(this.width / 2 / Math.cos(angle)),
Math.abs(this.height / 2 / Math.sin(angle))) + borderWidth;
Expand Down
2 changes: 1 addition & 1 deletion lib/network/modules/components/shared/ComponentUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ComponentUtil {
let x = node.x;
let y = node.y;

if(ctx && typeof node.distanceToBorder === "function"){
if(typeof node.distanceToBorder === "function"){
//calculating opposite and adjacent
//distaneToBorder becomes Hypotenuse.
//Formulas sin(a) = Opposite / Hypotenuse and cos(a) = Adjacent / Hypotenuse
Expand Down
4 changes: 2 additions & 2 deletions test/edges/bezier-edge-dynamic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ describe('BezierEdgeDynamic', function(): void {
)

expect(edge.getPoint(0.5)).to.deep.equal({
x: 421,
y: -404,
x: 400,
y: -846,
})
})
})
Expand Down

0 comments on commit 2abf6f4

Please sign in to comment.