Skip to content

Commit 41431c1

Browse files
authored
Merge pull request #18 from wwlib/feature/andrewrapo/merge-data
added support for merging new d3 data with existing d3 data
2 parents 95bc9d0 + 058e059 commit 41431c1

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"dependencies": {
5353
"d3": "^4.12.0",
5454
"font-awesome": "^4.7.0",
55-
"graph-diagram": "0.0.10",
55+
"graph-diagram": "wwlib/graph-diagram#v0.0.11",
5656
"graphlib-dot": "^0.6.4",
5757
"neo4j-driver": "^4.2.3",
5858
"osenv": "^0.1.5",

src/components/graphDiagram/CypherPanel.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ export default class CypherPanel extends React.Component<CypherPanelProps, Cyphe
8989
case 'run':
9090
this.executeCypher(this.state.activeCypher);
9191
break;
92+
case 'runAdd': // add to the existing graph
93+
this.executeCypher(this.state.activeCypher, true);
94+
break;
9295
case 'new':
9396
this.newSavedCypher();
9497
break;
@@ -116,9 +119,9 @@ export default class CypherPanel extends React.Component<CypherPanelProps, Cyphe
116119
}
117120
}
118121

119-
executeCypher(activeCypher: SavedCypher): void {
122+
executeCypher(activeCypher: SavedCypher, addToExistingGraph: boolean = false): void {
120123
// this.props.appModel.executeCypher(activeCypher.cypher);
121-
this.props.appModel.createGraphModelWithCypherQuery(activeCypher.cypher);
124+
this.props.appModel.createGraphModelWithCypherQuery(activeCypher.cypher, { addToExistingGraph: addToExistingGraph });
122125
}
123126

124127
newSavedCypher(): void {
@@ -200,6 +203,8 @@ export default class CypherPanel extends React.Component<CypherPanelProps, Cyphe
200203
</ReactBootstrap.Table>
201204
<ReactBootstrap.Button variant={'default'} key={"run"} style = {{width: 80}}
202205
onClick={this.onButtonClicked.bind(this, "run")}>Run</ReactBootstrap.Button>
206+
<ReactBootstrap.Button variant={'default'} key={"runAdd"} style = {{width: 80}}
207+
onClick={this.onButtonClicked.bind(this, "runAdd")}>Run+</ReactBootstrap.Button>
203208
<ReactBootstrap.Button variant={'default'} key={"new"} style = {{width: 80}}
204209
onClick={this.onButtonClicked.bind(this, "new")}>New</ReactBootstrap.Button>
205210
<ReactBootstrap.Button variant={'default'} key={"delete"} style = {{width: 80}}

src/model/AppModel.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,31 @@ circle.node-base {
208208
case "neo4j":
209209
this.neo4jController = new Neo4jController({ debug: true, connection: graph.connection });
210210
graph.config = new Neo4jGraphConfig(graph.config);
211-
this.createGraphModelWithCypherQuery(graph.connection.initialCypher, graph);
211+
this.createGraphModelWithCypherQuery(graph.connection.initialCypher, { graph: graph });
212212
break;
213213
}
214214
}
215215

216-
createGraphModelWithCypherQuery(cypher: string, graph?: Graph): void {
217-
console.log(`createGraphModelWithCypherQuery: cypher: ${cypher}`, graph);
218-
graph = graph || this.activeGraph;
216+
createGraphModelWithCypherQuery(cypher: string, options?: any): void {
217+
let graph: Graph | undefined = this.activeGraph;
218+
let addToExistingGraph: boolean = false;
219+
if (options) {
220+
graph = options.graph || graph;
221+
addToExistingGraph = options.addToExistingGraph;
222+
}
223+
console.log(`createGraphModelWithCypherQuery: cypher: ${cypher}`, graph, addToExistingGraph);
219224
if(this.neo4jController) {
220225
this.neo4jController.getCypherAsD3(cypher)
221226
.then(data => {
222227
console.log(data);
223-
this.graphModel = ModelToD3.parseD3(data, undefined, this.getSvgOrigin());
228+
let newGraphModel = ModelToD3.parseD3(data, undefined, this.getSvgOrigin());
229+
if (addToExistingGraph) {
230+
const existingData: any = ModelToD3.convert(this.graphModel);
231+
const mergedData = ModelToD3.mergeD3(data, existingData);
232+
console.log(mergedData);
233+
newGraphModel = ModelToD3.parseD3(mergedData, undefined, this.getSvgOrigin());
234+
}
235+
this.graphModel = newGraphModel;
224236
this._activeNode = this.graphModel.nodeList()[0];
225237
this._activeRelationship = this.graphModel.relationshipList()[0];
226238
this.activeGraph = graph;

src/neo4j/helpers/BoltToD3.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ export default class BoltToD3 {
1212
}
1313

1414
isLink(field: any) {
15-
return field.start && field.end;
15+
let result: boolean = false;
16+
if (field && field.start && field.end) {
17+
result = true;
18+
}
19+
return result;
1620
}
1721

1822
isNode(field: any) {
@@ -124,7 +128,7 @@ export default class BoltToD3 {
124128
fieldCandidate.forEach((field: any) => {
125129
fieldArray.push(field);
126130
})
127-
} else {
131+
} else if (fieldCandidate){
128132
fieldArray.push(fieldCandidate);
129133
}
130134
fieldArray.forEach((field: any) => {

yarn.lock

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6296,10 +6296,9 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6
62966296
resolved "https://npm.jibo.com/repository/ntt/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
62976297
integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==
62986298

6299-
6300-
version "0.0.10"
6301-
resolved "https://registry.npmjs.org/graph-diagram/-/graph-diagram-0.0.10.tgz#56611ff6e9d32c6355c756f0519fb04eb644f540"
6302-
integrity sha1-VmEf9unTLGNVx1bwUZ+wTrZE9UA=
6299+
graph-diagram@wwlib/graph-diagram#v0.0.11:
6300+
version "0.0.11"
6301+
resolved "https://codeload.github.com/wwlib/graph-diagram/tar.gz/00620064fe934a7df44d33f3d979c4307e0a8a37"
63036302

63046303
graphlib-dot@^0.6.4:
63056304
version "0.6.4"

0 commit comments

Comments
 (0)