dagrejs / dagre-d3

A D3-based renderer for Dagre
MIT License
2.85k stars 587 forks source link

a.copy is not a function dagre-d3.min.js:1 #89

Open hastebrot opened 10 years ago

hastebrot commented 10 years ago

Seems that graphlib-dot#0.5.0 does not work together with dagre-d3#0.2.9. I already changed dot.parse() to dot.read(). This worked with a previous version of graphlib-dot.

Code:

var model = graphlibDot.read($graphvizGraphSource.text());
var renderer = new dagreD3.Renderer();
var layout = dagreD3.layout().nodeSep(20).rankDir("LR");
renderer.layout(layout).run(model, d3.select($graphvizGraphTarget.get(0)));

Error:

TypeError: a.copy is not a function dagre-d3.min.js:1
hastebrot commented 10 years ago

It works with a dagreD3.Digraph().

var model = new dagreD3.Digraph();
model.addNode("A", { label: "A" });
model.addNode("B", { label: "B" });
model.addEdge(null, "A", "B", { label: "AB" });
hastebrot commented 10 years ago

I see, you updated the dependency for release of dagre#0.5.0. Seems that this release will fix the API incompatibilities.

cpettitt commented 10 years ago

Yes, sorry for the inconvenience. I made significant changes to graphlib for performance and a more consistent API. I've got it updated in dagre, but I need to update dagre-d3 for the changes. This should be done soon (in the next day or two).

The goal is to get all projects (graphlib, graphlib-dot, dagre, and dagre-d3) to v1.0.0 releases in the next month or so, after which the API will be stable until a 2.0 release.

hastebrot commented 10 years ago

Ah, I see. Sounds great!

One small question: Will the dagre-d3 build include dagre (as before) or will it be like graphlib-dot (where I also have to include graphlib)?

cpettitt commented 10 years ago

I could use input from folks using these libraries with bower. I did some work to publish it using bower, but I don't use it myself and I don't have a good sense for the best practices. Whatever path is chosen, it should be consistent across all of the libraries.

Currently I'm using browserify to create a bundle with all of the dependencies. Graphlib-dot actually includes graphlib, it's just not exposed. One option would be to expose all of these dependencies from the bundle - something like "graphlibDot.graphlib.Graph" or even re-export some of the common functions, like "graphlibDot.Graph". The downside is that dagre-d3 doesn't use graphlib-dot. I could create a separate bundle that includes dagre-d3 and graphlib-dot, I suppose.

Another would be to strip each of these libraries of all of their dependencies and express them via bower. I haven't found good documentation on if / how this can be done with browserify, but it might involve stubbing out "requires" with accesses to the global.

Do you have a sense for best practices with bower in this regard?

hastebrot commented 10 years ago

Graphlib-dot actually includes graphlib, it's just not exposed.

Didn't know that. So if I only need graphlib-dot and dagre-d3 in order to read a dot file into d3.

Do you have a sense for best practices with bower in this regard?

Unfortunately not. I think in terms of file size and modularity a dependency in graphlib-dot to graphlib and in dagre-d3 to dagre makes sense, if browserify can somehow be instructed to stub the dependencies out. Nevertheless personally the current configuration is good enough for my use cases.

anvaka commented 10 years ago

The downside is that dagre-d3 doesn't use graphlib-dot. I could create a separate bundle that includes dagre-d3 and graphlib-dot, I suppose.

I think this makes sense. Also as long as you keep versions of graphlib the same among your packages, it will be deduped by browserify