Skip to main content
100%

Linear scale interpolation in Ruby based on d3.js's implementation

✓ Published0🌍 Public
CCaged
Last edited Nov 21, 2012
Created on Nov 22, 2012

This example demonstrates a minimal implementation of D3.js-style linear scale interpolation in Ruby. It shows how a numeric value from an input domain is mapped to a corresponding output range using two closures: `uninterpolate_number` and `interpolate_number`. The `scale` function combines these to normalize and then rescale values, while also clamping input to the domain via a sort. The code’s output, printed with `puts`, confirms the mapping for domain [0, 500] to range [0.0, 1.0], producing 0.0, 0.5, and 1.0 for the given test points, mirroring the behavior of `d3.scaleLinear` in Ruby.

AI-generated description

Similar vizzes