### Run Built-in Example Source: https://redhog.github.io/gladly/docs/docs/Quickstart Install dependencies and start the development server to view the built-in Gladly demo. ```bash npm install npm start ``` -------------------------------- ### Install Dependencies Source: https://redhog.github.io/gladly/docs Use this command to install project dependencies. ```bash npm install ``` -------------------------------- ### Install Dependencies from Source Source: https://redhog.github.io/gladly/docs/docs/Quickstart When building from source, install the required dependencies like regl and d3. ```bash npm install regl d3 ``` -------------------------------- ### Complete Plot Configuration Example Source: https://redhog.github.io/gladly/docs/docs/configuration/PlotConfiguration Demonstrates a full HTML page setup for creating a scatter plot with custom data and axis ranges. Ensure the Plotly.js library and necessary layer modules are imported. ```html
``` -------------------------------- ### Install Gladly from npm Source: https://redhog.github.io/gladly/docs/docs/Quickstart Install the Gladly plotting library using npm for use in Node.js projects or with bundlers. ```bash npm install gladly-plot ``` -------------------------------- ### Points Layer Example (Simple Flat Format) Source: https://redhog.github.io/gladly/docs/docs/configuration/BuiltInLayerTypes Example of using the points layer with a simple flat data format. It maps 'x' and 'y' for coordinates and 'temperature' for color, with a specified colorscale for the temperature axis. ```javascript plot.update({ data: { x, y, temperature }, config: { layers: [ { points: { xData: "x", yData: "y", vData: "temperature" } } ], axes: { temperature: { min: 0, max: 100, colorscale: "plasma" } } } }) ``` -------------------------------- ### Install Gladly via CDN Source: https://redhog.github.io/gladly/docs/docs/Quickstart Include the pre-built standalone bundle directly in your HTML using a script tag. No build step or npm is required. ```html ``` -------------------------------- ### WeightedAverageComputation Example Source: https://redhog.github.io/gladly/docs/docs/extension-api/Computations Example implementation of a custom texture computation for weighted average, demonstrating the use of `compute` and `schema` methods. ```APIDOC ## WeightedAverageComputation ### Description An example implementation of a `TextureComputation` that calculates a weighted average. It demonstrates how to access `ArrayColumn` data, perform calculations, and upload results to a texture. ### Methods #### compute(regl, inputs, getAxisDomain) ##### Description Calculates the weighted average of values binned according to the `bins` parameter. ##### Parameters - **regl** (regl context) - Required - The regl rendering context. - **inputs** (object) - Required - Contains `values` (ArrayColumn), `weights` (ArrayColumn), and `bins` (number). - **getAxisDomain** (`(axisId: string) => [min|null, max|null] | null`) - Required - Function to get axis domains. ##### Return value A regl texture containing the computed weighted averages for each bin. #### schema(data) ##### Description Defines the schema for the `weightedAverage` computation parameters. ##### Return value A JSON schema object specifying `values`, `weights`, and `bins` as required properties. ``` -------------------------------- ### Points Layer Example (Columnar Format with Quantity Kinds) Source: https://redhog.github.io/gladly/docs/docs/configuration/BuiltInLayerTypes Example demonstrating the points layer with columnar data format and quantity kinds. The axis key in `config.axes` uses the resolved quantity kind (e.g., 'temperature_K') instead of the raw column name. ```javascript plot.update({ data: { data: { x, y, temperature }, quantity_kinds: { x: "distance_m", y: "voltage_V", temperature: "temperature_K" } }, config: { layers: [ { points: { xData: "x", yData: "y", vData: "temperature" } } ], axes: { // key is the resolved quantity kind, not the column name "temperature" temperature_K: { min: 0, max: 100, colorscale: "plasma" } } } }) ``` -------------------------------- ### Minimal Gladly Plot Example Source: https://redhog.github.io/gladly/docs/docs/Quickstart Create a basic Gladly plot by preparing data as Float32Arrays, initializing the Plot, and updating it with configuration and data. ```javascript import { Plot, pointsLayerType } from 'gladly-plot' // 1. Register layer types once at startup // pointsLayerType is auto-registered on import — no manual registerLayerType call needed // 2. Prepare data as Float32Arrays const x = new Float32Array([10, 20, 30, 40, 50]) const y = new Float32Array([15, 25, 35, 25, 45]) const v = new Float32Array([0.2, 0.4, 0.6, 0.8, 1.0]) // 3. Create plot const plot = new Plot(document.getElementById("plot-container")) // 4. Apply configuration and data plot.update({ data: { x, y, v }, config: { layers: [ { points: { xData: "x", yData: "y", vData: "v" } } ], axes: { xaxis_bottom: { min: 0, max: 60 }, yaxis_left: { min: 0, max: 50 } } } }) ``` -------------------------------- ### Import Gladly from npm Source: https://redhog.github.io/gladly/docs/docs/Quickstart Import necessary components like Plot and layer types when using Gladly installed via npm. ```javascript import { Plot, pointsLayerType } from 'gladly-plot' ``` -------------------------------- ### Usage in createLayer Source: https://redhog.github.io/gladly/docs/docs/extension-api/Computations Example of how to use a registered texture computation within the `createLayer` function's attributes. ```javascript attributes: { count: { weightedAverage: { values: 'normalized', weights: 'importance', bins: 50 } } } ``` -------------------------------- ### Install Gladly via ES Module CDN Source: https://redhog.github.io/gladly/docs/docs/Quickstart Use the ES module build with an import map or a script tag of type "module" for modern JavaScript projects. ```html ``` -------------------------------- ### Quick Start: Enable Lasso Selection Source: https://redhog.github.io/gladly/docs/docs/configuration/Selection Initializes a plot and updates it with data and configuration, enabling lasso selection by default. Ensure 'myData' is defined and the container element exists. ```javascript import { Plot } from 'gladly' const plot = new Plot(container) await plot.update({ data: myData, config: { layers: [ { points: { xData: 'input.x', yData: 'input.y', color: 'input.value', selection: 'brush1' // opt this layer into a named selection channel } } ], interactions: { lasso: true } // shift-drag to draw a lasso over any selection } }) ``` -------------------------------- ### Create Layer with 2D Column Source: https://redhog.github.io/gladly/docs/docs/extension-api/Computations Example of creating a layer attribute backed by a 2D column using ArrayColumn. This sets up the data structure for shader access. ```javascript const weightsCol = new ArrayColumn(myFloat32Array, { shape: [rows, cols] }) return [{ attributes: { weights: weightsCol }, ... }] ``` -------------------------------- ### WebGL 2.0 Context Setup Shims Source: https://redhog.github.io/gladly/docs/docs/architecture/Modules Compatibility shims for regl to use WebGL 2.0 features, specifically for `gl.getExtension` and `gl.texImage2D` to handle float textures and ANGLE extensions. ```javascript gl.getExtension("OES_texture_float") gl.getExtension("OES_texture_float_linear") gl.getExtension("ANGLE_instanced_arrays") ``` ```javascript gl.texImage2D(target, level, internalformat, width, height, border, format, type, pixels) ``` -------------------------------- ### Subscribe to Selection Changes Source: https://redhog.github.io/gladly/docs/docs/user-api/Selection Subscribe to selection changes to receive updates on selected points. This example logs the number of selected points per tile when a lasso is drawn and points are selected. ```javascript plot.selections['brush1'].subscribe(sel => { const arrays = sel.arrays // Float32Array[] | null if (arrays) { arrays.forEach((tileArr, t) => { const indices = [...tileArr.keys()].filter(i => tileArr[i] > 0.5) console.log(`tile ${t}: ${indices.length} points selected`) }) } }) ``` -------------------------------- ### Filter Axis Range Examples Source: https://redhog.github.io/gladly/docs/docs/concepts/Overview Demonstrates different ways to define filter axis ranges, including open and closed intervals. Bounds are optional. ```javascript { min: 10 } // discards values below 10, no upper limit ``` ```javascript { max: 500 } // discards values above 500, no lower limit ``` ```javascript { min: 10, max: 500 } // closed interval ``` -------------------------------- ### GLSL Filter Integration Example Source: https://redhog.github.io/gladly/docs/docs/extension-api/LayerTypes Demonstrates how to use the `filter_in_range` function in GLSL to discard vertices that do not meet the filter criteria. The `filter_range` uniform and `filter_data` input are used for this check. ```glsl // Using suffix '' — GLSL uniform name is: filter_range uniform vec4 filter_range; in float filter_data; void main() { if (!filter_in_range(filter_range, filter_data)) { gl_Position = vec4(2.0, 2.0, 2.0, 1.0); // vertex shader discard return; } // ... } ``` -------------------------------- ### Attribute Value Examples Source: https://redhog.github.io/gladly/docs/docs/concepts/Overview Illustrates different types of values that can be assigned to attributes. Column names are resolved to ColumnData at draw time, while computed expressions are resolved during command build time. ```javascript // Attribute values — column name string, ColumnData, or computed expression attributes: { x: 'survey1.x', // column name → resolved to ColumnData at draw time count: { histogram: { input: 'input.v', bins: 50 } } // computed expression } ``` -------------------------------- ### Get All Column Names Source: https://redhog.github.io/gladly/docs/docs/user-api/ComputePipeline Use `output.columns()` to retrieve an array of all available column names, including input data and transform outputs. Column names use dot notation. ```javascript output.columns() // ['input.depth', 'input.vp', 'hist.counts', 'hist.binCenters', ...] ``` -------------------------------- ### Vertex Shader Call to Sample 2D Column Source: https://redhog.github.io/gladly/docs/docs/extension-api/Computations Example of how to call the injected sampling function within the vertex shader's main function to access the 'weights' attribute. ```glsl void main() { float w = sample_weights(ivec2(row, col)); // ... } ``` -------------------------------- ### Expression Types for Parameters Source: https://redhog.github.io/gladly/docs/docs/configuration/BuiltInLayerTypes Examples of how to specify expressions for parameters. Expressions can be plain data column names, computed attributes, or transform outputs. This allows for flexible data binding and computation. ```javascript xData: "temperature" ``` ```javascript xData: { histogram: { input: "raw_data", bins: 50 } } ``` ```javascript xData: "histogram.binCenters" ``` -------------------------------- ### Constructor Source: https://redhog.github.io/gladly/docs/docs/user-api/ComputePipeline Initializes a new ComputePipeline instance. The WebGL context is created immediately upon construction. ```APIDOC ## Constructor ```javascript new ComputePipeline() ``` No arguments. The WebGL context is created immediately in the constructor. ``` -------------------------------- ### Get Colorscale Index Source: https://redhog.github.io/gladly/docs/docs/architecture/Modules Returns the integer colorscale index used as a GLSL uniform. Implemented in AxisRegistry.js. ```javascript getColorscaleIndex(qk) ``` -------------------------------- ### Run Test Suite Source: https://redhog.github.io/gladly/docs Execute the test suite to verify functionality. This launches a real Chromium browser via Playwright. ```bash npm test ``` -------------------------------- ### Instantiate ComputePipeline Source: https://redhog.github.io/gladly/docs/docs/user-api/ComputePipeline Creates a new ComputePipeline instance. The WebGL context is created immediately upon construction. No arguments are required. ```javascript new ComputePipeline() ``` -------------------------------- ### Get Registered Axis Quantity Kinds Source: https://redhog.github.io/gladly/docs/docs/architecture/Modules Returns an array of all registered quantity kind names. Used to iterate over available axis types. ```javascript getRegisteredAxisQuantityKinds() ``` -------------------------------- ### Update Plot with Lines Layer Source: https://redhog.github.io/gladly/docs/docs/configuration/BuiltInLayerTypes Example of updating a plot with data and configuration, including the lines layer with specified data mappings and axis configurations. ```javascript plot.update({ data: { x, y, temperature }, config: { layers: [ { lines: { xData: "x", yData: "y", vData: "temperature", lineColorMode: "gradient" } } ], axes: { temperature: { min: 0, max: 100, colorscale: "plasma" } } }) } ``` -------------------------------- ### Import Gladly from Source Source: https://redhog.github.io/gladly/docs/docs/Quickstart Import Gladly components when working directly with the source code. ```javascript import { Plot, pointsLayerType } from './src/index.js' ``` -------------------------------- ### Configure Tile Layer with XYZ Source Source: https://redhog.github.io/gladly/docs/docs/configuration/BuiltInLayerTypes Configure a tile layer to display geographic maps using XYZ tile services. The 'url' parameter should be a template for tile URLs. ```javascript { tile: { source: { xyz: { url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" } }, tileCrs: "EPSG:3857" } } ``` -------------------------------- ### Get Quantity Kind Source: https://redhog.github.io/gladly/docs/docs/user-api/Data Retrieves the quantity kind string for a column, falling back to the column name if none is specified. Used for axis identity. ```javascript const qk = d.getQuantityKind(params.vData) ?? params.vData ``` -------------------------------- ### Render Cycle Overview Source: https://redhog.github.io/gladly/docs/docs/architecture/DataFlow This diagram outlines the main steps in the per-frame rendering process, from clearing the canvas to executing post-render callbacks. ```mermaid plot.render() │ ├─> regl.clear({ color: [1, 1, 1, 1] }) — white background │ ├─> Refresh axis-reactive column data: │ └─> For each ColumnData in layer._dataColumns (populated during createDrawCommand): │ └─> col.refresh(plot) │ └─> If any tracked axis domain changed: recompute texture in-place │ (dynamic uniform fn () => ref.texture picks up new texture automatically) │ ├─> For each (layer, drawCommand): │ │ │ ├─> Collect runtimeProps: │ │ ├─> xDomain ← axisRegistry.scales[layer.xAxis].domain() │ │ ├─> yDomain ← axisRegistry.scales[layer.yAxis].domain() │ │ ├─> viewport ← { x:0, y:0, width, height } │ │ ├─> count ← layer.vertexCount ?? layer.attributes.x.length │ │ ├─> Per color slot: │ │ │ colorscale_