38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { Element } from './Element';
|
|
import { NodeStyles } from './Styles';
|
|
import { Color } from './Color';
|
|
|
|
export class Node extends Element {
|
|
public label?: string;
|
|
public is_table = false;
|
|
public table_contents?: Array<Array<string>>;
|
|
public style?: NodeStyles;
|
|
public color?: Color;
|
|
|
|
public constructor (name: string, parent?: string, label?: string) {
|
|
super (name, parent);
|
|
this.label = label;
|
|
}
|
|
|
|
private get serialized_table (): string {
|
|
if (typeof this.table_contents === 'undefined')
|
|
throw new Error ('table contents are undefined');
|
|
|
|
const mapped_columns = this.table_contents
|
|
.map ((val) => `<td>${val.join ('</td><td>')}</td>`);
|
|
return `<table>\n <tr>${
|
|
mapped_columns.join ('</tr>\n <tr>')
|
|
}</tr>\n</table>`;
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
public toString (): string {
|
|
if (this.is_table || typeof this.label !== 'undefined') {
|
|
return `${this.full_name} [label=<${this.is_table
|
|
? this.serialized_table
|
|
: this.label}>]`;
|
|
}
|
|
return `${this.full_name}`;
|
|
}
|
|
}
|