Get value expression

0

In my javascript code I use this expression to make a calculation to obtain value of a graph with the position of the mouse (posY). 460 is the position of my axis, and the maximum and minimum values of the graph of the y-axis.

value =  ((460 - posY) * (maxtemp-txtmintemp)/(460-60)+txtmintemp);

From this expression I wanted to get the Y position, and I have the value, such as this:

10.30 =  ((460 - posY) * (maxtemp-txtmintemp)/(460-60)+txtmintemp);

How can I calculate this expression by isolating posY, which is the value I want to get.

    
asked by anonymous 30.12.2014 / 11:10

1 answer

1

This is an algebra exercise. By changing positions, you can isolate posY. It would look like this:

posY = - ((((10.30 - txtmintemp) * (460 - 60)) / (maxtemp - txtmintemp)) - 460);

Testing:

var maxtemp = 96;
var txtmintemp = 2;
var posY = -((((10.30 - txtmintemp) * (460 - 60)) / (maxtemp - txtmintemp)) - 460);
alert('posY dá: ' + posY);
var original = ((460 - posY) * (maxtemp - txtmintemp) / (460 - 60) + txtmintemp);
original = Math.round(original * 100) / 100
alert('verificação: ' + (10.30 == original));
    
30.12.2014 / 12:08