I am making a simplistic in-browser IDE for some very domain-specific coding. Because I like Bret Victor's thoughts on Learnable Programming so much I thought I'd throw in some draggable numbers ala Tangle.js (click here to see what I'm talking about).
My implementation is a much simpler slider input control but the idea is the same. One issue comes up however. The dragging slider needs values for min, max, and step. Since the values are user-entered I cannot hard code them. Currently I do {min: currentValue/10, max: currentValue*5}
but this is so simplistic that it fails to make sense in a large class of cases.
What I would like is an algorithm (which I imagine would be just a simple calculation) that given a value for a number would make good guesses on min, max, and step values. (Or any 2 of those since getting the third would be trivial).
eg.
fn(15) -> {min: 0, max: 35, step: 1}
fn(1.478) -> {min: -2, max: 5, step: .2}
fn(-7034) -> {min: -35000, max: -500, step: 100}
Obviously it need not and cannot be perfect but I'm wondering if anyone has an idea for an algorithm or something mathy that makes sense here.