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

leaflet-regular-grid-cluster

v0.3.4

Published

leaflet plugin that implements custom grid-style visualisation and clustering method

Readme

(experimental) Regular-grid-cluster plugin/library for Leaflet

image

Demo

Motivation

the basic idea of this library is to present the custom method to both visualise and cluster larger dataset (or to be able to visually compare correlation between two different datasets). This method is based on the idea of distributing the dataset(elements) into regular shaped zones. Plugin can work with point data in the form of L.Marker or L.Circle/L.CircleMarker. This concept is suitable to visualise multivariate datasets. Grid consists of 3 different component classes, each could styled separately or optionally turned on and off:

  • cells - regularly shaped polygon (squares and hexagons are implemented) (graphical variables - fill/stroke color, fill/stoke opacity, ...)
  • markers - circle-shaped marker centered to cell (graphical variables - radius, fill/stroke colorm fill/stoke opacity, ...)
  • texts - text inside the cell that holds selected information about clustered data (graphical variables - font, font size, color,...)

Options

  • gridMode (default: 'square') 'square' of 'hexagon' values. The shape of cells

  • zoneSize (default: 10000) size of the cell at a scale of 10

  • gridOrigin (default: 'auto') setting the value of a L.latLng instance will manually define the SW corner of the grid. Value 'auto' will define the origin based on data and gridBoundsPadding,

  • gridEnd (default: 'auto') NE corner of the grid. In case value "auto" is used, corner will be calculated from data and gridBoundsPadding option.

  • gridBoundsPadding (default: 0.1) ratio to extend bounding box of elements

  • showCells (default: true) turning cells off and on

  • showMarkers (default: true) turning markers off and on

  • showTexts (default: true) turning texts off and on

  • showEmptyCells (default: false) whether display cells where no elements fall

  • emptyCellOptions styling of empty cells

  • zoomShowElements (default: 10) level of zoom when to turn elements on and off

  • zoomHideGrid (default: 10) level of zoom when to turn grid on and off

  • indexSize (default: 12) for a better performence, zones and elements are pre-indexed. Option indexSize difenes the number of super-zones within each axis

  • rules (default rules: {cells: {}, markers: {}, texts: {} }) values to define how components will look like. Every rule can be defined as dynamic or static (see section rules or random data example)

  • defaultStyle

  • paneElementsZ (default: 10000)

  • paneCellsZ (default: 700)

  • paneMarkersZ (default: 800)

  • paneTextsZ (default: 900)

Rules

Rules object consists of 3 key-values pairs - **cells, markers and texts. Most of the naming is technicaly the same as in the L.Path class (see leaflet documentation). Differences are mainly within texts (fontSize, fontWeight). To create a dynamical rule, one has to define a method, scale, style, domain and **attribute** parameters:

  • method ('count', 'mean', 'median', 'mode', 'min', 'max' and 'sum') - operation how the result value will be calculated from the overlapping elements
  • scale ('size' - equal size, 'quantile', 'continuous') - how threshold values will be defined for intervals. 'Continous' value will create a continuous scale
  • range - array with values to set how to style the variable
  • domain - array of two values to define minimum (first value) and maximum (second value) of input manually. If this is not defined, maximum and minimum will be set based on the data.
  • attribute - name of the property that defines the rule (could be ommited in case, the method is 'count')

To test how these parameters work, please have a look at the random data example

How to

  1. Create/Access some point data
    const maxX = 50, minX = 0, maxY = 49.5, minY = 0;
    const randomData = [];

    for (i=0; i < 1000; i++) {
        const coordinates = [
            minX + Math.random() * (maxX - minX),
            minY + Math.random() * (maxY - minY)
        ];
        const properties = {
            a: 5 + Math.floor(Math.random() * 5),
            b: Math.floor(Math.random() * 5)
        };

        const marker = L.circleMarker(coordinates, {radius: 1, fillColor: 'black'});
        randomData.push( {
            marker: marker,
            properties: properties
        });
    };
  1. Define the ruleset
    const rules = {
        cells: {
            "fillColor": {
                "method": "mean",
                "attribute": "b",
                "scale": "size",
                "range": ["#d7191c","#fdae61","#ffffbf","#a6d96a","#1a9641"]
            },
            "color": "black",
            "fillOpacity": 0.2,
            "weight": 0
        },
        markers: {
            "color": "white",
            "weight": 2,
            "fillOpacity": 0.9,
            "fillColor": {
                "method": "mean",
                "attribute": "b",
                "scale": "continuous",
                "range": ["#ffffb2","#fecc5c","#fd8d3c","#e31a1c"]
            },
            "radius": {
                "method": "count",
                "attribute": "",
                "scale": "continuous",
                "range": [7, 17]
            }
        },
        texts: {}
    }
  1. create a new instance of L.RegularGridCluster and set the options and ruleset
    const grid = L.regularGridCluster(
        {
            rules: rules,
            gridMode: 'hexagon,
            showCells: true,
            showMarkers: true,
            showTexts: false
        }
    );
  1. add data to the L.regularGridCluster instance
    grid.addLayers(pointData);

Develop

    1. npm install to download dependencies
    1. npm start for development
    1. npm build for production