-
Notifications
You must be signed in to change notification settings - Fork 89
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
Try to replicate a dagre layout #21
Comments
Balanced:
There's an option 'favorStraightEdges'. If you set it to false it should
give you a balanced layout (I'll check later).
Regarding the order:
We (so far) do not regard the input order of the elements (as dagre does
afaik). But you could set 'crossingMinimization.semiInteractive' and define
an order for the three nodes via the 'elk.position' option: e.g. assign an
x of 0 to one, an x of 10 to two and so on.
|
I set I think I've found a bug: edge label is not inline. I will create a new issue to track it. Update: as @uruuru said, the key is |
That's because the favourStraightEdges option has different default values
for orthogonal and polyline edges.
Unless you set it explicitly, that is.
|
@uruuru I cannot make the const graph = {
id: 'root',
layoutOptions: {
'elk.direction': 'DOWN',
'elk.layered.crossingMinimization.semiInteractive': true
},
children: [
{
id: 'n1',
width: 100,
height: 50,
labels: [{ text: 'Chrismas' }]
},
{
id: 'n2',
width: 100,
height: 50,
labels: [{ text: 'Go shopping' }]
},
{
id: 'n3',
width: 100,
height: 50,
labels: [{ text: 'Let me think' }]
},
{
id: 'n4',
width: 100,
height: 50,
labels: [{ text: 'Laptop' }],
layoutOptions: { 'elk.position': '[x=0,y=0]' }
},
{
id: 'n5',
width: 100,
height: 50,
labels: [{ text: 'iPhone' }],
layoutOptions: { 'elk.position': '[x=10,y=0]' }
},
{
id: 'n6',
width: 100,
height: 50,
labels: [{ text: 'Car' }],
layoutOptions: { 'elk.position': '[x=20,y=0]' }
}
],
edges: [
{
id: 'e1',
sources: ['n1'],
targets: ['n2'],
type: 'DIRECTED',
labels: [{ width: 80, height: 20, text: 'Get money' }]
},
{
id: 'e2',
sources: ['n2'],
targets: ['n3'],
type: 'DIRECTED'
},
{
id: 'e3',
sources: ['n3'],
targets: ['n4'],
type: 'DIRECTED',
labels: [{ width: 60, height: 20, text: 'One' }]
},
{
id: 'e4',
sources: ['n3'],
targets: ['n5'],
type: 'DIRECTED',
labels: [{ width: 60, height: 20, text: 'Two' }]
},
{
id: 'e5',
sources: ['n3'],
targets: ['n6'],
type: 'DIRECTED',
labels: [{ width: 60, height: 20, text: 'Three' }]
}
]
} But it has no effect. Could you please kindly advise? |
I've got it: const elk = new ELK({
defaultLayoutOptions: {
'elk.algorithm': 'layered',
'elk.direction': 'RIGHT',
'elk.padding': '[top=25,left=25,bottom=25,right=25]',
'elk.spacing.componentComponent': 25,
'elk.layered.spacing.nodeNodeBetweenLayers': 25,
'elk.edgeLabels.inline': true,
'elk.edgeRouting': 'SPLINES'
}
}) const graph = {
id: 'root',
layoutOptions: {
'elk.direction': 'DOWN',
'elk.layered.crossingMinimization.semiInteractive': true,
'elk.layered.crossingMinimization.strategy': 'INTERACTIVE'
},
children: [
{
id: 'n1',
width: 100,
height: 50,
labels: [{ text: 'Chrismas' }]
},
{
id: 'n2',
width: 100,
height: 50,
labels: [{ text: 'Go shopping' }]
},
{
id: 'n3',
width: 100,
height: 50,
labels: [{ text: 'Let me think' }]
},
{
id: 'n4',
width: 100,
height: 50,
labels: [{ text: 'Laptop' }],
layoutOptions: { 'elk.position': '[x=0,y=0]' }
},
{
id: 'n5',
width: 100,
height: 50,
labels: [{ text: 'iPhone' }],
layoutOptions: { 'elk.position': '[x=10,y=0]' }
},
{
id: 'n6',
width: 100,
height: 50,
labels: [{ text: 'Car' }],
layoutOptions: { 'elk.position': '[x=20,y=0]' }
}
],
edges: [
{
id: 'e1',
sources: ['n1'],
targets: ['n2'],
type: 'DIRECTED',
labels: [{ width: 80, height: 20, text: 'Get money' }]
},
{
id: 'e2',
sources: ['n2'],
targets: ['n3'],
type: 'DIRECTED'
},
{
id: 'e3',
sources: ['n3'],
targets: ['n4'],
type: 'DIRECTED',
labels: [{ width: 60, height: 20, text: 'One' }]
},
{
id: 'e4',
sources: ['n3'],
targets: ['n5'],
type: 'DIRECTED',
labels: [{ width: 60, height: 20, text: 'Two' }]
},
{
id: 'e5',
sources: ['n3'],
targets: ['n6'],
type: 'DIRECTED',
labels: [{ width: 60, height: 20, text: 'Three' }]
}
]
} |
Setting |
Ok, let's not close it until you post the update. |
Can you try setting the positions like so: |
I confirm the following works: const graph = {
id: 'root',
layoutOptions: {
'elk.direction': 'DOWN',
'elk.layered.crossingMinimization.semiInteractive': true
},
children: [
{
id: 'n1',
width: 100,
height: 50,
labels: [{ text: 'Chrismas' }]
},
{
id: 'n2',
width: 100,
height: 50,
labels: [{ text: 'Go shopping' }]
},
{
id: 'n3',
width: 100,
height: 50,
labels: [{ text: 'Let me think' }]
},
{
id: 'n4',
width: 100,
height: 50,
labels: [{ text: 'Laptop' }],
layoutOptions: { 'elk.position': '(1,0)' }
},
{
id: 'n5',
width: 100,
height: 50,
labels: [{ text: 'iPhone' }],
layoutOptions: { 'elk.position': '(2,0)' }
},
{
id: 'n6',
width: 100,
height: 50,
labels: [{ text: 'Car' }],
layoutOptions: { 'elk.position': '(3,0)' }
}
],
edges: [
{
id: 'e1',
sources: ['n1'],
targets: ['n2'],
type: 'DIRECTED',
labels: [{ width: 80, height: 20, text: 'Get money' }]
},
{
id: 'e2',
sources: ['n2'],
targets: ['n3'],
type: 'DIRECTED'
},
{
id: 'e3',
sources: ['n3'],
targets: ['n4'],
type: 'DIRECTED',
labels: [{ width: 60, height: 20, text: 'One' }]
},
{
id: 'e4',
sources: ['n3'],
targets: ['n5'],
type: 'DIRECTED',
labels: [{ width: 60, height: 20, text: 'Two' }]
},
{
id: 'e5',
sources: ['n3'],
targets: ['n6'],
type: 'DIRECTED',
labels: [{ width: 60, height: 20, text: 'Three' }]
}
]
} So the correct way to specify position is |
And if I specify Sample: const graph = {
id: 'root',
layoutOptions: {
'elk.direction': 'DOWN',
// 'elk.layered.crossingMinimization.semiInteractive': true,
'elk.layered.crossingMinimization.strategy': 'INTERACTIVE'
},
children: [
{
id: 'n1',
width: 100,
height: 50,
labels: [{ text: 'Chrismas' }]
},
{
id: 'n2',
width: 100,
height: 50,
labels: [{ text: 'Go shopping' }]
},
{
id: 'n3',
width: 100,
height: 50,
labels: [{ text: 'Let me think' }]
},
{
id: 'n4',
width: 100,
height: 50,
labels: [{ text: 'Laptop' }]
// layoutOptions: { 'elk.position': '(1,0)' }
},
{
id: 'n5',
width: 100,
height: 50,
labels: [{ text: 'iPhone' }]
// layoutOptions: { 'elk.position': '(2,0)' }
},
{
id: 'n6',
width: 100,
height: 50,
labels: [{ text: 'Car' }]
// layoutOptions: { 'elk.position': '(3,0)' }
}
],
edges: [
{
id: 'e1',
sources: ['n1'],
targets: ['n2'],
type: 'DIRECTED',
labels: [{ width: 80, height: 20, text: 'Get money' }]
},
{
id: 'e2',
sources: ['n2'],
targets: ['n3'],
type: 'DIRECTED'
},
{
id: 'e3',
sources: ['n3'],
targets: ['n4'],
type: 'DIRECTED',
labels: [{ width: 60, height: 20, text: 'One' }]
},
{
id: 'e4',
sources: ['n3'],
targets: ['n5'],
type: 'DIRECTED',
labels: [{ width: 60, height: 20, text: 'Two' }]
},
{
id: 'e5',
sources: ['n3'],
targets: ['n6'],
type: 'DIRECTED',
labels: [{ width: 60, height: 20, text: 'Three' }]
}
]
} |
@uruuru Do you have any idea why |
I'd assume that it's by chance. |
Many thanks! |
I have experience with https://github.com/dagrejs/dagre. And below is a layout produced by it:
Let's ignore the shapes and assume all of them are rectangles.
I tried the following:
What I produced is:
It is actually not bad!
But I am wondering is it possible to do the following:
One
,Two
&Three
.With above two points achieved, it will be a perfect dagre layout replication.
I am not saying dagre is better. Actually I think elkjs is more flexible. Here I just investigate and learn something about elkjs.
The text was updated successfully, but these errors were encountered: