Git Product home page Git Product logo

graphism's Introduction

Graphism Logo

A tool to create graph visualization

Playground โ€ข Documentation

Features

  • Vanilla JavaScript - integrate into any framework you like
  • Run algorithms on the graph (like Kruskal's algorithm, Dijkstra's algorithm, etc)
  • Design your own graph
  • Save graph in .png

Install

npm i graphism
<canvas id="canvas">
import { createGraphism } from 'graphism'

const graphism = createGraphism({
    el: '#canvas',
    canvasBackground: '#eee'
})

// Generate an random graph
graphism.generateGraph()

API

// Create new node and return the Node instance
createNode: (name: string, coordinate: Coordinate, config?: NodeConfig) => NodeInterface

// Clear selected
clearSelectedNode: () => void
clearSelectedLine: () => void

// Select a node
selectNode: (node: NodeInterface, mode: CanvasMode = "normal") => NodeInterface

// Connect two node
addNodeNeighbor: (from: NodeInterface, to: NodeInterface, distance: number) => void

// Generate random graph 
generateGraph: () => void

// Event listener
on: (event: string, callback: any, once: boolean = false) => void

Events

Event Usage

Example of event usage

graphism.on("node:select", (node1: NodeInterface) => {
    console.log(`The node clicked contains value = ${node1.value}`)
})

// If you want the event only trigger once, add `true` to the third param
graphism.on("grab", () => {
    console.log("You are grabbing the canvas, this will only run once")
}, true)

Event list

Name Param Description
mounted Graphism is successfully mounted
grab User grabbing on the canvas
error (message: string) Triggered when error occured
canvas:click (coordinate: Coordinate) Canvas clicked by user
node:created New node created
node:move (node: NodeInterface) Node moved
node:mouseover The cursor is on the node
node:mouseleave The cursor is going out from the node
node:select Node is selected
node:deselect Node is deselected
node:clearSelect All nodes is deselected
node:connect Two nodes are connected
line:select Line is selected
line:deselect Line is deselected
line:clearSelect All lines is deselected
line:mouseover The cursor is on the line

License

MIT License

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.