more graph attributes
This commit is contained in:
29
lib/Graph.ts
29
lib/Graph.ts
@ -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
4
lib/GraphLayouts.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum GraphLayouts {
|
||||
neato= 'neato',
|
||||
dot= 'dot'
|
||||
}
|
@ -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';
|
||||
|
Reference in New Issue
Block a user