Skip to main content
100%

Invert d3 scaleBand

✓ Published0🌍 Public
LLuisSevillano
Last edited Jan 4, 2021
Created on Jan 4, 2021

This example demonstrates how to invert a `d3.scaleBand` scale, allowing a pixel position to be mapped back to the corresponding categorical domain value. The code defines a custom `invert` method that calculates the band index by accounting for outer and inner padding, the step size, and the range’s direction. It uses the `d3-scale` API, specifically the scale’s `domain()`, `range()`, `paddingOuter()`, `paddingInner()`, and `step()` methods, to compute the result. The implementation handles both ascending and descending ranges, returning the appropriate category for any point in the range.

AI-generated description

Similar vizzes