diff --git a/lib/Graph.ts b/lib/Graph.ts index 5b53124..a61693a 100644 --- a/lib/Graph.ts +++ b/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') diff --git a/lib/GraphLayouts.ts b/lib/GraphLayouts.ts new file mode 100644 index 0000000..a856eef --- /dev/null +++ b/lib/GraphLayouts.ts @@ -0,0 +1,4 @@ +export enum GraphLayouts { + neato= 'neato', + dot= 'dot' +} diff --git a/lib/index.ts b/lib/index.ts index d1f0946..e029ed0 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -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'; diff --git a/yarn.lock b/yarn.lock index c81220b..3b27672 100644 --- a/yarn.lock +++ b/yarn.lock @@ -233,26 +233,26 @@ integrity sha512-f7hJzrHjI5D+yC8KnwGV1q/vARE0ZOUHe0f3fybCmzU38wobs0Jm+XgYi98ViXqFmvt18cz1NI1c4q9sdrcsQQ== "@scode/eslint-config-es6@^1.0.1": - version "1.0.23" - resolved "https://npm.scode.ovh/@scode%2feslint-config-es6/-/eslint-config-es6-1.0.23.tgz#9e1cf74350217c202aaa8dfc46838416715fbf60" - integrity sha512-Ux1BOuKa9W7MoKID8VyWzJZo3je5k8h2lnc66KmBedDSruTwMhUqx2JzALoO2MeUFkvjtoVvdKXbSPvFPc54YQ== + version "1.0.24" + resolved "https://npm.scode.ovh/@scode%2feslint-config-es6/-/eslint-config-es6-1.0.24.tgz#c3c88ac98beb9dc73da7812f614e8f289cec763b" + integrity sha512-FyMzNbI6ZgGTr7bG1av+VSuYYWZIRbUp+ZvjVwtZduKkijXotOTg3jw0vMWi09IEq7esusQQZ/lZInAjvXJWKA== dependencies: "@scode/eslint-config" "^2.0.1" eslint-plugin-import "^2.20.1" "@scode/eslint-config-ts@^1.0.22": - version "1.0.26" - resolved "https://npm.scode.ovh/@scode%2feslint-config-ts/-/eslint-config-ts-1.0.26.tgz#fd980c8e1dcd8bc52e182643487af9e40393ee82" - integrity sha512-PLfaNdPXyz7V4PRDsUpcqY+l9yP3d1aRf93U55aAmA3NXmpucA8twoFgB1Li9pE8NTHbEC612gUD/pdQ+1/cQg== + version "1.0.27" + resolved "https://npm.scode.ovh/@scode%2feslint-config-ts/-/eslint-config-ts-1.0.27.tgz#d3d068df6f287273041029f4549378ecaa17972b" + integrity sha512-KapsP1enFNw4kBjI4L3WKBnwKeKp6Ka9ml3OoT7zpGZZLd9nzvyD1SpGks9PQ1ZJse9nBy2HVuRVPAHzfIBvmw== dependencies: "@scode/eslint-config-es6" "^1.0.1" "@typescript-eslint/eslint-plugin" "^2.26.0" "@typescript-eslint/parser" "^2.26.0" "@scode/eslint-config@^2.0.1": - version "2.0.12" - resolved "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-2.0.12.tgz#eccd5205541fd63cbb84f72427d58873850224b0" - integrity sha512-llgvCpThp6ZDWzPPw1zmXMNwWp3oIndwX/FLigeyPQx/T1ucrbadf3iyTo0ZReJiUobGTiVBta6N13qGyzQsjA== + version "2.0.13" + resolved "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-2.0.13.tgz#e7e4d3c9185449de7a7d810f3ee783459b779e8a" + integrity sha512-ans0dulrnReK+9+XD5nw04kKEdveEVbRL9AKH3PTr8jUQJBY/pzeDznkf6oWnLPBKqbDn/MEKlS5MOExAgooWw== dependencies: eslint-plugin-jsdoc "^24.0.0" eslint-plugin-node "^11.0.0"