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

Mitigate one-line-of-nodes layouts #679

Merged
merged 2 commits into from Nov 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 54 additions & 0 deletions client/app/scripts/charts/__tests__/node-layout-test.js
@@ -1,4 +1,5 @@
jest.dontMock('../nodes-layout');
jest.dontMock('../topology-utils');
jest.dontMock('../../constants/naming'); // edge naming: 'source-target'

import { fromJS, Map } from 'immutable';
Expand Down Expand Up @@ -69,6 +70,26 @@ describe('NodesLayout', () => {
edges: fromJS({
'n1-n4': {id: 'n1-n4', source: 'n1', target: 'n4'}
})
},
single3: {
nodes: fromJS({
n1: {id: 'n1'},
n2: {id: 'n2'},
n3: {id: 'n3'}
}),
edges: fromJS({})
},
singlePortrait: {
nodes: fromJS({
n1: {id: 'n1'},
n2: {id: 'n2'},
n3: {id: 'n3'},
n4: {id: 'n4'},
n5: {id: 'n5'}
}),
edges: fromJS({
'n1-n4': {id: 'n1-n4', source: 'n1', target: 'n4'}
})
}
};

Expand Down Expand Up @@ -232,4 +253,37 @@ describe('NodesLayout', () => {
expect(resultCoords.slice(0, 2)).toEqual(coords.slice(0, 2));
expect(resultCoords.slice(2, 6)).toEqual(coords.slice(4, 8));
});

it('renders single nodes in a square', () => {
const result = NodesLayout.doLayout(
nodeSets.single3.nodes,
nodeSets.single3.edges);

nodes = result.nodes.toJS();

expect(nodes.n1.x).toEqual(nodes.n3.x);
expect(nodes.n1.y).toEqual(nodes.n2.y);
expect(nodes.n1.x).toBeLessThan(nodes.n2.x);
expect(nodes.n1.y).toBeLessThan(nodes.n3.y);
});

it('renders single nodes next to portrait graph', () => {
const result = NodesLayout.doLayout(
nodeSets.singlePortrait.nodes,
nodeSets.singlePortrait.edges);

nodes = result.nodes.toJS();

// first square row on same level as top-most other node
expect(nodes.n1.y).toEqual(nodes.n2.y);
expect(nodes.n1.y).toEqual(nodes.n3.y);
expect(nodes.n4.y).toEqual(nodes.n5.y);

// all singles right to other nodes
expect(nodes.n1.x).toEqual(nodes.n4.x);
expect(nodes.n1.x).toBeLessThan(nodes.n2.x);
expect(nodes.n1.x).toBeLessThan(nodes.n3.x);
expect(nodes.n1.x).toBeLessThan(nodes.n5.x);
expect(nodes.n2.x).toEqual(nodes.n5.x);
});
});
109 changes: 109 additions & 0 deletions client/app/scripts/charts/__tests__/topology-utils-test.js
@@ -0,0 +1,109 @@
jest.dontMock('../topology-utils');
jest.dontMock('../../constants/naming'); // edge naming: 'source-target'

import { fromJS } from 'immutable';

describe('TopologyUtils', () => {
let TopologyUtils;
let nodes;

const nodeSets = {
initial4: {
nodes: fromJS({
n1: {id: 'n1'},
n2: {id: 'n2'},
n3: {id: 'n3'},
n4: {id: 'n4'}
}),
edges: fromJS({
'n1-n3': {id: 'n1-n3', source: 'n1', target: 'n3'},
'n1-n4': {id: 'n1-n4', source: 'n1', target: 'n4'},
'n2-n4': {id: 'n2-n4', source: 'n2', target: 'n4'}
})
},
removeEdge24: {
nodes: fromJS({
n1: {id: 'n1'},
n2: {id: 'n2'},
n3: {id: 'n3'},
n4: {id: 'n4'}
}),
edges: fromJS({
'n1-n3': {id: 'n1-n3', source: 'n1', target: 'n3'},
'n1-n4': {id: 'n1-n4', source: 'n1', target: 'n4'}
})
},
removeNode2: {
nodes: fromJS({
n1: {id: 'n1'},
n3: {id: 'n3'},
n4: {id: 'n4'}
}),
edges: fromJS({
'n1-n3': {id: 'n1-n3', source: 'n1', target: 'n3'},
'n1-n4': {id: 'n1-n4', source: 'n1', target: 'n4'}
})
},
removeNode23: {
nodes: fromJS({
n1: {id: 'n1'},
n4: {id: 'n4'}
}),
edges: fromJS({
'n1-n4': {id: 'n1-n4', source: 'n1', target: 'n4'}
})
},
single3: {
nodes: fromJS({
n1: {id: 'n1'},
n2: {id: 'n2'},
n3: {id: 'n3'}
}),
edges: fromJS({})
},
singlePortrait: {
nodes: fromJS({
n1: {id: 'n1'},
n2: {id: 'n2'},
n3: {id: 'n3'},
n4: {id: 'n4'},
n5: {id: 'n5'}
}),
edges: fromJS({
'n1-n4': {id: 'n1-n4', source: 'n1', target: 'n4'}
})
}
};

beforeEach(() => {
TopologyUtils = require('../topology-utils');
});

it('sets node degrees', () => {
nodes = TopologyUtils.updateNodeDegrees(
nodeSets.initial4.nodes,
nodeSets.initial4.edges).toJS();

expect(nodes.n1.degree).toEqual(2);
expect(nodes.n2.degree).toEqual(1);
expect(nodes.n3.degree).toEqual(1);
expect(nodes.n4.degree).toEqual(2);

nodes = TopologyUtils.updateNodeDegrees(
nodeSets.removeEdge24.nodes,
nodeSets.removeEdge24.edges).toJS();

expect(nodes.n1.degree).toEqual(2);
expect(nodes.n2.degree).toEqual(0);
expect(nodes.n3.degree).toEqual(1);
expect(nodes.n4.degree).toEqual(1);

nodes = TopologyUtils.updateNodeDegrees(
nodeSets.single3.nodes,
nodeSets.single3.edges).toJS();

expect(nodes.n1.degree).toEqual(0);
expect(nodes.n2.degree).toEqual(0);
expect(nodes.n3.degree).toEqual(0);
});
});