anvaka / anvaka/ngraph.graph

Linking nodes in the graph doesn't create links in the nodes

Open
#42 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
580
Forks
72
PR merge metrics
No merged PRs in 30d

Description

Hello! I am using `ngraph.graph` version `^20.0.0` as specified in my `package.json`.

I am creating a graph from a file `planet-route-data.json` like so:

```js

import createGraph from 'ngraph.graph'

function makeTravelGraph () {
const graph = createGraph()
const travelGraphData = JSON.parse(fs.readFileSync('./src/planet-route-data.json'))

// first, we create nodes
travelGraphData.forEach(sourcePlanet => {
graph.addNode(sourcePlanet.name)
})

// then, we link them
travelGraphData.forEach(sourcePlanet => {
sourcePlanet.destinations.forEach(destination => {
graph.addLink(sourcePlanet.name, destination.name, { fuelCost: destination.cost })
})
})

return graph
}
```

My `planet-route-data.json` file looks like this (please ignore the values themselves, haha):

```json
[
{
"name": "Earth",
"destinations": [
{
"name": "Mars",
"cost": 13
},
{
"name": "Venus",
"cost": 23
}
]
},
{
"name": "Mars",
"destinations": [
{
"name": "Jupiter",
"cost": 22
},
{
"name": "Saturn",
"cost": 25
}
]
},
{
"name": "Saturn",
"destinations": [
{
"name": "Jupiter",
"cost": 30
},
{
"name": "Earth",
"cost": 12
}
]
},

{
"name": "Venus",
"destinations": [
{
"name": "Earth",
"cost": 20
},
{
"name": "Mars",
"cost": 25
},
{
"name": "Mercury",
"cost": 15
}
]
}
]
```

The nodes in the graph are being created, and links seem to be created successfully -- that is, I can list them as expected with something like:
```js
returnedGraph.forEachLink(link => {
console.log(link)
}
```

However, the nodes themselves, which contain a property named `links`, do not seem to be updated. If I try to print them, their `links` property looks like an empty object: `{}`. If I do:
```js
returnedGraph.forEachLinkedNode(node => {
console.log(node)
}
```

nothing is iterated upon, presumably as there are no nodes with links to be found.

Is this, by any chance, by design, or is it not intended behavior?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the graph construction from package.json and planet-route-data.json, then inspect the ngraph.graph entry points used by addNode, addLink, forEachLink, and forEachLinkedNode. Compare the node and link representations with the behavior described; done means the intended behavior is established and covered by an appropriate project test or documentation update.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.