Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 75c0561

Browse files
committed
update map animation dataset to one that has more contrast and fix buggy
frame generation logic.
1 parent 5153224 commit 75c0561

File tree

1 file changed

+28
-88
lines changed

1 file changed

+28
-88
lines changed

_posts/plotly_js/animations/map-animations/2017-08-22-choropleth-animation.html

Lines changed: 28 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,56 @@
11
---
22
name: Map Animations
3-
plot_url: https://codepen.io/plotly/embed/YoZLGQ/?height=500&theme-id=15263&default-tab=result
3+
plot_url: https://codepen.io/plotly/embed/WqZOVG/?height=500&theme-id=15263&default-tab=result
44
language: plotly_js
55
suite: map-animations
66
order: 1
77
sitemap: false
88
arrangement: horizontal
99
---
1010

11-
Plotly.d3.csv("https://raw.githubusercontent.com/bcdunbar/datasets/master/usa_pop_melted.csv", function(err, rows){
11+
Plotly.d3.csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminder_with_codes.csv", function(err, rows){
1212

13-
function unpack(rows, key) {
14-
return rows.map(function(row) { return row[key]; })
13+
function filter_and_unpack(rows, key, year) {
14+
return rows.filter(row => row['year'] == year).map(row => row[key])
1515
}
1616

1717
var frames = []
18-
var z = unpack(rows, 'pop')
19-
var locations = unpack(rows, 'abb')
18+
var slider_steps = []
2019

21-
var n = 7;
22-
var j = 51;
23-
var k = 0;
24-
var num = 2009
25-
for (var i = 0; i < n; i++) {
26-
k++
27-
j = 51
28-
j = j*k
29-
num++
30-
frames[i] = {data: [{z: [], locations: []}], name: num}
31-
frames[i].data[0].z = z.slice(0, j);
32-
frames[i].data[0].locations = locations.slice(0, j);
20+
var n = 11;
21+
var num = 1952;
22+
for (var i = 0; i <= n; i++) {
23+
var z = filter_and_unpack(rows, 'lifeExp', num)
24+
var locations = filter_and_unpack(rows, 'iso_alpha', num)
25+
frames[i] = {data: [{z: z, locations: locations, text: locations}], name: num}
26+
slider_steps.push ({
27+
label: num.toString(),
28+
method: "animate",
29+
args: [[num], {
30+
mode: "immediate",
31+
transition: {duration: 300},
32+
frame: {duration: 300}
33+
}
34+
]
35+
})
36+
num = num + 5
3337
}
3438

3539
var data = [{
3640
type: 'choropleth',
37-
locationmode: 'USA-states',
41+
locationmode: 'world',
3842
locations: frames[0].data[0].locations,
3943
z: frames[0].data[0].z,
4044
text: frames[0].data[0].locations,
4145
zauto: false,
42-
zmin: 500000,
43-
zmax: 50000000
46+
zmin: 30,
47+
zmax: 90
4448

4549
}];
46-
4750
var layout = {
48-
title: 'USA State Population<br>2010 - 2016',
51+
title: 'World Life Expectency<br>1952 - 2007',
4952
geo:{
50-
scope: 'usa',
53+
scope: 'world',
5154
countrycolor: 'rgb(255, 255, 255)',
5255
showland: true,
5356
landcolor: 'rgb(217, 217, 217)',
@@ -97,70 +100,7 @@
97100
}],
98101
sliders: [{
99102
active: 0,
100-
steps: [{
101-
label: "2010",
102-
method: "animate",
103-
args: [["2010"], {
104-
mode: "immediate",
105-
transition: {duration: 300},
106-
frame: {duration: 300}
107-
}
108-
]
109-
},{
110-
label: "2011",
111-
method: "animate",
112-
args: [["2011"], {
113-
mode: "immediate",
114-
transition: {duration: 300},
115-
frame: {duration: 300}
116-
}
117-
]
118-
}, {
119-
label: "2012",
120-
method: "animate",
121-
args: [["2012"], {
122-
mode: "immediate",
123-
transition: {duration: 300},
124-
frame: {duration: 300}
125-
}
126-
]
127-
}, {
128-
label: "2013",
129-
method: "animate",
130-
args: [["2013"], {
131-
mode: "immediate",
132-
transition: {duration: 300},
133-
frame: {duration: 300}
134-
}
135-
]
136-
}, {
137-
label: "2014",
138-
method: "animate",
139-
args: [["2014"], {
140-
mode: "immediate",
141-
transition: {duration: 300},
142-
frame: {duration: 300}
143-
}
144-
]
145-
}, {
146-
label: "2015",
147-
method: "animate",
148-
args: [["2015"], {
149-
mode: "immediate",
150-
transition: {duration: 300},
151-
frame: {duration: 300}
152-
}
153-
]
154-
}, {
155-
label: "2016",
156-
method: "animate",
157-
args: [["2016"], {
158-
mode: "immediate",
159-
transition: {duration: 300},
160-
frame: {duration: 300}
161-
}
162-
]
163-
}],
103+
steps: slider_steps,
164104
x: 0.1,
165105
len: 0.9,
166106
xanchor: "left",

0 commit comments

Comments
 (0)