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.0.4 to 0.0.5

11

lib/model/cluster/Cluster.d.ts

@@ -8,3 +8,3 @@ import { DotBase } from '../../common';

import { Edge } from '../Edge';
import { Node } from '../Node';
import { Node, NodeLike } from '../Node';
export declare type RootClusterType = 'digraph' | 'graph';

@@ -34,4 +34,11 @@ export declare type ClusterType = RootClusterType | 'subgraph';

createNode(id: string): Node;
createEdge(node1: Node, node2: Node, ...nodes: Node[]): Edge;
getSubgraph(id: string): Subgraph | undefined;
getNode(id: string): Node | undefined;
createEdge(node1: NodeLike, node2: NodeLike, ...nodes: NodeLike[]): Edge;
createEdge(...nodes: NodeLike[]): 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;
toDot(): string;
private toNodeLikeObject;
}

@@ -38,0 +45,0 @@ export declare abstract class RootCluster<ATTR extends Attributes> extends Cluster<ATTR> {

@@ -57,3 +57,11 @@ "use strict";

};
Cluster.prototype.getSubgraph = function (id) {
return this.subgraphs.get(id);
};
Cluster.prototype.getNode = function (id) {
return this.nodes.get(id);
};
Cluster.prototype.createEdge = function (node1, node2) {
var _a;
var _this = this;
var nodes = [];

@@ -63,6 +71,34 @@ for (var _i = 2; _i < arguments.length; _i++) {

}
var edge = new (Edge_1.Edge.bind.apply(Edge_1.Edge, __spreadArrays([void 0, this.context.graphType, node1, node2], nodes)))();
if ((Node_1.isNodeLike(node1) && Node_1.isNodeLike(node2)) === 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); }))))();
this.edges.add(edge);
return edge;
};
Cluster.prototype.subgraph = function (id, callback) {
var _a;
var subgraph = (_a = this.getSubgraph(id), (_a !== null && _a !== void 0 ? _a : this.createSubgraph(id)));
if (callback) {
callback(subgraph);
}
return subgraph;
};
Cluster.prototype.node = function (id, callback) {
var _a;
var node = (_a = this.getNode(id), (_a !== null && _a !== void 0 ? _a : this.createNode(id)));
if (callback) {
callback(node);
}
return node;
};
Cluster.prototype.edge = function (nodes, callback) {
var edge = this.createEdge.apply(this, nodes);
if (callback) {
callback(edge);
}
return edge;
};
Cluster.prototype.toDot = function () {

@@ -89,2 +125,14 @@ var type = this.type;

};
Cluster.prototype.toNodeLikeObject = function (node) {
if (Node_1.isNodeLikeObject(node)) {
return node;
}
// FIXME
var _a = node.split(':'), id = _a[0], port = _a[1];
var n = this.node(id);
if (port) {
return n.port(port);
}
return n;
};
return Cluster;

@@ -91,0 +139,0 @@ }(common_1.DotBase));

21

lib/model/Edge.d.ts
import { DotBase } from '../common';
import { EdgeAttributes } from './attributes';
import { RootClusterType } from './cluster';
import { Node } from './Node';
import { NodeLikeObject } from './Node';
/**
* @category Primary
*/
export declare class Edge extends DotBase {
readonly graphType: RootClusterType;
private get arrow();
export declare abstract class Edge extends DotBase {
readonly attributes: EdgeAttributes;
private readonly nodes;
constructor(graphType: RootClusterType, node1: Node, node2: Node, ...nodes: Node[]);
readonly nodes: NodeLikeObject[];
protected abstract arrow: string;
constructor(node1: NodeLikeObject, node2: NodeLikeObject, ...nodes: NodeLikeObject[]);
toDot(): string;
}
/**
* @category Primary
*/
export declare class GraphEdge extends Edge {
protected arrow: string;
}
export declare class DigraphEdge extends Edge {
protected arrow: string;
}

@@ -31,24 +31,21 @@ "use strict";

__extends(Edge, _super);
function Edge(graphType, node1, node2) {
function Edge(node1, node2) {
var nodes = [];
for (var _i = 3; _i < arguments.length; _i++) {
nodes[_i - 3] = arguments[_i];
for (var _i = 2; _i < arguments.length; _i++) {
nodes[_i - 2] = arguments[_i];
}
var _this = _super.call(this) || this;
_this.graphType = graphType;
_this.attributes = new attributes_1.EdgeAttributes();
_this.nodes = new Set(__spreadArrays([node1, node2], nodes).filter(function (n) { return n instanceof Node_1.Node; }));
_this.nodes = __spreadArrays([node1, node2], nodes).filter(function (n) { return Node_1.isNodeLikeObject(n); });
return _this;
}
Object.defineProperty(Edge.prototype, "arrow", {
get: function () {
return this.graphType === 'graph' ? '--' : '->';
},
enumerable: true,
configurable: true
});
Edge.prototype.toDot = function () {
var arrow = this.arrow;
var target = Array.from(this.nodes.values())
.map(function (n) { return Edge.quoteString(n.id); })
var target = this.nodes
.map(function (n) {
if (n instanceof Node_1.Node) {
return Edge.quoteString(n.id);
}
return Edge.quoteString(n.node.id + ":" + n.port);
})
.join(" " + arrow + " ");

@@ -62,1 +59,26 @@ var attrs = this.attributes.size > 0 ? " " + this.attributes.toDot() : '';

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;

@@ -11,2 +11,12 @@ import { DotBase } from '../common';

toDot(): string;
port(port: string): NodeWithPort;
}
export declare class NodeWithPort {
readonly node: Node;
readonly port: string;
constructor(node: Node, port: 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;

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

};
Node.prototype.port = function (port) {
return new NodeWithPort(this, port);
};
return Node;
}(common_1.DotBase));
exports.Node = Node;
// tslint:disable-next-line: max-classes-per-file
var NodeWithPort = /** @class */ (function () {
function NodeWithPort(node, port) {
this.node = node;
this.port = port;
}
return NodeWithPort;
}());
exports.NodeWithPort = NodeWithPort;
function isNodeLikeObject(node) {
return node instanceof Node || node instanceof NodeWithPort;
}
exports.isNodeLikeObject = isNodeLikeObject;
function isNodeLike(node) {
return typeof node === 'string' || isNodeLikeObject(node);
}
exports.isNodeLike = isNodeLike;
import { Digraph, Graph } from './model/cluster';
export declare function digraph(): Digraph;
export declare function graph(): Graph;
export declare const digraph: (id?: string | undefined, callback?: ((g: Digraph) => void) | undefined) => Digraph;
export declare const graph: (id?: string | undefined, callback?: ((g: Graph) => void) | undefined) => Graph;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var cluster_1 = require("./model/cluster");
function digraph() {
var g = new cluster_1.Digraph();
var builder = function (cls) { return function (id, callback) {
var g = new cls(id);
if (typeof callback === 'function') {
callback(g);
}
return g;
}
exports.digraph = digraph;
function graph() {
var g = new cluster_1.Graph();
return g;
}
exports.graph = graph;
}; };
exports.digraph = builder(cluster_1.Digraph);
exports.graph = builder(cluster_1.Graph);
{
"name": "ts-graphviz",
"version": "0.0.4",
"version": "0.0.5",
"author": "kamiazya <yuki@kamiazya.tech>",

@@ -5,0 +5,0 @@ "description": "Graphviz library for TypeScript.",

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

[![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)
[![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)

@@ -51,2 +51,24 @@ # ts-graphviz

### Callback style API
```typescript
import { digraph } from 'ts-graphviz';
const G = digraph('G', g => {
g.subgraph('A', A => {
const node1 = A.node('A_node1');
const node2 = A.node('A_node2');
A.edge([node1, node2]);
});
g.subgraph('B', B => {
const node1 = B.node('B_node1');
const node2 = B.node('B_node2');
B.edge([node1, node2]);
});
g.edge(['node1', 'node2']);
});
const dot = G.toDot();
console.log(dot);
```
### Output

@@ -53,0 +75,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