--- /dev/null
+_ = require 'kraken/underscore'
+
+config = tbody = null
+
+render = (n, settings={}) ->
+ n = Number n
+ unless typeof n is 'number' and not isNaN n
+ console.error 'Supply a number!'
+ return false
+
+ values = [n].concat do
+ <[ toFixed toPrecision toExponential ]>.map -> n[it] settings[it]
+ # _.dump values, 'values'
+ row = $ "<tr>#{ values.map -> "<td>#it</td>" }</tr>" .prependTo tbody
+ # console.log 'row:', row
+
+$ ->
+ config := $ '#config'
+ tbody := $ '#results'
+
+ config.on 'submit', ->
+ settings = _.synthesize do
+ config.serializeArray()
+ ({name, value}) ->
+ [ name,
+ if name is 'n' then value else if value then Number value else void
+ ]
+ # _.dump settings, 'settings'
+
+ ns = delete settings.n
+ ns.split /\s+/g .map -> render it, settings
+ false
+
+ settings = { fixed:3 }
+ render 1234.5, settings
+ render 123.45, settings
+ render 12.345, settings
+ render 1.2345, settings
+ render 0.12345, settings
+ config.trigger 'submit'
--- /dev/null
+extends ../layout
+
+block title
+ title Number Formatting
+
+append styles
+ style
+ #config .options .control-group { display:inline-block; width:33%; }
+
+block content
+ .page-header
+ h1 Number Formatting
+
+ form#config.well.form-horizontal
+ input.btn-primary(type="submit") Format
+
+ .control-group
+ label.control-label(for="n") Numbers
+ .controls
+ input#n(name="n", type="text", value="54321.09876")
+ p.help-block You can separate multiple numbers with whitespace.
+
+ .options
+ .control-group
+ label.control-label(for="toFixed") .toFixed
+ .controls: input#toFixed.span1(type="text", name="toFixed", value="3")
+
+ .control-group
+ label.control-label(for="toPrecision") .toPrecision
+ .controls: input#toPrecision.span1(type="text", name="toPrecision", value="")
+
+ .control-group
+ label.control-label(for="toExponential") .toExponential
+ .controls: input#toExponential.span1(type="text", name="toExponential", value="")
+
+
+ table#results.table.table-striped.table-bordered.table-condensed
+ thead: tr
+ th n
+ th toFixed
+ th toPre
+ th toExp
+ tbody
+
+
+block scripts
+ script(src="/vendor/jquery.js")
+ script(src="/vendor/browserify.js")
+ script(src="/vendor/bootstrap.min.js")
+ script(src="/vendor/underscore.mod.js")
+ script(src="/vendor/underscore.string.mod.js")
+ script(src="/js/kraken/underscore/array.mod.js")
+ script(src="/js/kraken/underscore/object.mod.js")
+ script(src="/js/kraken/underscore/string.mod.js")
+ script(src="/js/kraken/underscore/index.mod.js")
+ script(src="numbers.js")
+
--- /dev/null
+Seq = require 'seq'
+Backbone = require 'backbone'
+
+{ _, op,
+} = require 'kraken/util'
+Cascade = require 'kraken/util/cascade'
+
+{ ChartLibrary, DygraphsLibrary,
+} = require 'kraken/chart'
+{ BaseView, BaseModel, BaseList,
+} = require 'kraken/base'
+{ Field, FieldList, FieldView, Scaffold,
+} = require 'kraken/scaffold'
+{ GraphOption, GraphOptionList, GraphOptionView,
+ GraphOptionsScaffold, TagSet,
+} = require 'kraken/graph'
+{ VisView, VisModel, VisList,
+} = require 'kraken/vis'
+
+
+root = this
+CHART_OPTIONS_SPEC = []
+CHART_DEFAULT_OPTIONS = {}
+ROOT_VIS_DATA = {}
+ROOT_VIS_OPTIONS = {}
+
+
+# Create the Graph Scaffold
+main = ->
+ # 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
+ ROOT_VIS_OPTIONS := delete root.ROOT_VIS_DATA.options
+
+ # Bind to URL changes
+ History.Adapter.bind window, 'statechange', ->
+ console.log 'StateChange!\n\n', String(root.location), '\n\n'
+
+
+ data = {}
+
+ # 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')
+ data.parents = JSON.parse that if data.parents
+ 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
+ data.slug = match[1]
+
+ vis = root.vis = new VisModel data, {+parse}
+ # graph = root.graph = new VisView do
+ # graph_spec : root.CHART_OPTIONS_SPEC
+ # model : vis
+ # $ '#content .inner' .append graph.el
+
+
+
+# Load data files
+Seq([ <[ CHART_OPTIONS_SPEC /schema/dygraph.json ]>,
+ <[ ROOT_VIS_DATA /presets/root.json ]>
+])
+.parEach_ (next, [key, url]) ->
+ jQuery.ajax do
+ url : url,
+ dataType : 'json'
+ success : (data) ->
+ root[key] = data
+ next.ok()
+ error : (err) -> console.error err
+.seq ->
+ console.log 'All data loaded!'
+ jQuery main
+