{Parsers, ParserMixin} = require 'kraken/util/parser'
+KNOWN_LIBRARIES = exports.KNOWN_LIBRARIES = {}
+
/**
* @class Specification for an option.
*/
* @class Abstraction of a charting library, encapsulating its logic and options.
*/
class exports.ChartLibrary extends EventEmitter
+
+ @lookupLibrary = (name) ->
+ KNOWN_LIBRARIES[name]
+
/**
* Ordered ChartOption objects.
* @type ChartOption[]
*/
(@name, options) ->
@options_ordered = _.map options, (opt) ~> new ChartOption this, opt
- @options = _.synthesize @options, -> [it.name, it]
+ @options = _.synthesize @options_ordered, -> [it.name, it]
+
+ # register library
+ KNOWN_LIBRARIES[@name] = this
/**
getParserFor: (name) ->
@getParser @get(name).type
-
+ parseOption: (name, value) ->
+ @getParserFor(name)(value)
Seq = require 'seq'
{ _, op,
} = require 'kraken/util'
+{ ChartLibrary, DygraphsLibrary,
+} = require 'kraken/chart'
{ BaseView, BaseModel, BaseList,
} = require 'kraken/base'
-{ Field, FieldList, FieldView, Scaffold,
+{ Field, FieldList, FieldView, Scaffold,
} = require 'kraken/scaffold'
-{ GraphOption, GraphOptionList, GraphOptionView,
- GraphOptionsScaffold, TagSet,
+{ GraphOption, GraphOptionList, GraphOptionView,
+ GraphOptionsScaffold, TagSet,
} = require 'kraken/graph'
{ VisView, VisModel,
} = require 'kraken/vis'
# Create the Graph Scaffold
main = ->
- opts = root.CHART_DEFAULT_OPTIONS = {}
- for opt of root.CHART_OPTIONS_SPEC
- opts[opt.name] = opt.default
+ # opts = root.CHART_DEFAULT_OPTIONS = {}
+ # for opt of root.CHART_OPTIONS_SPEC
+ # opts[opt.name] = opt.default
+
+ dyglib = new DygraphsLibrary CHART_OPTIONS_SPEC
# TODO: create a preset manager
# Remove chart options from data so we don't have to deepcopy
# If we got querystring args, apply them to the graph
if loc.split '?' .1
data = _.uncollapseObject _.fromKV that.replace('#', '%23')
+ data.options = _.synthesize do
+ data.options or {}
+ (v, k) -> [ k, dyglib.parseOption(k,v) ]
# Extract slug from URL
if match = /\/graph\/(?!view)([^\/?]+)/i.exec loc