Skip to content

Commit

Permalink
Set up visualization of team.json data with vis.js network
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Dec 10, 2020
1 parent a82d587 commit 1ed3e93
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ typings/
# gatsby files
.cache/
public
bin
target

# Mac files
.DS_Store
Expand Down
5 changes: 5 additions & 0 deletions gatsby/lobid/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ exports.createPages = ({ actions }) => {
path: "/team",
component: path.resolve(`./src/pages/team-de.js`)
});

createPage({
path: "/visual",
component: path.resolve(`./src/pages/visual.js`)
});
};
47 changes: 47 additions & 0 deletions gatsby/lobid/src/components/visual.html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { Component, createRef } from "react";
import { DataSet, Network} from 'vis-network/standalone/esm/vis-network';

import "./css/lobid.css";

export class Visual extends Component {

constructor(props) {
super(props);
this.props = props;
this.state = {
infoToggled: false
};
this.network = {};
this.appRef = createRef();
}

componentDidMount() {
console.log("Props", this.props)

var ns = [
{ id: 'm', label: "Members","shape":"dot","size":"5"},
{ id: 'o', label: "Offers","shape":"dot","size":"5"}
];
this.props.members.forEach((item,index) => { ns.push({ id: "m"+index, label: item.member.name, "shape":"box" }); });
this.props.products.forEach((item,index) => { ns.push({ id: "o"+index, label: item.name, "shape":"box" }); });
const nodes = new DataSet(ns);

var es = [];
this.props.members.forEach((item,index) => { es.push({ from: 'm', to: 'm'+index }); });
this.props.products.forEach((item,index) => { es.push({ from: 'o', to: 'o'+index }); });
const edges = new DataSet(es);

const data = {
nodes: nodes,
edges: edges
};
const options = {};
this.network = new Network(this.appRef.current, data, options);
}

render() {
return (
<div id="lobid-network" ref={this.appRef} />
);
}
}
34 changes: 34 additions & 0 deletions gatsby/lobid/src/pages/visual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";
import { graphql } from "gatsby";
import { Visual } from "../components/visual.html";

export default ({ data }) => (
<Visual
members = {data.dataJson.member}
products = {data.dataJson.makesOffer}
/>
);

export const query = graphql`
query {
dataJson {
makesOffer {
alternateName {
de
}
id
name
}
member {
member {
id
image
name
}
roleName {
de
}
}
}
}
`;
7 changes: 7 additions & 0 deletions gatsby/lobid/static/stylesheets/lobid.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#lobid-network {
width: 900px;
height: 600px;
border: 1px solid lightgray;
margin: 20px;
}

#header {
width: 100%;
background-image: url('https://lobid.org/images/clouds.jpg');
Expand Down

0 comments on commit 1ed3e93

Please sign in to comment.