removeAllSubviews: ->
@subviews.forEach @removeSubview, this
- @subviews = new ViewList
+ # @subviews = new ViewList
this
/* * * * Events * * * */
- bubbleEvent: (evt) ->
+ bubbleEventDown: (evt) ->
@invokeSubviews 'trigger', ...arguments
this
- redispatch: (evt) ->
- @trigger ...arguments
+ redispatch: (evt, ...args) ->
+ @trigger evt, this, ...args
this
onlyOnReturn: (fn, ...args) ->
json = ChartOptionView.__super__.toTemplateLocals ...
json.id or= _.camelize json.name
json.value ?= ''
- json.value = JSON.stringify v if v = json.value and (_.isArray(v) or _.isPlainObject(v))
+ v = json.value
+ json.value = JSON.stringify(v) if v and ( _.isArray(v) or _.isPlainObject(v) )
json
/**
* @type String
* @readonly
*/
- CHART_SPEC_URL : null
+ SPEC_URL : null
/**
* Chart-type name.
return this if @ready
proto = @constructor::
jQuery.ajax do
- url : @CHART_SPEC_URL
+ url : @SPEC_URL
success : (spec) ~>
+ proto.spec = spec
proto.options_ordered = spec
proto.options = _.synthesize spec, -> [it.name, it]
proto.ready = true
data = @getData()
options = @getDefaultOptions() import @transform @model, @view
viewport = @getElementsForRole 'viewport'
+ return @lastChart unless data?.length and viewport?.length
@lastChart = @renderChart data, viewport, options, @chart
class exports.DygraphsChartType extends ChartType
__bind__ : <[ dygNumberFormatter dygNumberFormatterHTML ]>
- CHART_SPEC_URL : '/schema/dygraph.json'
+ SPEC_URL : '/schema/dygraph.json'
+
+ # NOTE: ChartType.register() must come AFTER `typeName` declaration.
typeName : 'dygraphs'
ChartType.register this
{ width, height }
+ /**
+ * Resizes the HTML viewport.
+ */
resizeViewport: ->
size = @determineSize()
@getElementsForRole 'viewport' .css size
@model.once 'ready', @onReady, this
onReady: ->
- console.log "#this.onReady! #{@model.metrics}"
+ # console.log "#this.onReady! #{@model.metrics}"
dataset = @model
@model.metrics.each @addMetric, this
@dataset_view = new DataSetView {@model, @graph_id, dataset, @datasources}
{ @graph_id, @datasources } import attrs
addMetric: (metric) ->
- console.log "#this.addMetric!", metric
+ # console.log "#this.addMetric!", metric
return metric if @metric_views.findByModel metric
view = new MetricEditView {model:metric, @graph_id, dataset:@model, @datasources}
.on 'metric-update', @onUpdateMetric, this
metric
removeMetric: (metric) ->
- console.log "#this.removeMetric!", metric
+ # console.log "#this.removeMetric!", metric
return unless view = @metric_views.findByModel metric
@metric_views.remove view
@removeSubview view
@$el.css 'min-height', newMinHeight
onUpdateMetric: ->
- console.log "#this.onUpdateMetric!"
+ # console.log "#this.onUpdateMetric!"
@trigger 'metric-change', @model, this
@render()
BaseModel::initialize ...
@set 'metrics', @metrics, {+silent}
@on 'change:metrics', @onMetricChange, this
+ # @metrics.on 'add remove reset', ~>
+ # @trigger 'change:metrics', @metrics, this
load: (opts={}) ->
unless @metrics.length
return @triggerReady()
- console.log "#this.load()..."
+ # console.log "#this.load()..."
@wait()
@loading = true
@trigger 'load', this
Seq @metrics.models
.parEach_ (next, metric) ->
metric.once 'ready', next.ok .load()
- # .parEach_ (next, metric) ->
- # metric.on 'load-data-success', next.ok .loadData()
.seq ~>
- console.log "#{this}.load() complete!"
+ # console.log "#{this}.load() complete!"
@loading = false
@unwait() # terminates the `load` wait
@triggerReady()
*/
getData: ->
return [] unless @ready
- _.zip ...@getColumns()
+ columns = @getColumns()
+ if columns?.length
+ _.zip ...columns
+ else
+ []
/**
* @returns {Array<Array>} List of all columns (including date column).
newMetric: ->
index = @metrics.length
@metrics.add m = new Metric { index, color:ColorBrewer.Spectral[11][index] }
- # @get 'metrics' .push m.attributes
+ m.on 'ready', ~> @trigger 'metric-data-loaded', this, m
# @trigger 'change:metrics', this, @metrics, 'metrics'
# @trigger 'change', this, @metrics, 'metrics'
m
onMetricChange: ->
- console.log "#this.onMetricChange! ready=#{@ready}"
+ # console.log "#this.onMetricChange! ready=#{@ready}"
@resetReady()
@load()
template : require 'kraken/template/dataset'
events:
- 'click .new-metric-button' : 'newMetric'
- 'click .metrics .dataset-metric' : 'selectMetric'
+ 'click .new-metric-button' : 'onNewMetric'
+ 'click .delete-metric-button' : 'onDeleteMetric'
+ 'click .metrics .dataset-metric' : 'selectMetric'
views_by_cid : {}
active_view : null
@model.metrics
.on 'add', @addMetric, this
.on 'remove', @removeMetric, this
+ .on 'change', @onMetricChange, this
.on 'reset', @addAllMetrics, this
- newMetric: ->
- console.log "#this.newMetric!"
- # triggers 'add' on @model.metrics
- @model.newMetric()
- false
-
addMetric: (metric) ->
- console.log "#this.addMetric!", metric
+ # console.log "#this.addMetric!", metric
if @views_by_cid[metric.cid]
@removeSubview that
delete @views_by_cid[metric.cid]
view = @addSubview new DataSetMetricView {model:metric, @graph_id}
@views_by_cid[metric.cid] = view
- # @$ '.metrics' .append view.render().el
@trigger 'add-metric', metric, view, this
@render()
view
removeMetric: (metric) ->
- console.log "#this.removeMetric!", metric
+ if metric instanceof [jQuery.Event, Event]
+ metric = @getMetricForElement metric.target
+ # console.log "#this.removeMetric!", metric
+ return unless metric
if view = @views_by_cid[metric.cid]
@removeSubview view
delete @views_by_cid[metric.cid]
view
addAllMetrics: ->
- console.log "#this.addAllMetrics! --> #{@model.metrics}"
+ &n