36 lines
969 B
TypeScript
36 lines
969 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;
|
|
private _directional: boolean;
|
|
|
|
public constructor (origin: string, target: string, directional: boolean) {
|
|
this.origin = origin;
|
|
this.target = target;
|
|
this._directional = directional;
|
|
}
|
|
|
|
// 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._directional ? '>' : '-'
|
|
} ${this.target}${attributes.length > 0
|
|
? attr_string
|
|
: ''}`;
|
|
}
|
|
}
|