forked from PacktPublishing/How-to-Visualize-Data-with-D3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDomainAndRange.rtf
57 lines (53 loc) · 5.24 KB
/
DomainAndRange.rtf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{\rtf1\ansi\ansicpg1252\cocoartf2513
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 HelveticaNeue;\f1\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;\red46\green45\blue42;\red255\green255\blue255;\red162\green70\blue22;
\red31\green36\blue45;\red63\green69\blue80;\red190\green191\blue193;}
{\*\expandedcolortbl;;\cssrgb\c23529\c23137\c21569;\cssrgb\c100000\c100000\c100000;\cssrgb\c70196\c35294\c10588;
\cssrgb\c16078\c18824\c23137;\cssrgb\c31373\c34118\c38824;\cssrgb\c79216\c79608\c80000;}
{\*\listtable{\list\listtemplateid1\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{none\}.}{\leveltext\leveltemplateid1\'01.;}{\levelnumbers;}\fi-360\li720\lin720 }{\listname ;}\listid1}
{\list\listtemplateid2\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{none\}.}{\leveltext\leveltemplateid101\'01.;}{\levelnumbers;}\fi-360\li720\lin720 }{\listname ;}\listid2}}
{\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}{\listoverride\listid2\listoverridecount0\ls2}}
{\info
{\author Elisabeth Robson}}\margl1440\margr1440\vieww19520\viewh25200\viewkind0
\deftab720
\pard\pardeftab720\sl920\partightenfactor0
\f0\fs72 \cf2 \cb3 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec2 Do the Work: Domain and Range\
\pard\pardeftab720\sa400\partightenfactor0
\fs36 \cf2 Sometimes you need to convert one value to another in order to be able to use it. For instance, in our project, we need to map temperature anomalies to colors to visualize them. This is a common problem when working with data.\cb1 \
\cb3 In D3, when we want to convert a value in one set of values (known as the domain) to another set of values (known as the range), we write a scale function. We'll get into a lot more detail about writing a scale function for our temperature anomalies in the next few lessons; in the meantime, practice by doing this exercise to convert dog ages into human years, and human ages into dog years. It's often said that a dog ages 5 years for every human year.\cb1 \
\cb3 Write two functions, one to convert a dog's age into human years, and another to convert a human's age into dog years. It's important that we use integer values here, so make sure your code produces a year like 1, 2, or 5, not a floating point value, like 1.4 or 10.2.\cb1 \
\pard\tx220\tx720\pardeftab720\li720\fi-720\sl340\partightenfactor0
\ls1\ilvl0
\f1\fs24 \cf4 \cb3 \kerning1\expnd0\expndtw0 \outl0\strokewidth0 {\listtext . }\expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec4 function\cf5 \strokec5 dogToHuman(dogAge) \{\cf6 \cb1 \strokec6 \
\pard\tx220\tx720\pardeftab720\li720\fi-720\sl340\partightenfactor0
\ls1\ilvl0\cf5 \cb3 \kerning1\expnd0\expndtw0 \outl0\strokewidth0 {\listtext . }\expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec5 \cf4 \strokec4 let\cf5 \strokec5 humanYears = YOUR CODE HERE;\cf6 \cb1 \strokec6 \
\ls1\ilvl0\cf5 \cb3 \kerning1\expnd0\expndtw0 \outl0\strokewidth0 {\listtext . }\expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec5 \cf4 \strokec4 return\cf5 \strokec5 humanYears;\cf6 \cb1 \strokec6 \
\ls1\ilvl0\cf5 \cb3 \kerning1\expnd0\expndtw0 \outl0\strokewidth0 {\listtext . }\expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec5 \}\cf6 \cb1 \strokec6 \
\pard\tx220\tx720\pardeftab720\li720\fi-720\sl340\partightenfactor0
\ls1\ilvl0\cf4 \cb3 \kerning1\expnd0\expndtw0 \outl0\strokewidth0 {\listtext . }\expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec4 function\cf5 \strokec5 humanToDog(humanAge) \{\cf6 \cb1 \strokec6 \
\pard\tx220\tx720\pardeftab720\li720\fi-720\sl340\partightenfactor0
\ls1\ilvl0\cf5 \cb3 \kerning1\expnd0\expndtw0 \outl0\strokewidth0 {\listtext . }\expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec5 \cf4 \strokec4 let\cf5 \strokec5 dogYears = YOUR CODE HERE;\cf6 \cb1 \strokec6 \
\ls1\ilvl0\cf5 \cb3 \kerning1\expnd0\expndtw0 \outl0\strokewidth0 {\listtext . }\expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec5 \cf4 \strokec4 return\cf5 \strokec5 dogYears;\cf6 \cb1 \strokec6 \
\ls1\ilvl0\cf5 \cb3 \kerning1\expnd0\expndtw0 \outl0\strokewidth0 {\listtext . }\expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec5 \}\cf6 \cb1 \strokec6 \
\pard\pardeftab720\sa400\partightenfactor0
\f0\fs36 \cf2 \cb3 \strokec2 Test your code with the following tests:\cb1 \
\pard\tx220\tx720\pardeftab720\li720\fi-720\sl340\partightenfactor0
\ls2\ilvl0
\f1\fs24 \cf5 \cb3 \kerning1\expnd0\expndtw0 \outl0\strokewidth0 {\listtext . }\expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec5 dogToHuman(3); \cf7 \strokec7 // should produce 15\cf6 \cb1 \strokec6 \
\ls2\ilvl0\cf5 \cb3 \kerning1\expnd0\expndtw0 \outl0\strokewidth0 {\listtext . }\expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec5 humanToDog(52); \cf7 \strokec7 // should produce 10\cf6 \cb1 \strokec6 \
\ls2\ilvl0\cf5 \cb3 \kerning1\expnd0\expndtw0 \outl0\strokewidth0 {\listtext . }\expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec5 humanToDog(62); \cf7 \strokec7 // should produce 12\cf6 \cb1 \strokec6 \
\pard\pardeftab720\sa400\partightenfactor0
\f0\fs36 \cf2 \cb3 \strokec2 This exercise is good practice for the lessons coming up where we'll be writing a function to convert temperature anomaly values to colors.\cb1 \
}