npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cytoscape-snap-to-grid

v2.0.0

Published

Adds snap-to-grid and gridlines to Cytoscape.js graphs.

Readme

cytoscape-snap-to-grid

cytoscape-snap-to-grid

Description

Adds snap-to-grid and gridlines to Cytoscape.js graphs.

Dependencies

Usage instructions

Download the library:

  • via npm: npm install cytoscape-snap-to-grid,
  • via bower: bower install cytoscape-snap-to-grid, or
  • via direct download in the repository (probably from a tag).

require() the library as appropriate for your project:

CommonJS:

var cytoscape = require('cytoscape');
var snapToGrid = require('cytoscape-snap-to-grid');

snapToGrid( cytoscape ); // register extension

AMD:

require(['cytoscape', 'cytoscape-snap-to-grid'], function( cytoscape, snapToGrid ){
  snapToGrid( cytoscape ); // register extension
});

Plain HTML/JS has the extension registered for you automatically, because no require() is needed.

API

The extension is enabled by invoking snapToGrid on your Cytoscape object:

cy.snapToGrid();

Optionally, a settings object can be passed as argument. The available settings are:

  • stackOrder (default: -1): Cytoscape graphs are drawn on several layers on a stack. This setting adjust the position of the grid layer on that stack. -1 draws the grid behind everything drawn by Cytoscape and higher values bring the grid to the front. A value of 4 should be enough to draw the grid over everything drawn by Cytoscape.
  • gridSpacing (default: 40): distance between the lines of the grid.
  • strokeStyle (default: "#CCCCCC"): determines the style of the grid lines. Any valid CSS color value is acceptable.
  • lineWidth (default: 1.0): thickness of the grid lines.
  • lineDash (default: [5,8]): array of numbers that defines the style of the dash. The first number specifies the length of the first dash, the second number specifies the length of the first gap. The length of this array should be even. If it is odd, the array is copied and concatenated. Read this for more details. For a solid line, set this parameter to [].
  • zoomDash (default: true): determines whether the size of the dashes should change when the drawing is zoomed in and out.
  • panGrid (default: true): determines whether the grid should move then the user moves the graph.
  • snapToGrid (default: true): when enabled, centers the nodes on the nearest grid cell.
  • drawGrid (default: true): enables or disables the grid drawing.

After the extension is enabled, other functions can be invoked by passing the function name as a parameter to the snapToGrid function. For example:

cy.snapToGrid('snapOn');

The available functions are:

  • snapOn: enables the snap-to-grid functionality. All the nodes currently added to the graph are moved to the center of the nearest cell.
  • snapOff: disables the snap-to-grid functionality.
  • gridOn: enables the grid drawing.
  • gridOff: disables the grid drawing.
  • refresh: forces the grid to be redrawn.
  • option: when invoked with a single string argument, returns the current value of the option corresponding to that argument. When invoked with a string and a value, sets the value of that option. The options drawGrid and snapToGrid should be changed by the snapOn, snapOff, gridOn and gridOff methods and not by this function.