-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdashboard.js.coffee
57 lines (39 loc) · 2.18 KB
/
dashboard.js.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
ready = ->
# Because Chartkick requires an ID on the div where the chart is being inserted
for panel_id in ['left-panel', 'right-panel', 'bottom-row-1', 'bottom-row-2']
for element, i in $("##{panel_id} .panel-wrapper .stage")
$(element).attr 'id', "#{panel_id}-stage-#{i + 1}"
$('#main-panel .panel-wrapper .stage').attr 'id', 'main-panel-stage'
place_chart = (title, type, id, metric, options = {}) ->
$('#' + id).siblings('.title').text(title)
if options.onclick
options = $.extend options,
library:
plotOptions:
series:
point:
events:
click: (event) ->
options.onclick this.category, this.y
chart:
events:
load: ->
$("##{id} .highcharts-axis-labels text").click ->
options.onclick $(this).text()
new Chartkick[type + 'Chart'] id, "/dashboard/data/#{metric}", options
user_click_fn = (label, value) -> window.location.href = "/users/#{label}"
tweet_click_fn = (label, value) -> window.location.href = "/tweets/#{label}"
place_chart 'Top Tweeters', 'Bar', 'left-panel-stage-1', 'top_tweeters', onclick: user_click_fn
place_chart 'Top Retweeters', 'Bar', 'left-panel-stage-2', 'top_retweeters', onclick: user_click_fn
place_chart 'Original Tweets Over Time', 'Column', 'main-panel-stage', 'original_tweets_over_time',
library:
xAxis:
labels:
step: 80
place_chart 'Most Favorited Tweets', 'Bar', 'right-panel-stage-1', 'most_favorited_tweets', onclick: tweet_click_fn
place_chart 'Most Retweeded Tweets', 'Bar', 'right-panel-stage-2', 'most_retweeted_tweets', onclick: tweet_click_fn
$(document).ready ready
$(document).on 'page:load', ready