Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-graphviz

Package Overview
Dependencies
Maintainers
1
Versions
181
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-graphviz - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

lib/model/Attributes.d.ts

3

lib/common/interface.d.ts
export interface IDot {
toDot(): string;
}
export interface IEdgeTarget {
toEdgeTargetDot(): string;
}

40

lib/model/cluster/Cluster.d.ts
import { DotBase } from '../../common';
import { SubgraphAttributes } from '../attributes';
import { Attributes } from '../attributes/Attributes';
import { EdgeAttributes } from '../attributes/EdgeAttributes';
import { NodeAttributes } from '../attributes/NodeAttributes';
import { Attributes } from '../Attributes';
import { Context } from '../Context';
import { Edge } from '../Edge';
import { Node, NodeLike } from '../Node';
import { EdgeTargetLike, Node } from '../Node';
export declare type RootClusterType = 'digraph' | 'graph';

@@ -14,6 +11,6 @@ export declare type ClusterType = RootClusterType | 'subgraph';

*/
export interface IClusterCommonAttributes<ATTR extends Attributes> {
graph: ATTR;
edge: EdgeAttributes;
node: NodeAttributes;
export interface IClusterCommonAttributes {
graph: Attributes;
edge: Attributes;
node: Attributes;
}

@@ -23,11 +20,12 @@ /**

*/
export declare abstract class Cluster<ATTR extends Attributes> extends DotBase {
readonly id: string;
export declare abstract class Cluster extends DotBase {
get id(): string | undefined;
set id(idValue: string | undefined);
abstract readonly context: Context;
abstract readonly type: ClusterType;
readonly attributes: Readonly<IClusterCommonAttributes<ATTR>>;
readonly attributes: Readonly<IClusterCommonAttributes>;
private idLiteral?;
private nodes;
private edges;
private subgraphs;
constructor(id: string, attributes: ATTR);
add(object: Node | Edge | Subgraph): void;

@@ -39,3 +37,3 @@ addNode(node: Node): void;

existEdge(edge: Edge): boolean;
existSubgraph(subgraphId: string): boolean;
existSubgraph(subgraph: Subgraph): boolean;
createSubgraph(id: string): Subgraph;

@@ -45,15 +43,15 @@ remove(object: Node | Subgraph | Edge): void;

removeEdge(edge: Edge): void;
removeSubgraph(subgraph: Subgraph | string): void;
removeSubgraph(subgraph: Subgraph): void;
createNode(id: string): Node;
getSubgraph(id: string): Subgraph | undefined;
getNode(id: string): Node | undefined;
createEdge(node1: NodeLike, node2: NodeLike, ...nodes: NodeLike[]): Edge;
createEdge(...nodes: NodeLike[]): Edge;
createEdge(target1: EdgeTargetLike, target2: EdgeTargetLike): Edge;
createEdge(...targets: EdgeTargetLike[]): Edge;
subgraph(id: string, callback?: (subgraph: Subgraph) => void): Subgraph;
node(id: string, callback?: (edge: Node) => void): Node;
edge(nodes: NodeLike[], callback?: (edge: Edge) => void): Edge;
edge(nodes: EdgeTargetLike[], callback?: (edge: Edge) => void): Edge;
toDot(): string;
private toNodeLikeObject;
}
export declare abstract class RootCluster<ATTR extends Attributes> extends Cluster<ATTR> {
export declare abstract class RootCluster extends Cluster {
abstract readonly type: RootClusterType;

@@ -64,8 +62,8 @@ }

*/
export declare class Subgraph extends Cluster<SubgraphAttributes> {
export declare class Subgraph extends Cluster {
readonly context: Context;
type: ClusterType;
constructor(context: Context, id: string, attributes?: SubgraphAttributes);
constructor(context: Context);
isSubgraphCluster(): boolean;
toDot(): string;
}

@@ -25,6 +25,5 @@ "use strict";

var dot_rendering_1 = require("../../utils/dot-rendering");
var attributes_1 = require("../attributes");
var EdgeAttributes_1 = require("../attributes/EdgeAttributes");
var NodeAttributes_1 = require("../attributes/NodeAttributes");
var Attributes_1 = require("../Attributes");
var Edge_1 = require("../Edge");
var Literal_1 = require("../Literal");
var Node_1 = require("../Node");

@@ -36,15 +35,25 @@ /**

__extends(Cluster, _super);
function Cluster(id, attributes) {
var _this = _super.call(this) || this;
_this.id = id;
function Cluster() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.attributes = {
graph: new Attributes_1.Attributes(),
edge: new Attributes_1.Attributes(),
node: new Attributes_1.Attributes(),
};
_this.nodes = new Map();
_this.edges = new Set();
_this.subgraphs = new Map();
_this.attributes = {
graph: attributes,
edge: new EdgeAttributes_1.EdgeAttributes(),
node: new NodeAttributes_1.NodeAttributes(),
};
_this.subgraphs = new Set();
return _this;
}
Object.defineProperty(Cluster.prototype, "id", {
get: function () {
var _a;
return (_a = this.idLiteral) === null || _a === void 0 ? void 0 : _a.value;
},
set: function (idValue) {
this.idLiteral = typeof idValue === 'string' ? new Literal_1.Literal(idValue) : undefined;
},
enumerable: true,
configurable: true
});
Cluster.prototype.add = function (object) {

@@ -68,3 +77,3 @@ if (object instanceof Node_1.Node) {

Cluster.prototype.addSubgraph = function (subgraph) {
this.subgraphs.set(subgraph.id, subgraph);
this.subgraphs.add(subgraph);
};

@@ -77,8 +86,8 @@ Cluster.prototype.existNode = function (nodeId) {

};
Cluster.prototype.existSubgraph = function (subgraphId) {
return this.subgraphs.has(subgraphId);
Cluster.prototype.existSubgraph = function (subgraph) {
return this.subgraphs.has(subgraph);
};
Cluster.prototype.createSubgraph = function (id) {
var graph = this.context.createSubgraph(id);
this.subgraphs.set(id, graph);
this.subgraphs.add(graph);
return graph;

@@ -104,3 +113,3 @@ };

Cluster.prototype.removeSubgraph = function (subgraph) {
this.subgraphs.delete(subgraph instanceof Subgraph ? subgraph.id : subgraph);
this.subgraphs.delete(subgraph);
};

@@ -113,3 +122,3 @@ Cluster.prototype.createNode = function (id) {

Cluster.prototype.getSubgraph = function (id) {
return this.subgraphs.get(id);
return Array.from(this.subgraphs.values()).find(function (subgraph) { return subgraph.id === id; });
};

@@ -119,15 +128,15 @@ Cluster.prototype.getNode = function (id) {

};
Cluster.prototype.createEdge = function (node1, node2) {
var _a;
Cluster.prototype.createEdge = function (target1, target2) {
var _this = this;
var nodes = [];
var targets = [];
for (var _i = 2; _i < arguments.length; _i++) {
nodes[_i - 2] = arguments[_i];
targets[_i - 2] = arguments[_i];
}
if ((Node_1.isNodeLike(node1) && Node_1.isNodeLike(node2)) === false) {
if ((Node_1.isEdgeTargetLike(target1) && Node_1.isEdgeTargetLike(target2)) === false) {
// TODO
throw new Error();
}
var edge = new ((_a = (this.context.graphType === 'graph' ? Edge_1.GraphEdge : Edge_1.DigraphEdge)).bind.apply(_a, __spreadArrays([void 0, this.toNodeLikeObject(node1),
this.toNodeLikeObject(node2)], nodes.map(function (n) { return _this.toNodeLikeObject(n); }))))();
var edge = new (Edge_1.Edge.bind.apply(Edge_1.Edge, __spreadArrays([void 0, this.context,
this.toNodeLikeObject(target1),
this.toNodeLikeObject(target2)], targets.map(function (n) { return _this.toNodeLikeObject(n); }))))();
this.edges.add(edge);

@@ -160,4 +169,5 @@ return edge;

Cluster.prototype.toDot = function () {
var _a;
var type = this.type;
var id = dot_rendering_1.quote(dot_rendering_1.escape(this.id));
var id = (_a = this.idLiteral) === null || _a === void 0 ? void 0 : _a.toDot();
// attributes

@@ -178,7 +188,7 @@ var commonAttributes = Object.entries(this.attributes)

var clusterContents = dot_rendering_1.joinLines.apply(void 0, __spreadArrays(commonAttributes, nodes, subgraphs, edges));
var src = dot_rendering_1.joinLines(type + " " + id + " {", clusterContents ? dot_rendering_1.indent(clusterContents) : undefined, '}');
var src = dot_rendering_1.joinLines(dot_rendering_1.concatWords(type, id, '{'), clusterContents ? dot_rendering_1.indent(clusterContents) : undefined, '}');
return src;
};
Cluster.prototype.toNodeLikeObject = function (node) {
if (Node_1.isNodeLikeObject(node)) {
if (Node_1.isEdgeTarget(node)) {
return node;

@@ -210,5 +220,4 @@ }

__extends(Subgraph, _super);
function Subgraph(context, id, attributes) {
if (attributes === void 0) { attributes = new attributes_1.SubgraphAttributes(); }
var _this = _super.call(this, id, attributes) || this;
function Subgraph(context) {
var _this = _super.call(this) || this;
_this.context = context;

@@ -219,3 +228,6 @@ _this.type = 'subgraph';

Subgraph.prototype.isSubgraphCluster = function () {
return this.id.startsWith('cluster_');
if (typeof this.id === 'string') {
return this.id.startsWith('cluster_');
}
return false;
};

@@ -222,0 +234,0 @@ Subgraph.prototype.toDot = function () {

@@ -1,2 +0,1 @@

import { GraphAttributes } from '../attributes/GraphAttributes';
import { Context } from '../Context';

@@ -7,6 +6,6 @@ import { RootCluster, RootClusterType } from './Cluster';

*/
export declare class Digraph extends RootCluster<GraphAttributes> {
export declare class Digraph extends RootCluster {
readonly context: Context;
type: RootClusterType;
constructor(id?: string, attributes?: GraphAttributes);
constructor(id?: string);
}

@@ -16,3 +16,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var GraphAttributes_1 = require("../attributes/GraphAttributes");
var Context_1 = require("../Context");

@@ -25,8 +24,8 @@ var Cluster_1 = require("./Cluster");

__extends(Digraph, _super);
function Digraph(id, attributes) {
if (id === void 0) { id = 'G'; }
if (attributes === void 0) { attributes = new GraphAttributes_1.GraphAttributes(); }
var _this = _super.call(this, id, attributes) || this;
_this.context = new Context_1.Context(_this);
function Digraph(id) {
var _this = _super.call(this) || this;
_this.context = new Context_1.Context();
_this.type = 'digraph';
_this.id = id;
_this.context.root = _this;
return _this;

@@ -33,0 +32,0 @@ }

@@ -1,2 +0,1 @@

import { GraphAttributes } from '../attributes/GraphAttributes';
import { Context } from '../Context';

@@ -7,6 +6,6 @@ import { RootCluster, RootClusterType } from './Cluster';

*/
export declare class Graph extends RootCluster<GraphAttributes> {
export declare class Graph extends RootCluster {
readonly context: Context;
type: RootClusterType;
constructor(id?: string, attributes?: GraphAttributes);
constructor(id?: string);
}

@@ -16,3 +16,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var GraphAttributes_1 = require("../attributes/GraphAttributes");
var Context_1 = require("../Context");

@@ -25,8 +24,8 @@ var Cluster_1 = require("./Cluster");

__extends(Graph, _super);
function Graph(id, attributes) {
if (id === void 0) { id = 'G'; }
if (attributes === void 0) { attributes = new GraphAttributes_1.GraphAttributes(); }
var _this = _super.call(this, id, attributes) || this;
_this.context = new Context_1.Context(_this);
function Graph(id) {
var _this = _super.call(this) || this;
_this.context = new Context_1.Context();
_this.type = 'graph';
_this.id = id;
_this.context.root = _this;
return _this;

@@ -33,0 +32,0 @@ }

@@ -1,10 +0,9 @@

import { Digraph, Graph, RootClusterType, Subgraph } from './cluster';
import { RootCluster, RootClusterType, Subgraph } from './cluster';
export interface IContext {
graphType: RootClusterType;
graphType: RootClusterType | undefined;
}
export declare class Context implements IContext {
readonly root: Graph | Digraph;
get graphType(): RootClusterType;
constructor(root: Graph | Digraph);
createSubgraph(id: string): Subgraph;
get graphType(): RootClusterType | undefined;
root?: RootCluster;
createSubgraph(id?: string): Subgraph;
}

@@ -5,8 +5,8 @@ "use strict";

var Context = /** @class */ (function () {
function Context(root) {
this.root = root;
function Context() {
}
Object.defineProperty(Context.prototype, "graphType", {
get: function () {
return this.root.type;
var _a;
return (_a = this.root) === null || _a === void 0 ? void 0 : _a.type;
},

@@ -17,3 +17,5 @@ enumerable: true,

Context.prototype.createSubgraph = function (id) {
return new cluster_1.Subgraph(this, id);
var subgraph = new cluster_1.Subgraph(this);
subgraph.id = id;
return subgraph;
};

@@ -20,0 +22,0 @@ return Context;

import { DotBase } from '../common';
import { EdgeAttributes } from './attributes';
import { NodeLikeObject } from './Node';
import { IEdgeTarget } from '../common/interface';
import { Attributes } from './Attributes';
import { IContext } from './Context';
/**
* @category Primary
*/
export declare abstract class Edge extends DotBase {
readonly attributes: EdgeAttributes;
readonly nodes: NodeLikeObject[];
protected abstract arrow: string;
constructor(node1: NodeLikeObject, node2: NodeLikeObject, ...nodes: NodeLikeObject[]);
export declare class Edge extends DotBase {
private context;
readonly attributes: Attributes;
readonly targets: IEdgeTarget[];
constructor(context: IContext, target1: IEdgeTarget, target2: IEdgeTarget);
constructor(context: IContext, ...targets: IEdgeTarget[]);
toDot(): string;
}
/**
* @category Primary
*/
export declare class GraphEdge extends Edge {
protected arrow: string;
}
export declare class DigraphEdge extends Edge {
protected arrow: string;
}

@@ -24,4 +24,3 @@ "use strict";

var common_1 = require("../common");
var dot_rendering_1 = require("../utils/dot-rendering");
var attributes_1 = require("./attributes");
var Attributes_1 = require("./Attributes");
var Node_1 = require("./Node");

@@ -33,17 +32,16 @@ /**

__extends(Edge, _super);
function Edge(node1, node2) {
var nodes = [];
for (var _i = 2; _i < arguments.length; _i++) {
nodes[_i - 2] = arguments[_i];
function Edge(context, target1, target2) {
var targets = [];
for (var _i = 3; _i < arguments.length; _i++) {
targets[_i - 3] = arguments[_i];
}
var _this = _super.call(this) || this;
_this.attributes = new attributes_1.EdgeAttributes();
_this.nodes = __spreadArrays([node1, node2], nodes).filter(function (n) { return Node_1.isNodeLikeObject(n); });
_this.context = context;
_this.attributes = new Attributes_1.Attributes();
_this.targets = __spreadArrays([target1, target2], targets).filter(function (n) { return Node_1.isEdgeTarget(n); });
return _this;
}
Edge.prototype.toDot = function () {
var arrow = this.arrow;
var target = this.nodes
.map(function (n) { return (n instanceof Node_1.Node ? dot_rendering_1.quote(dot_rendering_1.escape(n.id)) : dot_rendering_1.quote(dot_rendering_1.escape(n.node.id)) + ":" + dot_rendering_1.quote(dot_rendering_1.escape(n.port))); })
.join(" " + arrow + " ");
var arrow = this.context.graphType === 'digraph' ? '->' : '--';
var target = this.targets.map(function (n) { return n.toEdgeTargetDot(); }).join(" " + arrow + " ");
var attrs = this.attributes.size > 0 ? " " + this.attributes.toDot() : '';

@@ -56,26 +54,1 @@ var src = "" + target + attrs + ";";

exports.Edge = Edge;
/**
* @category Primary
*/
// tslint:disable-next-line: max-classes-per-file
var GraphEdge = /** @class */ (function (_super) {
__extends(GraphEdge, _super);
function GraphEdge() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.arrow = '--';
return _this;
}
return GraphEdge;
}(Edge));
exports.GraphEdge = GraphEdge;
// tslint:disable-next-line: max-classes-per-file
var DigraphEdge = /** @class */ (function (_super) {
__extends(DigraphEdge, _super);
function DigraphEdge() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.arrow = '->';
return _this;
}
return DigraphEdge;
}(Edge));
exports.DigraphEdge = DigraphEdge;

@@ -1,6 +0,6 @@

export * from './attributes';
export * from './Literal';
export * from './Attributes';
export * from './cluster';
export * from './values';
export * from './Context';
export * from './Edge';
export * from './Node';

@@ -6,7 +6,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./attributes"));
__export(require("./Literal"));
__export(require("./Attributes"));
__export(require("./cluster"));
__export(require("./values"));
__export(require("./Context"));
__export(require("./Edge"));
__export(require("./Node"));
import { DotBase } from '../common';
import { NodeAttributes } from './attributes';
import { IEdgeTarget } from '../common/interface';
import { Attributes } from './Attributes';
import { Literal } from './Literal';
/**
* @category Primary
*/
export declare class Node extends DotBase {
export declare class Node extends DotBase implements IEdgeTarget {
readonly id: string;
readonly attributes: NodeAttributes;
readonly idLiteral: Literal;
readonly attributes: Attributes;
constructor(id: string);
toDot(): string;
toEdgeTargetDot(): string;
port(port: string): NodeWithPort;
}
export declare class NodeWithPort {
export declare class NodeWithPort implements IEdgeTarget {
readonly node: Node;
readonly port: string;
readonly port: Literal;
constructor(node: Node, port: string);
toEdgeTargetDot(): string;
}
export declare type NodeLikeObject = Node | NodeWithPort;
export declare type NodeLike = NodeLikeObject | string;
export declare function isNodeLikeObject(node: any): node is NodeLikeObject;
export declare function isNodeLike(node: any): node is NodeLike;
export declare type EdgeTargetLike = IEdgeTarget | string;
/**
* @hidden
*/
export declare function isEdgeTarget(node: any): node is IEdgeTarget;
/**
* @hidden
*/
export declare function isEdgeTargetLike(node: any): node is EdgeTargetLike;

@@ -17,4 +17,4 @@ "use strict";

var common_1 = require("../common");
var dot_rendering_1 = require("../utils/dot-rendering");
var attributes_1 = require("./attributes");
var Attributes_1 = require("./Attributes");
var Literal_1 = require("./Literal");
/**

@@ -28,10 +28,14 @@ * @category Primary

_this.id = id;
_this.attributes = new attributes_1.NodeAttributes();
_this.attributes = new Attributes_1.Attributes();
_this.idLiteral = new Literal_1.Literal(id);
return _this;
}
Node.prototype.toDot = function () {
var target = dot_rendering_1.quote(dot_rendering_1.escape(this.id));
var target = this.idLiteral.toDot();
var attrs = this.attributes.size > 0 ? " " + this.attributes.toDot() : '';
return "" + target + attrs + ";";
};
Node.prototype.toEdgeTargetDot = function () {
return this.idLiteral.toDot();
};
Node.prototype.port = function (port) {

@@ -47,14 +51,23 @@ return new NodeWithPort(this, port);

this.node = node;
this.port = port;
this.port = new Literal_1.Literal(port);
}
NodeWithPort.prototype.toEdgeTargetDot = function () {
return this.node.idLiteral.toDot() + ":" + this.port.toDot();
};
return NodeWithPort;
}());
exports.NodeWithPort = NodeWithPort;
function isNodeLikeObject(node) {
/**
* @hidden
*/
function isEdgeTarget(node) {
return node instanceof Node || node instanceof NodeWithPort;
}
exports.isNodeLikeObject = isNodeLikeObject;
function isNodeLike(node) {
return typeof node === 'string' || isNodeLikeObject(node);
exports.isEdgeTarget = isEdgeTarget;
/**
* @hidden
*/
function isEdgeTargetLike(node) {
return typeof node === 'string' || isEdgeTarget(node);
}
exports.isNodeLike = isNodeLike;
exports.isEdgeTargetLike = isEdgeTargetLike;

@@ -12,2 +12,6 @@ /**

*/
export declare function concatWords(...lines: (string | undefined)[]): string;
/**
* @hidden
*/
export declare function joinLines(...lines: (string | undefined)[]): string;

@@ -14,0 +18,0 @@ /**

@@ -20,2 +20,13 @@ "use strict";

*/
function concatWords() {
var lines = [];
for (var _i = 0; _i < arguments.length; _i++) {
lines[_i] = arguments[_i];
}
return lines.filter(function (l) { return typeof l === 'string'; }).join(' ');
}
exports.concatWords = concatWords;
/**
* @hidden
*/
function joinLines() {

@@ -22,0 +33,0 @@ var lines = [];

{
"name": "ts-graphviz",
"version": "0.2.0",
"version": "0.3.0",
"author": "kamiazya <yuki@kamiazya.tech>",

@@ -25,3 +25,3 @@ "description": "Graphviz library for TypeScript.",

"jest": "^24.9.0",
"jest-graphviz": "^0.0.2",
"jest-graphviz": "^0.1.1",
"prettier": "^1.18.2",

@@ -28,0 +28,0 @@ "ts-jest": "^24.1.0",

@@ -32,3 +32,3 @@ [![GitHub Action](https://github.com/kamiazya/ts-graphviz/workflows/NodeCI/badge.svg)](https://github.com/kamiazya/ts-graphviz/actions?workflow=NodeCI) [![npm version](https://badge.fury.io/js/ts-graphviz.svg)](https://badge.fury.io/js/ts-graphviz) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![Maintainability](https://api.codeclimate.com/v1/badges/12a586dde710859d58c7/maintainability)](https://codeclimate.com/github/kamiazya/ts-graphviz/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/12a586dde710859d58c7/test_coverage)](https://codeclimate.com/github/kamiazya/ts-graphviz/test_coverage)

const g = digraph();
const g = digraph('G');

@@ -78,15 +78,15 @@ const subgraphA = g.createSubgraph('A');

digraph G {
"node1";
"node2";
node1;
node2;
subgraph A {
"A_node1";
"A_node2";
"A_node1" -> "A_node2";
"B_node1" -> "B_node2";
A_node1;
A_node2;
A_node1 -> A_node2;
B_node1 -> B_node2;
};
subgraph B {
"B_node1";
"B_node2";
B_node1;
B_node2;
};
"node1" -> "node2";
node1 -> node2;
}

@@ -93,0 +93,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc