Skip to content

Commit

Permalink
feat(text): preserve group color in nodes and links
Browse files Browse the repository at this point in the history
  • Loading branch information
davidballester committed Oct 19, 2019
1 parent ba809f5 commit 83b85cf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
4 changes: 2 additions & 2 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module.exports = {
'nodes',
'links',
'graph',
'groups',
'canvas',
'groups',
'canvas',
],
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const styles = (theme) => ({
});

function ColorBox({ color = '#ccc', classes }) {
console.log(color);
return <div className={classes.root} style={{ backgroundColor: color }} />;
}

Expand Down
12 changes: 6 additions & 6 deletions src/services/graph-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ const mapEntities = (entities) => {
[node.id]: {
...existingNode,
...node,
groups: [...existingGroups, ...node.groups].filter(
(item, index, groups) => groups.findIndex((candidate) => candidate.name === item.name) === index
),
groups: [...existingGroups, ...node.groups]
.filter((item, index, groups) => groups.findIndex((candidate) => candidate.name === item.name) === index)
.map(({ name }) => groups.find(({ name: existingGroupName }) => existingGroupName === name)),
},
};
}, {});
Expand Down Expand Up @@ -276,9 +276,9 @@ const mapEntities = (entities) => {
[sourceAndTargetId]: {
...existingLink,
...link,
groups: [...existingGroups, ...link.groups].filter(
(item, index, groups) => groups.findIndex((candidate) => candidate.name === item.name) === index
),
groups: [...existingGroups, ...link.groups]
.filter((item, index, groups) => groups.findIndex((candidate) => candidate.name === item.name) === index)
.map(({ name }) => groups.find(({ name: existingGroupName }) => existingGroupName === name)),
},
};
}, {});
Expand Down
35 changes: 35 additions & 0 deletions src/services/graph-grammar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,40 @@ describe('graph-grammar', () => {
groups: expect.anything(),
});
});

it('preserves first color defined for a group', () => {
const result = graphGrammar.eval(graphGrammar.match(':foo #red;:foo #yellow'));
expect(result).toEqual({
nodes: expect.anything(),
links: expect.anything(),
groups: [
{
id: expect.anything(),
name: 'foo',
color: red['A700'],
},
],
});
});

it('includes colors of groups in nodes', () => {
const result = graphGrammar.eval(graphGrammar.match(':foo #red;(bar:foo)'));
expect(result).toEqual({
nodes: [
{
id: 'bar',
groups: [
{
id: expect.anything(),
name: 'foo',
color: red['A700'],
},
],
},
],
links: expect.anything(),
groups: expect.anything(),
});
});
});
});

0 comments on commit 83b85cf

Please sign in to comment.