43 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-05-17 17:17:39 +02:00
/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of graphviz-builder which is released under MIT.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
2020-05-06 20:24:37 +02:00
import { EdgeStyles } from '../enums/Styles';
2020-04-24 17:01:26 +02:00
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 = [];
2020-04-28 11:26:21 +02:00
2020-04-24 17:01:26 +02:00
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
}
}