Giter Site home page Giter Site logo

maastrichtu-ids / perfect-graph Goto Github PK

View Code? Open in Web Editor NEW
9.0 6.0 3.0 73.07 MB

Create perfect graph visualisations easily

Home Page: https://maastrichtu-ids.github.io/perfect-graph-docs/

License: MIT License

JavaScript 74.53% TypeScript 25.47%
react react-native-web pixijs cytoscapejs knowledge-graph

perfect-graph's Introduction

PerfectGraph

Motivation

We want to build a collaborative Knowledge Graph Editor. To achive that goal we need a Graph Visualizer on a web browser and it needs to have a declarative rendering. Because in imperative style we need to call appropriate api functions respect to the data changes like addNode, deleteNode etc. But we just want to change JSON data (node and edge information) and render elements respectively to the changes.

First, install Nodejs and Yarn to your working environment. Then

yarn global add expo-cli

Then,

expo init my-project
cd my-project
yarn add perfect-graph colay colay-ui immer

After you can write this command to the terminal in your project directory

yarn web

So let's start coding

import {Graph} from 'perfect-graph'

export default function MyGraph() {
  return (
    <Graph
      style={{width: 600, height: 400}}
      nodes={[
        {id: '1', position: {x: 10, y: 10}},
        {id: '2', position: {x: 300, y: 100}}
      ]}
      edges={[{id: '51', source: '1', target: '2'}]}
    />
  )
}

To use GraphEditor you need to install material-ui packages. We use the latest version:

yarn add @mui/icons-material @mui/material @mui/styles @emotion/react @emotion/styled react-beautiful-dnd @rjsf/core @rjsf/material-ui react-color

To support material-ui v5 with @rjsf/material-ui, we need to add some special configuration until they have fully support for v5. Also add some packages.

yarn add @expo/webpack-config babel-plugin-module-resolver -D
// webpack.config.js
const createExpoWebpackConfigAsync = require('@expo/webpack-config')

module.exports = async function (env, argv) {
  const config = await createExpoWebpackConfigAsync(
    {
      ...env,
      babel: {
        dangerouslyAddModulePathsToTranspile: ['@rjsf/material-ui']
      }
    },
    argv
  )
  return config
}
// babel.config.js
module.exports = function (api) {
  api.cache(true)
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      [
        'module-resolver',
        {
          extensions: ['.js', '.jsx', '.es', '.es6', '.mjs', '.ts', '.tsx'],
          alias: {
            '@material-ui/core': '@mui/material',
            '@material-ui/icons': '@mui/icons-material',
            '@material-ui/styles': '@mui/styles'
          }
        }
      ]
    ]
  }
}
import {GraphEditor} from 'perfect-graph/components/GraphEditor'
import {useController} from 'perfect-graph/plugins/controller'

export default function MyGraphEditor() {
  const [controllerProps] = useController({
    nodes: [
      {id: '1', position: {x: 10, y: 10}},
      {id: '2', position: {x: 300, y: 100}}
    ],
    edges: [{id: '51', source: '1', target: '2'}]
  })

  return <GraphEditor style={{width: 600, height: 400}} {...controllerProps} />
}

Start development server again:

yarn web

To have json editor:

yarn add brace jsoneditor jsoneditor-react
import {GraphEditor} from 'perfect-graph/components/GraphEditor'
import {useController} from 'perfect-graph/plugins/controller'

export default function MyGraphEditor() {
  const [controllerProps] = useController({
    nodes: [
      {id: '1', position: {x: 10, y: 10}},
      {id: '2', position: {x: 300, y: 100}}
    ],
    edges: [{id: '51', source: '1', target: '2'}],
    dataBar: {
      editable: true
    }
  })

  return <GraphEditor style={{width: 600, height: 400}} {...controllerProps} />
}

To use rdf based operation please install the required dependencies:

yarn add jsonld jsonld-context-parser n3 rdf-literal rdflib

To use layouts, please install the required dependencies:

yarn add cytoscape-avsdf cytoscape-cise cytoscape-cola cytoscape-d3-force cytoscape-dagre cytoscape-euler cytoscape-fcose cytoscape-klay cytoscape-spread

If the PIXI.js renderer takes a lot time to render all elements and blocks the UI then consider on:

  • Decreasing the view resolution and settings quality In example when a huge data chunk imported to perfect-graph, if the view quality is very high ; then PIXI.js will block (to render the elements with high view quality) the UI thread and cause strange issues. Set low view quality settings before importing the data chunk and let Adaptive Performance Optimizer do the rest of the optimization.

  • If there is an error: Can not set readonly 'x' of '#Object' That could be related with position ; If you use cy.$(id).position() in somewhere and store it that can cause an issue. Use cy.$(id).position().x , cy.$(id).position().y

Furthermore please refer to the Components Section.

perfect-graph's People

Contributors

cloud956 avatar sabaturgay avatar thendriks avatar vemonet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

perfect-graph's Issues

Issue with pixi.js in Firefox

Issue when using perfect-graph with Firefox

The console outputs:

Uncaught Error: WebGL unsupported in this browser, use "pixi.js-legacy" for fallback canvas2d support.

The same works on Chrome

With Firefox 83.0 (64-bit) on Ubuntu 18.04

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.