Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. ...
  2. F = d3.time.format("%Y%U"), # Time formatter for "${year}${week_number}", with year as a 4 digit number
  3. q = d3.time.format("%m-%y"), # Time formatter for month-year, each as a 2 digit integer
  4. y = d3.time.format("%b"), # Time formatter for abbreviated month name
  5. I = {}, # Keys are "$year$week_number" from F above, values are [Date, Score] pairs
  6. j = {}, # Keys are "$month-$year" from q above, values are a count of how many $week_numbers begin in that month
  7. a.forEach(function(t) { # Function to set I above
  8. var e;
  9. return
  10. e = F(t[0]), # Get "$year$week_number" for this day
  11. I[e] || (I[e] = []), # Default I[e] to an empty list, if its not already been initialized
  12. I[e].push(t) # Push this [Date, Score] pair onto the appropriate keys array
  13. }),
  14. I = d3.entries(I), # Convert associative array to array of objects with {key, value} attributes
  15. I.forEach(function(t) { # Function to set j above
  16. var e;
  17. return
  18. e = q(t.value[0][0]), # Get "$month-$year" for first day of this week (noteworthy: January 1st is a different week from December 31st, even if they fall on the same calendar line)
  19. j[e] || (j[e] = [t.value[0][0], 0]),# If key is not already initialized, create it with [First_Date, 0]
  20. j[e][1] += 1 # Increment this months counter by one
  21. }),
  22. j = d3.entries(j).sort(function(t, e) { # Convert hash of j[$month-$year] = [first_day_a_week_starts_in_this_month, counter_of_weeks_that_begin_in_this_month] to array of {key, value} objects
  23. return d3.ascending(t.value[0], e.value[0])
  24. }),
  25. ...
  26. M.selectAll("text.month") # Now were working on months
  27. .data(j) # Using the $month-$year mapping
  28. .enter().append("text") # Make the text labels
  29. .attr("x", function(e) { # Set the x coordinate to $cell_size * $offset
  30. var n;
  31. return
  32. n = t * d, # Calculate $cell_size * $offset
  33. d += e.value[1], # Then increment the offset by the size of this month
  34. n # Then return the previously calculated value
  35. })
  36. .attr("y", -5) # Set the y coord
  37. .attr("class", "month") # Class it up
  38. .style("display", function(t) { # If it would be on the very left edge, hide it
  39. return t.value[1] <= 2 ? "none" : void 0
  40. })
  41. .text(function(t) { # The text is the abbreviated month name ("Jan")
  42. return y(t.value[0])
  43. }),
  44. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement