Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphology-canvas

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphology-canvas

Canvas rendering routines for graphology.

  • 0.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
61
decreased by-66.11%
Maintainers
2
Weekly downloads
 
Created
Source

Graphology Canvas

Canvas rendering routines for graphology.

Installation

npm install graphology-canvas

If you need to use this package's functions in node, you will also need to install node-canvas thusly:

npm install canvas

If you experience any issue when installing the libray check that you have the required dependencies as listed here.

Usage

Pre-requisites

Each node's position must be set before rendering a graph. Two attributes called x and y must therefore be defined for all the graph nodes. graphology-layout or graphology-layout-forceatlas2, for instance, can be used to give positions to nodes if they don't have one already.

Rendering a graph in an arbitrary canvas context

import {render} from 'graphology-canvas';

render(graph, context, settings);

Rendering asynchronously to avoid freezing main thread

import {renderAsync} from 'graphology-canvas';

renderAsync(graph, context, settings, function () {
  console.log('Done!');
});

Rendering a graph to PNG in node

import {renderToPNG} from 'graphology-canvas/node';

renderToPNG(graph, './graph.png', () => console.log('Done!'));
renderToPNG(graph, './graph.png', settings, () => console.log('Done!'));

Settings

  • width ?number [2048]: width of the canvas. Will be the same as height if not provided.
  • height ?number [2048]: height of the canvas. Will be the same as width if not provided.
  • padding ?number [20]: padding to keep around the drawing.
  • nodes ?object: node-related settings:
    • defaultColor ?string [#999]: default color for nodes.
    • reducer ?function: reducer fonction for nodes taking the rendering settings, the node key and its attributes and tasked to return rendering info such as color, size etc.
  • edges ?object: node-related settings:
    • defaultColor ?string [#ccc]: default color for edges.
    • reducer ?function: reducer fonction for edges taking the rendering settings, the node key and its attributes and tasked to return rendering info such as color, size etc.

Async Settings

  • batchSize ?number [500]: number of items to render on canvas on each animation frame, increase or decrease to tweak performance vs. UI availability.

Keywords

FAQs

Package last updated on 15 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc