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

gremlin-graphviz

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gremlin-graphviz - npm Package Compare versions

Comparing version 1.0.1 to 1.0.3

75

lib/index.js

@@ -7,2 +7,3 @@ // lib/index.js

var _ = require('lodash');
var assert = require('assert');

@@ -13,6 +14,4 @@ var graphviz = require('graphviz');

// Construct a Graphviz graph from a Gremlin graph.
module.exports = Q.promised(function (gremlinGraph, opts) {
var opts = opts || {};
var graphName = opts.graphName || 'G';
var graphvizGraph = graphviz.digraph(graphName);
var factory = module.exports = Q.promised(function (gremlinGraph, opts) {
var graphvizGraph = new GraphvizGraph(gremlinGraph, opts);
var gremlin = gremlinGraph.gremlin;

@@ -33,2 +32,54 @@

var GraphvizGraph = function (gremlinGraph, opts) {
var opts = opts || {};
var graphName = opts.graphName || 'G';
this.impl = graphviz.digraph(graphName);
};
// Haul a property getter from the implementation class.
var haulProperty = function (name) {
Object.defineProperty(GraphvizGraph.prototype, name,
{ get: function () {
return this.impl[name];
}});
};
// ## Expose certain immutable properties of the graphviz graph.
['id',
'type'
].map(haulProperty);
// Haul a property getter/setter from the implementation class.
var haulMutableProperty = function (name) {
Object.defineProperty(GraphvizGraph.prototype, name,
{
get: function () {
return this.impl[name];
},
set: function (value) {
return this.impl[name] = value;
}
});
};
// ## Expose certain mutable properties of the graphviz graph.
['use'
].map(haulMutableProperty);
// Haul a method from the implementation class.
var haulMethod = function (name) {
GraphvizGraph.prototype[name] = function () {
// var args = Array.prototype.slice.call(arguments);
return this.impl[name].apply(this.impl, arguments);
};
};
// All of the useful read-only methods are exported.
['getNode',
'edgeCount',
'nodeCount',
'output',
'to_dot'
].map(haulMethod);
var iterate = function (traversal, process) {

@@ -49,8 +100,15 @@ return traversal.hasNext().

// Check whether we have a valid vertex ID.
var assertVertexId = function (id) {
assert(_.isNumber(id));
};
// Add a vertex (synchronously) to a Graphviz graph based on a Gremlin vertex.
var addVertex = function (graphvizGraph, gremlinVertex) {
assert(graphvizGraph);
assert(graphvizGraph.impl);
assert(gremlinVertex);
var id = gremlinVertex.getId();
graphvizGraph.addNode(id.toString());
assertVertexId(id);
graphvizGraph.impl.addNode(id.toString());
};

@@ -61,2 +119,3 @@

assert(graphvizGraph);
assert(graphvizGraph.impl);
assert(gremlinEdge);

@@ -68,8 +127,8 @@ // TODO: Switch this from a Java edge object to something from gremlin-v3.

var inId = inV.idSync();
assert(inId);
assertVertexId(inId);
var outV = iterators.vertexIteratorSync(Direction.OUT).nextSync();
assert(outV);
var outId = outV.idSync();
assert(outId);
graphvizGraph.addEdge(outId.toString(), inId.toString());
assertVertexId(outId);
graphvizGraph.impl.addEdge(outId.toString(), inId.toString());
};

3

package.json
{
"name": "gremlin-graphviz",
"version": "1.0.1",
"version": "1.0.3",
"description": "Use Graphviz to visualize Gremlin graphs.",

@@ -44,4 +44,5 @@ "main": "lib/index.js",

"graphviz": "0.0.8",
"lodash": "^2.4.1",
"q": "^1.1.2"
}
}

@@ -9,3 +9,2 @@ // test/test.js

var expect = chai.expect;
var fs = require('fs');
var Gremlin = require('gremlin-v3');

@@ -137,2 +136,3 @@ var gremlin = new Gremlin();

expect(g.edgeCount()).to.equal(6);
expect(g.getNode('1').id).to.equal('1');
})

@@ -139,0 +139,0 @@ .done(done);

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