Socket
Socket
Sign inDemoInstall

graphology-canvas

Package Overview
Dependencies
4
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    graphology-canvas

Canvas rendering routines for graphology.


Version published
Maintainers
2
Install size
124 kB
Created

Changelog

Source

0.4.2

  • Adding missing built files to the npm package.

Readme

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

Last updated on 15 Apr 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc