Skip to content

Commit

Permalink
Merge pull request #17 from OKN-CollabNext/add-entity-attributes
Browse files Browse the repository at this point in the history
Add attributes to node entities; add click event listener to nodes
  • Loading branch information
whymath committed Apr 20, 2024
2 parents d00083a + c6f6879 commit 0555e52
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
57 changes: 54 additions & 3 deletions collabnext/openalex/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,77 @@

def make_institution_nodes(institutions: list[Institution]) -> list[dict]:
return [
{"id": x["id"], "label": x["display_name"], "type": "INSTITUTION"}
{
"id": x["id"],
"name": x["display_name"],
"institution_type": x["type"],
"homepage": x["homepage_url"],
"works_count": x["works_count"],
"cited_by_count": x["cited_by_count"],
"field": None,
"description": None,
"subfield": None,
"domain": None,
"label": x["display_name"],
"type": "INSTITUTION"
}
for x in institutions
]


def make_author_nodes(authors: list[Author]) -> list[dict]:
return [
{"id": x["id"], "label": x["display_name"], "type": "AUTHOR"} for x in authors
{
"id": x["id"],
"name": x["display_name"],
"institution_type": None,
"homepage": None,
"works_count": x["works_count"],
"cited_by_count": x["cited_by_count"],
"field": None,
"description": None,
"subfield": None,
"domain": None,
"label": x["display_name"],
"type": "AUTHOR"
}
for x in authors
]


def make_work_nodes(works: list[Work]) -> list[dict]:
return [{"id": x["id"], "label": x["title"], "type": "WORK"} for x in works]
return [
{
"id": x["id"],
"name": None,
"institution_type": None,
"homepage": None,
"works_count": None,
"cited_by_count": None,
"field": None,
"description": None,
"subfield": None,
"domain": None,
"label": x["title"],
"type": "WORK"
}
for x in works]


def make_topic_nodes(topics: list[Topic]) -> list[dict]:
seen = set()
return [
{
"id": x["id"],
"name": None,
"institution_type": None,
"homepage": None,
"works_count": None,
"cited_by_count": None,
"field": x["field"]["display_name"],
"description": x.get("description"),
"subfield": x["subfield"]["display_name"],
"domain": x["domain"]["display_name"],
"label": x["field"]["display_name"],
"type": "TOPIC",
}
Expand Down
15 changes: 14 additions & 1 deletion observable/docs/data/graph.sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,20 @@
]

# Create nodes dataframe
df_nodes = pd.DataFrame(nodes, columns=["id", "label", "type"])
df_nodes = pd.DataFrame(nodes, columns=[
"id",
"label",
"type",
"name",
"institution_type",
"homepage",
"works_count",
"cited_by_count",
"field",
"description",
"subfield",
"domain",
])

# Create edges dataframe
df_edges = pd.DataFrame(
Expand Down
12 changes: 12 additions & 0 deletions observable/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ orb.data.setDefaultStyle({
},
});


// Initialize nodes and edges
orb.data.setup({ nodes, edges });

Expand All @@ -127,4 +128,15 @@ orb.view.render(() => {
});
```

```js
orb.events.on('node-click', (event) => {
getData(event)
});


function getData(event) {
console.log('Node clicked: ', event.node);
}
```

<div id="graph" style="width:100%; height:800px"></div>

0 comments on commit 0555e52

Please sign in to comment.