Skip to content

Variable: TRANSFORM_GLSL

ts
const TRANSFORM_GLSL: "\nuniform vec2 uDomainX;   // linear: (lo-ref, hi-ref) ; log: (log10 lo, log10 hi)\nuniform vec2 uDomainY;\nuniform float uXRef;\nuniform float uYRef;\nuniform float uLogX;     // >0.5 => log axis\nuniform float uLogY;\n\nvec2 dataToNorm(vec2 p) {\n  float cx = (uLogX > 0.5) ? log(p.x + uXRef) / 2.302585092994046 : p.x;\n  float cy = (uLogY > 0.5) ? log(p.y + uYRef) / 2.302585092994046 : p.y;\n  float nx = (cx - uDomainX.x) / (uDomainX.y - uDomainX.x);\n  float ny = (cy - uDomainY.x) / (uDomainY.y - uDomainY.x);\n  return vec2(nx, ny);\n}\n\nvec2 dataToClip(vec2 p) {\n  return dataToNorm(p) * 2.0 - 1.0;\n}\n";

Defined in: gl/transform.ts:14

Shared data→clip transform used by every layer's vertex shader.

Two subtleties it handles:

  • Log axes — when uLogX/uLogY is set, the real coordinate is log10-transformed on the GPU.
  • Float32 precision — vertex buffers are float32 (~7 significant digits), which is not enough for large values like epoch-millisecond timestamps. Layers upload coordinates relative to a reference (x - xRef) and pass uXRef; the domain is passed in the same offset space, so the subtraction that computes the normalized position never suffers catastrophic cancellation. For log axes the reference is added back before log10.

MIT licensed. WebGL2 required.