Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
v.posn.y = clamp(v.posn.y, distance, this.height - distance);
}
if (this.options.icon) {
v.$el.translate(v.posn.x, v.posn.y);
} else {
v.$el.setCenter(v.posn);
}
}
for (const e of this.edges) {
if (e.vertices[0] === e.vertices[1]) {
// Connected to self
if (!center) center = Point.average(...this.vertices.map(v => v.posn));
const v = new Vector(e.vertices[0].posn.x - center.x, e.vertices[0].posn.y - center.y).unitVector;
const v0 = new Vector(v[0] + v[1], v[1] - v[0]).scale(40);
const v1 = new Vector(v[0] - v[1], v[1] + v[0]).scale(40);
e.$el.setAttr('d', `M${e.vertices[0].posn.x},${e.vertices[0].posn.y}c${v0[0]},${v0[1]},${v1[0]},${v1[1]},0,0`);
} else if (this.options.arc) {
// Arcs
const dx = e.vertices[1].posn.x - e.vertices[0].posn.x;
const dy = e.vertices[1].posn.y - e.vertices[0].posn.y;
const dr = Math.sqrt(dx * dx + dy * dy);
e.$el.setAttr('d', `M${e.vertices[0].posn.x},${e.vertices[0].posn.y}A${dr},${dr},0,0,1,${e.vertices[1].posn.x},${e.vertices[1].posn.y}`);
} else {
e.$el.setLine(e.vertices[0].posn, e.vertices[1].posn);
}
}
}
if (this.options.icon) {
v.$el.translate(v.posn.x, v.posn.y);
} else {
v.$el.setCenter(v.posn);
}
}
for (const e of this.edges) {
if (e.vertices[0] === e.vertices[1]) {
// Connected to self
if (!center) center = Point.average(...this.vertices.map(v => v.posn));
const v = new Vector(e.vertices[0].posn.x - center.x, e.vertices[0].posn.y - center.y).unitVector;
const v0 = new Vector(v[0] + v[1], v[1] - v[0]).scale(40);
const v1 = new Vector(v[0] - v[1], v[1] + v[0]).scale(40);
e.$el.setAttr('d', `M${e.vertices[0].posn.x},${e.vertices[0].posn.y}c${v0[0]},${v0[1]},${v1[0]},${v1[1]},0,0`);
} else if (this.options.arc) {
// Arcs
const dx = e.vertices[1].posn.x - e.vertices[0].posn.x;
const dy = e.vertices[1].posn.y - e.vertices[0].posn.y;
const dr = Math.sqrt(dx * dx + dy * dy);
e.$el.setAttr('d', `M${e.vertices[0].posn.x},${e.vertices[0].posn.y}A${dr},${dr},0,0,1,${e.vertices[1].posn.x},${e.vertices[1].posn.y}`);
} else {
e.$el.setLine(e.vertices[0].posn, e.vertices[1].posn);
}
}
if (this.options.icon) {
v.$el.translate(v.posn.x, v.posn.y);
} else {
v.$el.setCenter(v.posn);
}
}
for (const e of this.edges) {
if (e.vertices[0] === e.vertices[1]) {
// Connected to self
if (!center) center = Point.average(...this.vertices.map(v => v.posn));
const v = new Vector(e.vertices[0].posn.x - center.x, e.vertices[0].posn.y - center.y).unitVector;
const v0 = new Vector(v[0] + v[1], v[1] - v[0]).scale(40);
const v1 = new Vector(v[0] - v[1], v[1] + v[0]).scale(40);
e.$el.setAttr('d', `M${e.vertices[0].posn.x},${e.vertices[0].posn.y}c${v0[0]},${v0[1]},${v1[0]},${v1[1]},0,0`);
} else if (this.options.arc) {
// Arcs
const dx = e.vertices[1].posn.x - e.vertices[0].posn.x;
const dy = e.vertices[1].posn.y - e.vertices[0].posn.y;
const dr = Math.sqrt(dx * dx + dy * dy);
e.$el.setAttr('d', `M${e.vertices[0].posn.x},${e.vertices[0].posn.y}A${dr},${dr},0,0,1,${e.vertices[1].posn.x},${e.vertices[1].posn.y}`);
} else {
e.$el.setLine(e.vertices[0].posn, e.vertices[1].posn);
}
}
this.trigger('update');