Published
Edited
Apr 16, 2021
Insert cell
Insert cell
neo4j = {
const neo4j = await require('neo4j-driver');
return neo4j;
}
Insert cell
Insert cell
driver = neo4j.driver(
"neo4j+s://df82a806.databases.neo4j.io:7687",
neo4j.auth.basic("Reader", "Reader")
)
Insert cell
Insert cell
Insert cell
Insert cell
//allOriginal = buildDataArrayOriginal("MATCH ()-[r:Assoc]->(), (n) RETURN n,r")
Insert cell
allNodeOriginal = buildDataArrayOriginal("MATCH (n) RETURN n")
Insert cell
allRelationshipOriginal = buildDataArrayOriginal("MATCH ()-[r:Assoc]->() RETURN r")
Insert cell
allNode = allNodeOriginal.records
Insert cell
allRelationship = allRelationshipOriginal.records
Insert cell
all = allNode.concat(allRelationship)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
queryForNode = 'MATCH (n) RETURN n';
Insert cell
queryForRelationship = 'MATCH p=()-[r:Assoc]->() RETURN p';
Insert cell
function buildDataArrayNodeOriginal() {
const session1 = driver.session();
const dataArrayNodeOriginal = session1.run(queryForNode);
return dataArrayNodeOriginal;
}
Insert cell
dataArrayNodeOriginal = buildDataArrayNodeOriginal();
Insert cell
function buildDataArrayRelationshipOriginal() {
const session2 = driver.session();
const dataArrayRelationshipOriginal = session2.run(queryForRelationship);
return dataArrayRelationshipOriginal;
}
Insert cell
dataArrayRelationshipOriginal = buildDataArrayRelationshipOriginal();
Insert cell
dataArrayNodeSecond = dataArrayNodeOriginal.records.map(d => d.toObject())
Insert cell
dataArrayRelationshipSecond = dataArrayRelationshipOriginal.records.map(d => d.toObject()).map(d => d.p)
Insert cell
// viewof, generators, dependency, mutable (things to look at for sync)
dataNodeArray = []
Insert cell
{
for (let i = 0; i < dataArrayNodeSecond.length; i++) {
dataNodeArray[i] = {ID: dataArrayNodeSecond[i].n.identity.low, LABEL:dataArrayNodeSecond[i].n.labels[0]};
for (const property in dataArrayNodeSecond[i].n.properties) {
if (dataNodeArray[i].LABEL == "Restaurant") {
dataNodeArray[i][property] = dataArrayNodeSecond[i].n.properties[property]
} else {
dataNodeArray[i]['name'] = dataArrayNodeSecond[i].n.properties[property]
}
}
}
}
Insert cell
dataNodeArray[8730]
Insert cell
dataRelationshipArray = []
Insert cell
{
for (let i = 0; i < dataArrayRelationshipSecond.length; i++) {
dataRelationshipArray[i] = {ID: dataArrayRelationshipSecond[i].segments[0].relationship.identity.low, source: dataArrayRelationshipSecond[i].start.identity.low, target: dataArrayRelationshipSecond[i].end.identity.low}
for (const property in dataArrayRelationshipSecond[i].segments[0].relationship.properties) {
dataRelationshipArray[i][property] = dataArrayRelationshipSecond[i].segments[0].relationship.properties[property]
}
}
}
Insert cell
dataRelationshipArray
Insert cell
function buildDataArray(node, link) {
const dataArray = {Node: node, Link: link}
return dataArray;
}
Insert cell
dataArray = buildDataArray(dataNodeArray, dataRelationshipArray)
Insert cell
Table(dataNodeArray)
Insert cell
Table(dataRelationshipArray)
Insert cell
function checkCountCity(object) {
if (object.count >= 150) {
return object
}
}
Insert cell
function checkCountCategory(object) {
if (object.count >= 500) {
return object
}
}
Insert cell
Insert cell
Insert cell
Insert cell
{
const data =cityArray.filter(checkCountCity);
const color = d3.scaleSequential(d3.interpolateViridis).domain([0, data.length-1]);
const colors = {
domain: data.map(d=>d.group),
range: data.map( (i,j) => color(j) )
};
return vl.markArc({outerRadius: 150})
.data(data)
.encode(
vl.theta().fieldQ('count'),
vl.color().fieldN('name'),
vl.tooltip([
{ field: "name", type: "nominal" },
{ field: "count", type: "quantitative" }
])
)
.config({view: {stroke: null}})
.width(300)
.height(300)
.render();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
categoryArray = dataArray.Node.filter(d => d.LABEL === "Food")
Insert cell
categoryArray.map(d => d.count = countRelations(d,dataArray)).filter(d => d.count != 0)
Insert cell
cityArray.map(d => d.count = countRelations(d, dataArray)).filter(d => d.count !== 0)
Insert cell
Insert cell
starsArray = dataArray.Node.filter(d => d.LABEL === "stars")
Insert cell
starsArray.map(d => d.count = countRelations(d, dataArray)).filter(d => d.count !== 0)
Insert cell
Insert cell
Insert cell
Insert cell
import {select, text, number, password as passwordInput} from "@jashkenas/inputs"
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {Table} from "@observablehq/inputs"
Insert cell
// npm i @observablehq/runtime
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more