import { SimulationNodeDatum } from 'd3'; export class Node implements SimulationNodeDatum { index?: number; x?: number; y?: number; vx?: number; vy?: number; fx?: number | null; fy?: number | null; name?: string; codec?: string; linkCount = 0; fontSizeName = 6.5; fontSizeCodec = 6; selected = false; coSelected = false; id: string; color: string; dropshadow: string; constructor(id: string, name?: string, codec?: string) { this.id = id; this.name = name; this.codec = codec; this.reset(); } normal = (nonZero: boolean = false) => { if (this.linkCount === 0) { return nonZero ? 0.2 : 0; } return Math.sqrt(this.linkCount / 100); } get r(): number { if (this.selected) { return 48; } if (this.linkCount > 0) { return 15; } return 12.5; } get rBase(): number { return this.selected ? this.r + 2 : this.r; } get rContent(): number { return this.r - 10; } get fontSizeId(): number { if (this.selected) { return 32; } if (this.linkCount > 0) { return 14; } return 13; } get chargeFactor(): number { if (this.selected) { return this.r * 2; } return this.r; } fontSize(factor: number, add: number, nonZeroNormal = false): number { return factor * this.normal(nonZeroNormal) + add; } reset(): void { this.color = 'url(#blueGradient)'; this.dropshadow = 'url(#dropshadow)'; this.selected = false; this.coSelected = false; } }