Skip to content

Instantly share code, notes, and snippets.

@retrohacker
Created February 6, 2014 04:19
Show Gist options
  • Save retrohacker/8838335 to your computer and use it in GitHub Desktop.
Save retrohacker/8838335 to your computer and use it in GitHub Desktop.
(function () {
var e;
e = function () {
var e;
return e = $(".js-fullscreen"), e.css("height", $(window).height()), e = $(".js-min-fullscreen"), e.css("min-height", $(window).height())
}, $(function () {
return e()
})
}).call(this),
function () {
$(document).ready(function () {
return $(".scroll").click(function (e) {
var t, n, r, i, s;
return e.preventDefault(), t = this.href, n = t.split("#"), s = n[1], r = $("#" + s).offset(), i = r.top, $("html, body").animate({
scrollTop: i
}, "slow")
}), $(function () {
var e, t, n, r, i, s, o, u, a, f, l, c, h;
return r = $("#page-nav"), i = r.find("a.section-link"), a = {}, t = $(document.documentElement), e = $(document.body), o = $(window), s = e, t.scrollTop() ? s = t : (u = e.scrollTop(), e.scrollTop(u + 1).scrollTop() === u ? s = t : e.scrollTop(u - 1)), i.each(function (e, t) {
var n, r;
r = $(this).attr("href"), n = $(r);
if (n.length) return a[this.href] = {
link: $(t),
target: n
}
}), r.delegate("a.scroll", "click", function (e) {
e.preventDefault();
if (a[this.href] && a[this.href].target) return s.animate({
scrollTop: a[this.href].target.position().top
}, 600, "swing")
}), l = !1, h = !1, c = !1, f = function () {
var t, n, r;
return n = s.scrollTop(), t = e.height(), r = o.height() * (n / t), $.each(a, function (e, t) {
return n + r > t.target.position().top ? (c && c.removeClass("active"), c = t.link.addClass("active")) : (t.link.removeClass("active"), !1)
}), clearTimeout(h), l = !1
}, n = $(document).scroll(function () {
if (!l) return h = setTimeout(f, 250), l = !0
}),
function () {
return n.scroll(), setTimeout(arguments.callee, 1500)
}()
}), $(window).scroll(function () {
var e;
return e = $(".page-nav .gh-link"), $(this).scrollTop() > 600 ? e.addClass("visible") : e.removeClass("visible")
})
})
}.call(this),
function () {
var e, t, n;
t = function (e) {
return e.replace(/[&<>"']/g, "")
}, n = function (e, t) {
var n, r, i, s, o;
o = $(e.node()).width(), s = $(e.node()).width(), r = window.devicePixelRatio || 1, n = t.webkitBackingStorePixelRatio || t.mozBackingStorePixelRatio || t.msBackingStorePixelRatio || t.oBackingStorePixelRatio || t.backingStorePixelRatio || 1, i = r / n;
if (window.devicePixelRatio !== n) return e.attr("width", o * i).attr("height", s * i).style("width", o + "px").style("height", s + "px"), t.scale(i, i)
}, e = function () {
var e, t, r, i, s, o, u, a, f, l;
return o = $(".js-traffic"), s = o.get(0), l = o.width(), i = o.height(), o.find("canvas").remove(), l = i = Math.min(l, i), f = d3.geo.orthographic().clipAngle(90).precision(.5), e = d3.select(".js-traffic .js-graph").append("canvas").attr("width", l).attr("height", i).attr("class", "traffic-map-canvas"), t = e.node().getContext("2d"), n(e, t), r = d3.geo.graticule(), u = d3.geo.path().projection(f).context(t), a = function (e, n) {
var r, s, o, a, c, h, p, d;
return e != null ? console.log(e) : (o = {
type: "Sphere"
}, a = topojson.feature(n, n.objects.land), s = topojson.mesh(n, n.objects.countries, function (e, t) {
return e !== t
}), f.scale(1).translate([0, 0]), r = u.bounds(a), c = .9 / Math.max((r[1][0] - r[0][0]) / l, (r[1][1] - r[0][1]) / i), p = [(l - c * (r[1][0] + r[0][0])) / 2, (i - c * (r[1][1] + r[0][1])) / 2], f.scale(c).translate(p), h = function () {
return t.fillStyle = "#10112e", t.strokeStyle = "#10112e", t.beginPath(), t.lineWidth = 2, u(o), t.stroke(), t.fill(), t.fillStyle = "#3a4385", t.strokeStyle = "#10112e", t.beginPath(), u(a), t.stroke(), t.fill(), t.strokeStyle = "#2d346b", t.lineWidth = 1, t.beginPath(), u(s), t.stroke()
}, h(), d = function (e, n) {
var r, s;
return r = parseFloat(n.lat), s = parseFloat(n.lon),
function () {
return d3.transition().duration(1200).tween("rotate", function () {
var e;
return e = d3.interpolate(f.rotate(), [-s, -r]),
function (n) {
var o, u, a, c;
if ($.isScrolled) return;
return f.rotate(e(n)), t.clearRect(0, 0, l, i), c = f([s, r]), o = c[0], u = c[1], h(), a = "#9DA3C0", t.fillStyle = a, t.lineWidth = 8, t.beginPath(), t.arc(o, u, 22, 0, Math.PI * 2, !1), t.fill(), t.fillStyle = a, t.beginPath(), t.arc(o, u, 7, 0, Math.PI * 2, !1), t.strokeStyle = "#FFFFFF", t.fill(), t.stroke()
}
})
}()
}, $(document).on("event", d))
}, d3.json("/data/world-110m.json", a)
}, $(document).on("data.loaded", e)
}.call(this),
function () {
$(document).on("data.loaded", function (e, t) {
var n, r, i, s, o, u, a, f, l, c, h, p, d, v, m, g, y, b, w, E, S, x, T;
return m = $(".js-streamgraph"), v = m.get(0), u = t.eventSchema, m.find("svg").remove(), b = t.totals, h = {
top: 0,
right: 0,
bottom: 0,
left: 0
}, w = m.width() - h.left - h.right, f = m.height() - h.top - h.bottom, p = d3.keys(b[0]).filter(function (e) {
return e !== "created_at"
}), o = d3.time.format("%Y-%m-%d"), d = d3.nest().key(function (e) {
return d3.time.week(o.parse(e.created_at))
}).rollup(function (e) {
var t, n, r, i;
n = {};
for (r = 0, i = p.length; r < i; r++) t = p[r], n[t] = d3.sum(e, function (e) {
return e[t]
});
return n
}).entries(b), l = p.map(function (e) {
return {
key: e,
values: d.map(function (t) {
return {
date: (new Date(t.key)).getTime(),
value: parseFloat(t.values[e]),
metric: e
}
})
}
}), g = d3.layout.stack().values(function (e) {
return e.values
}).x(function (e) {
return e.date
}).y(function (e) {
return +e.value
}).offset("wiggle"), c = g(l), E = d3.scale.ordinal().domain(d3.range(12)).rangeRoundBands([0, w]), x = d3.time.scale().range([0, w]).domain(d3.extent(l[0].values, function (e) {
return e.date
})), a = function () {
switch (!1) {
case !(w < 768):
return "%m";
case !(w < 1028):
return "%b";
default:
return "%B"
}
}(), S = d3.svg.axis().scale(x).orient("middle").ticks(d3.time.months).tickSize(f).tickFormat(d3.time.format(a)), T = d3.scale.linear().range([f, 0]).domain([0, d3.max(l, function (e) {
return d3.max(e.values, function (e) {
return e.y0 + e.y
})
})]), s = d3.scale.linear().range(["blue", "red"]), i = d3.scale.category10(), n = d3.svg.area().x(function (e) {
return x(e.date)
}).y0(function (e) {
return T(e.y0)
}).y1(function (e) {
return T(e.y0 + +e.value)
}).interpolate("cardinal"), y = d3.select(".js-streamgraph .js-graph").append("svg").attr("width", w).attr("height", f).attr("class", "streamgraph"), y.selectAll("path").data(c).enter().append("path").attr("d", function (e) {
return n(e.values)
}).attr("class", function (e) {
return u[e.key]
}).style({
stroke: "#10112f",
"stroke-opacity": .25
}), r = y.append("g").attr("class", "x-axis").call(S), r.selectAll("line").style("stroke", "white").style("opacity", .3).attr("stroke-dasharray", "5, 5"), r.selectAll("text").style("text-anchor", "middle").attr("x", E.rangeBand() / 2).attr("y", f * .5)
})
}.call(this),
function () {
$(document).on("data.loaded", function (e, t) {
var n, r, i, s, o, u, a, f, l, c, h, p, d, v, m, g, y, b, w, E, S;
return v = $(".js-graph-week"), d = v.get(0), o = t.eventSchema, v.find("svg").remove(), y = t.totals, l = {
top: 0,
right: 0,
bottom: 60,
left: 0
}, w = v.width(), a = v.height() - l.bottom, g = d3.tip().attr("class", "d3-tip").offset([-10, 0]).html(function (e) {
var t;
return t = d3.format(",")(e.value) + " " + e.metric, "<span>" + t.replace(/_/g, " ") + "</span>"
}), p = d3.keys(y[0]).filter(function (e) {
return e !== "created_at"
}), i = d3.time.format("%Y-%m-%d").parse, b = y.filter(function (e) {
var t;
return t = new Date("2013-03-10"), d3.time.week(new Date(e.created_at)).getTime() === d3.time.week(t).getTime()
}), h = d3.layout.stack()(p.map(function (e) {
return b.map(function (t) {
return {
x: i(t.created_at),
y: +t[e],
value: +t[e],
metric: e
}
})
})), E = d3.scale.ordinal().domain(h[0].map(function (e) {
return e.x
})).rangeRoundBands([0, w], .1), S = d3.scale.linear().range([a, 0]).domain([0, d3.max(h[h.length - 1], function (e) {
return e.y0 + e.y
})]), m = d3.select(".js-averages .js-graph-week").append("svg").attr("width", w + l.left + l.right).attr("height", a + l.top + l.bottom).attr("id", "average-week-barchart").attr("class", "stacked-barchart").append("svg:g").attr("transform", "translate(" + l.left + "," + l.top + ")"), s = m.append("defs").selectAll("clipPath").data(h[h.length - 1]).enter().append("clipPath").attr({
id: function (e, t) {
return "cpweek-" + t
}
}).append("rect").attr({
x: function (e) {
return E(e.x)
},
y: function (e) {
return S(e.y0 + e.y)
},
height: function (e) {
return a - S(e.y0 + e.y)
},
width: E.rangeBand(),
rx: 3
}), c = m.selectAll("g.metric").data(h).enter().append("g").attr("class", "metric").attr("id", function (e) {
return e[0].metric
}), n = c.selectAll("rect").data(Object).enter().append("rect").attr({
x: function (e) {
return E(e.x)
},
y: function (e) {
return S(e.y0 + e.y)
},
height: function (e) {
return S(e.y0) - S(e.y0 + e.y)
},
width: E.rangeBand(),
"class": function (e) {
return o[e.metric]
},
"clip-path": function (e, t) {
return "url(#cpweek-" + t + ")"
}
}).on("mouseover", g.show).on("mouseout", g.hide), m.call(g), u = d3.time.format("%A"), f = m.selectAll("text").data(E.domain()).enter().append("g").attr("class", "text-bg").attr("transform", function (e) {
return "translate(" + (E(e) + E.rangeBand() / 2) + ", " + (a + 20) + ")"
}), f.append("rect").attr({
width: function () {
return E.rangeBand()
},
height: 20,
x: -(E.rangeBand() / 2),
y: -14,
rx: 3
}), f.append("text").attr("text-anchor", "middle").text(u), r = m.append("g").attr("class", "bottom-label").attr("transform", function (e) {
return "translate( 7 , " + (a + 30) + ")"
}), r.append("rect").attr({
fill: "#10132D",
width: w - 13,
height: "24",
rx: 3
}), r.append("text").text("DAILY").style("fill", "white").attr({
x: 10,
y: 16
}), r.append("text").text("activity over an average week on GitHub.com").style("fill", "#5965B1").attr({
x: 50,
y: 16
})
})
}.call(this),
function () {
$(document).on("data.loaded", function (e, t) {
var n, r, i, s, o, u, a, f, l, c, h, p, d, v, m, g, y, b, w, E, S, x, T, N, C;
m = $(".js-graph-day"), v = m.get(0), o = t.eventSchema, m.find("svg").remove(), b = t.averageDay, c = {
top: 0,
right: 0,
bottom: 60,
left: 0
}, w = m.width(), f = m.height() - c.bottom, y = d3.tip().attr("class", "d3-tip").offset([-10, 0]).html(function (e) {
var t;
return t = d3.format(",")(e.value) + " " + e.metric, "<span>" + t.replace(/_/g, " ") + "</span>"
}), d = ["pushes", "pull_request_created", "comments", "issues_created", "follows", "gists", "watches"], a = [], T = function (e) {
var t, n;
return n = e.hour, t = e.activity, a[n] === void 0 && (a[n] = {}), a[n][t] = e.count, a[n].hour = n
};
for (N = 0, C = b.length; N < C; N++) i = b[N], T(i);
return p = d3.layout.stack()(d.map(function (e) {
return a.map(function (t) {
return {
x: t.hour,
y: +t[e],
value: +t[e],
metric: e,
hour: t.hour
}
})
})), E = d3.scale.ordinal().domain(p[0].map(function (e) {
return e.x
})).rangeRoundBands([0, w], .1), x = d3.max(p, function (e) {
return d3.max(e, function (e) {
return e.y0 + e.y
})
}), S = d3.scale.linear().range([f, 0]).domain([0, x]), g = d3.select(".js-averages .js-graph-day").append("svg").attr("width", w + c.left + c.right).attr("height", f + c.top + c.bottom).attr("id", "average-day-barchart").attr("class", "stacked-barchart").append("svg:g").attr("transform", "translate(" + c.left + "," + c.top + ")"), s = g.append("defs").selectAll("clipPath").data(p[p.length - 1]).enter().append("clipPath").attr({
id: function (e, t) {
return "cpday-" + t
}
}).append("rect").attr({
x: function (e) {
return E(e.x)
},
y: function (e) {
return S(e.y0 + e.y)
},
height: function (e) {
return f - S(e.y0 + e.y)
},
width: E.rangeBand(),
rx: 3
}), h = g.selectAll("g.metric").data(p).enter().append("g").attr("class", "metric").attr("id", function (e) {
return e[0].metric
}), n = h.selectAll("rect").data(Object).enter().append("rect").attr({
x: function (e) {
return E(e.x)
},
y: function (e) {
return S(e.y0 + e.y)
},
height: function (e) {
return S(e.y0) - S(e.y0 + e.y)
},
width: E.rangeBand(),
"class": function (e) {
return o[e.metric]
},
"clip-path": function (e, t) {
return "url(#cpday-" + t + ")"
}
}).on("mouseover", y.show).on("mouseout", y.hide), g.call(y), u = d3.time.format("%H"), l = g.selectAll("text").data(E.domain()).enter().append("g").attr("class", "text-bg").attr("transform", function (e) {
return "translate(" + (E(e) + E.rangeBand() / 2) + ", " + (f + 20) + ")"
}), l.append("rect").attr({
width: function () {
return E.rangeBand()
},
height: 20,
x: -(E.rangeBand() / 2),
y: -14,
rx: 3
}), l.append("text").attr("text-anchor", "middle").text(function (e, t) {
var n;
return n = u.parse(e), t === 0 || t === 12 ? d3.time.format("%I%p")(n).toLowerCase().substr(0, 3) : d3.time.format("%I")(n).replace(/^0/, "")
}), r = g.append("g").attr("class", "bottom-label").attr("transform", function (e) {
return "translate( 12 , " + (f + 30) + ")"
}), r.append("rect").attr({
fill: "#10132D",
width: w - 24,
height: "24",
rx: 3
}), r.append("text").text("HOURLY").style("fill", "white").attr({
x: 10,
y: 16
}), r.append("text").text("activity over an average week on GitHub.com").style("fill", "#5965B1").attr({
x: 56,
y: 16
})
})
}.call(this),
function () {
$(document).on("data.loaded", function (e, t) {
var n, r, i, s, o, u, a, f, l, c, h, p, d, v, m;
return f = $(".js-community-map"), a = f.get(0), f.find("svg").remove(), o = {
top: 0,
right: 0,
bottom: 100,
left: 0
}, v = f.width() - o.left - o.right, s = f.height() - o.top - o.bottom, r = t.drinkups, h = t.sponsorships, n = r.concat(h), n = n.filter(function (e) {
return e.lat && e.lon
}), u = d3.nest().key(function (e) {
return "" + e.lat + ":" + e.lon
}).rollup(function (e) {
return {
lat: parseFloat(e[0].lat),
lon: parseFloat(e[0].lon),
place: e[0].location,
events: e.map(function (e) {
return e.name
})
}
}).entries(n), p = n[0].date, i = n[n.length - 1].date, m = d3.time.scale().domain([p, i]).range([0, v]), c = d3.geo.equirectangular().precision(.1), d = d3.tip().attr("class", "d3-tip community").offset([-10, 0]).html(function (e) {
var t;
return t = "<h3>" + e.values.place + "</h3>", "" + t + " <span>" + e.values.events.join(", ") + "</span>"
}), l = d3.geo.path().projection(c), d3.json("/data/world-wo-a-110m.json", function (e, t) {
var n, r, i, o, a, f;
return e != null ? console.log(e) : (i = topojson.feature(t, t.objects.land), r = topojson.mesh(t, t.objects.countries, function (e, t) {
return e !== t
}), c.scale(1).translate([0, 0]), n = l.bounds(i), o = .95 / Math.max((n[1][0] - n[0][0]) / v, (n[1][1] - n[0][1]) / s), a = [(v - o * (n[1][0] + n[0][0])) / 2, (s - o * (n[1][1] + n[0][1])) / 2], c.scale(o).translate(a), f = d3.select(".js-community-map").append("svg").attr("id", "community-map map-graphic").attr("width", v).attr("height", s).call(d), f.insert("path").datum(i).attr("class", "land").attr("d", l), f.insert("path").datum(r).attr("class", "borders").attr("d", l), f.selectAll("circle").data(u).enter().append("circle").attr("class", "community-event").attr("r", 3).attr("id", function (e) {
return e.name
}).on("mouseover", function (e) {
return d3.select(this).transition().duration(200).attr("r", 5), d.show(e)
}).on("mouseout", function (e) {
return d3.select(this).transition().duration(200).attr("r", 3), d.hide(e)
}).each(function (e) {
var t, n, r;
return r = c([e.values.lon, e.values.lat]), t = r[0], n = r[1], d3.select(this).attr("cx", t).attr("cy", n)
}))
})
})
}.call(this),
function () {
$.when($.ajax("/data/totals.csv"), $.ajax("/data/shipped-drinkups.csv"), $.ajax("/data/requested-sponsorships.csv"), $.ajax("/data/daily-activity.csv"), $.ajax("/data/sample-events.csv")).then(function (e, t, n, r, i) {
var s, o, u, a, f, l, c, h, p;
return p = d3.csv.parse(e[0]), a = d3.csv.parse(t[0]), h = d3.csv.parse(n[0]), s = d3.csv.parse(r[0]), l = d3.csv.parse(i[0]), u = ["#703293", "#9452A0", "#A3A3D1", "#6082C1", "#70C8E4", "#10ABD7", "#8ED4D9"], o = d3.scale.ordinal().range(u).domain(u.length), $(window).ready(function () {
return $("#frontpage .content").delay(300).fadeIn(1600)
}), f = {
total_pushes: "pushes",
total_pull_requests: "pulls",
pull_request_created: "pulls",
total_comments: "comments",
comments: "comments",
total_issues: "issues",
issues_created: "issues",
gists: "gists",
follows: "follows",
watches: "watches",
pushes: "pushes"
}, c = function () {
return $(document).trigger("data.loaded", {
totals: p,
drinkups: a,
sponsorships: h,
averageDay: s,
eventSchema: f
})
}, c(), $(window).on("resize", c), $(document).trigger("event", d3.shuffle(l)[0]), setInterval(function () {
return $(document).trigger("event", d3.shuffle(l)[0])
}, 3e3)
})
}.call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment