initialize: ->
BaseModel::initialize ...
- @getGraphs null @trigger 'ready'
-
+ @getGraphs null, ~> @triggerReady
defaults: ->
name : null
# addGraph: (graph, tabName) ->
# ...
-
- getGraphIds : (cb, tabs) ->
- console.log('[getGraphIds]\tentering')
- tab_ids = _.keys(tabs)
- tab_objs = _.values(tabs)
- graph_ids = _.map tab_objs, (tab_obj) -> tab_obj.graph_ids
- kvlists = _.zip(tab_ids, graph_ids)
- # console.log(keys)
- # console.log(values)
- # console.log(kvlists)
- cb null, kvlists
-
- expand : (cb, kvlist) ->
- console.log('[expand]\tentering')
- # console.log(kvlist)
- [key, vlist] = kvlist
- # console.log('[expand]\tkey:')
- # console.log(key)
- # console.log('[expand]\tvlist:')
- # console.log(vlist)
- tmp = [[key, v] for v of vlist]
- # console.log('[expand]\ttmp:')
- # console.log(tmp)
- cb null [[key, v] for v of vlist]
-
nest : (cb, records) ->
console.log('[nest]\tentering')
- console.log('[nest]\torig:')
- console.log(records)
- tab_tree = d3.nest()
+ # console.log('[nest]\torig:')
+ # console.log(records)
+ graph_map = d3.nest()
.key (graph_rec) ->
graph_rec[0]
- .key (graph_rec) ->
- graph_rec[1]
- .rollup (arr) -> arr[0][2]
- # .key (graph_rec) ->
- # graph_rec[2]
+ .rollup (arr) ->
+ arr[0][1]
.map(records)
- console.log('[nest]\tnew:')
- console.log(tab_tree)
- cb null tab_tree
+ # console.log('[nest]\tnew:')
+ # console.log(graph_map)
+ cb null graph_map
show : (cb, obj) ->
console.log('[show]')
pushAsync : (cb, arr) ->
(err, elem) ->
- console.log('[appendInner]\tentering')
- console.log('[appendInner]\tarr:')
- console.log(arr)
arr.push elem
cb null
-
-
+
getGraphs : (err, cb) ->
console.log('[getGraphs]\tentering')
- _this = this
- Seq [@tabs]
- .seq_ @getGraphIds
- # .parEach_ @show
- .flatten(false)
- # .parEach_ @show
- .parMap_ @expand # turn ['core', ['x','y','z']] into [['core','x'],['core','y'],['core','z']]
- # .parEach_ @show
- .flatten(false)
- .flatten(false)
- # .parEach_ @show
- .parEach_ (next, kv) ->
- console.log('this:')
- console.log(this)
- Graph.lookup kv[1], _this.pushAsync next, kv
+ # consolidate graph_ids to one array
+ graph_ids = _(@tabs).chain().values().map((tab_obj) -> tab_obj.graph_ids).flatten().value()
+
+ Seq [graph_ids]
+ .flatten()
+ .parMap_ (next, graph_id) ->
+ next null [graph_id]
+ .parEach_ (next, graph_id_arr) ~>
+ Graph.lookup graph_id_arr[0], @pushAsync next, graph_id_arr
+ # Graph.lookup graph_id_arr[0], (err, el) ->
+ # graph_id_arr.push el
+ # next null
# .parEach_ @show
.unflatten()
- .seq_ @nest
- .parEach_ @show
+ .seq_ (next, graph_tuples) ->
+ # console.log('[setter]\tgraph_tuples:')
+ # console.log(graph_tuples)
+ @graphs = _.generate graph_tuples
+ # console.log('[setter]\t@graphs:')
+ # console.log(@graphs)
+ cb null
+ # .parEach_ @show
className : 'dashboard'
template : require 'kraken/template/dashboard/dashboard'
- graph_ids : <[
- unique_visitors
- reach
- pageviews
- pageviews_mobile
- pageviews_mobile_target
- commons
- articles
- articles_per_day
- edits
- new_editors
- active_editors
- active_editors_target
- very_active_editors
- ]>
-
- core_tab :
- graph_ids : <[
- unique_visitors
- pageviews
- pageviews_mobile
- pageviews_mobile_target
- new_editors
- active_editors
- active_editors_target
- ]>
- name: ".core-graphs-pane"
-
- other_tab :
- graph_ids : <[
- reach
- commons
- articles
- articles_per_day
- edits
- very_active_editors
- ]>
- name: ".other-graphs-pane"
-
- dev_tab :
- graph_ids : <[
- mobile_devices
- mobile_devices_browsers
- mobile_devices_applications
- ]>
- name: ".dev-graphs-pane"
events:
# Select the whole permalink URI text when it receives focus.
ready : false
- constructor: function DashboardView
+ constructor: function DashboardView(options={})
+ @model = options.model
@subviews = []
@graphs = new GraphList
Backbone.View ...
BaseView::initialize ...
# @graphs.on 'add', @attachGraphs, this
# @graphs.on 'add', @attachGraph, this
- @load()
+ console.log('[dashboard-view::initialize]\tentering')
+ @model.on('ready', @load, this)
# FIXME:
# TODO:
# - only render graph when scrolling makes it visible
load: ->
- @addTab(@core_tab)
- @addTab(@other_tab)
- @addTab(@dev_tab)
+ console.log('[dashboard-view::load]\tentering')
+ _.map(@model.tabs, @addTab)
addTab: (tab) ->
+ console.log('[dashboard-view::addTab]\tentering')
self = this
- Seq(tab.graph_ids)
- .parMap (id) ->
- Graph.lookup id, this
+ graphs = _(tab.graph_ids).map((graph_id) -> @model.graphs[graph_id])
+ Seq(graphs)
.parMap (graph) ->
self.graphs.add graph
this null, new GraphDisplayView {model:graph}
self.subviews.push view
view.isAttached = true
-
### Tabs {{{
onTabShown: (e) ->
} = require 'kraken/chart'
{ Graph, GraphList, GraphDisplayView,
} = require 'kraken/graph'
-{ DashboardView,
+{ DashboardView, Dashboard,
} = require 'kraken/dashboard'
main = ->
# Instantiate model & view
root.app = new AppView ->
- @view = root.dashboard = new DashboardView {@model}
+ @model = root.dashboard = new Dashboard
+ @view = root.view = new DashboardView {@model}
jQuery main