Skip to content

Instantly share code, notes, and snippets.

@poezn
Created February 25, 2013 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poezn/5034444 to your computer and use it in GitHub Desktop.
Save poezn/5034444 to your computer and use it in GitHub Desktop.
temperatures matrix chart (by year and by decade)
{"description":"temperatures matrix chart (by year and by decade)","endpoint":"","display":"svg","public":true,"require":[{"name":"TopoJSON","url":"http://d3js.org/topojson.v0.min.js"},{"name":"TopoJSON","url":"http://d3js.org/topojson.v0.min.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"stations.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"countries.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"stations_1910.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"observations.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01}
//var values = _.map(stations.features
var colorScale = d3.scale.linear()
.domain([500, 1750, 3000])
.range(['#21C4F7', '#F0F8B3', '#D52323'])
.interpolate(d3.interpolateLab);
var yearMin = 1868;
var yearMax = 2012;
var r = 200,
minRadius = 0.2*r;
var data = _.chain(tb['observations'])
.map(function(d, i) {
return _.map(_.range(12), function(idx) {
return {
value: parseInt(d['val' + (idx + 1)]),
yr: parseInt(d['yr']),
month: idx + 1
};
});
})
.flatten()
.filter(function(d, i) {
return d.yr >= yearMin && d.yr <= yearMax;
})
.value();
var months = _.range(1, 13, 1);
var decadeData = _.chain(data)
.groupBy(function(d, i) {
return d.yr - d.yr % 10;
})
.map(function(d, decade) {
return _.map(months, function(month, i) {
var numYears = 0;
var sumValue = _.chain(d)
.filter(function(d) {
return month == d.month;
})
.reduce(function(memo, num) {
if (num.value) {
numYears++;
return num.value + memo;
}
return memo;
}, 0)
.value();
console.log('sumValue', sumValue, 'numYears', numYears)
var avgValue = sumValue / numYears;
//console.log(sumValue);
return {
decade: parseInt(decade),
month: month,
value: avgValue
}
})
})
.flatten()
.value();
var decadeMin = yearMin - yearMin % 10;
var decadeMax = yearMax - yearMax % 10 + 10;
console.log(decadeData);
//console.log(data);
var width = 30;
var height = 2;
g.selectAll('rect.years')
.data(data)
.enter().append('rect')
.attr({
'class': 'years',
'transform': function(d, i) {
var tx = (d.month - 1) * width;
var ty = (d.yr - yearMin) * height
return 'translate(' + [tx, ty] + ')';
},
'height': height,
'width': width
})
.style({
fill: function(d, i) {
return d.value ? colorScale(d.value) : '#E7E7E7';
},
"stroke-width": 0
})
g.selectAll('rect.decade')
.data(decadeData)
.enter().append('rect')
.attr({
'class': 'decade',
'transform': function(d, i) {
var tx = (d.month - 1) * width;
var ty = 300 + (d.decade - yearMin) * height
return 'translate(' + [tx, ty] + ')';
},
'height': height*10,
'width': width
})
.style({
fill: function(d, i) {
return colorScale(d.value);
},
"stroke-width": 0
});
id yr val1 val2 val3 val4 val5 val6 val7 val8 val9 val10 val11 val12
10160390000 1856 1272 1062 1262 1462 1862 1972 2262 2362 2132 1872 1292 1112
10160390000 1857 742 1122 1242 1392 1662 1962 2152 2322 2312 1862 1752 1192
10160390000 1858 892 1152 1262 1672 1732 2192 2392 2492 2382 2022 1652 1242
10160390000 1859 922 1002 1152 1672 2042 1980 2550 2480 2140 1980 1460 1150
10160390000 1860 1300 920 1170 1420 1810 2290 2290 2190 1760 1120 1340
10160390000 1861 1010 1090 1450 1560 1780 2180 2370 2330 2120 1950 1517 1497
10160390000 1862 1177 1177 1577 1667 2047 2097 2327 2337 2067 1817 1437
10160390000 1863 947 1187 1567 1767 2277 2357 2327 2027 1717 1237 827
10160390000 1864 787 1007 1417 1487 1907 2287 2587 2477 2217 1947 1347 1007
10160390000 1865 1177 1077 1657 1897 2097 2357 2477 2277 1937 1437
10160390000 1866 1047 1297 1257 1517 1617 2047 2337
10160390000 1878 987 1117 1217 1667 1887 2107 2357 2627 2237 1977 1337 1267
10160390000 1879 1247 1217 1207 1397 1517 2127 2207 2307 2117 1787 1367 917
10160390000 1880 987 1117 1247 1497 1637 2017 2447 2457 2217 1987 1447 1207
10160390000 1881 1357 1327 1477 1557 1727 1947 2457 2667 2297 1887 1437 1197
10160390000 1882 1007 1167 1187 1567 1867 2037 2257 2327 1987 1777 1507 1217
10160390000 1883 1157 1137 1117 1377 1677 1957 2267 2257 2167 1747 1487 1047
10160390000 1884 977 1217 1673 1333 1043
10160390000 1885 883 1483 1243 1243 1753 1923 2263 2563 2293 1673 1323 1193
10160390000 1886 953 1013 1303 1453 1753 1933 2243 2223 2213 1833 1353 1093
10160390000 1887 933 943 1233 1343 1683 2113 2423 2433 2253 1493 1423 1033
10160390000 1888 1095 905 1295 1525 1675 2045 2245 2215 2145 1815 1515 1325
10160390000 1889 935 1045 1135 1355 1665 1955 2285 2265 2105 1595 1395 975
10160390000 1890 1105 1045 1095 1325 1535 1975 2035 2315 2085 1725 1305 1045
10160390000 1891 765 935 1245 1435 1695 1975 2375 2315 2175 1915 1555 1245
10160390000 1892 1155 1225 1295 1395 1755 2155 2455 2345 2235 1925 1535 1165
10160390000 1893 965 1235 1395 1585 1845 2145 2335 2305 2375 1955 1455 1145
10160390000 1894 2219 2029 1649 1139
10160390000 1895 939 1259 1179 1509 1609 2069 2489 2269 2329 2069 1729 1329
10160390000 1896 1049 1079 1279 1249 1549 2069 2559 2289 2249 1659 1209 1129
10160390000 1897 1079 1139 1459 1539 1729 2159 2559 2539 2179 1779 1629 1149
10160390000 1898 1189 1039 1139 1319 1689 2069 2429 2469 2209 1869 1459 1049
10160390000 1899 1209 1339 1259 1559 1799 2049 2359 2459 2379 2179 1659 1189
10160390000 1900 1079 1429 1109 1319 1659 2159 2169 2309 2319 2009 1329 1169
10160390000 1901 1069 879 1199 1569 1599 2389 2479 2399 2249 1639 1399 1039
10160390000 1902 1019 1229 1289 1579 1549 2019 2519 2609 2199 1729 1529 1169
10160390000 1903 1179 1099 1269 1349 1649 1909 2329 2449 2149 1929 1359 1059
10160390000 1904 929 1129 1139 1409 1839 2129 2519 2609 2079 1829 1379 1249
10160390000 1905 909 869 1389 1579 1599 2149 2329 2499 2209 1719 1389 1079
10160390000 1906 1089 889 1189 1279 1639 2079 2259 2409 2229 1859 1429 1079
10160390000 1907 949 839 1079 1289 1649 2159 2189 2509 2129 1729 1559 1329
10160390000 1908 1159 969 1039 1219 1929 1969 2339 2509 2289 1889 1619 1219
10160390000 1909 889 959 1239 1499 1649 1947 2217 2427 2097 1917 1457 1337
10160390000 1910 997 1107 1107 1367 1487 2037 2297 2337 2027 1967 1497 1217
10160390000 1911 827 1087 1147 1297 1547 2047 2447 2567 2377 1917 1457 1437
10160390000 1912 1117 1417 1437 1257 1877 2097 2227 2347 1897 1747 1177 1107
10160390000 1913 1167 1027 1277 1347 1727 2057 2347 2517 2167 1967 1647 1147
10160390000 1914 887 1157 1277 1647 1667 1847 2257 2257 2177 1767 1397 1177
10160390000 1915 977 1017 1307 1177 1747 2067 2507 2497 2117 1687 1457 1317
10160390000 1916 1027 1067 1207 1357 1697 1957 2327 2457 2037 1887 1487 1267
10160390000 1917 967 1077 1037 1217 1727 1997 2337 2497 2367 1777 1237 817
10160390000 1918 1167 977 1037 1267 1657 2017 2387 2387 2437 1557 1367 1187
10160390000 1919 967 1237 1247 1317 1747 1957 2157 2437 2187 1617 1467 1097
10160390000 1920 1087 1177 1237 1567 1847 2127 2487 2397 2227 1797 1337 1197
10160390000 1921 1077 1117 1127 1237 1637 1997 2387 2357 2407 2027 1377 1047
10160390000 1922 1087 1137 1267 1567 1797 2027 2247 2507 2007 1937 1347 1057
10160390000 1923 787 1147 1197 1337 1717 1707 2477 2587 2037 2067 1467 977
10160390000 1924 1047 957 1257 1537 2087 2137 2457 2347 2187 1847 1517 1127
10160390000 1925 1027 1097 917 1367 1597 2057 2207 2507 2077 1747 1317 1267
10160390000 1926 1177 1387 1327 1457 1677 1997 2367 2307 2287 2237 1457 1017
10160390000 1927 1037 1077 1257 1547 1767 2087 2307 2517 2277 1847 1497 1267
10160390000 1928 1027 1127 1307 1477 1577 2127 2467 2647 2327 1867 1357 1057
10160390000 1929 917 1047 1167 1507 1687 2137 2327 2277 2277 1807 1407 1277
10160390000 1930 1147 957 1367 1377 1727 2037 2337 2447 2257 2017 1707 1267
10160390000 1931 1077 887 1457 1427 1797 2387 2417 2447 2067 1807 1507 997
10160390000 1932 1057 907 1227 1387 1717 1807 2157 2467 2287 1847 1507 1297
10160390000 1933 1007 1107 1227 1587 1887 2057 2337 2537 2397 2107 1287 967
10160390000 1934 857 977 1037 1397 1697 2097 2417 2347 2187 1777 1347 1347
10160390000 1935 807 1037 1127 1547 1537 2177 2487 2477 2327 1717 1457 1227
10160390000 1936 1327 1347 1257 1507 1667 1957 2367 2277 2367 1627 1387 997
10160390000 1937 1177 1267 1257 1467 1677 2077 2357 2437 2147 1807 1667 1037
10160390000 1938 987 847 1107 1227 1547 2317 2387 2367 2127 1847 1477 1067
10160390000 1939 1197 1007 1047 1287 1457 1927 2297 2257
10160390000 1940
10160390000 1941 1047 1207 1257 1377 1527 2017 2307 2427 2067 1737 1397 1067
10160390000 1942 917 827 1357 1487 1907 2157 2407 2327 2227
10160390000 1943 2337 2357 2277 1177
10160390000 1944 1077 827 1127 1517 1847 1987 2337 2497 2267 1677 1477
10160390000 1945 817 1167 1227 1787 2097 2227 2427 2347 2367 1877 1577 1277
10160390000 1946 977 1157 1257 1497 1647 1987 2347 2527 2297 2087 1527 987
10160390000 1947 1087 1257 1647
10160390000 1951 982 1102 1332 1412 1642 2132 2302 2472 2272 1662 1502 1192
10160390000 1952 932 962 1462 1522 1712 2392 2532 2592 2242 2002 1442 1172
10160390000 1953 752 862 1092 1492 1822 2062 2352 2352 2272 1842 1482 1432
10160390000 1954 852 932 1272 1372 1712 2132 2232 2332 2262 1752 1592 1182
10160390000 1955 1322 1242 1252 1382 1902 2182 2552 2542 2162 1832 1452 1322
10160390000 1956 1122 672 1213 1413 1633 1893 2273 2563 2313 1813 1233 1023
10160390000 1957 823 1213 1393 1373 1613 1953 2303 2403 2243 1863 1373 1063
10160390000 1958 1053 1283 1283 1343 1913 2173 2253 2483 2363 1853 1393 1343
10160390000 1959 1083 1023 1473 1513 1733 2073 2393 2403 2343 1823 1433 1183
10160390000 1960 1003 1293 1363 1413 1783 2153 2323 2493 2103 1863 1523 1013
10160390000 1961 963 1153 1163 1673 1923 2193 2423 2293 2353 1763 1503 1153
10160390000 1962 1123 953 1243 1433 1833 1973 2383 2373 2343 1903 1233 983
10160390000 1963 1053 1043 1183 1453 1603 2063 2443 2473 2163 1663 1583 1283
10160390000 1964 933 1163 1343 1403 1883 2133 2373 2393 2323 1743 1223 1023
10160390000 1965 983 863 1253 1303 1783 2153 2483 2373 2043 2043 1533 1213
10160390000 1966 1193 1383 1033 1543 1733 2103 2313 2403 2183 1813 1173 933
10160390000 1967 943 1113 1223 1303 1803 1963 2473 2553 2213 2063 1603 943
10160390000 1968 973 1193 1263 1493 1733 2063 2483 2423 2183 1873 1493 1153
10160390000 1969 1123 1043 1293 1423 1793 1963 2243 2403 2103 1783 1483 973
10160390000 1970 1223 1023 1173 1343 1633 2063 2323 2493 2263 1693 1403 1073
10160390000 1971 1013 933 1013 1453 1733 1973 2363 2693 2233 1853 1253 1093
10160390000 1972 1033 1233 1243 1533 1943 2233 2003 1783 1543 1023
10160390000 1973 1013 913 963 1283 1743 2063 2343 2413 2253 1733 1343 1033
10160390000 1974 1073 1033 1233 1303 1823
10160390000 1975 1003 1023 1123 1333 1953 2443 2213 1723 1293 1113
10160390000 1976 833 1053 1393 1343 1683 2053 2343 2243 1713 1183 1233
10160390000 1977 1113 1203 1213 1383 1633 1983 2243 2223 2223 2033 1263
10160390000 1978 933 1303 1193 1323 1603 1963 2283 2373 2133 1593 1203 1333
10160390000 1979 1273 1213 1193 1273 1673 2143 2363 2413 2073 1833 1173 1053
10160390000 1980 1253 1243 1643 2073 2233 2453 2253 1713 1473 913
10160390000 1981 983 1703 2053 2203 2313 2233 1973 1373 1363
10160390000 1982 1053 1203 1403 1743 1393 1013
10160390000 1983 923 1483 1713 2413 2303 1943 1653 1123
10160390000 1984 1023 973 1053 1473 1553 1423 1873 2313 1533 1723 1163 1113
10160390000 1985 853 1303 1103 1693 2463 2443 2233 1933 1193
10160390000 1986 1133 1183 1353 2123 2363 1973 1423
10160390000 1987 983 1113 1253 1593 1713 2153 2483 2623 2493 2193 1483 1313
10160390000 1988 1243 1033 1173 1483 1813 2143 2463 2613 2183 2073 1533
10160390000 1989 963 1133 1313 1453 1793 2183 2593 2713 2313 1933 1663 1513
10160390000 1991 943 983 1353 1293 1513 2493 2633 2443 1863 1323 963
10160390000 1993 973 1173 1143 1853 2183 2393 2533 2213 1873 1403 1123
10160390000 1994 1153 1333 1403 1953 2183 2623 2803 2323 1963 1523 1133
10160390000 1995 1033 1223 1223 1343 1903 2153 2153 1973 1613
10160390000 1996 1363 1053 1273 1473 1713 2093 2393 2550 2140 1680 1490 1320
10160390000 1997 1320 1180 1200 1550 1980 2320 2390 2560 2080 1610 1280
10160390000 1998 1200 1220 1280 1550 1780 2190 2480 2560 2420 1730 1440 1070
10160390000 1999 1120 980 1370 1510 2000 2310 2550 2760 2440 2280 1350 1180
10160390000 2000 840 1120 1360 1620 2230 2560 2630 2330 1850 1540 1300
10160390000 2001 1160 1060 1640 1510 1810 2400 2550 2650 2230 1400 960
10160390000 2002 1060 1100 1380 1500 1680 2270 2320 1960 1570 1350
10160390000 2003 1070 1030 1350 1550 1840 2540 2830 2390 2050 1590 1140
10160390000 2004 1110 1200 1290 1480 1660 2230 2490 2720 2410 2230 1310 1210
10160390000 2005 760 850 1260 1540 1950 2350 2580 2520 2250 2020 1380 1090
10160390000 2006 970 1010 1380 1730 2070 2280 2620 2540 2330 2140 1750 1230
10160390000 2007 1100 1350 1260 1580 1930 2270 2520 2630 2290 1930 1370 1130
10160390000 2008 1100 1250 1340 1610 1880 2240 2620 2620 2420 2070 1390 1060
10160390000 2009 1130 1040 1240 1440 2070 2370 2760 2670 2270 1940 1600 1350
10160390000 2010 1190 1360 1420 1620 1800 2210 2600 2530 2350 1930 1470 1210
10160390000 2011 1110 1090 1410 1710 1990 2270 2650 2690 2390 1990 1620 1200
10160390000 2012 990 760 1310 1540 1890 2500 2610 2800 2350 2100 1640 1220
10160390000 2013 1130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment