math - How to calculate the range in d3.js? -


i new d3.js library, , trying understand concept of domain , ranges.

i read scott murray's book, don't know how calculate it.

i have this:

var scale = d3.scale.linear()     .domain([100, 500])     .range([10, 350]);   scale(100);  //returns 10 scale(300);  //returns 180 scale(500);  //returns 350 

i know 100 units of input represent 10 in output, , same 500 , 350... why 180 300 input? how can calculate value?

i read this tutorial too, explains how calculate it, when follow method, don't same value, i.e., scale(300) doesn't return 180

any idea why?

yes try explain why 180.

we have 300 value ideally divide domain 2 subdomains of same size, can do: 500 - 100 / 2 = 200 (this subdomain size), implies middle value located at:
200 + 100 = 300 (note add starting point 100)

so range same:
350 - 10 / 2 = 170 , add starting point 170 + 10 = 180


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -