Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8110013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:36:04+00:00 2026-06-06T01:36:04+00:00

I’m trying to put together a GUI for setting some pricing. There are three

  • 0

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.

  1. 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.
  2. 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:36:05+00:00Added an answer on June 6, 2026 at 1:36 am

    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:

    • Have an event listener on the keyup or change or input events of the inputs, and update the SVG to match accordingly.
    • Add dragging to your SVG element, and during dragging calculate the appropriate value(s) and set the .value for the input(s) accordingly.

    As a tip, during dragging don’t attempt to detect mousemove on 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:

    • On mousedown:
      1. Record the current cursor position
      2. Register a mousemove handler on the root of the document
      3. Register a mouseup handler on the root of the document
    • On mousemove:
      1. Detect the screenspace delta between the current cursor position and the position at drag start, and use this to calculate the delta in the local space of the element being dragged to update its transformation.
    • On mouseup:
      1. Unregister the mousemove handler.

    Here’s the full source code, in the unlikely event that my site is down:

    <!DOCTYPE HTML>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head> 
      <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
      <title>SVG Complex Plane Input</title>
      <style type="text/css" media="screen">
        html, body { background:#eee; margin:0 }
        p { margin:0.5em; text-align:center }
        .complex-plane-picker svg { width:200px; height:200px; display:block; margin:1em auto; stroke-linejoin:round; stroke-linecap:round; pointer-events:all; }
        .complex-plane-picker rect.bg { fill:#fff; }
        .complex-plane-picker .axes * { stroke:#ccc; fill:none }
        .complex-plane-picker .dot { fill:#090; fill-opacity:0.4; stroke:#000; stroke-opacity:0.6; cursor:move; }
        .complex-plane-picker input { width:6em; }
        .complex-plane-picker .labels { stroke:none; font-size:6px; font-family:'Verdana'; text-anchor:middle; alignment-baseline:middle; }
        .complex-plane-picker .scalers { pointer-events:all; }
      </style>
    </head><body>
    <p>Drag the dot to set the complex value.<br/> TODO: Hold down shift to affect only the magnitude. Hold down alt to affect only the angle. Hold down both to snap to the nearest real- or imaginary-only value.</p>
    <div class="complex-plane-picker">
      <p class="rectangular"><input type="number" value="0" class='real' />+<input type="number" value="0" class='imaginary' />i</p>
      <svg viewBox="-50 -50 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full">
        <rect class="bg" x="-50" y="-50" width="100" height="100" />
        <g class="scalers">
          <rect x="-5" y="-5" width="10" height="10" fill="#ffc"/>
          <rect x="-45" y="-45" width="90" height="90" fill="none" stroke="#ffc" stroke-width="10" />
        </g>
        <g class="axes">
          <g>
            <line x1="-49" y1="0" x2="49" y2="0" />
            <polyline points="-44,5 -49,0 -44,-5" />
            <polyline points="44,5 49,0 44,-5" />
          </g>
          <g transform="rotate(90)">
            <line x1="-49" y1="0" x2="49" y2="0" />
            <polyline points="-44,5 -49,0 -44,-5" />
            <polyline points="44,5 49,0 44,-5" />
          </g>
        </g>
        <g class="labels" id="labels">
          <text x="0" y="0">0</text>
          <text x="0" y="0">0</text>
          <text x="0" y="0">0</text>
          <text x="0" y="0">0</text>
        </g>
        <use class="labels" xlink:href="#labels" transform="rotate(90)" />
        <circle class="dot" r="4" />
      </svg>
      <p class="polar"><input type="number" value="0" class='magnitude' />@<input type="number" value="0" class='angle'/>°</p>
    </div>
    <script type="text/javascript"><![CDATA[
      var svg   = document.getElementsByTagName('svg')[0];
      var svgNS = svg.getAttribute('xmlns');
      var pt    = svg.createSVGPoint();
    
      function mxy(evt){
        pt.x = evt.clientX;
        pt.y = evt.clientY;
        return pt.matrixTransform(svg.getScreenCTM().inverse());
      }
    
      var dot  = document.querySelector('.complex-plane-picker .dot');
      var real = document.querySelector('.real');
      var imag = document.querySelector('.imaginary');
      var size = document.querySelector('.magnitude');
      var angl = document.querySelector('.angle');
    
      var labels = svg.querySelectorAll('.complex-plane-picker #labels text');
      var scale, maxValue;
      var updateScale = function(newScale){
        scale = newScale;
        maxValue = 50*scale;
        var tickSize=1e-6;
        var e=-5;
        var f=-1;
        var fs = [1,2,5]
        while (tickSize/scale < 10){
          if (++f%fs.length==0) ++e;
          tickSize = fs[f%fs.length]*Math.pow(10,e);
        }
        for (var i=labels.length;i;--i){
          labels[i-1].firstChild.nodeValue = (tickSize*i).toString().replace(/(\.0*[^0]+)0{3,}.*/,'$1');
          labels[i-1].setAttribute('y', -tickSize*i/scale);
        }
        // updateRectangularFromDot();
        // updatePolarFromDot();
      };
    
      var rescaleAsNeeded = function(x,y,jump){
        var scaleFactor = 1.03;
        if (jump && (x>maxValue || y>maxValue || (x<maxValue*0.1 && y<maxValue*0.1))){
          updateScale(Math.max(x,y)*2/50);
        } else if (x>maxValue*0.8 || y>maxValue*0.8) updateScale(scale*scaleFactor);
        else if (x<maxValue*0.1 && y<maxValue*0.1) updateScale(scale/scaleFactor);
      };  
    
      var updateFromRectangular = function(){
        var x = real.value*1;
        var y = imag.value*1;
        rescaleAsNeeded(x,y,true);
        dot.cx.baseVal.value =  x/scale;
        dot.cy.baseVal.value = -y/scale;
        updatePolarFromDot();
      };
      real.addEventListener('input',updateFromRectangular,false);
      imag.addEventListener('input',updateFromRectangular,false);
    
      var updateFromPolar = function(){
        var hyp = size.value*1;
        var rad = angl.value*Math.PI/180;
        var x   = Math.cos(rad)*hyp;
        var y   = Math.sin(rad)*hyp;
        rescaleAsNeeded(x,y,true);
        dot.cx.baseVal.value =  x/scale;
        dot.cy.baseVal.value = -y/scale;
        updateRectangularFromDot();
      };
      size.addEventListener('input',updateFromPolar,false);
      angl.addEventListener('input',updateFromPolar,false);
    
      var updateRectangularFromDot = function(){
        real.value = ( dot.cx.baseVal.value*scale).toFixed(2);
        imag.value = (-dot.cy.baseVal.value*scale).toFixed(2);
      };
      var updatePolarFromDot = function(){
        var x =  dot.cx.baseVal.value*scale;
        var y = -dot.cy.baseVal.value*scale;
        size.value = Math.sqrt(x*x+y*y).toFixed(2);
        angl.value = (Math.atan2(y,x)*180/Math.PI).toFixed(1);
      }
      var dragging = false;
      dot.addEventListener('mousedown',function(evt){
        var offset = mxy(evt);
        dragging = true;
        offset.x = dot.cx.baseVal.value - offset.x;
        offset.y = dot.cy.baseVal.value - offset.y;
        var scaleTimer;
        var move = function(evt){
          clearTimeout(scaleTimer);
          var now = mxy(evt);
          var x = offset.x + now.x;
          var y = -(offset.y + now.y);
          dot.cx.baseVal.value = x;
          dot.cy.baseVal.value = -y;
          x = Math.abs(x)*scale, y=Math.abs(y)*scale;
          var oldScale = scale;
          rescaleAsNeeded(x,y);
          updatePolarFromDot();
          updateRectangularFromDot();
          if (oldScale != scale) scaleTimer = setTimeout(function(){move(evt)},1000/30);
        };
        document.documentElement.style.userSelect = 
        document.documentElement.style.MozUserSelect = 
        document.documentElement.style.webkitUserSelect = 'none';
        svg.addEventListener('mousemove',move,false);
        document.documentElement.addEventListener('mouseup',function(){
          dragging = false;
          clearTimeout(scaleTimer);
          svg.removeEventListener('mousemove',move,false);
          document.documentElement.style.userSelect = 
          document.documentElement.style.MozUserSelect = 
          document.documentElement.style.webkitUserSelect = '';
        },false);
      },false);
    
      dot.addEventListener('dblclick',function(){
        dot.cx.baseVal.value = dot.cy.baseVal.value = 0;
        updateScale(1.0);
        updatePolarFromDot();
        updateRectangularFromDot();
      },false);
    
      updateScale(1.0);
    
    ]]></script>
    </body></html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.