I’m trying to put together a GUI for setting some pricing.
There are three categories to be represented graphically, and two sliders with which we want for setting suggested Buy/Sell prices.
As an exercise, I scratched together some prototypes and put them here on jsFiddle.
please take a quick look, it will explain it MUCH more effectively than my words ever could 🙂
(Please forgive my JS … haven’t refactored it yet)
Since our goal is to have the sliders set a float in an HTML input, I’m leaning toward the SVG.
- My first request is simply a peer-review of my choice to persue an SVG solution … just want to make sure there isn’t some inherent and painful hitch that I’m bound to encounter. I’m open to arguments for other solutions too.
- Second is a question. Does anyone have any good links/examples to post that can help me understand how to set an input value based on the position of a shape?
(I’m expecting that the position will represent a percentage of a defined $$ range, and therefore we can extrapolate a specific $$ value)
Any and all help is greatly appreciated.
Here’s a demo I made that uses SVG to set four inputs, and vice-versa:
http://phrogz.net/svg/complex-plane-picker.xhtml
The top two inputs are the X and Y (real and complex components); the bottom two are polar coordinates (magnitude and angle).
There’s likely more code in there than you need (auto-scaling as you get near the edge/middle, drawing updated axis ticks), which may make it more confusing as a demo than helpful.
In general, though, you need to:
keyuporchangeorinputevents of the inputs, and update the SVG to match accordingly..valuefor the input(s) accordingly.As a tip, during dragging don’t attempt to detect
mousemoveon your draggable element itself. If the mouse moves outside this, you’ll stop getting drag events and it won’t keep up. Instead, I generally use this logic:mousedown:mousemovehandler on the root of the documentmouseuphandler on the root of the documentmousemove:mouseup:mousemovehandler.Here’s the full source code, in the unlikely event that my site is down: