{ GraphModel, GraphOption, GraphOptionList, TagSet,
} = require 'kraken/graph/model'
+root = do -> this
DEBOUNCE_RENDER = exports.DEBOUNCE_RENDER = 100ms
collectionType : GraphOptionList
subviewType : GraphOptionView
+ # GraphView will set this
+ ready : false
+
+
initialize : ->
- Scaffold::initialize ...
@render = _.debounce @render.bind(this), DEBOUNCE_RENDER
+ Scaffold::initialize ...
render: ->
- console.log "#this.render() -> .isotope()"
+ # console.log "#this.render() -> .isotope()"
@__super__.render ...
+ return this unless @ready
@$el.isotope do
itemSelector : '.field.option'
layoutMode : 'masonry'
masonry : columnWidth : 10
# itemPositionDataEnabled : true
- # animationEngine : 'jquery'
/**
* Add a GraphOption to this scaffold, rerendering the isotope
GraphView = exports.GraphView = BaseView.extend do # {{{
- __bind__ : <[ render renderAll ]>
+ __bind__ : <[ render renderAll onReady ]>
ctorName : 'GraphView'
tagName : 'section'
className : 'graph'
'keypress form.options .value' : 'onKeypress'
'submit form.options' : 'onSubmit'
+ ready: false
+
+
initialize : (o={}) ->
@model or= new GraphModel
@model.on 'change', @render, this
@model.on 'change:options', ~>
changes = @model.changedAttributes()
- console.log 'Model.changed(options) ->', changes
+ # console.log 'Model.changed(options) ->', changes
@chartOptions changes, {+silent}
@build()
@scaffold.collection.reset that if o.graph_spec
@scaffold.on 'change', (scaffold, value, key, field) ~>
- console.log "scaffold.change!", value, key, field
- @model.setOption key, value, {+silent}
+ # console.log "scaffold.change!", value, key, field
+ @model.setOption key, value, {+silent} unless field.isDefault()
options = @model.get 'options', {}
@chartOptions options, {+silent}
- _.delay @renderAll, DEBOUNCE_RENDER
+ _.delay @onReady, DEBOUNCE_RENDER
+ onReady: ->
+ @ready = @scaffold.ready = true
+ @renderAll()
chartOptions: (values, opts) ->
# Handle @chartOptions(k, v, opts)
render: ->
+ return this unless @ready
options = @chartOptions()
w = options.width or= @scaffold.get 'width' .getValue() or 480
h = options.height or= @scaffold.get 'height' .getValue() or 320
# Remove old style, as it confuses dygraph after options update
@viewport.attr 'style', ''
- console.log "#this"
- console.log do
- " .viewport.{ width=%s, height=%s, style=%s }"
- @viewport.css('width')
- @viewport.css('height')
- @viewport.attr 'style'
- # @viewport
- console.log ' .options:', JSON.stringify options
+ # console.log "#this"
+ # console.log do
+ # " .viewport.{ width=%s, height=%s, style=%s }"
+ # @viewport.css('width')
+ # @viewport.css('height')
+ # @viewport.attr 'style'
+ # console.log ' .options:', JSON.stringify options
# @chart?.destroy()
unless @chart
@chart.updateOptions options
@chart.resize w, h
+ path = root.location?.path or '/'
+ url = "#path?#{@toKVPairs()}"
+ # console.log 'History.pushState', url
+ History.pushState url, @model.get('name', root.document?.title or ''), url
+
this
renderAll: ->
+ return this unless @ready
_.invoke @scaffold.subviews, 'render'
@scaffold.render()
@render()
$(evt.target).submit() if evt.keyCode is 13
onSubmit: ->
- console.log "#this.onSubmit!"
+ # console.log "#this.onSubmit!"
@render()
false
toKVPairs: ->
- @model.toKVPairs ...
+ @model.toKVPairs.apply @model, arguments
toString: -> "#{@ctorName}(#{@model})"
# }}}
-{_, op} = require 'kraken/util'
-{BaseView} = require 'kraken/base'
-{ Field, FieldList, FieldView, Scaffold
-} = require 'kraken/scaffold'
+{ _, op
+} = require 'kraken/util'
+{ BaseView, BaseModel, BaseList,
+} = require 'kraken/base'
+{ Field, FieldList, FieldView, Scaffold,
+} = require 'kraken/scaffold'
{ GraphView, GraphModel, TagSet,
GraphOption, GraphOptionList, GraphOptionView,
GraphOptionsScaffold,
-} = require 'kraken/graph'
+} = require 'kraken/graph'
root = do -> this
# Create the Graph Scaffold
main = ->
- graph = root.graph = new GraphView {
- graph_spec: CHART_OPTIONS_SPEC
- }
+ History.Adapter.bind window, 'statechange', ->
+ console.log 'StateChange!', String root.location
+
+ graph = root.graph = new GraphView do
+ graph_spec : CHART_OPTIONS_SPEC
+
+ # If we got querystring args, apply them to the graph
+ if root.location?.search.slice 1
+ g = _.uncollapseObject _.fromKVPairs that
+ # yarr, have to do options separately or everything goes to shit
+ options = delete g.options
+ graph.model.set g, {+silent}
+ graph.chartOptions options, {+silent}
+
+ # Flush all changes once the DOM settles
+ _.defer do
+ -> graph.scaffold.invoke 'change'
+ 50
+
$ '#content .inner' .append graph.el