# From npm (for use in your projects)
npm install screengrid
npm install maplibre-gl
# Or clone for development
git clone https://github.com/danylaksono/screengrid.git
cd screengrid
npm install
npm run build
# Start a local HTTP server
npx http-server -p 8000
# or
npm start
The full constructor remains the most flexible API, but common map types can
start from small presets. Each preset returns a normal ScreenGridLayerGL
instance, so you can still pass any advanced option.
Use density() for the default rectangular screen-space grid.
const layer = ScreenGridLayerGL.density({
data,
getPosition: (d) => d.coordinates,
getWeight: (d) => d.count,
cellSizePixels: 60
});
Use hexDensity() when hexagonal cells reduce square-grid artefacts or fit the
visual style better.
const layer = ScreenGridLayerGL.hexDensity({
data,
getPosition: (d) => d.coordinates,
getWeight: (d) => d.value,
aggregationModeConfig: {
hexSize: 48
}
});
Use glyphMap() for point data where each grid cell should carry a glyph such
as a pie, bar, or custom onDrawCell mark.
const layer = ScreenGridLayerGL.glyphMap({
data,
getPosition: (d) => d.coordinates,
getWeight: (d) => d.total,
glyph: 'pie',
glyphConfig: {
colors: ['#2a9d8f', '#e9c46a', '#e76f51']
}
});
Use featureGlyphs() when the source is GeoJSON and the glyph should be placed
on polygon or line anchors rather than aggregated into screen cells.
const layer = ScreenGridLayerGL.featureGlyphs({
source: geojson,
placement: { strategy: 'centroid' },
glyph: 'circle'
});
screengrid/
├── src/ # Source code (modular architecture)
│ ├── index.js # Main entry point
│ ├── ScreenGridLayerGL.js # MapLibre layer facade
│ ├── controllers/ # Layer lifecycle controllers
│ ├── core/ # Core business logic
│ ├── canvas/ # Canvas rendering
│ ├── events/ # Event system
│ ├── glyphs/ # Glyph utilities & plugins
│ ├── aggregation/ # Aggregation modes & functions
│ ├── normalization/ # Normalization functions
│ ├── utils/ # Utilities (Logger, DataUtilities)
│ └── legend/ # Legend system
├── dist/ # Built distribution files
├── docs/ # Documentation
├── examples/ # Curated demo gallery and examples
├── package.json # NPM package configuration
└── README.md # Main documentation
examples/index.html: Curated entry point for ready-to-show demosgetting-started/basic-density.html: Minimal density grid using the density() presetgetting-started/interactive-controls.html: Full demo with controls for data, colours, cell size, glyphs, and basemap optionsaggregation/hex-density.html: Complete hexagonal aggregation with controlsaggregation/hex-density-minimal.html: Smaller hex mode demonstrationglyphs/plugin-glyph.html: Custom plugin registration (grouped-bar plugin)glyphs/legend.html: Colour, categorical, and temporal legend examplesglyphs/nightingale-rose.html: Multivariate radial glyph designtemporal/time-series.html: Single-variable temporal visualizationtemporal/multivariate-time-series.html: Multi-attribute temporal datageometry/feature-anchors-us-states.html: Polygon features with centroid, polylabel, and grid-screen anchorsdomain/public-transport-accessibility.html: Public transport accessibility glyph maputilities/data-utilities.html: Utility functions: groupBy, extractAttributes, computeStats, groupByTimeshowcases/bristle-map.html: Expressive bristle glyph mapshowcases/creative-coding.html: Artistic visualizations and creative coding patternsinternal/: Smoke tests and legacy scratch examples that are not part of the public demo gallerynpm run build
# Outputs to dist/ folder:
# - screengrid.mjs (ESM)
# - screengrid.cjs (CJS)
# - screengrid.umd.js (UMD)
# - screengrid.umd.min.js (UMD minified)
core/, canvas/, etc.)src/index.jsdocs/examples/When you switch to glyph-based rendering (enableGlyphs: true with either onDrawCell or a glyph plugin), the default behaviour is to turn off the colored cell background so the glyphs stand out. If you want to keep the heatmap-style background behind your glyphs, set:
const gridLayer = new ScreenGridLayerGL({
// ...other options
enableGlyphs: true,
onDrawCell: myGlyphFn,
aggregationModeConfig: {
showBackground: true // explicitly opt-in to background when using glyphs
}
});
cellSizePixels for performance vs detail tradeoffenableGlyphs: true and glyph callback/plugin is providedsource and placement are correctly configuredEnable verbose debug logging via the debugLogs option:
const gridLayer = new ScreenGridLayerGL({
// ... other options
debugLogs: true // Enable verbose debug logging
});
Or programmatically:
import { setDebug } from 'screengrid';
setDebug(true); // Enable debug logging globally
The library provides detailed logging for:
Note: Debug logs are disabled by default for performance. Enable only when troubleshooting.
npm install screengrid maplibre-gl
const gridLayer = new ScreenGridLayerGL({ data: yourData, getPosition: (d) => d.coordinates, getWeight: (d) => d.weight, cellSizePixels: 60 });
map.addLayer(gridLayer);
### With Build Tools
The library is ES module compatible and works with:
- Webpack
- Vite
- Rollup
- Parcel
- Native ES modules
### CDN Usage
```html
<script src="https://unpkg.com/screengrid/dist/screengrid.umd.min.js"></script>
<script src="https://unpkg.com/maplibre-gl@^4/dist/maplibre-gl.js"></script>
<script>
const { ScreenGridLayerGL } = ScreenGrid;
// use ScreenGridLayerGL here
</script>
Run tests (if test framework is configured):
npm test