Skip to content

Instantly share code, notes, and snippets.

@bmount
Last active December 20, 2015 13:09
Show Gist options
  • Select an option

  • Save bmount/6136428 to your computer and use it in GitHub Desktop.

Select an option

Save bmount/6136428 to your computer and use it in GitHub Desktop.
Manhattan building construction dates as reported by MapPLUTO
<!doctype html>
<meta charset="utf-8">
<style>
rect {
fill: steelblue;
}
.leg {
font-size: 1.4em;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var h = 500,
w = 960;
var svg = d3.select('body').append('svg').attr('width', w).attr('height', h);
var text = svg.append('text')
.attr('x', 50)
.attr('y', 100)
.classed('leg', true)
.text('mouse over a bar to see figures for that year ↳')
g = svg.append('g')
d3.csv('../manhattan_building_age.csv', function (data) {
// make year 0 null
var start = d3.min(data, function (d) { return +d.yearbuilt? +d.yearbuilt: null; }),
nyears = 2013 - start,
maxBldgs = d3.max(data, function (d) { return +d.count; }),
timeScale = d3.scale.linear().domain([start, 2013]).range([0, w-35]),
countScale = d3.scale.linear().domain([0, maxBldgs]).range([0, h-15]);
g.selectAll('rect').data(data).enter()
.append('rect')
.attr('height', function (d) { return countScale(+d.count) })
.attr('y', function (d) { return h - countScale(+d.count) })
.attr('width', w/nyears)
.attr('x', function (d) { return timeScale(+d.yearbuilt); })
.on('mouseenter', function (d) {
text.text('year: ' + d.yearbuilt + ' reported built: ' + d.count)
})
})
</script>
yearbuilt count
0 2414
1765 1
1785 1
1798 1
1799 1
1800 24
1801 1
1805 1
1821 1
1826 1
1827 3
1830 2
1834 1
1836 2
1839 1
1841 4
1842 1
1843 2
1844 1
1845 2
1846 1
1847 1
1848 1
1849 1
1850 11
1851 1
1852 3
1853 2
1855 3
1856 1
1857 2
1858 1
1859 2
1860 11
1862 1
1863 1
1865 3
1866 2
1867 1
1868 2
1869 5
1870 7
1872 3
1873 2
1874 1
1875 10
1876 1
1877 1
1878 1
1879 2
1880 61
1881 1
1882 7
1883 2
1884 4
1885 9
1886 5
1887 5
1888 8
1889 7
1890 191
1891 7
1892 5
1893 9
1894 8
1895 21
1896 28
1897 10
1898 13
1899 1817
1900 6761
1901 1659
1902 85
1903 80
1904 85
1905 560
1906 168
1907 158
1908 99
1909 526
1910 8387
1911 226
1912 255
1913 173
1914 154
1915 1292
1916 150
1917 140
1918 67
1919 32
1920 5694
1921 153
1922 191
1923 213
1924 248
1925 1099
1926 804
1927 315
1928 303
1929 314
1930 1231
1931 153
1932 62
1933 14
1934 16
1935 91
1936 56
1937 65
1938 89
1939 107
1940 497
1941 58
1942 32
1943 4
1944 7
1945 42
1946 59
1947 42
1948 51
1949 44
1950 301
1951 81
1952 42
1953 33
1954 64
1955 77
1956 66
1957 85
1958 98
1959 98
1960 221
1961 98
1962 131
1963 176
1964 114
1965 107
1966 68
1967 61
1968 62
1969 57
1970 88
1971 49
1972 51
1973 66
1974 71
1975 58
1976 22
1977 33
1978 23
1979 30
1980 73
1981 34
1982 45
1983 47
1984 38
1985 84
1986 104
1987 108
1988 72
1989 82
1990 49
1991 28
1992 31
1993 17
1994 31
1995 22
1996 53
1997 61
1998 92
1999 89
2000 162
2001 139
2002 126
2003 129
2004 111
2005 144
2006 118
2007 140
2008 169
2009 81
2010 68
2011 44
2012 65
2013 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment