π For complete API documentation with detailed parameter descriptions, return types, and comprehensive examples, see API_REFERENCE.md
This guide provides quick lookup snippets and common patterns. Use it when you know what youβre looking for and need a quick reminder.
// Main class (unchanged API)
import { ScreenGridLayerGL } from 'screengrid';
// Core modules (pure business logic)
import { Aggregator } from 'screengrid'; // Grid aggregation
import { Projector } from 'screengrid'; // Coordinate projection
import { CellQueryEngine } from 'screengrid'; // Spatial queries
// Geometry placement (v2.1.0+)
import { PlacementEngine, PlacementValidator, PlacementStrategyRegistry, GeometryUtils } from 'screengrid';
// Canvas modules
import { CanvasManager } from 'screengrid'; // Canvas lifecycle
import { Renderer } from 'screengrid'; // Drawing logic
// Event modules
import { EventBinder } from 'screengrid'; // Event attachment
import { EventHandlers } from 'screengrid'; // Event logic
// Glyph utilities & plugins
import { GlyphUtilities } from 'screengrid'; // Glyph drawing
import { GlyphRegistry } from 'screengrid'; // Plugin registry
// Aggregation system (v2.1.0+)
import { AggregationModeRegistry, ScreenGridMode, ScreenHexMode } from 'screengrid';
import { AggregationFunctionRegistry, AggregationFunctions } from 'screengrid';
// Normalization system (v2.1.0+)
import { NormalizationFunctionRegistry, NormalizationFunctions } from 'screengrid';
// Utilities (v2.1.0+)
import { Logger, setDebug } from 'screengrid'; // Debug logging
import { groupBy, extractAttributes, computeStats, groupByTime } from 'screengrid'; // Data utils
// Legend system (v2.0.0+)
import { Legend, LegendDataExtractor, LegendRenderers } from 'screengrid';
// Configuration
import { ConfigManager } from 'screengrid'; // Configuration
What: Configuration defaults and merging
When: Use when creating or updating layer config
API:
ConfigManager.create(options)
ConfigManager.update(config, updates)
ConfigManager.isValid(config)
What: Geographic β Screen space transformation
When: Need to project coordinates
API:
Projector.projectPoints(data, getPos, getWeight, map)
projector.project(data, getPos, getWeight)
What: Grid aggregation algorithm (pure)
When: Aggregate points into grid cells
API:
Aggregator.aggregate(points, data, width, height, cellSize, aggFn, onAfterAggregate)
aggregator.getStats(result)
onAfterAggregate (Multivariate)What: Calculate complex stats per cell once per render.
Use case: Averages, medians, or multi-attribute scores.
onAfterAggregate: (cellPoints, aggVal, idx, grid) => ({
avg: cellPoints.reduce((s, p) => s + p.data.v, 0) / cellPoints.length,
maxScore: Math.max(...cellPoints.map(p => p.data.score))
})
onDrawCell (Context)What: Draw to canvas with enriched context.
onDrawCell: (ctx, x, y, normVal, cellInfo) => {
const { customData, isHovered, zoomLevel } = cellInfo;
// Use customData from onAfterAggregate
if (isHovered) { /* Highlight effect */ }
}
What: Spatial queries on grid
When: Find cells at point, in bounds, or above threshold
API:
CellQueryEngine.getCellAt(result, point)
CellQueryEngine.getCellsInBounds(result, bounds)
CellQueryEngine.getCellsAboveThreshold(result, threshold)
What: Canvas lifecycle (create, size, cleanup)
When: Managing canvas overlay
API:
canvasManager.init(map)
canvasManager.getContext()
canvasManager.resize()
canvasManager.cleanup()
canvasManager.getDisplaySize()
What: Draw grid to canvas
When: Rendering grid cells
API:
Renderer.render(result, ctx, config)
renderer.renderColors(result, ctx, colorScale)
renderer.renderGlyphs(result, ctx, onDrawCell, size)
What: Attach/detach events
When: Managing event lifecycle
API:
eventBinder.bind(map, handlers)
eventBinder.unbind()
eventBinder.bindEvent(name, handler)
eventBinder.unbindEvent(name)
What: Event handler logic
When: Processing map events
API:
EventHandlers.handleHover(event, engine, callback)
EventHandlers.handleClick(event, engine, callback)
EventHandlers.handleZoom(map, config, callback)
EventHandlers.handleMove(callback)
What: Glyph drawing functions
When: Custom visualization in cells
API:
GlyphUtilities.drawCircleGlyph(ctx, x, y, r, color, alpha)
GlyphUtilities.drawBarGlyph(ctx, x, y, vals, max, size, colors)
GlyphUtilities.drawPieGlyph(ctx, x, y, vals, radius, colors)
GlyphUtilities.drawScatterGlyph(ctx, x, y, points, size, color)
GlyphUtilities.drawDonutGlyph(ctx, x, y, vals, outer, inner, colors)
GlyphUtilities.drawHeatmapGlyph(ctx, x, y, r, normVal, colorScale)
GlyphUtilities.drawRadialBarGlyph(ctx, x, y, vals, max, radius, color)
GlyphUtilities.drawTimeSeriesGlyph(ctx, x, y, data, size, options)
What: Plugin registry for reusable glyphs
When: Register custom glyph plugins
API:
GlyphRegistry.register(name, plugin, { overwrite })
GlyphRegistry.get(name)
GlyphRegistry.has(name)
GlyphRegistry.list()
GlyphRegistry.unregister(name)
What: Registry for aggregation modes
When: Use or register custom aggregation modes
API:
AggregationModeRegistry.register(name, mode)
AggregationModeRegistry.get(name)
ScreenGridMode // Rectangular mode
ScreenHexMode // Hexagonal mode (v2.2.0+)
What: Built-in aggregation functions
When: Customize aggregation behavior
API:
AggregationFunctions.sum // Default
AggregationFunctions.mean
AggregationFunctions.count
AggregationFunctions.max
AggregationFunctions.min
AggregationFunctionRegistry.register(name, fn)
What: Built-in normalization functions
When: Customize normalization strategy
API:
NormalizationFunctions.maxLocal // Default
NormalizationFunctions.maxGlobal
NormalizationFunctions.zScore
NormalizationFunctions.percentile
NormalizationFunctionRegistry.register(name, fn)
What: Debug logging utility
When: Troubleshooting and development
API:
setDebug(true) // Enable globally
Logger.log('message')
Logger.warn('warning')
Logger.error('error') // Always shown
What: Data processing helpers
When: Extract/aggregate cellData
API:
groupBy(cellData, key, value, aggregator)
extractAttributes(cellData, extractors)
computeStats(cellData, valueExtractor)
groupByTime(cellData, time, value, period)
What: Auto-generated legends
When: Display data-driven legends
API:
legend = new Legend({ layer, type, position, title })
legend.update(gridData, config)
legend.show() / legend.hide()
legend.remove()
What: Geometry placement for non-point inputs
When: Use GeoJSON with polygons/lines
API:
PlacementEngine.processFeatures(features, config)
PlacementValidator.validate(config)
PlacementStrategyRegistry.get(strategy)
GeometryUtils.getCentroid(geometry)
What: Orchestrator (main class)
When: Using the library normally
API:
layer = new ScreenGridLayerGL(options)
layer.setData(newData)
layer.setConfig(updates)
layer.getCellAt(point)
layer.getCellsInBounds(bounds)
layer.getGridStats()
import { ScreenGridLayerGL } from 'screengrid';
const layer = new ScreenGridLayerGL({
data: myData,
cellSizePixels: 50
});
map.addLayer(layer);
import { Projector, Aggregator } from 'screengrid';
const projector = new Projector(map);
const aggregator = new Aggregator();
const points = projector.project(data, d => d.coords, d => d.value);
const grid = aggregator.aggregate(points, data, 800, 600, 50);
const stats = aggregator.getStats(grid);
console.log(`Found ${stats.cellsWithData} cells with data`);
import { CellQueryEngine } from 'screengrid';
const engine = new CellQueryEngine(gridData);
map.on('mousemove', (e) => {
const cell = engine.getCellAt({ x: e.point.x, y: e.point.y });
if (cell) {
console.log(`Cell [${cell.col}, ${cell.row}] = ${cell.value}`);
}
});
import { ScreenGridLayerGL, GlyphUtilities } from 'screengrid';
const layer = new ScreenGridLayerGL({
enableGlyphs: true,
onDrawCell: (ctx, x, y, norm, info) => {
GlyphUtilities.drawPieGlyph(
ctx, x, y,
[10, 20, 30], 15,
['#ff0000', '#00ff00', '#0000ff']
);
}
});
map.addLayer(layer);
import { CellQueryEngine } from 'screengrid';
const engine = new CellQueryEngine(gridData);
// Get all cells in a region
const cells = engine.getCellsInBounds({
minX: 100, minY: 100, maxX: 300, maxY: 300
});
// Get high-value hotspots
const hotspots = engine.getCellsAboveThreshold(50);
console.log(`Found ${hotspots.length} hotspots`);
βββββββββββββββββββββββββββββββββββ
β ScreenGridLayerGL β
β (Main Class - Orchestrator) β
ββββββββββββββββ¬βββββββββββββββββββ
β
ββββββββββββΌβββββββββββ¬ββββββββββββββ¬βββββββββββ
β β β β β
βΌ βΌ βΌ βΌ βΌ
ββββββββββ βββββββββ ββββββββββββ ββββββββββ ββββββββββββ
βConfig β βCanvas β βEvents β βCore β βGlyphs β
βManager β βMgr β βBinder β βLogic β βUtilities β
ββββββββββ βββββ¬ββββ ββββββ¬ββββββ βββββ¬βββββ β β
β β β β β
βββββββββββββΌββββββββββββ β β
β β β
βββββββΌβββββββ β β
βRenderer β ββββββββββ β
βEvent β β
βHandlers β βββββββββββββββββββ¬ββ
ββββββββββββββ β
βββββββΌβββββ
βCell Queryβ
βEngine β
ββββββββββββ
Legend:
βββββββ = Single responsibility module
βββββββ = Composed by orchestrator
β
βΌ = Dependency arrow
Key Points:
src/
βββ index.js
β βββ Exports all modules
β
βββ ScreenGridLayerGL.js
β βββ Main orchestrator class
β
βββ config/
β βββ ConfigManager.js
β
βββ core/
β βββ Projector.js
β βββ Aggregator.js
β βββ CellQueryEngine.js
β
βββ canvas/
β βββ CanvasManager.js
β βββ Renderer.js
β
βββ events/
β βββ EventBinder.js
β βββ EventHandlers.js
β
βββ glyphs/
βββ GlyphUtilities.js
// Hexagonal aggregation mode
aggregationMode: 'screen-hex'
aggregationModeConfig: { hexSize: 50, showBackground: true }
// Geometry input (non-point geometries)
source: geojsonData
placement: { strategy: 'centroid', spacing: { meters: 200 } }
renderMode: 'feature-anchors'
anchorSizePixels: 18
// Aggregation functions
aggregationFunction: 'mean' | 'sum' | 'count' | 'max' | 'min'
aggregationFunction: AggregationFunctions.mean
// Normalization functions
normalizationFunction: 'max-local' | 'max-global' | 'z-score' | 'percentile'
normalizationFunction: NormalizationFunctions.zScore
normalizationContext: { globalMax: 1000 }
// Data utilities
groupBy, extractAttributes, computeStats, groupByTime
// Logger
setDebug(true), Logger.log()
// Glyph plugin system
glyph: 'circle' | 'bar' | 'pie' | 'heatmap'
GlyphRegistry.register(name, plugin)
// Legend system
Legend class
legend = new Legend({ layer, type, position })
// Time series glyph
GlyphUtilities.drawTimeSeriesGlyph(...)
// Additional glyph types
GlyphUtilities.drawDonutGlyph(...)
GlyphUtilities.drawHeatmapGlyph(...)
GlyphUtilities.drawRadialBarGlyph(...)
aggregator.getStats(result)
// Returns: {totalCells, cellsWithData, maxValue, minValue, avgValue, totalValue}
engine.getCellsInBounds(bounds)
engine.getCellsAboveThreshold(threshold)
layer.getGridStats() // Get aggregation statistics
layer.getCellsInBounds(...) // Region query
const layer = new ScreenGridLayerGL(options);
map.addLayer(layer);
layer.setData(newData);
layer.render();
map.on('mousemove', (e) => {
const cell = layer.getCellAt({x: e.point.x, y: e.point.y});
if (cell) updateUI(cell);
});
const projector = new Projector(map);
const aggregator = new Aggregator();
const engine = new CellQueryEngine();
// Use independently
const points = projector.project(data, pos, weight);
const result = aggregator.aggregate(points, data, w, h, size);
engine.setAggregationResult(result);
const layer = new ScreenGridLayerGL({
enableGlyphs: true,
onDrawCell: (ctx, x, y, norm, info) => {
// Draw custom visualization
}
});
docs/API_REFERENCE.md - Comprehensive API documentation with all methods, parameters, and examplesdocs/ARCHITECTURE.md - Module design and architecture detailsdocs/USAGE.md - Development, examples, and troubleshootingdocs/GLYPH_DRAWING_GUIDE.md - Comprehensive glyph visualization guidedocs/PLUGIN_GLYPH_ECOSYSTEM.md - Plugin system documentationdocs/SPATIO_TEMPORAL_GUIDE.md - Time series visualization patternsdocs/GEOMETRY_INPUT_AND_PLACEMENT.md - Non-point geometry workflowsdocs/PLACEMENT_CONFIG.md - Formal placement configuration schemadocs/DATA_UTILITIES.md - Utility functions for data processingdocs/CARTOGRAPHY_AND_MULTIVARIATE_DESIGN.md - Design patterns and principlesGood news: All original code works unchanged!
// All of this still works exactly the same:
const layer = new ScreenGridLayerGL({...});
map.addLayer(layer);
layer.setData(newData);
layer.setConfig(updates);
ScreenGridLayerGL.drawCircleGlyph(...); // Static method still available
The refactoring is 100% backward compatible with the original API.