Skip to main content
100%

linear gradient with draggable stops.

✓ Published0🌍 Public
FFraserChapman
Last edited Feb 19, 2025
Created on Aug 30, 2015

This example demonstrates an interactive linear gradient with draggable axis ticks, where the color stops align proportionally to their corresponding domain values. It shows how gradient offsets update in real time as users drag ticks horizontally to modify the domain. Built with D3.js (v3), it uses a linear scale, SVG `linearGradient` definitions, and drag behavior to redraw the gradient dynamically. The color scheme is selectable from a dropdown, and the domain regenerates randomly, while tick labels display both the value and its percentage offset. Rendering is handled via SVG, with data represented as hardcoded hex color ranges and generated numeric domains.

AI-generated description

Linear gradient with stops offset proportionally to the input domain value they represent.

For example given the domain: [0, 5, 10, 50, 100] And the range: ["#190729", "#191996", "#2F972F", "#FFFF66", "#FF1919"] The stops would be offset by: 0%, 5%, 10%, 50%, 100%

The colour at the percentage offset is represented by the hex value at the same index position in the scheme, colours between stops are interpolated in a linear fashion.

When a scheme is selected a random domain is generated and the gradient is redrawn using it. Information on the current domain and selected range is given along with the stop percentages and the domain values that they correspond to.

Aditionally the axis ticks can be dragged horizontally to alter the gradient.

Run gist here

Similar vizzes