Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no exported class LayoutDagRoot, LayoutDagNode, LayoutChildLink #57

Closed
Arnaud-Nauwynck opened this issue Apr 21, 2021 · 8 comments
Closed

Comments

@Arnaud-Nauwynck
Copy link

Arnaud-Nauwynck commented Apr 21, 2021

Hello,

the following classes are not exported: LayoutDagRoot, LayoutDagNode, LayoutChildLink.
I tryed to import theses classe, and use them directly to build with custom code the DAG graph.

import { LayoutDagRoot, LayoutDagNode, LayoutChildLink } from 'd3-dag'; /// does not compile!!
import { LayoutDagRoot, LayoutDagNode, LayoutChildLink } from 'd3-dag/dist/dag/node'; // compile in IDE, but does not work at runtime !!

..
let fooObjs: Fooj[] = ...  with child dependencies to bars
let barObjs: Fooj[] = ...  with child dependencies to some baz, and parent dependencies from some baz (typically, read/write relation between data and process)
let bazObjs: Fooj[] = ...  other dependencies ...

// create node objects
let dagNodeMap = new Map<string,LayoutDagNode>();
fooObjs.forEach(obj => {
    let fooId = 'foo:' + obj.id;
    let nodeData = { type:'foo', foo };
    dagNodeMap.set(fooId, new LayoutDagNode(fooId, nodeData));
});
barObjs.forEach(barObj =>  ... similar create  LayoutDagNode ..
bazObjs.forEach(bazObj =>  ... similar create  LayoutDagNode ..
// create child dependency links between objects..
// dependency between foo-[dep1]->bar(s)
fooObjs.forEach(fooObj => {
   let fooNode = dagNodeMap.get('foo:' + fooObj.id);
   fooObj.dep1Bars.forEach(barObj => {
      let childBarNode = dagNodeMap.get('bar:' + barObj.id);
      let linkData = { linkType:'foo_dep1_bar' };
      fooNode.dataChildren.push( new LayoutChildLink(barObj, linkData));
   });
 // dependency between bar-[dep2]->foo(s) 
 fooObj.dep2Bars.forEach(barObj => {
      let  = dagNodeMap.get('bar:' + barObj.id);
      let linkData = { linkType:'bar_dep2_foo' };
      parentBarNode.dataChildren.push( new LayoutChildLink(fooNode, linkData));
   });
   // other dendencies between foo,bar,baz...   
});

Maybe I could use directly some other graph builder operator?
I did not understand the doc, and what is effectively exported/private from the doc

Thanks for your answer, or fix

@erikbrinkman
Copy link
Owner

This was by design. Dags are supposed to be created with any of the creation functions (connect, hierarchy, stratify), but not created manually, which is why those members were not exported.

Is there a reason why you need to create nodes manually? I'm not overly opposed to exporting them, but I would want to see a compelling argument to. Part of the benefit of "controlling" dag creation is to prevent someone creating a cycle or something else which would break expected invariants around dags.

you also point to the fact that:
import { LayoutDagRoot, LayoutDagNode, LayoutChildLink } from 'd3-dag/dist/dag/node';
will compile in an IDE, but does not work at runtime. I think this is due to the poor way that I export types. It's evolved over time, but isn't great. I think I have a solution though, so I'll address and fix that problem separately.

@Arnaud-Nauwynck
Copy link
Author

can you provide detailed typescript example/doc/urls of using connect(), hierarchy(), stratify() ?
Can I still control it objets by objets (given that I already have a graph of objects in typescript), or do I need to fully export it in a typescript (json?) array, and import it in one method call.

@Arnaud-Nauwynck
Copy link
Author

by the way... this link was broken https://erikbrinkman.github.io/d3-dag/

@erikbrinkman
Copy link
Owner

Thanks for pointing that out. I just fixed the documentation which should be up now and should answer your questions. There was an update to typedoc, so unfortunately some of the links in the documentation are going to be broken until I fix it, but it should be pretty easy to figure out where they were pointing.

If you already have typescript objects that look like a dag, then you can use hierarchy which is exported as dagHierarchy() until I resolve the common js / es module stuff. Say for example that you had objects with the following interface:

interface MyObj {
   uniqueString: string;
   nextObjects: MyObj[];
}

then you could create a dag with:

const myDag: Dag<MyObj> = dagHierarchy().id(obj => obj.uniqueString).children(obj => obj.nextObjects)(root)

@Arnaud-Nauwynck
Copy link
Author

ok, looks good

this also raises another question:
In my typescripts objects, I have several types of objects and several types of ChildLink (LinkData) dependencies.
Is it possible with dagHierarchy() to enrich the method ".children(obj => childObjects)" to have instead ".childLinks(obj => childObjectLinks)" where a childLinkObject would be a pair of object reference and user-defined LinkData .
I would like to use these LinkData attribute to give different style and behavior on rendered graphical elements.

@erikbrinkman
Copy link
Owner

Look at the documentation (which unfortunately seems to do a poor job with the typescript annotations, the source is probably a better place to turn). Instead of children you can use childrenData

@erikbrinkman
Copy link
Owner

As of version 0.7 (which has some breaking changes), the full build should be pushed, so importing from d3-dag/dist/... should now work in case you really still need LayoutDagNode, although I will caution that it's use still isn't recommended.

@erikbrinkman
Copy link
Owner

A new version 0.8 which is effectively 1.0-rc is out. The documentation should be up to date and mostly working, although there are probably a few missing things here and there. Everything is updated, although I did remove the ability to create your own nodes automatically.

Let me know if you're still unable to do what you want. Otherwise I'm going to close this in a week or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants