-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.js
68 lines (56 loc) · 1.78 KB
/
random.js
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
58
59
60
61
62
63
64
65
66
67
68
const cities = d3.csv("./cities.csv", data => data);
const tweets = d3.json("./tweets.json");
const dailyhours = d3.json("./hoursbyday.json");
d3.csv("cities.csv", data => console.log(data));
d3.json("tweets.json", data => console.log(data));
const newRamp = d3
.scaleLinear()
.domain([500000, 13000000])
.range([0, 500]);
const colorRamp = d3
.scaleLinear()
.domain([500000, 13000000])
.range(["blue", "red"]);
newRamp(1000000);
newRamp(9000000);
newRamp.invert(313);
const sampleArray = [423, 124, 66, 424, 58, 10, 900, 44, 1];
const range = [0, 1, 2, 3, 4];
const qScale = d3
.scaleQuantile()
.domain(sampleArray)
.range(range);
console.log("sampleArray for qScale examples: ", sampleArray);
console.log("range for qScale: ", range);
console.log(
"Range gives me the buckets, or bins, to stuff the values in the data into."
);
console.log("qScale for 50 is :", qScale(50));
console.log("qScale for 423 is :", qScale(423));
console.log("qScale for 10000 is :", qScale(10000));
const namedBins = ["tiny", "small", "medium", "large"];
console.log(
"And now we'll map values to bins that have the following names: ",
namedBins
);
const qScaleName = d3
.scaleQuantile()
.domain(sampleArray)
.range(namedBins);
console.log(`qScaleName for 1 is ${qScaleName(1)}`);
console.log(`qScaleName for 68 is ${qScaleName(68)}`);
console.log(`qScaleName for 400 is ${qScaleName(400)}`);
console.log(`qScaleName for 680 is ${qScaleName(680)}`);
console.log(`qScaleName for 68000 is ${qScaleName(68000)}`);
// Nesting
d3.json("tweets.json", data => {
const tweetData = data.tweets;
const nestedTweets = d3
.nest()
.key(d => d.user)
.entries(tweetData);
console.log(
`Nested Tweets, or grouping data by an attribute in a json file:`
);
console.log(nestedTweets);
});