Graph Slider
May 2023
The graph is an svg
element. And the rounded indicator itself has offset-path defined with the same path definition that renders the graph stroke. Basically, this property enables moving an element along a given path. For brevity, some details are omitted but here is the general idea:
Now to move the indicator, on mouse move the mouse distance is mapped to offset-distance as a percentage:
We could also use offset-path
for the vertical indicator but I think that the label moving makes it tricky to read the value:
So we want to make sure the label position stays fixed, and translate the line with transform
. However, we can't just map the mouse movement one-to-one since the dot moves along a non-linear path. It would be out of sync that way, like so:
Instead, we can calculate the distance between the start and its current position, and center it relative to the indicator dot:
Lastly, in the SVG there are two paths on top of each other: a grayscaled and a colored one. To partially highlight the graph, clip-path
is used to reveal the colored elements based on the same variable from above:
Acknowledgements
Thanks to Family's iOS app for the idea, Siddhartha for the graph, and Paco and Jonnie for their help and feedback.