|
1 | 1 | ---
|
2 | 2 | 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 |
4 | 4 | language: plotly_js
|
5 | 5 | suite: map-animations
|
6 | 6 | order: 1
|
7 | 7 | sitemap: false
|
8 | 8 | arrangement: horizontal
|
9 | 9 | ---
|
10 | 10 |
|
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){ |
12 | 12 |
|
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]) |
15 | 15 | }
|
16 | 16 |
|
17 | 17 | var frames = []
|
18 |
| - var z = unpack(rows, 'pop') |
19 |
| - var locations = unpack(rows, 'abb') |
| 18 | + var slider_steps = [] |
20 | 19 |
|
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 |
33 | 37 | }
|
34 | 38 |
|
35 | 39 | var data = [{
|
36 | 40 | type: 'choropleth',
|
37 |
| - locationmode: 'USA-states', |
| 41 | + locationmode: 'world', |
38 | 42 | locations: frames[0].data[0].locations,
|
39 | 43 | z: frames[0].data[0].z,
|
40 | 44 | text: frames[0].data[0].locations,
|
41 | 45 | zauto: false,
|
42 |
| - zmin: 500000, |
43 |
| - zmax: 50000000 |
| 46 | + zmin: 30, |
| 47 | + zmax: 90 |
44 | 48 |
|
45 | 49 | }];
|
46 |
| - |
47 | 50 | var layout = {
|
48 |
| - title: 'USA State Population<br>2010 - 2016', |
| 51 | + title: 'World Life Expectency<br>1952 - 2007', |
49 | 52 | geo:{
|
50 |
| - scope: 'usa', |
| 53 | + scope: 'world', |
51 | 54 | countrycolor: 'rgb(255, 255, 255)',
|
52 | 55 | showland: true,
|
53 | 56 | landcolor: 'rgb(217, 217, 217)',
|
|
97 | 100 | }],
|
98 | 101 | sliders: [{
|
99 | 102 | 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, |
164 | 104 | x: 0.1,
|
165 | 105 | len: 0.9,
|
166 | 106 | xanchor: "left",
|
|
0 commit comments