Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.vertices = list(vertices).map((v) => {
let x = posn ? (posn[v][0] || posn[v].x) : this.width * (0.3 + 0.4 * Math.random());
let y = posn ? (posn[v][1] || posn[v].y) : this.height * (0.3 + 0.4 * Math.random());
let $el = this.options.icon ?
$N('path', { 'class': 'node', d: this.options.icon }, this.$vertices) :
$N('circle', { 'class': 'node', r: this.options.r || 5 }, this.$vertices);
if (this.options.vertex) $el.css('fill', run(this.options.vertex, v));
return { $el: $el, posn: { x: x, y: y }, neighbours: [], v: { x: 0, y: 0 } };
});
function loadView(router, view, params = {}, url = '') {
router.$viewport.css({ opacity: 0.4, 'pointer-events': 'none' });
const template = run(view.template, params) || loadUrl(url);
if (template.then) {
template.then(response => renderView(router, view, response, params));
} else {
renderView(router, view, template, params);
}
}
return new Vector(new Array(n).map((_, i) => run(value, i)));
}
this.vertices = list(vertices).map((v) => {
let x = posn ? posn[v].x : this.width * (0.3 + 0.4 * Math.random());
let y = posn ? posn[v].y : this.height * (0.3 + 0.4 * Math.random());
let $el = (this.options.icon ?
$N('path', {'class': 'node', d: this.options.icon}, this.$vertices) :
$N('circle', {'class': 'node', r: this.options.r || 5}, this.$vertices)) as SVGView;
if (this.options.vertex) $el.css('fill', run(this.options.vertex, v));
return {$el: $el, posn: {x: x, y: y}, neighbours: [], v: {x: 0, y: 0}};
});
this.edges = edges.map((e) => {
let v1 = this.vertices[e[0]];
let v2 = this.vertices[e[1]];
let type = (v1 === v2) || this.options.arc ? 'path' : 'line';
let $el = $N(type, { 'class': 'link' }, this.$edges);
if (this.options.directed) $el.setAttr('marker-end', 'url(#arrow-head)');
if (this.options.edge) $el.css('stroke', run(this.options.edge, e[0], e[1]));
let edge = { $el: $el, vertices: [v1, v2] };
v1.neighbours.push(v2);
v2.neighbours.push(v1);
return edge;
});
this.edges = edges.map(([a, b]) => {
let v1 = this.vertices[a];
let v2 = this.vertices[b];
let type = (v1 === v2) || this.options.arc ? 'path' : 'line';
let $el = $N(type, {'class': 'link'}, this.$edges) as SVGView;
if (this.options.directed) $el.setAttr('marker-end', 'url(#arrow-head)');
if (this.options.edge) $el.css('stroke', run(this.options.edge, a, b));
let edge = {$el: $el, vertices: [v1, v2] as [Vertex, Vertex]};
v1.neighbours.push(v2);
v2.neighbours.push(v1);
return edge;
});