Extending the Framework
Creating Operators covers adding an operator to Noodles.gl. This page covers the rest: registering operators and color ramps from an application, converting older projects, and debugging.
Registering from an application
An application that embeds the planner can add to its catalog at startup, without editing packages/planner:
import { registerOperator, registerRamp } from '@noodles.gl/planner'
// An operator, by the same OpDef shape as the built-ins. Registering an existing type
// replaces it. One without `lower` is skipped by lowering, as host operators are.
registerOperator(myOperatorDef)
// A color ramp for ramp(), colorscale nodes and every ramp menu: 0 to 1 RGB stops,
// evenly spaced
registerRamp('sunset', [[0.1, 0.0, 0.3], [0.9, 0.3, 0.2], [1.0, 0.9, 0.5]], 'Sunset')
The editor does this itself: registerDeckOperators() (in src/runtime/deck-ops.ts) adds the deck operators, and registerNoodlesRamps() (in src/runtime/ramps.ts) adds the editor's d3 color schemes.
Converting older projects
Projects saved before documents are operator graphs (noodles.json schema 1 to 23). When one loads, its schema migrations in src/noodles/__migrations__/ run first, then toEditorDoc in src/runtime/migrate/to-editor-doc.ts converts it to an EditorDoc.
op-catalog.tssays what each older operator type becomes: planner operators, row operators, acodenode, a deck operator, a subnet, a host operator, or refused (the ForLoop operators).to-editor-doc.tsholds the conversions, andgis-conversions.tsthe GIS ones. A conversion writes every older default explicitly, sincenoodles.jsonstored only what was set and planner defaults differ.- Anything a conversion cannot express throws a
MigrationErrornaming the node and why. It never falls back to a JavaScript accessor or a silent default. - Test a conversion with a case in
src/runtime/migrate/*-conversions.node.test.tsthat converts a node, lowers it, and checks the rows.
To migrate such files on disk, run npm run migrate-projects -- <file or folder> from noodles-editor/. --check lists what would change without writing. To check a document against the operator registry, run npm run validate:projects -- path/to/noodles.json from the repo root.
Debugging
- Debug mode. Turn on Show editor debug info in the top menu to see each node's SQL, memoization, routes and engine badges. Users never see these otherwise.
- The engine.
window.plannerEngineis the running engine:errors()lists errors by node,lowering()returns the lowered graph and scalar program, andvis()what was drawn. - Logging. The
debugpackage logs nothing until enabled. SetlocalStorage.debug = 'noodles:*'in the console and reload;src/utils/debug.tslists the namespaces. To add a log line:
import { debugMigration } from '../utils/debug'
debugMigration('converted %s to %d nodes', name, doc.nodes.length)
- Tests. A failing project is usually quickest to reproduce as a
*.node.test.tsthat lowers a small document with DuckDB in Node; see Creating Operators.