{"url":"https://api.github.com/gists/1573240","forks_url":"https://api.github.com/gists/1573240/forks","commits_url":"https://api.github.com/gists/1573240/commits","id":"1573240","node_id":"MDQ6R2lzdDE1NzMyNDA=","git_pull_url":"https://gist.github.com/1573240.git","git_push_url":"https://gist.github.com/1573240.git","html_url":"https://gist.github.com/mbostock/1573240","files":{"evaluator.js":{"filename":"evaluator.js","type":"text/javascript","language":"JavaScript","raw_url":"https://gist.githubusercontent.com/mbostock/1573240/raw/8ee9fa6dba17986a5a056a8f804a6b7d251752fc/evaluator.js","size":463,"truncated":false,"content":"var options = require(\"./evaluator-config\"),\n    cube = require(\"cube\"),\n    server = cube.server(options);\n\nserver.register = function(db, endpoints) {\n  cube.evaluator.register(db, endpoints);\n  cube.visualizer.register(db, endpoints);\n  endpoints.http.push(cube.endpoint.exact(\"/us/map\", cube.endpoint.file(\"static/us/map.html\")));\n  endpoints.http.push(cube.endpoint.exact(\"/us/states.json\", cube.endpoint.file(\"static/us/states.json\")));\n};\n\nserver.start();\n","encoding":"utf-8"},"map.html":{"filename":"map.html","type":"text/html","language":"HTML","raw_url":"https://gist.githubusercontent.com/mbostock/1573240/raw/206a3f49a2c9c3939896a4fcba69256d0f2ed5e0/map.html","size":2214,"truncated":false,"content":"<!DOCTYPE html>\n<script src=\"/d3/d3.js?2.7.1\"></script>\n<style>\n\nbody {\n  margin: 0 auto 0 auto;\n  width: 1920px;\n}\n\nsvg, canvas {\n  position: absolute;\n}\n\npath {\n  fill: none;\n  stroke: #ccc;\n}\n\n</style>\n<svg width=\"1920\" height=\"1080\"></svg>\n<canvas width=\"1920\" height=\"1080\"></canvas>\n<script>\n\nvar canvas = d3.select(\"canvas\"),\n    w = +canvas.attr(\"width\"),\n    h = +canvas.attr(\"height\");\n\nvar duration = 1000 * 60 * 30, // 30 minutes\n    start = new Date(Date.now() - duration),\n    utc = d3.time.format.iso;\n\nvar socket = new WebSocket(\"ws://localhost:1081/1.0/event/get\"),\n    events = []; // cache of visible events\n\nvar context = canvas.node().getContext(\"2d\"),\n    image = context.createImageData(w, h);\n\nvar projection = d3.geo.albersUsa()\n    .scale(2000)\n    .translate([w / 2, h / 2]);\n\n// Save as on alt-click.\ncanvas.on(\"click\", function() {\n  if (d3.event.altKey) window.open(this.toDataURL());\n});\n\n// Display the states in the background.\nd3.json(\"/us/states.json\", function(collection) {\n  d3.select(\"svg\").selectAll(\"path\")\n      .data(collection.features)\n    .enter().append(\"path\")\n      .attr(\"d\", d3.geo.path()\n      .projection(projection));\n});\n\n// On open, send the event request. Here, a generic event type called \"event\".\nsocket.onopen = function() {\n  socket.send(JSON.stringify({\n    expression: \"event(location)\",\n    start: utc(start)\n  }));\n};\n\n// On message, record the event.\nsocket.onmessage = function(message) {\n  var d = JSON.parse(message.data),\n      l = d.data.location,\n      p = projection(l),\n      x = Math.max(0, Math.min(w - 1, Math.round(p[0]))),\n      y = Math.max(0, Math.min(h - 1, Math.round(p[1]))),\n      i = w * y + x,\n      j = i << 2;\n  d.time = new Date(d.time);\n  d.next = events[i];\n  events[i] = d;\n  image.data[j + 3] = 255;\n  d3.timer(draw);\n};\n\n// Expire old events.\nsetInterval(function() {\n  var i = -1,\n      n = w * h,\n      o,\n      j,\n      expire = new Date(Date.now() - duration);\n  while (++i < n) {\n    if ((o = events[i]) && (o.time < expire)) {\n      image.data[(i << 2) + 3] = 0;\n      events[i] = null;\n      d3.timer(draw);\n    }\n  }\n}, 5000);\n\nfunction draw() {\n  context.putImageData(image, 0, 0);\n  return true;\n}\n\n</script>\n","encoding":"utf-8"},"readme.md":{"filename":"readme.md","type":"text/markdown","language":"Markdown","raw_url":"https://gist.githubusercontent.com/mbostock/1573240/raw/ad9d27c2ef54678406c16cef7d279a82e20d316f/readme.md","size":188,"truncated":false,"content":"An implementation of a realtime event map, seen here: <http://square.github.com/cube/>\n\nYou can obtain [states.json](http://mbostock.github.com/d3/data/us-states.json) from the D3 website.","encoding":"utf-8"}},"public":false,"created_at":"2012-01-07T00:31:01Z","updated_at":"2016-02-09T01:02:26Z","description":"Cube Realtime Map","comments":0,"user":null,"comments_enabled":true,"comments_url":"https://api.github.com/gists/1573240/comments","owner":{"login":"mbostock","id":230541,"node_id":"MDQ6VXNlcjIzMDU0MQ==","avatar_url":"https://avatars.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","user_view_type":"public","site_admin":false},"forks":[],"history":[{"user":{"login":"mbostock","id":230541,"node_id":"MDQ6VXNlcjIzMDU0MQ==","avatar_url":"https://avatars.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","user_view_type":"public","site_admin":false},"version":"67ff073d6e6b34e0dda674c2e4302eef4ec7968b","committed_at":"2012-01-07T00:31:01Z","change_status":{"total":116,"additions":116,"deletions":0},"url":"https://api.github.com/gists/1573240/67ff073d6e6b34e0dda674c2e4302eef4ec7968b"}],"truncated":false}