35 lines
968 B
TypeScript
Raw Normal View History

2020-04-24 17:01:26 +02:00
import { EdgeStyles } from './Styles';
import { Color } from './Color';
2020-04-17 15:43:34 +02:00
export class Edge {
public origin: string;
public target: string;
2020-04-24 17:01:26 +02:00
public style?: EdgeStyles;
public color?: Color;
2020-04-28 08:39:57 +02:00
private _directional: boolean;
2020-04-17 15:43:34 +02:00
2020-04-28 08:39:57 +02:00
public constructor (origin: string, target: string, directional: boolean) {
2020-04-24 12:02:32 +02:00
this.origin = origin;
this.target = target;
2020-04-28 08:39:57 +02:00
this._directional = directional;
2020-04-24 12:02:32 +02:00
}
2020-04-17 15:43:34 +02:00
// eslint-disable-next-line @typescript-eslint/naming-convention
public toString (): string {
2020-04-24 17:01:26 +02:00
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 (',')}]`;
2020-04-28 08:39:57 +02:00
return `${this.origin} -${
this._directional ? '>' : '-'
} ${this.target}${attributes.length > 0
2020-04-24 17:01:26 +02:00
? attr_string
: ''}`;
2020-04-17 15:43:34 +02:00
}
}