Timo Hocker 3b67053b3e styles
2020-04-24 17:01:26 +02:00

31 lines
833 B
TypeScript

import { EdgeStyles } from './Styles';
import { Color } from './Color';
export class Edge {
public origin: string;
public target: string;
public style?: EdgeStyles;
public color?: Color;
public constructor (origin: string, target: string) {
this.origin = origin;
this.target = target;
}
// eslint-disable-next-line @typescript-eslint/naming-convention
public toString (): string {
const attributes = [];
if (this.style)
attributes.push ({ name: 'style', value: this.style.toString () });
if (this.color)
attributes.push ({ name: 'color', value: this.color.toString () });
const attr_string = ` [${attributes.map ((v) => `${v.name}="${v.value}"`)
.join (',')}]`;
return `${this.origin} -> ${this.target}${attributes.length > 0
? attr_string
: ''}`;
}
}