Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
davidballester committed Nov 6, 2019
2 parents d8b750a + 9905957 commit 28c9aa2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/scenes/welcome/new-graph/new-graph.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ function mapStateToProps(state) {

function mapDispatchToProps(dispatch) {
return {
saveNewGraph: (graphName, includeSampleGraph) => dispatch(createGraph({ name: graphName }, includeSampleGraph)),
saveNewGraph: (graphName, includeSampleGraph) => {
dispatch(createGraph({ name: graphName }, includeSampleGraph));
dispatch(closeDialog(DIALOG_IDS.NEW_GRAPH));
},
cancelNewGraph: () => dispatch(closeDialog(DIALOG_IDS.NEW_GRAPH)),
};
}
Expand Down
10 changes: 8 additions & 2 deletions src/services/graph-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Grapher {
= identifier space identifier --withBlanks
| alnum+ --string
separator = ";" | "\\n"+ | "\\r"+
separator = ";" | "\\n"+
}
`;
Expand Down Expand Up @@ -195,6 +195,8 @@ class GraphGrammar {
}

match(string = '') {
string = string.replace(/( )*# (.*)(?!\\n)/gi, ''); // Remove comments before line breaks
string = string.replace(/( )*# (.*)(?!$)/gi, '\n'); // Remove trailing comments
return this.grammar.match(string);
}

Expand Down Expand Up @@ -289,15 +291,18 @@ const mapEntities = (entities) => {
};
};

export const sampleGraph = `:King #red
export const sampleGraph = `# First, we define groups to assign them colors
:King #red
:Queen #purple
:Wizard #blue
:Antagonist #grey
:Knight #green
# These are normal groups, but we'll use them for links, which have no coloring
:family
:lovers
# Now, nodes. You do not need to define nodes independently, but it's a good way to assign them groups and later just use them by name.
(Arthur:King)
(Guinevere:Queen)
(Merlin:Wizard)
Expand All @@ -307,6 +312,7 @@ export const sampleGraph = `:King #red
(Lamorak:Knight)
(Bors:Knight)
# And throw in some paths between your nodes
(Arthur)-[:lovers]->(Guinevere)<-[:lovers]-(Lancelot)
(Arthur)-[:family]->(Mordred)
(Lancelot)-[:family]->(Galahad)
Expand Down
49 changes: 49 additions & 0 deletions src/services/graph-grammar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,42 @@ describe('graph-grammar', () => {
(bar);(foo)-[baz]->(bar)`);
expect(matchResult.succeeded()).toBeTruthy();
});

it('matches a node with a comment', () => {
const matchResult = graphGrammar.match('(foo) # This is a random comment');
expect(matchResult.succeeded()).toBeTruthy();
});

it('matches a node with a comment separated by multiple spaces', () => {
const matchResult = graphGrammar.match('(foo) # This is a random comment');
expect(matchResult.succeeded()).toBeTruthy();
});

it('matches a group with a comment', () => {
const matchResult = graphGrammar.match(':foo #red # This is a random comment');
expect(matchResult.succeeded()).toBeTruthy();
});

it('matches a group with a comment separated by multiple spaces', () => {
const matchResult = graphGrammar.match(':foo #fafafa # This is a random comment');
expect(matchResult.succeeded()).toBeTruthy();
});

it('matches a complex path with a comment', () => {
const matchResult = graphGrammar.match(`(foo)-[:baz:qux quux]->(corge)
(bar);(foo)-[baz]->(bar) # This is a random comment
`);
expect(matchResult.succeeded()).toBeTruthy();
});

it('matches a complex path with a comment separated by multiple spaces', () => {
const matchResult = graphGrammar.match(`(foo)-[:baz:qux quux]->(corge)
(bar);(foo)-[baz]->(bar) # This is a random comment
`);
expect(matchResult.succeeded()).toBeTruthy();
});
});

describe('#eval', () => {
Expand Down Expand Up @@ -663,5 +699,18 @@ describe('graph-grammar', () => {
const matchResult = graphGrammar.match(sampleGraph);
expect(matchResult.succeeded()).toBeTruthy();
});

it.only('translates to something with nodes, links and groups', () => {
const matchResult = graphGrammar.match(sampleGraph);
const result = graphGrammar.eval(matchResult);
expect(result).toEqual({
nodes: expect.anything(),
links: expect.anything(),
groups: expect.anything(),
});
expect(result.nodes.length).toBeTruthy();
expect(result.links.length).toBeTruthy();
expect(result.groups.length).toBeTruthy();
});
});
});

0 comments on commit 28c9aa2

Please sign in to comment.