Code Monkey home page Code Monkey logo

jsgraph's People

Contributors

aembke avatar chrisrus avatar gitter-badger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsgraph's Issues

Empty start vector error message

For breadth and depth-first traversal, default behavior is to call DirectedGraph.getRootVertices to obtain the start vertex set. Depending on graph topology, this set might be empty resulting in a v0.5.14 errors message:

'''jsgraph.directed.depthFirstTraverse algorithm failure: You have specified an empty starting vertex set for this traversal. This is allowed only if you set request.options.allowEmptyStartVector === true.'''

True, but not really enough to infer back root cause if you happen to dislike reading documentation, forget, or whatever.

Ideas:

We can track if we are taking default behavior or caller override (DirectedGraph.getRootVertices vs. client-provided start vertex set) and make the error message more descriptive:

Set 'request.options.allowEmptyStartVector true or provide a graph that has one or more root vertices, or specify your own start vertex set`

+digraph raw serialization object

It's sometimes necessary to serialize a digraph (and deserialize a serialized digraph) directly from the JavaScript object produced internally by digraph.toJSON. Make this internal object accessible to client code via new methods, constructor re-work etc.

Normalize digraph edge method signatures

A suggestion from @aembke is to make all digraph.Edge methods that currently accept discrete in-parameter vertex identifier strings for the u and v vertices instead accept a single edge descriptor object (i.e. {u: 'dfsdf', v: 'sdfsdfs'}) as is returned by the digraph.get*Edges methods. This is reasonable: I don't like discrete parameters anyway (but plan only this small change for 0.5 with more sweeping API switch to full request/response API in a later release).

createBF*/DF*Context export cut API?

The createDepthFirstSearchContext and createBreadthFirstSearchContext are poorly documented and may not need to be exposed at all to 95% of likely jsgraph library users. Action:

  • Take a look at DFS implementation. Why does it inconsistently appear to manage its own context? Does this imply the need to expose context (aka the color map) externally only in the case of BFS?

I smell a rat. Budget a couple hours to encapsulate the color map in all standard cases (i.e. calling the search algorithm will internally allocate and initialize whatever colormap it needs on your behalf and you don't need to worry about it). update tests and docs.

Need a way to obtain root and leaf vertex count w/out obtaining the list

... working to ensure that there's a reasonable way for client code to always get what they need out of a DirectedGraph container without actually touching the object's private state. Currently, if you want to know the size of either the root or leaf vertex set, you need to request that the set be constructed via a call to DirectedGraph.getLeafVertices/getRootVertices and then take the length of the array. That's just a waste when I just need the count. No need to allocate a new array and then throw it away just to xfer the count.

Add container-scope methods:

  • DirectedGraph.leafVerticesCount()
  • Directedgraph.rootVerticesCount()

No way to clear vertex or edge properties back to undefined state...

... without reaching into DirectedGraph's private state and deleting the hash table row.

Add the following methods to DirectedGraph, test, and document.

  • DirectedGraph.hasVertexProperty
  • DirectedGraph.clearVertexProperty
  • DirectedGraph.hasEdgeProperty
  • DirectedGraph.clearEdgeProperty

jsgraph.directed.create request enhancements

Add public member variables DirectedGraph.name and DirectedGraph.description and include their values in exported data. Optionally accept name/description values as input in serialized data (on construction or via DirectedGraph.fromObject/fromJSON methods.

Convert jsgraph.directed.create to accept either a raw JSON string, raw data export object, or request object containing all optional name/description/data props.

DFT visitor failing to return Boolean error message...

jsgraph.directed.depthFirstTraverse algorithm failure: BFS visitor.backEdge returned type '[object Number]' instead of expected '[object Boolean]'.

The routine that checks the return type of all visitor interface callback functions is a shared code path now. No need for an algorithm-specific string in the error message: the context is provided when the caller notices the error and adds the outer context to the error.

Drop BFS out above, reset expected results in tests.

Methods that return edges don't include properties

If I create a digraph with edges like

var digraph = new DirectedGraph()
digraph.addEdge({ e: { u: 'a', v: 'b' }, p: {/* some other stuff */} })

Methods like getEdges() or outEdges(nodeId) return simply Array<{ u: string, v: string }> and I'm unable to access {/* some other stuff */}.

Is it possible to access that data in the current API?

Document graph name/description use

Document methods DirectedGraph.getGraphName, setGraphName, getGraphDescription, setGraphDescription. Also update the JSON import/export docs with these properties.

DFT visitor callback order bugs

  • treeEdge should not fire before discoverVertex for the edge's target vertex
  • finishEdge callback is not implemented

Noticed some inconsistencies while writing a new DTF-derived visitor algorithm for JBUS vs. my recollection of how the BGL implementation works. Go through this carefully and review.

Document how to clone a DirectedGraph

Add documentation about how to clone a DirectedGraph instance (because it's not necessarily obvious).

Currently, the best way is as follows:

const arccore = require("@encapsule/arccore");
var response = arccore.graph.directed.create({ name: "Source Graph" });
if (response.error) throw new Error(response.error);
var sourceDigraph = response.result;

// Clone sourceDigraph
response = arccore.graph.directed.create(sourceDigraph.toJSON());
if (response.error) throw new Error(response.error);
var clonedDigraph = response.result;

Import/Export

It'd be nice to have import and export functions on a graph instance. I'd imagine this would just be stringified json of a wrapper around the vertexMap, rootMap, leafMap, and edgeCount, but maybe not.

Add the ability to pass a context reference through to visitor interface callbacks...

Developers are currently forced to manage any context their visitor interfaces require above and beyond the context provided by the request object passed to each callback by the algorithm. Typically, developers leverage a JavaScript closure scope and define their visitor object and invocation of the jsgraph algorithm in that scope.

For example, it is typical that visitor interface function implementations record information that is required in part or in whole to produce the result of the operation. Currently, it is assumed that developers will take care of this detail on their own.

cycleEdges = [];
var dftVisitor = {
    forwardOrCrossEdge: function(request) {
        cyclesEdges.push(request.e); // record the edge
        // What I want is rather: request.context.cyclesEdges.push(request.e);
       return true; // continue the traversal
    }
};
var response = jsgraph.directed.depthFirstTraverse({ digraph: digraph, visitor: dftVisitor });
if (response.error) {
    throw new Error(response.error); // e.g.
}
if (cycleEdges.length) {
    console.log("Digraph contains cycles on the following edges: " + JSON.stringify(cycleEdges) );
}

'''

However, in more advanced scenarios it would be helpful to have a standard way to direct visitor interfaces to a specific sandbox for keeping track of intermediate state and building results.

Make it possible to pass a context reference via traversal algorithm request object that gets passed to visitor callbacks. This will allow the algorithm caller far more flexibility and control than is now convenient.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.