Compare commits

...

4 Commits

Author SHA1 Message Date
cef87ba4a5 lint
All checks were successful
continuous-integration/drone/push Build is passing
2023-03-25 14:17:58 +01:00
78556c6c98 node shape
Some checks failed
continuous-integration/drone/push Build is failing
2023-03-25 14:12:10 +01:00
019647b04a formatting, update
Some checks failed
continuous-integration/drone/push Build is failing
2021-05-02 11:30:21 +02:00
fa8e0d25c6 bump version
All checks were successful
continuous-integration/drone/push Build is passing
2020-10-05 20:16:10 +02:00
13 changed files with 893 additions and 1443 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## 1.4.0
Allow specifying shapes for nodes
## 1.3.0
Stream:

View File

@ -1,6 +1,6 @@
# @sapphirecode/graphviz-builder
version: 1.3.x
version: 1.4.x
constructing graphviz files using an easy typescript interface

View File

@ -5,20 +5,13 @@
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
import { GraphStyles, NodeStyles } from '../enums/Styles';
import { GraphStyles } from '../enums/Styles';
import { GraphLayouts } from '../enums/GraphLayouts';
import { Element } from './Element';
import { Edge } from './Edge';
import { Node } from './Node';
import { Color } from './Color';
interface NodeOptions {
name: string;
label: string;
style: NodeStyles;
color: Color;
}
export class Graph extends Element {
public children: Array<Graph> = [];
public nodes: Array<Node> = [];
@ -83,7 +76,7 @@ export class Graph extends Element {
.replace (/^\s+$/gmu, '');
}
public add_node (constructor: ((n: Node) => void) | string): string {
public add_node (constructor: string | ((n: Node) => void)): string {
const node = new Node ('unnamed', this.full_name);
if (typeof constructor === 'string') {
@ -96,7 +89,7 @@ export class Graph extends Element {
return node.full_name;
}
public add_graph (constructor: ((g: Graph) => void) | string): string {
public add_graph (constructor: string | ((g: Graph) => void)): string {
const graph = new Graph ('unnamed', this.full_name);
graph.directional = this.directional;

View File

@ -168,7 +168,7 @@ export class GraphStream extends Transform {
// this.write ({ type: 'en', args: [] });
}
public create_graph (name: string, type: 'u'|'d'|'s' = 's'): void {
public create_graph (name: string, type: 'd' | 's' | 'u' = 's'): void {
const instr_type = `c${type}g` as GraphStreamCommand;
this.write ({ type: instr_type, args: [ validate_name (name) ] });
}

View File

@ -6,6 +6,7 @@
*/
import { NodeStyles } from '../enums/Styles';
import { NodeShapes } from '../enums/Shapes';
import { Element } from './Element';
import { Color } from './Color';
@ -15,6 +16,7 @@ export class Node extends Element {
public table_contents?: Array<Array<string>>;
public style?: NodeStyles;
public color?: Color;
public shape?: NodeShapes;
public constructor (name: string, parent: string, label?: string) {
super (name, parent);
@ -47,6 +49,8 @@ export class Node extends Element {
}
if (this.style)
attributes.push ({ name: 'style', value: this.style.toString () });
if (this.shape)
attributes.push ({ name: 'shape', value: this.shape.toString () });
if (this.color)
attributes.push ({ name: 'color', value: this.color.toString () });

View File

@ -6,11 +6,4 @@
*/
export type GraphLayouts =
'neato'
| 'dot'
| 'circo'
| 'fdp'
| 'sfdp'
| 'osage'
| 'twopi'
| 'patchwork'
'circo' | 'dot' | 'fdp' | 'neato' | 'osage' | 'patchwork' | 'sfdp' | 'twopi'

View File

@ -8,13 +8,7 @@
/* eslint-disable line-comment-position */
/* eslint-disable no-inline-comments */
type GraphStreamCommand =
'cn'|
'cug'|
'cdg'|
'csg'|
'eg'|
'at'|
'ce'
'at' | 'cdg' | 'ce' | 'cn' | 'csg' | 'cug' | 'eg'
function translate_command (cmd: GraphStreamCommand|''): string {
const translations = {

14
lib/enums/Shapes.ts Normal file
View File

@ -0,0 +1,14 @@
type NodeShapes =
'' | 'assembly' | 'box' | 'box3d' | 'cds' | 'circle' | 'component'
| 'cylinder' | 'diamond' | 'doublecircle' | 'doubleoctagon' | 'egg'
| 'ellipse' | 'fivepoverhang' | 'folder' | 'hexagon' | 'house'
| 'insulator' | 'invhouse' | 'invtrapezium' | 'invtriangle' | 'larrow'
| 'lpromoter' | 'Mcircle' | 'Mdiamond' | 'Msquare' | 'none' | 'note'
| 'noverhang' | 'octagon' | 'oval' | 'parallelogram' | 'pentagon'
| 'plain' | 'plaintext' | 'point' | 'polygon' | 'primersite' | 'promoter'
| 'proteasesite' | 'proteinstab' | 'rarrow' | 'rect' | 'rectangle'
| 'restrictionsite' | 'ribosite' | 'rnastab' | 'rpromoter' | 'septagon'
| 'signature' | 'square' | 'star' | 'tab' | 'terminator' | 'threepoverhang'
| 'trapezium' | 'triangle' | 'tripleoctagon' | 'underline' | 'utr'
export { NodeShapes };

View File

@ -6,34 +6,15 @@
*/
type EdgeStyles =
''
|'solid'
|'dashed'
|'dotted'
|'bold'
'' | 'bold' | 'dashed' | 'dotted' | 'solid'
type NodeStyles =
''
|'solid'
|'dashed'
|'dotted'
|'bold'
|'rounded'
|'diagonals'
|'filled'
|'striped'
|'wedged'
|'invis'
'' | 'bold' | 'dashed' | 'diagonals' | 'dotted'
| 'filled' | 'invis' | 'rounded' | 'solid' | 'striped' | 'wedged'
type GraphStyles =
'solid'
| 'dashed'
| 'dotted'
| 'bold'
| 'rounded'
| 'filled'
| 'striped'
'bold' | 'dashed' | 'dotted' | 'filled' | 'rounded' | 'solid' | 'striped'
export { EdgeStyles, NodeStyles, GraphStyles };

View File

@ -1,7 +1,7 @@
{
"name": "@sapphirecode/graphviz-builder",
"main": "dist/lib/index.js",
"version": "1.3.3",
"version": "1.4.0",
"author": {
"name": "Timo Hocker",
"email": "timo@scode.ovh"

View File

@ -8,7 +8,8 @@
import { Node, Color } from '../../lib';
const serialized_simple
= 'bar_foo [label="baz", style="dashed", color="#00ff00"]';
= 'bar_foo [label="baz", style="dashed",'
+ ' shape="tripleoctagon", color="#00ff00"]';
const serialized_table = `bar_foo [label=<<table>
<tr><td>foo</td><td>bar</td><td>baz</td></tr>
<tr><td>bar</td><td>baz</td><td>foo</td></tr>
@ -21,6 +22,7 @@ describe ('node', () => {
g.color = Color.green;
g.style = 'dashed';
g.shape = 'tripleoctagon';
const serialized = g.toString ();

View File

@ -43,7 +43,7 @@ const complex = `digraph foo {
// eslint-disable-next-line max-lines-per-function
describe ('stream', () => {
it ('stream graph', () => new Promise ((resolve) => {
it ('stream graph', () => new Promise<void> ((resolve) => {
let output = '';
const stream = (new GraphStream);
stream.on ('data', (data) => {
@ -60,7 +60,7 @@ describe ('stream', () => {
}));
// eslint-disable-next-line max-statements
it ('complex stream graph', () => new Promise ((resolve) => {
it ('complex stream graph', () => new Promise<void> ((resolve) => {
let output = '';
const stream = (new GraphStream);
stream.on ('data', (data) => {

2217
yarn.lock

File diff suppressed because it is too large Load Diff