Skip to content

Commit

Permalink
neo4j-arc should be node/rel-ID agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi committed Nov 22, 2023
1 parent 51168eb commit 01d3a7b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
23 changes: 17 additions & 6 deletions docs/modules/ROOT/pages/neo4j-arc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,27 @@ export default function MyGraphComponent(): JSX.Element {

= Neo4J Browser Internals

neo4j-arc does not genreate node ID. It is

The Neo4J Browser is logically composed of 2 parts:

1. A slightly coupled graphing module
2. A user-interface that combines the graph rendering (supported by the graphing module), database, and user
. The neo4j-arc, which is the current part we are discussing

.. The neo4j-arc is based on D3 and implements its own layout, coloring, and link drawing. For example, the calculation
of arrow, i.e. links, between nodes uses some
https://github.com/QubitPi/neo4j-browser/blob/master/src/neo4j-arc/graph-visualization/utils/ArcArrow.ts[very complicated math]
along with very prelimiary MDN standard basic shap specification.
.. IMPORTANT
====
Although we see `<id>` property for every node or relationship in the node inspection panel of Neo4J Browser, those
ID's are NOT generated by neo4j-arc, but https://stackoverflow.com/a/67702695[instead by Neo4J database]

Note: the displayed `<id>` is the value of NodeMode.id
====

. A user-interface that combines the graph rendering (supported by the graphing module), database, and user
interaction together

The graphing is based on D3 and implements its own layout, coloring, and link drawing. For example, the calculation of
arrow, i.e. links, between nodes uses some
https://github.com/QubitPi/neo4j-browser/blob/master/src/neo4j-arc/graph-visualization/utils/ArcArrow.ts[very complicated math]
along with very prelimiary MDN standard basic shap specification.

[WARNING]
====
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,25 +400,24 @@ LIMIT ${maxNewNeighbours}`
if (event == NODE_ON_CANVAS_CREATE) {
if (properties == null) {
throw new Error(
'A property map with id, name, and labels keys are required'
'A property map with name, and labels keys are required'
)
}

const id = properties['id']
const name = properties['name']
const description = properties['description']
const variableName = `node${id}`
const variableName = `node`
const labels = (properties['labels'] as string[])
.map(label => `\`${label}\``)
.join(':')

const query = `CREATE (${variableName}:${labels} { id: ${id}, name: "${name}", description: "${description}" });`
const query = `CREATE (${variableName}:${labels} { name: "${name}", description: "${description}" });`

this.props.bus.self(
CYPHER_REQUEST,
{
query,
params: { labels, id, name, description },
params: { labels, name, description },
queryType: NEO4J_BROWSER_USER_ACTION_QUERY
},
(response: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,12 @@ export class GraphEventHandlerModel {
}

onCanvasDblClicked(): void {
const maxId: number = Math.max(
...this.graph.nodes().map(node => parseInt(node.id))
)
const newId = maxId + 1
const transientId: string =
'transient' + Math.random().toString(36).slice(2)

this.graph.addNodes([
new NodeModel(
newId.toString(),
transientId,
['Undefined'],
{
name: 'New Node',
Expand All @@ -267,7 +265,6 @@ export class GraphEventHandlerModel {
this.graphModelChanged()

this.onGraphInteraction(NODE_ON_CANVAS_CREATE, {
id: newId,
name: 'New Node',
description: 'New Node',
labels: ['Undefined']
Expand Down Expand Up @@ -300,18 +297,14 @@ export class GraphEventHandlerModel {
) {
this.altCreatedRelTargetNode = node

const maxId: number = Math.max(
...this.graph
.relationships()
.map(relationship => parseInt(relationship.id))
)
const newId = maxId + 1
const transientId: string =
'transient' + Math.random().toString(36).slice(2)

const altCreatedRel: RelationshipModel = new RelationshipModel(
newId.toString(),
transientId,
this.altCreatedRelSourceNode,
this.altCreatedRelTargetNode,
newId.toString(),
transientId,
{ name: 'new link' },
{ name: 'string' }
)
Expand All @@ -324,7 +317,7 @@ export class GraphEventHandlerModel {
this.graphModelChanged()

this.onGraphInteraction(REL_ON_CANVAS_CREATE, {
type: newId,
type: transientId,
sourceNodeId: this.altCreatedRelSourceNode.id,
targetNodeId: this.altCreatedRelTargetNode.id
})
Expand Down

0 comments on commit 01d3a7b

Please sign in to comment.