Linear Scale
Introduction to the linear scale
We'll cover the following
Scales are functions that map input from a domain to output in a range. They take an input, typically a data point, and convert it into position, length, and color.
We will cover the linear scale, which maps continuous input to continuous output.
Introduction
Let’s look into the detail of the scales and explore the linear scale, the most common scale and an automatic choice when we want to map continuous input to continuous output. The linear scale maps continuous input to continuous output through a linear function.
.
Where x is the input, and y represents the output. Input is generally data such as the population of cities, and output is generally a dimension graph, which will be covered in the next chapter.
Example
Now, we are going to look at an example to further understand how the linear scale works. Let’s look at an example where we want to convert the student 10-point CGPA ranging from 0 to 10, to the 4-point CGPA system ranging from 0 to 4 with a linear scale function.
We will use the domain()
and the range()
functions to define the domain and range for the scale respectively.
In the above code, from line 1 to line 3, we have defined a cgpaconv
scale that takes input, ranging from 0 to 10 using the domain()
function. The range of cgpaconv
is from 0 to 4, as defined by the range()
function.
In line 5, we can see CGPA in the 4-point system by printing it on the console using the console.log()
function.