## bugs
-- defaults should only be filtered out for toURL() and toJSON()
- redraw button!
-- valueFormatter, axisLabelFormatter
- (Safari) dygraph on safari has a bug parsing dates, bug http://code.google.com/p/dygraphs/issues/detail?id=287
-- (Chrome) When changing a checkbox, the graph doesn't seem to get updated. The model is updated though, and when a non-checkbox option is modified the checkbox-option is also updated in the view
- - E.g. when setting showRoller=true , the input doesn't get displayed right away. Also, when resetting to showRoller=false it doesn't disappear
-- huge issues coordinating subview insertion of HTML blocks -- need to add events and provide an abstraction
## ux
console.log 'StateChange!\n\n', String(root.location), '\n\n'
- # If we got querystring args, apply them to the graph
data = {}
- if String(root.location).split '?' .1
+
+ # Process URL
+ loc = String root.location
+
+ # If we got querystring args, apply them to the graph
+ if loc.split '?' .1
data = _.uncollapseObject _.fromKV that.replace('#', '%23')
-
- # # yarr, have to do options separately or everything goes to shit
- # options = delete data.options
- # graph.model.set data, {+silent}
- # graph.chartOptions options, {+silent}
- # # Flush all changes once the DOM settles
- # _.delay do
- # ->
- # graph.change()
- # # graph.scaffold.invoke 'change'
- # 50
+ # Extract slug from URL
+ if match = /\/graph\/(?!view)([^\/?]+)/i.exec loc
+ data.slug = match[1]
vis = root.vis = new VisModel data
graph = root.graph = new VisView do
# console.log ' slug: ', slug
# console.log ' params:', req.params
unless _.str.include slug, '.'
- {pathname, search} = req.info
+ {pathname, search or ''} = req.info
req.url = "#pathname/view#search"
req.params.action = 'view'
next()
json
- toKVPairs: ->
+ toKVPairs: (keepSlug=false) ->
kvo = @toJSON()
+ delete kvo.slug unless keepSlug
# console.group 'toKVPairs'
# console.log '[IN]', JSON.stringify kvo
opts = kvo.options = _.clone kvo.options
# console.groupEnd()
_.collapseObject kvo
+ toKV: (keepSlug=false) ->
+ _.toKV @toKVPairs keepSlug
+
+
+ /**
+ * @returns {String} URL identifying this model.
+ */
+ toURL: ->
+ slug = @get 'slug', ''
+ slug = "/#slug" if slug
+ "/graph#slug?#{@toKV(false)}"
toString: -> "#{@ctorName}(id=#{@id})"
@scaffold.collection.reset that if o.graph_spec
@scaffold.on 'change', (scaffold, value, key, field) ~>
- console.log "scaffold.change!", key, value, field
+ # console.log "scaffold.change!", key, value
@model.setOption key, value, {+silent} #unless field.isDefault()
options = @model.get 'options', {}