Skip to content

konradst/snap-to-grid-clustering

Repository files navigation

npm type definitions GitHub code size in bytes GitHub repo size npm bundle size npm bundle size npm typescript-starter CircleCI GitHub issues GitHub pull requests GitHub last commit GitHub

CircleCI

GitHub followers Twitter Follow

Snap to Grid Clustering

Clustering based on grid. Snaps coords to the nearest grid point determined by gridSize. Grid coords are rounded. Point (1.2, 1) is snapped to (1, 1). Point (1.6, 1) is snapped to (2, 1) for gridSize = 1.

Installation

npm install snap-to-grid-clustering

Methods

snap(coords: Coords, gridSize: number) { ... }

Immutable. Returns snapped ids hashmap at cluster coords.

Example (ts module)

import { snap } from 'snap-to-grid-clustering';
console.log(snap([[-1, 1], [2, 3], [10, 10], [11, 11]], 5))
// => { '0,0': [ 0 ], '0,1': [ 1 ], '2,2': [ 2, 3 ] }

Example (es module)

import { snap } from 'snap-to-grid-clustering'
console.log(snap([[-1, 1], [2, 3], [10, 10], [11, 11]], 5))
// => { '0,0': [ 0 ], '0,1': [ 1 ], '2,2': [ 2, 3 ] }

Example (commonjs)

var snap = require('snap-to-grid-clustering').snap;
console.log(snap([[-1, 1], [2, 3], [10, 10], [11, 11]], 5))
// => { '0,0': [ 0 ], '0,1': [ 1 ], '2,2': [ 2, 3 ] }

snapList(coords: Coords, gridSize: number) { ... }

Immutable. Returns snapped ids as list.

Example (ts module)

import { snapList } from 'snap-to-grid-clustering';
console.log(snapList([[-1, 1], [2, 3], [10, 10], [11, 11]], 5))
// => [[0], [1], [2, 3]]

Example (es module)

import { snapList } from 'snap-to-grid-clustering'
console.log(snapList([[-1, 1], [2, 3], [10, 10], [11, 11]], 5))
// => [[0], [1], [2, 3]]

Example (commonjs)

var snapList = require('snap-to-grid-clustering').snapList;
console.log(snapList([[-1, 1], [2, 3], [10, 10], [11, 11]], 5))
// => [[0], [1], [2, 3]]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published