more graph attributes

This commit is contained in:
Timo Hocker
2020-04-28 10:52:02 +02:00
parent 8af030e54f
commit 4328d3a78f
4 changed files with 37 additions and 15 deletions

View File

@ -3,6 +3,7 @@ import { Edge } from './Edge';
import { Node } from './Node';
import { GraphStyles, NodeStyles } from './Styles';
import { Color } from './Color';
import { GraphLayouts } from './GraphLayouts';
interface NodeOptions {
name: string;
@ -19,19 +20,34 @@ export class Graph extends Element {
public style?: GraphStyles;
public color?: Color;
public directional = true;
public overlap?: boolean;
public splines?: boolean;
public layout?: GraphLayouts;
private get attributes (): Array<{name: string; value: string}> {
const attributes = [];
if (this.color)
attributes.push ({ name: 'color', value: this.color.toString () });
if (this.style)
attributes.push ({ name: 'style', value: this.style.toString () });
if (this.overlap)
attributes.push ({ name: 'overlap', value: this.overlap.toString () });
if (this.splines)
attributes.push ({ name: 'splines', value: this.splines.toString () });
if (this.layout)
attributes.push ({ name: 'layout', value: this.layout.toString () });
return attributes;
}
// eslint-disable-next-line @typescript-eslint/naming-convention
public toString (): string {
const header = this.parent
? `subgraph cluster_${this.full_name}`
: `${this.directional ? 'di' : ''}graph ${this.full_name}`;
const attributes = [];
if (this.color)
attributes.push ({ name: 'color', value: this.color.toString () });
if (this.style)
attributes.push ({ name: 'style', value: this.style.toString () });
let attrs = `\n${attributes.map ((v) => `${v.name} = ${v.value}`)
let attrs = `\n${this.attributes.map ((v) => `${v.name} = ${v.value}`)
.join ('\n')}\n`;
let children = `\n${this.children.map ((c) => c.toString ())
.join ('\n')}\n`;
@ -75,6 +91,7 @@ export class Graph extends Element {
public add_graph (constructor: ((g: Graph) => void) | string): string {
const graph = new Graph ('unnamed', this.full_name);
graph.directional = this.directional;
if (typeof constructor === 'string')

4
lib/GraphLayouts.ts Normal file
View File

@ -0,0 +1,4 @@
export enum GraphLayouts {
neato= 'neato',
dot= 'dot'
}

View File

@ -4,3 +4,4 @@ export { Element } from './Element';
export { Edge } from './Edge';
export { Color } from './Color';
export { EdgeStyles, NodeStyles, GraphStyles } from './Styles';
export { GraphLayouts } from './GraphLayouts';