Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleanup

  • Loading branch information...
commit 9322c424074160393696a478dec85bad53f94a41 1 parent f8b5f73
@vogievetsky authored
View
1,348 dvl.coffee
@@ -589,14 +589,15 @@ dvl.util = {
len = 0
push: (l) ->
len += 1
- minLevel = Math.min(minLevel, l.level)
- (queue[l.level] or= []).push l
- null;
+ level = l.level
+ minLevel = Math.min(minLevel, level)
+ (queue[level] or= []).push l
+ return
shift: ->
len -= 1
- while not queue[minLevel] or queue[minLevel].length == 0
+ while not (queue[minLevel] and queue[minLevel].length)
minLevel += 1
- return queue[minLevel].pop()
+ return queue[minLevel].shift()
length: -> len
)()
@@ -850,9 +851,17 @@ dvl.assert = ({data, fn, msg, allowNull}) ->
######################################################
##
-## Sets up a pipline stage that automaticaly applies the given fucntion.
+## Sets up a pipline stage that automaticaly applies the given function.
##
-dvl.apply = ({fn, args, out, name, invalid, allowNull, update}) ->
+dvl.apply = ->
+ switch arguments.length
+ when 1
+ {fn, args, out, name, invalid, allowNull, update} = arguments[0]
+ when 2
+ [args, fn] = arguments
+ else
+ throw "bad number of arguments"
+
fn = dvl.wrapConstIfNeeded(fn or dvl.identity)
throw 'dvl.apply only makes sense with at least one argument' unless args?
args = [args] unless dvl.typeOf(args) is 'array'
@@ -1711,138 +1720,142 @@ dvl.scale = {}
)()
# dvl.bind # --------------------------------------------------
+do ->
+ # {parent, self, data, join, attr, style, text, html, on, transition, transitionExit}
+ id_class_spliter = /(?=[#.:])/
+ def_data_fn = dvl.const((d) -> [d])
+ dvl.bind = (args) ->
+ throw "'parent' not defiend" unless args.parent
+ self = args.self
+ throw "'self' not defiend" unless typeof self is 'string'
+ parts = self.split(id_class_spliter)
+ nodeType = parts.shift()
+ staticId = null
+ staticClass = []
+ for part in parts
+ switch part[0]
+ when '#'
+ staticId = part.substring(1)
+ when '.'
+ staticClass.push part.substring(1)
+ else
+ throw "not currently supported in 'self' (#{part})"
-# {parent, self, data, join, attr, style, text, html, on, transition, transitionExit}
-id_class_spliter = /(?=[#.:])/
-dvl.bind = (args) ->
- throw "'parent' not defiend" unless args.parent
- self = args.self
- throw "'self' not defiend" unless typeof self is 'string'
- parts = self.split(id_class_spliter)
- nodeType = parts.shift()
- staticClass = []
- for part in parts
- c = part[0]
- if c is '.'
- staticClass.push part.slice(1)
- else
- throw "not currently supported in 'self' (#{part})"
-
- staticClass = staticClass.join(' ')
+ staticClass = staticClass.join(' ')
- parent = dvl.wrapConstIfNeeded(args.parent)
- data = dvl.wrapConstIfNeeded(args.data or [undefined])
- join = dvl.wrapConstIfNeeded(args.join)
- text = if args.text then dvl.wrapConstIfNeeded(args.text) else null
- html = if args.html then dvl.wrapConstIfNeeded(args.html) else null
- transition = dvl.wrapConstIfNeeded(args.transition)
- transitionExit = dvl.wrapConstIfNeeded(args.transitionExit)
+ parent = dvl.wrapConstIfNeeded(args.parent)
+ data = dvl.wrapConstIfNeeded(args.data or def_data_fn)
+ join = dvl.wrapConstIfNeeded(args.join)
+ text = if args.text then dvl.wrapConstIfNeeded(args.text) else null
+ html = if args.html then dvl.wrapConstIfNeeded(args.html) else null
+ transition = dvl.wrapConstIfNeeded(args.transition)
+ transitionExit = dvl.wrapConstIfNeeded(args.transitionExit)
- listen = [parent, data, join, text, html, transition, transitionExit]
+ listen = [parent, data, join, text, html, transition, transitionExit]
- attrList = {}
- for k, v of args.attr
- v = dvl.wrapConstIfNeeded(v)
- if k is 'class' and staticClass
- v = dvl.op.concat(v, ' ' + staticClass)
+ attrList = {}
+ for k, v of args.attr
+ v = dvl.wrapConstIfNeeded(v)
+ if k is 'class' and staticClass
+ v = dvl.op.concat(v, ' ' + staticClass)
- listen.push(v)
- attrList[k] = v
+ listen.push(v)
+ attrList[k] = v
- if staticClass and not attrList['class']
- attrList['class'] = dvl.const(staticClass)
+ if staticClass and not attrList['class']
+ attrList['class'] = dvl.const(staticClass)
- styleList = {}
- for k, v of args.style
- v = dvl.wrapConstIfNeeded(v)
- listen.push(v)
- styleList[k] = v
+ styleList = {}
+ for k, v of args.style
+ v = dvl.wrapConstIfNeeded(v)
+ listen.push(v)
+ styleList[k] = v
- onList = {}
- for k, v of args.on
- v = dvl.wrapConstIfNeeded(v)
- listen.push(v)
- onList[k] = v
+ onList = {}
+ for k, v of args.on
+ v = dvl.wrapConstIfNeeded(v)
+ listen.push(v)
+ onList[k] = v
- out = dvl.def(null, 'selection')
+ out = dvl.def(null, 'selection')
- dvl.register {
- listen
- change: [out]
- fn: ->
- _parent = parent.get()
- return unless _parent
-
- force = parent.hasChanged() or data.hasChanged() or join.hasChanged()
- _data = data.get()
- _join = join.get()
-
- if _data
- _transition = transition.get()
- _transitionExit = transitionExit.get()
-
- # prep
- enter = []
- preTrans = []
- postTrans = []
-
- add1 = (fn, v) ->
- if v.hasChanged() or force
- preTrans.push { fn, a1: v.getPrev() }
- postTrans.push { fn, a1: v.get() }
- else
- enter.push { fn, a1: v.get() }
- return
+ dvl.register {
+ listen
+ change: [out]
+ fn: ->
+ _parent = parent.get()
+ return unless _parent
+
+ force = parent.hasChanged() or data.hasChanged() or join.hasChanged()
+ _data = data.get()
+ _join = join.get()
+
+ if _data
+ _transition = transition.get()
+ _transitionExit = transitionExit.get()
+
+ # prep
+ enter = []
+ preTrans = []
+ postTrans = []
+
+ add1 = (fn, v) ->
+ if v.hasChanged() or force
+ preTrans.push { fn, a1: v.getPrev() }
+ postTrans.push { fn, a1: v.get() }
+ else
+ enter.push { fn, a1: v.get() }
+ return
- add2 = (fn, k, v) ->
- if v.hasChanged() or force
- preTrans.push { fn, a1: k, a2: v.getPrev() }
- postTrans.push { fn, a1: k, a2: v.get() }
- else
- enter.push { fn, a1: k, a2: v.get() }
- return
+ add2 = (fn, k, v) ->
+ if v.hasChanged() or force
+ preTrans.push { fn, a1: k, a2: v.getPrev() }
+ postTrans.push { fn, a1: k, a2: v.get() }
+ else
+ enter.push { fn, a1: k, a2: v.get() }
+ return
- addO = (fn, k, v) ->
- if v.hasChanged() or force
- preTrans.push { fn, a1: k, a2: v.get() }
- else
- enter.push { fn, a1: k, a2: v.get() }
- return
+ addO = (fn, k, v) ->
+ if v.hasChanged() or force
+ preTrans.push { fn, a1: k, a2: v.get() }
+ else
+ enter.push { fn, a1: k, a2: v.get() }
+ return
- add1('text', text) if text
- add1('html', html) if html
- add2('attr', k, v) for k, v of attrList
- add2('style', k, v) for k, v of styleList
- addO('on', k, v) for k, v of onList
+ add1('text', text) if text
+ add1('html', html) if html
+ add2('attr', k, v) for k, v of attrList
+ add2('style', k, v) for k, v of styleList
+ addO('on', k, v) for k, v of onList
- # d3 stuff
- s = _parent.selectAll(self).data(_data, _join)
- e = s.enter().append(nodeType)
+ # d3 stuff
+ s = _parent.selectAll(self).data(_data, _join)
+ e = s.enter().append(nodeType)
- e[a.fn](a.a1, a.a2) for a in enter
+ e[a.fn](a.a1, a.a2) for a in enter
- s[a.fn](a.a1, a.a2) for a in preTrans
+ s[a.fn](a.a1, a.a2) for a in preTrans
- if _transition and _transition.duration?
- t = s.transition()
- t.duration(_transition.duration or 1000)
- t.delay(_transition.delay) if _transition.delay
- t.ease(_transition.ease) if _transition.ease
- else
- t = s
+ if _transition and _transition.duration?
+ t = s.transition()
+ t.duration(_transition.duration or 1000)
+ t.delay(_transition.delay) if _transition.delay
+ t.ease(_transition.ease) if _transition.ease
+ else
+ t = s
- t[a.fn](a.a1, a.a2) for a in postTrans
+ t[a.fn](a.a1, a.a2) for a in postTrans
- ex = s.exit().remove()
- out.set(s).notify() unless e.empty() and ex.empty()
- else
- s = _parent.selectAll(self).remove()
- out.set(s).notify()
+ ex = s.exit().remove()
+ out.set(s).notify() unless e.empty() and ex.empty()
+ else
+ s = _parent.selectAll(self).remove()
+ out.set(s).notify()
- return
- }
+ return
+ }
- return out
+ return out
dvl.chain = (f, h) ->
@@ -2486,886 +2499,333 @@ dvl.compare = (acc, reverse) ->
## ~headerTooltip: The default herder tooltip (title element text).
## ~rowLimit: The maximum number of rows to show; if null all the rows are shown. [null]
##
-default_compare_modes = ['up', 'down']
-dvl.html.table2 = ({parent, data, sort, classStr, rowClass, rowLimit, columns}) ->
- table = dvl.valueOf(parent)
- .append('table')
- .attr('class', classStr)
-
- sort = sort or {}
- sortOn = dvl.wrapVarIfNeeded(sort.on)
- sortDir = dvl.wrapVarIfNeeded(sort.dir)
- sortOnIndicator = dvl.wrapVarIfNeeded(sort.onIndicator ? sortOn)
-
- headerCol = []
- bodyCol = []
- compareMap = {}
- compareList = [sortOn, sortDir]
- for c in columns
- c.sortable ?= true
- if c.sortable
- if c.compare?
- comp = dvl.wrapConstIfNeeded(c.compare)
- else
- comp = dvl.compare(c.value)
- compareMap[c.id] = comp
- compareList.push comp
-
- if not c.compareModes?[0]
- c.compareModes = default_compare_modes
-
- headerCol.push {
- id: c.id
- title: c.title
- classStr: c.classStr
- tooltip: c.headerTooltip
- }
- bodyCol.push {
- id: c.id
- class: c.classStr
- value: c.value
- render: c.render
- on: c.on
- }
-
- compare = dvl.def(null, 'compare')
- dvl.register {
- listen: compareList
- change: [compare]
- fn: ->
- _sortOn = sortOn.get()
- _sortDir = sortDir.get()
-
- if _sortOn?
- cmp = compareMap[_sortOn]?.get()
- if cmp and _sortDir is 'down'
- oldCmp = cmp
- cmp = (a,b) -> oldCmp(b,a)
- compare.set(cmp)
- else
- compare.set(null)
- compare.notify()
- return
- }
-
- dvl.html.table2.header {
- parent: table
- columns: headerCol
- onClick: (id) ->
- column = null
- for c in columns
- if c.id is id
- column = c
- break
-
- return unless column and column.sortable
-
- compareModes = column.compareModes
- if id is sortOn.get()
- sortDir.set(compareModes[(compareModes.indexOf(sortDir.get())+1) % compareModes.length])
- dvl.notify(sortDir)
- else
- sortOn.set(id)
- sortDir.set(compareModes[0])
- dvl.notify(sortOn, sortDir)
-
- return
- }
-
- dvl.html.table2.body {
- parent: table
- data
- rowClass
- rowLimit
- columns: bodyCol
- compare
- }
+do ->
+ default_compare_modes = ['up', 'down']
+ dvl.html.table = ({parent, data, sort, classStr, rowClass, rowLimit, columns}) ->
+ table = dvl.valueOf(parent)
+ .append('table')
+ .attr('class', classStr)
+
+ sort = sort or {}
+ sortOn = dvl.wrapVarIfNeeded(sort.on)
+ sortDir = dvl.wrapVarIfNeeded(sort.dir)
+ sortOnIndicator = dvl.wrapVarIfNeeded(sort.onIndicator ? sortOn)
+
+ headerCol = []
+ bodyCol = []
+ compareMap = {}
+ compareList = [sortOn, sortDir]
+ for c in columns
+ c.sortable ?= true
+ if c.sortable
+ if c.compare?
+ comp = dvl.wrapConstIfNeeded(c.compare)
+ else
+ comp = dvl.compare(c.value)
+ compareMap[c.id] = comp
+ compareList.push comp
+
+ if not c.compareModes?[0]
+ c.compareModes = default_compare_modes
+
+ headerCol.push {
+ id: c.id
+ title: c.title
+ classStr: c.classStr
+ tooltip: c.headerTooltip
+ }
+ bodyCol.push {
+ id: c.id
+ class: c.classStr
+ value: c.value
+ render: c.render
+ on: c.on
+ }
- return {}
+ compare = dvl.def(null, 'compare')
+ dvl.register {
+ listen: compareList
+ change: [compare]
+ fn: ->
+ _sortOn = sortOn.get()
+ _sortDir = sortDir.get()
+
+ if _sortOn?
+ cmp = compareMap[_sortOn]?.get()
+ if cmp and _sortDir is 'down'
+ oldCmp = cmp
+ cmp = (a,b) -> oldCmp(b,a)
+ compare.set(cmp)
+ else
+ compare.set(null)
+ compare.notify()
+ return
+ }
+ dvl.html.table.header {
+ parent: table
+ columns: headerCol
+ onClick: (id) ->
+ column = null
+ for c in columns
+ if c.id is id
+ column = c
+ break
+
+ return unless column and column.sortable
+
+ compareModes = column.compareModes
+ if id is sortOn.get()
+ sortDir.set(compareModes[(compareModes.indexOf(sortDir.get())+1) % compareModes.length])
+ dvl.notify(sortDir)
+ else
+ sortOn.set(id)
+ sortDir.set(compareModes[0])
+ dvl.notify(sortOn, sortDir)
-##-------------------------------------------------------
-##
-## HTML table header (thead)
-##
-## parent: Where to append the table.
-## columns:
-## ~title: The title of the column.
-## ~classStr: The class of the column
-## ~tooltip: The tooltip for the column
-## ~onClick: The click handler
-##
-dvl.html.table2.header = ({parent, columns, onClick}) ->
- throw 'there needs to be a parent' unless parent
- thead = dvl.valueOf(parent).append('thead').append('tr')
+ return
+ }
- listen = []
- for c in columns
- c.title = dvl.wrapConstIfNeeded(c.title)
- c.classStr = dvl.wrapConstIfNeeded(c.classStr)
- c.tooltip = dvl.wrapConstIfNeeded(c.tooltip)
- listen.push c.title, c.classStr, c.tooltip
+ dvl.html.table.body {
+ parent: table
+ data
+ rowClass
+ rowLimit
+ columns: bodyCol
+ compare
+ }
- dvl.register {
- name: 'head_render'
- listen
- fn: ->
- colSel = thead.selectAll('td').data(columns)
- colSel.enter().append('td')
- colSel.exit().remove()
+ return {}
- colSel
- .attr('class', (c) -> c.classStr.get())
- .attr('title', (c) -> c.tooltip.get())
- .text((c) -> c.title.get())
- .on('click', (c) -> onClick(c.id))
- return
- }
+ ##-------------------------------------------------------
+ ##
+ ## HTML table header (thead)
+ ##
+ ## parent: Where to append the table.
+ ## columns:
+ ## ~title: The title of the column.
+ ## ~classStr: The class of the column
+ ## ~tooltip: The tooltip for the column
+ ## ~onClick: The click handler
+ ##
+ dvl.html.table.header = ({parent, columns, onClick}) ->
+ throw 'there needs to be a parent' unless parent
+ thead = dvl.valueOf(parent).append('thead').append('tr')
- return
+ listen = []
+ for c in columns
+ c.title = dvl.wrapConstIfNeeded(c.title)
+ c.classStr = dvl.wrapConstIfNeeded(c.classStr)
+ c.tooltip = dvl.wrapConstIfNeeded(c.tooltip)
+ listen.push c.title, c.classStr, c.tooltip
+ dvl.register {
+ name: 'head_render'
+ listen
+ fn: ->
+ colSel = thead.selectAll('td').data(columns)
+ colSel.enter().append('td')
+ colSel.exit().remove()
-##-------------------------------------------------------
-##
-## HTML table body (tbody)
-##
-## parent: Where to append the table.
-## ~data: The data displayed.
-## ~compare: The function to sort the data on
-## ~rowClass The class of the row
-## ~rowLimit: The maximum number of rows to show; if null all the rows are shown. [null]
-## columns:
-## ~value: The value of the cell
-## ~class: The class of the column
-##
-dvl.html.table2.body = ({parent, data, compare, rowClass, rowLimit, columns}) ->
- throw 'there needs to be a parent' unless parent
- throw 'there needs to be data' unless data
- tbody = dvl.valueOf(parent).append('tbody')
-
- compare = dvl.wrapConstIfNeeded(compare)
- rowClass = dvl.wrapConstIfNeeded(rowClass) if rowClass?
- rowLimit = dvl.wrapConstIfNeeded(rowLimit)
- listen = [data, compare, rowClass, rowLimit]
- change = []
- for c in columns
- c.class = dvl.wrapConstIfNeeded(c.class)
- c.value = dvl.wrapConstIfNeeded(c.value)
- listen.push c.class # not value
-
- for k,v of c.on
- v = dvl.wrapConstIfNeeded(v)
- listen.push v
- c.on[k] = v
+ colSel
+ .attr('class', (c) -> c.classStr.get())
+ .attr('title', (c) -> c.tooltip.get())
+ .text((c) -> c.title.get())
+ .on('click', (c) -> onClick(c.id))
- change.push(c.selection = dvl.def(null, "#{c.id}_selection"))
+ return
+ }
+ return
- dvl.register {
- name: 'body_render'
- listen
- change
- fn: ->
- _data = data.get()
- if not _data
- tbody.selectAll('tr').remove()
- return
- dataSorted = _data
+ ##-------------------------------------------------------
+ ##
+ ## HTML table body (tbody)
+ ##
+ ## parent: Where to append the table.
+ ## ~data: The data displayed.
+ ## ~compare: The function to sort the data on
+ ## ~rowClass The class of the row
+ ## ~rowLimit: The maximum number of rows to show; if null all the rows are shown. [null]
+ ## columns:
+ ## ~value: The value of the cell
+ ## ~class: The class of the column
+ ##
+ dvl.html.table.body = ({parent, data, compare, rowClass, rowLimit, columns}) ->
+ throw 'there needs to be a parent' unless parent
+ throw 'there needs to be data' unless data
+ tbody = dvl.valueOf(parent).append('tbody')
+
+ compare = dvl.wrapConstIfNeeded(compare)
+ rowClass = dvl.wrapConstIfNeeded(rowClass) if rowClass?
+ rowLimit = dvl.wrapConstIfNeeded(rowLimit)
+ listen = [data, compare, rowClass, rowLimit]
+ change = []
+ for c in columns
+ c.class = dvl.wrapConstIfNeeded(c.class)
+ c.value = dvl.wrapConstIfNeeded(c.value)
+ listen.push c.class # not value
- _compare = compare.get()
- dataSorted = dataSorted.slice().sort(_compare) if _compare
+ for k,v of c.on
+ v = dvl.wrapConstIfNeeded(v)
+ listen.push v
+ c.on[k] = v
- _rowLimit = rowLimit.get()
- dataSorted = dataSorted.slice(0, _rowLimit) if _rowLimit?
+ change.push(c.selection = dvl.def(null, "#{c.id}_selection"))
- rowSel = tbody.selectAll('tr').data(dataSorted)
- rowSel.enter().append('tr')
- rowSel.exit().remove()
- if rowClass
- _rowClass = rowClass.get()
- rowSel.attr('class', _rowClass)
- colSel = rowSel.selectAll('td').data(columns)
- colSel.enter().append('td')
- colSel.exit().remove()
+ dvl.register {
+ name: 'body_render'
+ listen
+ change
+ fn: ->
+ _data = data.get()
+ if not _data
+ tbody.selectAll('tr').remove()
+ return
- for c,i in columns
- sel = tbody.selectAll("td:nth-child(#{i+1})").data(dataSorted)
- .attr('class', c.class.get())
+ dataSorted = _data
- for k,v of c.on
- sel.on(k, v.get())
+ _compare = compare.get()
+ dataSorted = dataSorted.slice().sort(_compare) if _compare
- c.selection.set(sel).notify()
+ _rowLimit = rowLimit.get()
+ dataSorted = dataSorted.slice(0, _rowLimit) if _rowLimit?
- return
- }
+ rowSel = tbody.selectAll('tr').data(dataSorted)
+ rowSel.enter().append('tr')
+ rowSel.exit().remove()
+ if rowClass
+ _rowClass = rowClass.get()
+ rowSel.attr('class', _rowClass)
- for c in columns
- render = if typeof c.render isnt 'function'
- dvl.html.table2.render[c.render or 'text']
- else
- c.render
+ colSel = rowSel.selectAll('td').data(columns)
+ colSel.enter().append('td')
+ colSel.exit().remove()
- render.call(c, c.selection, c.value)
+ for c,i in columns
+ sel = tbody.selectAll("td:nth-child(#{i+1})").data(dataSorted)
+ .attr('class', c.class.get())
- return
+ for k,v of c.on
+ sel.on(k, v.get())
+ c.selection.set(sel).notify()
-dvl.html.table2.render =
- text: (selection, value) ->
- dvl.register {
- listen: [selection, value]
- fn: ->
- _selection = selection.get()
- _value = value.get()
- if _selection? and _value
- _selection.text(_value)
return
}
- return
- html: (selection, value) ->
- dvl.register {
- listen: [selection, value]
- fn: ->
- _selection = selection.get()
- _value = value.get()
- if _selection? and _value
- _selection.html(_value)
- return
- }
- return
+ for c in columns
+ render = if typeof c.render isnt 'function'
+ dvl.html.table2.render[c.render or 'text']
+ else
+ c.render
+ render.call(c, c.selection, c.value)
- aLink: ({href}) -> (selection, value) ->
- dvl.bind {
- parent: selection
- self: 'a.link'
- data: (d) -> [d]
- attr: {
- href: href
- }
- text: value
- }
return
- spanLink: ({click}) ->
- titleGen = dvl.wrapConstIfNeeded(titleGen)
- return (sel, value) ->
- sel = sel.selectAll('span').data((d) -> [d])
- sel.enter().append('span').attr('class', 'span_link')
- sel.html(value).on('click', click)
- return
- img: (selection, value) ->
- dvl.bind {
- parent: selection
- self: 'img'
- data: (d) -> [d]
- attr: {
- src: value
+ dvl.html.table.render = {
+ text: (selection, value) ->
+ dvl.register {
+ listen: [selection, value]
+ fn: ->
+ _selection = selection.get()
+ _value = value.get()
+ if _selection? and _value
+ _selection.text(_value)
+ return
}
- }
- return
-
- imgDiv: (sel, value) ->
- sel = sel.selectAll('div').data((d) -> [d])
- sel.enter().append('div')
- sel.attr('class', value)
- return
+ return
- sparkline: ({width, height, x, y, padding}) ->
- padding ?= 0
- return (selection, value) ->
- lineFn = dvl.apply {
- args: [x, y, padding]
- fn: (x, y, padding) -> (d) ->
- mmx = dvl.util.getMinMax(d, ((d) -> d[x]))
- mmy = dvl.util.getMinMax(d, ((d) -> d[y]))
- sx = d3.scale.linear().domain([mmx.min, mmx.max]).range([padding, width-padding])
- sy = d3.scale.linear().domain([mmy.min, mmy.max]).range([height-padding, padding])
- return d3.svg.line().x((dp) -> sx(dp[x])).y((dp) -> sy(dp[y]))(d)
+ html: (selection, value) ->
+ dvl.register {
+ listen: [selection, value]
+ fn: ->
+ _selection = selection.get()
+ _value = value.get()
+ if _selection? and _value
+ _selection.html(_value)
+ return
}
+ return
- dataFn = dvl.apply {
- args: value
- fn: (value) -> (d,i) -> [value(d,i)]
- }
- svg = dvl.bind {
+ aLink: ({href}) -> (selection, value) ->
+ dvl.bind {
parent: selection
- self: 'svg.sparkline'
- data: dataFn
+ self: 'a.link'
+ data: (d) -> [d]
attr: {
- width
- height
+ href: href
}
+ text: value
}
+ return
+
+ spanLink: ({click}) ->
+ titleGen = dvl.wrapConstIfNeeded(titleGen)
+ return (sel, value) ->
+ sel = sel.selectAll('span').data((d) -> [d])
+ sel.enter().append('span').attr('class', 'span_link')
+ sel.html(value).on('click', click)
+ return
+ img: (selection, value) ->
dvl.bind {
- parent: svg
- self: 'path'
+ parent: selection
+ self: 'img'
data: (d) -> [d]
attr: {
- d: lineFn
+ src: value
}
}
return
-
-# Orig table
-
-
-##-------------------------------------------------------
-##
-## Table made with HTML
-##
-## This module draws an HTML table that can be sorted
-##
-## selector: Where to append the table.
-## classStr: The class to add to the table.
-## ~rowClassGen: The generator for row classes
-## ~visible: Toggles the visibility of the table. [true]
-## columns: A list of columns to drive the table.
-## column:
-## id: The id by which the column will be identified.
-## ~title: The title of the column header.
-## ~headerTooltip: The popup tool tip (title element text) of the column header.
-## classStr: The class given to the 'th' and 'td' elements in this column, if not specified will default to the id.
-## cellClassGen: The class generator for the cell
-## ~cellClick: The generator of click handlers
-## -gen: The generator that drives the column data.
-## ~sortable: Toggles wheather the column is sortable or not. [true]
-## -sortGen: The generator that will drive the sorting, if not provided then gen will be used instead. [gen]
-## ~hoverGen: The generator for the (hover) title.
-## ~showIndicator: Toggle the display of the sorting indicator for this column. [true]
-## ~reverseIndicator: Reverses the asc / desc directions of the indicator for this column. [false]
-## ~visible: Toggles the visibility of the column
-##
-## sort:
-## ~on: The id of the column on which to sort.
-## ~onIndicator: The id of the column on which the indicator is palced (defaults to sort.on)
-## ~order: The order of the sort. Must be one of {'asc', 'desc', 'none'}.
-## ~modes: The order rotation that is allowed. Must be an array of [{'asc', 'desc', 'none'}].
-## ~autoOnClick: Toggle wheather the table will be sorted (updating sort.on and/or possibly sort.order) automaticaly when clicked. [true]
-## ~indicator: [true / false]
-##
-## ~showHeader: Toggle showing the header [true]
-## ~onHeaderClick: Callback or url when the header of a column is clicked.
-## ~headerTooltip: The default herder tooltip (title element text).
-## ~rowLimit: The maximum number of rows to show; if null all the rows are shown. [null]
-##
-dvl.html.table = ({selector, classStr, rowClassGen, visible, columns, showHeader, sort, onHeaderClick, headerTooltip, rowLimit, htmlTitles}) ->
- throw 'selector has to be a plain string.' if dvl.knows(selector)
- throw 'columns has to be a plain array.' if dvl.knows(columns)
- throw 'sort has to be a plain object.' if dvl.knows(sort)
-
- visible = dvl.wrapConstIfNeeded(visible ? true)
-
- showHeader = dvl.wrapConstIfNeeded(showHeader ? true)
- onHeaderClick = dvl.wrapConstIfNeeded(onHeaderClick)
- headerTooltip = dvl.wrapConstIfNeeded(headerTooltip or null)
-
- rowLimit = dvl.wrapConstIfNeeded(rowLimit or null)
-
- sort = sort or {}
-
- sortOn = dvl.wrapVarIfNeeded(sort.on)
- sortOnIndicator = dvl.wrapVarIfNeeded(sort.onIndicator ? sortOn)
- sortOnClick = dvl.wrapConstIfNeeded(sort.autoOnClick ? true)
- sortModes = dvl.wrapConstIfNeeded(sort.modes or ['asc', 'desc', 'none'])
- modes = sortModes.get()
- sortOrder = dvl.wrapVarIfNeeded(sort.order or (if modes.length > 0 then modes[0] else 'none'))
-
- listen = [rowClassGen, visible, showHeader, headerTooltip, rowLimit, sortOn, sortOnIndicator, sortModes, sortOrder]
- listenColumnVisible = []
-
- sortIndicator = dvl.wrapConstIfNeeded(sort.indicator)
- listen.push sortIndicator
-
- numRows = dvl.def(null, 'num_rows')
-
- goOrCall = (arg, id, that) ->
- t = typeof(arg)
- if t is 'function'
- arg.call(that, id)
- else if t is 'string'
- window.location.href = arg
- return
-
- # flatten possible merge header columns
- if columns.length and columns[0].columns
- topHeader = []
- newColumns = []
- for tc in columns
- continue unless tc.columns and tc.columns.length isnt 0
- topHeader.push { title: dvl.wrapConstIfNeeded(tc.title), classStr: tc.classStr, span: tc.columns.length }
- listen.push tc.title
- for c in tc.columns
- newColumns.push c
- columns = newColumns
-
- # process columns
- for i, c of columns
- c.title = dvl.wrapConstIfNeeded(c.title or '')
- c.sortable = dvl.wrapConstIfNeeded(c.sortable ? true)
- c.showIndicator = dvl.wrapConstIfNeeded(c.showIndicator ? true);
- c.reverseIndicator = dvl.wrapConstIfNeeded(c.reverseIndicator or false);
- c.headerTooltip = dvl.wrapConstIfNeeded(c.headerTooltip or null)
- c.cellClick = dvl.wrapConstIfNeeded(c.cellClick or null)
- c.visible = dvl.wrapConstIfNeeded(c.visible ? true)
- c.hideHeader = dvl.wrapConstIfNeeded(c.hideHeader)
- c.renderer = if typeof(c.renderer) is 'function' then c.renderer else dvl.html.table.renderer[c.renderer or 'text']
- c.cellClassGen = if c.cellClassGen then dvl.wrapConstIfNeeded(c.cellClassGen) else null
- listen.push c.title, c.showIndicator, c.reverseIndicator, c.gen, c.sortGen, c.hoverGen, c.headerTooltip, c.cellClick, c.cellClassGen
- listenColumnVisible.push c.visible, c.hideHeader
- if c.renderer.depends
- listen.push d for d in c.renderer.depends
- c.uniquClass = 'column_' + i
-
- t = d3.select(selector).append('table')
- t.attr('class', classStr) if classStr
-
- colClass = (c) -> (c.classStr or c.id) + ' ' + c.uniquClass + (if c.sorted then ' sorted' else '') + (if c.sortable.get() then ' sortable' else ' unsortable')
-
- thead = t.append('thead')
- th = thead.append('tr').attr('class', 'top_header') if topHeader
- h = thead.append('tr')
- b = t.append('tbody')
-
- if topHeader
- th.selectAll('th')
- .data(topHeader)
- .enter().append('th')
- .attr('class', (d) -> d.classStr or null)
- .attr('colspan', (d) -> d.span)
- .append('div')
- .text((d) -> d.title.get());
-
- sel = h.selectAll('th')
- .data(columns)
- .enter().append('th')
- .on('click', (c) ->
- return unless c.id?
-
- goOrCall(onHeaderClick.get(), c.id, this)
-
- if sortOnClick.get() and c.sortable.get()
- if sortOn.get() is c.id
- modes = sortModes.get()
- si = modes.indexOf(sortOrder.get())
- sortOrder.set(modes[(si+1) % modes.length]).notify()
- else
- sortOn.set(c.id).notify()
- )
-
- sel.append('span') # title text container
-
- si = sortIndicator.get();
- if si
- sel.append('div')
- .attr('class', 'sort_indicator')
- .style('display', (c) -> if c.sortable.get() then null else 'none')
-
- tableLength = ->
- length = +Infinity
- for c in columns
- l = c.gen.len()
- length = l if l < length
- length = 1 if length == Infinity
-
- length
-
- makeTable = ->
- length = tableLength()
- r = d3.range(length)
-
- if visible.hasChanged()
- t.style('display', if visible.get() then null else 'none')
-
- if showHeader.hasChanged()
- thead.style('display', if showHeader.get() then null else 'none')
-
- if topHeader
- th.selectAll('th > div')
- .data(topHeader)
- .text((d) -> d.title.get());
-
- if headerTooltip.hasChanged()
- h.attr('title', headerTooltip.get());
-
- if sort
- sortOnId = sortOn.get()
- sortOnIndicatorId = sortOnIndicator.get()
- sortCol = null
- sortIndicatorCol = null
- for c in columns
- if c.sorted = (c.id is sortOnId)
- sortCol = c
- throw "sort on column marked unsortable (#{sortOnId})" unless sortCol.sortable.get()
-
- if c.sortedIndicator = (c.id is sortOnIndicatorId)
- sortIndicatorCol = c
-
- _sortOrder = sortOrder.get()
-
- if _sortOrder and sortCol
- sortGen = (sortCol.sortGen or sortCol.gen).gen()
- numeric = sortGen and typeof(sortGen(0)) is 'number'
-
- dir = String(_sortOrder).toLowerCase()
- if dir is 'desc'
- if numeric
- sortFn = (i,j) ->
- si = sortGen(i)
- sj = sortGen(j)
- if isNaN(si)
- if isNaN(sj)
- return 0
- else
- return 1
- else
- if isNaN(sj)
- return -1
- else
- return sj - si
- else
- sortFn = (i,j) ->
- return sortGen(j).toLowerCase().localeCompare(sortGen(i).toLowerCase())
- r.sort(sortFn)
- else if dir is 'asc'
- if numeric
- sortFn = (i,j) ->
- si = sortGen(j)
- sj = sortGen(i)
- if isNaN(si)
- if isNaN(sj)
- return 0
- else
- return 1
- else
- if isNaN(sj)
- return -1
- else
- return sj - si
- else
- sortFn = (i,j) ->
- return sortGen(i).toLowerCase().localeCompare(sortGen(j).toLowerCase())
- r.sort(sortFn)
- # else do nothing
-
- if _sortOrder and sortIndicator.get()
- dir = String(_sortOrder).toLowerCase()
- h.selectAll('th').data(columns)
- .select('div.sort_indicator')
- .style('display', (c) -> if c.sortable.get() then null else 'none')
- .attr('class', (c) ->
- which = if c is sortIndicatorCol and dir isnt 'none'
- if c.reverseIndicator.get() then (if dir is 'asc' then 'desc' else 'asc') else dir
- else
- 'none'
- return 'sort_indicator ' + which
- )
-
- h.selectAll('th').data(columns)
- .attr('class', colClass)
- .style('display', (c) -> if c.visible.get() and not c.hideHeader.get() then null else "none")
- .attr('title', (c) -> c.headerTooltip.get())
- .select('span')[if htmlTitles then 'html' else 'text']((c) -> c.title.get())
-
- limit = rowLimit.get()
- r = r.splice(0, Math.max(0, limit)) if limit?
- numRows.update(r.length)
-
- sel = b.selectAll('tr').data(r)
- ent = sel.enter().append('tr')
- if rowClassGen
- gen = rowClassGen.gen()
- ent.attr('class', gen)
- sel.attr('class', gen)
- sel.exit().remove()
-
- sel = b.selectAll('tr')
- row = sel.selectAll('td').data(columns)
- row.enter().append('td')
- row.attr('class', colClass)
- row.exit().remove()
-
- for col in columns
- gen = col.gen.gen();
- csel = sel.select('td.' + col.uniquClass)
-
- csel
- .on('click', (i) -> goOrCall(col.cellClick.gen()(i), col, this))
- .style('display', if col.visible.get() then null else 'none')
-
- if col.hoverGen
- csel.attr('title', col.hoverGen.gen())
-
- if col.cellClassGen
- cg = col.cellClassGen.gen()
- csel.attr('class', (i) -> colClass(col) + if cg? then ' ' + cg(i))
-
- col.renderer(csel, gen, col.sorted)
-
- return
-
- dvl.register {
- name: 'table_maker'
- fn: makeTable
- listen: listen
- change: [numRows]
- }
-
-
- columnVisible = ->
- h.selectAll('th').data(columns)
- .style('display', (c) -> if c.visible.get() and not c.hideHeader.get() then null else "none")
-
- for col in columns
- sel.select('td.' + col.uniquClass)
- .style('display', if col.visible.get() then null else 'none')
-
- return
-
- dvl.register {
- name: 'table_column_visible'
- fn: columnVisible
- listen: listenColumnVisible
- }
-
- return {
- sortOn
- sortOrder
- numRows
- node: t.node()
- }
-
-dvl.html.table.renderer =
- text: (col, dataFn) ->
- col.text(dataFn)
- return
- html: (col, dataFn) ->
- col.html(dataFn)
- return
- aLink: ({linkGen, html, poo}) ->
- what = if html then 'html' else 'text'
- linkGen = dvl.wrapConstIfNeeded(linkGen)
- f = (col, dataFn) ->
- sel = col.selectAll('a').data((d) -> [d])
- sel.enter().append('a')
- sel.attr('href', linkGen.gen())[what](dataFn)
+ imgDiv: (sel, value) ->
+ sel = sel.selectAll('div').data((d) -> [d])
+ sel.enter().append('div')
+ sel.attr('class', value)
return
- f.depends = [linkGen]
- return f
- spanLink: ({click}) ->
- titleGen = dvl.wrapConstIfNeeded(titleGen)
- f = (col, dataFn) ->
- sel = col.selectAll('span').data((d) -> [d])
- sel.enter().append('span').attr('class', 'span_link')
- sel.html(dataFn).on('click', click)
- return
- return f
- barDiv: (col, dataFn) ->
- sel = col.selectAll('div').data((d) -> [d])
- sel.enter().append('div').attr('class', 'bar_div').style('width', ((d) -> dataFn(d) + 'px'))
- sel.style('width', ((d) -> dataFn(d) + 'px'))
- return
- img: (col, dataFn) ->
- sel = col.selectAll('img').data((d) -> [d])
- sel.enter().append('img').attr('src', dataFn)
- sel.attr('src', dataFn)
- return
- imgDiv: (col, dataFn) ->
- sel = col.selectAll('div').data((d) -> [d])
- sel.enter().append('div').attr('class', dataFn)
- sel.attr('class', dataFn)
- return
-
-
-
-
-# Gens # --------------------------------------------------
-
-dvl.gen = {}
-
-dvl.gen.fromFn = (fn) ->
- gen = dvl.def(null, 'fn_generator')
- gen.setGen(fn, Infinity)
- return gen
-
-
-dvl.gen.fromValue = (value, acc, fn, name) ->
- value = dvl.wrapConstIfNeeded(value)
- acc = dvl.wrapConstIfNeeded(acc or dvl.identity)
- fn = dvl.wrapConstIfNeeded(fn or dvl.identity)
-
- gen = dvl.def(null, name or 'value_generator')
-
- makeGen = ->
- a = acc.get()
- f = fn.get()
- v = value.get()
- if a? and f? and v?
- rv = f(a(v))
- g = -> rv
-
- gen.setGen(g)
- else
- gen.setGen(null)
-
- dvl.notify(gen)
-
- dvl.register({fn:makeGen, listen:[value, acc, fn], change:[gen], name:'value_make_gen'})
- return gen
-
-
-dvl.gen.fromGen = (generator, fn, name) ->
- generator = dvl.wrapConstIfNeeded(generator)
- fn = dvl.wrapConstIfNeeded(fn or dvl.identity)
- gen = dvl.def(null, name or 'generator_generator')
-
- makeGen = ->
- _generator = generator.gen()
- _fn = fn.get()
- if _generator? and _fn?
- g = (i) -> _fn(_generator(i))
-
- gen.setGen(g, generator.len)
- else
- gen.setGen(null)
-
- dvl.notify(gen)
-
- dvl.register({fn:makeGen, listen:[generator, fn], change:[gen], name:'generator_make_gen'})
- return gen
-
-
-dvl.gen.fromArray = (data, acc, fn, name) ->
- data = dvl.wrapConstIfNeeded(data)
- acc = dvl.wrapConstIfNeeded(acc or dvl.identity)
- fn = dvl.wrapConstIfNeeded(fn or dvl.identity)
-
- gen = dvl.def(null, name or 'array_generator')
-
- d = []
- makeGen = ->
- _acc = acc.get()
- _fn = fn.get()
- _data = data.get()
- if _acc? and _fn? and _data? and _data.length > 0
- d = _data
- g = (i) ->
- i = i % d.length
- _fn(_acc(d[i], i))
-
- gen.setGen(g, _data.length)
- else
- gen.setGen(null)
-
- dvl.notify(gen)
-
- dvl.register({fn:makeGen, listen:[data, acc, fn], change:[gen], name:'array_make_gen'})
- return gen
-
-
-dvl.gen.fromRowData = dvl.gen.fromArray
-dvl.gen.fromColumnData = (data, acc, fn, name) ->
- data = dvl.wrapConstIfNeeded(data)
- acc = dvl.wrapConstIfNeeded(acc or dvl.identity)
- fn = dvl.wrapConstIfNeeded(fn or dvl.identity)
-
- gen = dvl.def(null, name or 'column_generator')
-
- d = []
- makeGen = ->
- a = acc.get()
- f = fn.get()
- dObj = data.get()
- if a? and f? and dObj? and d = a(dObj)
- g = (i) ->
- i = i % d.length
- f(d[i])
-
- gen.setGen(g, d.length)
- else
- gen.setGen(null)
-
- dvl.notify(gen)
-
- dvl.register({fn:makeGen, listen:[data, acc, fn], change:[gen], name:'array_make_gen'})
- return gen
-
-
-dvl.gen.equal = (genA, genB, retTrue, retFalse) ->
- retTrue = true if retTrue is undefined
- retFalse = false if retFalse is undefined
- retTrue = dvl.wrapConstIfNeeded(retTrue)
- retFalse = dvl.wrapConstIfNeeded(retFalse)
-
- gen = dvl.def(null, 'equal_generator')
-
- makeGen = ->
- a = genA.gen()
- b = genB.gen()
- ha = a?
- hb = b?
- rtg = retTrue.gen()
- rfg = retFalse.gen()
- rtl = retTrue.len()
- rfl = retFalse.len()
- if ha and ha
- lenA = genA.len() || Infinity
- lenB = genB.len() || Infinity
- gen.setGen(((i) -> if a(i) == b(i) then rtg(i) else rfg(i)), Math.min(lenA, lenB, rtl, rfl))
- else if not ha and not hb
- gen.setGen(rtg, rtl)
- else
- gen.setGen(rfg, rfl)
-
- dvl.notify(gen)
-
- dvl.register({fn:makeGen, listen:[genA, genB, retTrue, retFalse], change:[gen], name:'equal_make_gen'})
- return gen
-
-
-generator_maker_maker = (combiner, name) ->
- return () ->
- args = Array.prototype.slice.apply(arguments)
- gen = dvl.def(null, name + '_generator')
-
- makeGen = ->
- valid = (args.length > 0)
- gens = []
- lens = []
- for arg in args
- arg_gen = arg.gen()
- if arg_gen is null
- valid = false
- break
- gens.push arg_gen
- lens.push arg.len()
-
- if valid
- g = (i) ->
- gis = []
- gis.push cgen(i) for cgen in gens
- return combiner.apply(null, gis)
-
- gen.setGen(g, Math.min.apply(null, lens))
- else
- gen.setGen(null)
-
- dvl.notify(gen)
- return
+ sparkline: ({width, height, x, y, padding}) ->
+ padding ?= 0
+ return (selection, value) ->
+ lineFn = dvl.apply {
+ args: [x, y, padding]
+ fn: (x, y, padding) -> (d) ->
+ mmx = dvl.util.getMinMax(d, ((d) -> d[x]))
+ mmy = dvl.util.getMinMax(d, ((d) -> d[y]))
+ sx = d3.scale.linear().domain([mmx.min, mmx.max]).range([padding, width-padding])
+ sy = d3.scale.linear().domain([mmy.min, mmy.max]).range([height-padding, padding])
+ return d3.svg.line().x((dp) -> sx(dp[x])).y((dp) -> sy(dp[y]))(d)
+ }
- dvl.register({fn:makeGen, listen:args, change:[gen], name:name + '_make_gen'})
- return gen
+ dataFn = dvl.apply {
+ args: value
+ fn: (value) -> (d,i) -> [value(d,i)]
+ }
+ svg = dvl.bind {
+ parent: selection
+ self: 'svg.sparkline'
+ data: dataFn
+ attr: {
+ width
+ height
+ }
+ }
-dvl.gen.add = generator_maker_maker(((a,b,c) -> a+b+(c||0)), 'add')
-dvl.gen.sub = generator_maker_maker(((a,b,c) -> a-b-(c||0)), 'sub')
+ dvl.bind {
+ parent: svg
+ self: 'path'
+ data: (d) -> [d]
+ attr: {
+ d: lineFn
+ }
+ }
+ return
+ }
View
1,652 dvl.js
@@ -29,7 +29,7 @@ function lift(fn) {
return fn.apply(null, args);
};
}
-;var clipId, debug, default_compare_modes, dvl, dvl_get, dvl_op, fn, generator_maker_maker, id_class_spliter, k, op_to_lift, _ref;
+;var clipId, debug, dvl, dvl_get, dvl_op, fn, k, op_to_lift, _ref;
var __indexOf = Array.prototype.indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) {
if (this[i] === item) return i;
@@ -818,18 +818,18 @@ dvl.util = {
len = 0;
return {
push: function(l) {
- var _name;
+ var level;
len += 1;
- minLevel = Math.min(minLevel, l.level);
- (queue[_name = l.level] || (queue[_name] = [])).push(l);
- return null;
+ level = l.level;
+ minLevel = Math.min(minLevel, level);
+ (queue[level] || (queue[level] = [])).push(l);
},
shift: function() {
len -= 1;
- while (!queue[minLevel] || queue[minLevel].length === 0) {
+ while (!(queue[minLevel] && queue[minLevel].length)) {
minLevel += 1;
}
- return queue[minLevel].pop();
+ return queue[minLevel].shift();
},
length: function() {
return len;
@@ -1138,9 +1138,18 @@ dvl.assert = function(_arg) {
name: 'assert_fn'
});
};
-dvl.apply = function(_arg) {
- var allowNull, apply, args, fn, invalid, name, out, ret, update;
- fn = _arg.fn, args = _arg.args, out = _arg.out, name = _arg.name, invalid = _arg.invalid, allowNull = _arg.allowNull, update = _arg.update;
+dvl.apply = function() {
+ var allowNull, apply, args, fn, invalid, name, out, ret, update, _ref2;
+ switch (arguments.length) {
+ case 1:
+ _ref2 = arguments[0], fn = _ref2.fn, args = _ref2.args, out = _ref2.out, name = _ref2.name, invalid = _ref2.invalid, allowNull = _ref2.allowNull, update = _ref2.update;
+ break;
+ case 2:
+ args = arguments[0], fn = arguments[1];
+ break;
+ default:
+ throw "bad number of arguments";
+ }
fn = dvl.wrapConstIfNeeded(fn || dvl.identity);
if (args == null) {
throw 'dvl.apply only makes sense with at least one argument';
@@ -2194,194 +2203,205 @@ dvl.scale = {};
};
};
})();
-id_class_spliter = /(?=[#.:])/;
-dvl.bind = function(args) {
- var attrList, c, data, html, join, k, listen, nodeType, onList, out, parent, part, parts, self, staticClass, styleList, text, transition, transitionExit, v, _i, _len, _ref2, _ref3, _ref4;
- if (!args.parent) {
- throw "'parent' not defiend";
- }
- self = args.self;
- if (typeof self !== 'string') {
- throw "'self' not defiend";
- }
- parts = self.split(id_class_spliter);
- nodeType = parts.shift();
- staticClass = [];
- for (_i = 0, _len = parts.length; _i < _len; _i++) {
- part = parts[_i];
- c = part[0];
- if (c === '.') {
- staticClass.push(part.slice(1));
- } else {
- throw "not currently supported in 'self' (" + part + ")";
- }
- }
- staticClass = staticClass.join(' ');
- parent = dvl.wrapConstIfNeeded(args.parent);
- data = dvl.wrapConstIfNeeded(args.data || [void 0]);
- join = dvl.wrapConstIfNeeded(args.join);
- text = args.text ? dvl.wrapConstIfNeeded(args.text) : null;
- html = args.html ? dvl.wrapConstIfNeeded(args.html) : null;
- transition = dvl.wrapConstIfNeeded(args.transition);
- transitionExit = dvl.wrapConstIfNeeded(args.transitionExit);
- listen = [parent, data, join, text, html, transition, transitionExit];
- attrList = {};
- _ref2 = args.attr;
- for (k in _ref2) {
- v = _ref2[k];
- v = dvl.wrapConstIfNeeded(v);
- if (k === 'class' && staticClass) {
- v = dvl.op.concat(v, ' ' + staticClass);
- }
- listen.push(v);
- attrList[k] = v;
- }
- if (staticClass && !attrList['class']) {
- attrList['class'] = dvl["const"](staticClass);
- }
- styleList = {};
- _ref3 = args.style;
- for (k in _ref3) {
- v = _ref3[k];
- v = dvl.wrapConstIfNeeded(v);
- listen.push(v);
- styleList[k] = v;
- }
- onList = {};
- _ref4 = args.on;
- for (k in _ref4) {
- v = _ref4[k];
- v = dvl.wrapConstIfNeeded(v);
- listen.push(v);
- onList[k] = v;
- }
- out = dvl.def(null, 'selection');
- dvl.register({
- listen: listen,
- change: [out],
- fn: function() {
- var a, add1, add2, addO, e, enter, ex, force, k, postTrans, preTrans, s, t, v, _data, _j, _join, _k, _l, _len2, _len3, _len4, _parent, _transition, _transitionExit;
- _parent = parent.get();
- if (!_parent) {
- return;
+(function() {
+ var def_data_fn, id_class_spliter;
+ id_class_spliter = /(?=[#.:])/;
+ def_data_fn = dvl["const"](function(d) {
+ return [d];
+ });
+ return dvl.bind = function(args) {
+ var attrList, data, html, join, k, listen, nodeType, onList, out, parent, part, parts, self, staticClass, staticId, styleList, text, transition, transitionExit, v, _i, _len, _ref2, _ref3, _ref4;
+ if (!args.parent) {
+ throw "'parent' not defiend";
+ }
+ self = args.self;
+ if (typeof self !== 'string') {
+ throw "'self' not defiend";
+ }
+ parts = self.split(id_class_spliter);
+ nodeType = parts.shift();
+ staticId = null;
+ staticClass = [];
+ for (_i = 0, _len = parts.length; _i < _len; _i++) {
+ part = parts[_i];
+ switch (part[0]) {
+ case '#':
+ staticId = part.substring(1);
+ break;
+ case '.':
+ staticClass.push(part.substring(1));
+ break;
+ default:
+ throw "not currently supported in 'self' (" + part + ")";
+ }
+ }
+ staticClass = staticClass.join(' ');
+ parent = dvl.wrapConstIfNeeded(args.parent);
+ data = dvl.wrapConstIfNeeded(args.data || def_data_fn);
+ join = dvl.wrapConstIfNeeded(args.join);
+ text = args.text ? dvl.wrapConstIfNeeded(args.text) : null;
+ html = args.html ? dvl.wrapConstIfNeeded(args.html) : null;
+ transition = dvl.wrapConstIfNeeded(args.transition);
+ transitionExit = dvl.wrapConstIfNeeded(args.transitionExit);
+ listen = [parent, data, join, text, html, transition, transitionExit];
+ attrList = {};
+ _ref2 = args.attr;
+ for (k in _ref2) {
+ v = _ref2[k];
+ v = dvl.wrapConstIfNeeded(v);
+ if (k === 'class' && staticClass) {
+ v = dvl.op.concat(v, ' ' + staticClass);
}
- force = parent.hasChanged() || data.hasChanged() || join.hasChanged();
- _data = data.get();
- _join = join.get();
- if (_data) {
- _transition = transition.get();
- _transitionExit = transitionExit.get();
- enter = [];
- preTrans = [];
- postTrans = [];
- add1 = function(fn, v) {
- if (v.hasChanged() || force) {
- preTrans.push({
- fn: fn,
- a1: v.getPrev()
- });
- postTrans.push({
- fn: fn,
- a1: v.get()
- });
- } else {
- enter.push({
- fn: fn,
- a1: v.get()
- });
+ listen.push(v);
+ attrList[k] = v;
+ }
+ if (staticClass && !attrList['class']) {
+ attrList['class'] = dvl["const"](staticClass);
+ }
+ styleList = {};
+ _ref3 = args.style;
+ for (k in _ref3) {
+ v = _ref3[k];
+ v = dvl.wrapConstIfNeeded(v);
+ listen.push(v);
+ styleList[k] = v;
+ }
+ onList = {};
+ _ref4 = args.on;
+ for (k in _ref4) {
+ v = _ref4[k];
+ v = dvl.wrapConstIfNeeded(v);
+ listen.push(v);
+ onList[k] = v;
+ }
+ out = dvl.def(null, 'selection');
+ dvl.register({
+ listen: listen,
+ change: [out],
+ fn: function() {
+ var a, add1, add2, addO, e, enter, ex, force, k, postTrans, preTrans, s, t, v, _data, _j, _join, _k, _l, _len2, _len3, _len4, _parent, _transition, _transitionExit;
+ _parent = parent.get();
+ if (!_parent) {
+ return;
+ }
+ force = parent.hasChanged() || data.hasChanged() || join.hasChanged();
+ _data = data.get();
+ _join = join.get();
+ if (_data) {
+ _transition = transition.get();
+ _transitionExit = transitionExit.get();
+ enter = [];
+ preTrans = [];
+ postTrans = [];
+ add1 = function(fn, v) {
+ if (v.hasChanged() || force) {
+ preTrans.push({
+ fn: fn,
+ a1: v.getPrev()
+ });
+ postTrans.push({
+ fn: fn,
+ a1: v.get()
+ });
+ } else {
+ enter.push({
+ fn: fn,
+ a1: v.get()
+ });
+ }
+ };
+ add2 = function(fn, k, v) {
+ if (v.hasChanged() || force) {
+ preTrans.push({
+ fn: fn,
+ a1: k,
+ a2: v.getPrev()
+ });
+ postTrans.push({
+ fn: fn,
+ a1: k,
+ a2: v.get()
+ });
+ } else {
+ enter.push({
+ fn: fn,
+ a1: k,
+ a2: v.get()
+ });
+ }
+ };
+ addO = function(fn, k, v) {
+ if (v.hasChanged() || force) {
+ preTrans.push({
+ fn: fn,
+ a1: k,
+ a2: v.get()
+ });
+ } else {
+ enter.push({
+ fn: fn,
+ a1: k,
+ a2: v.get()
+ });
+ }
+ };
+ if (text) {
+ add1('text', text);
}
- };
- add2 = function(fn, k, v) {
- if (v.hasChanged() || force) {
- preTrans.push({
- fn: fn,
- a1: k,
- a2: v.getPrev()
- });
- postTrans.push({
- fn: fn,
- a1: k,
- a2: v.get()
- });
- } else {
- enter.push({
- fn: fn,
- a1: k,
- a2: v.get()
- });
+ if (html) {
+ add1('html', html);
}
- };
- addO = function(fn, k, v) {
- if (v.hasChanged() || force) {
- preTrans.push({
- fn: fn,
- a1: k,
- a2: v.get()
- });
+ for (k in attrList) {
+ v = attrList[k];
+ add2('attr', k, v);
+ }
+ for (k in styleList) {
+ v = styleList[k];
+ add2('style', k, v);
+ }
+ for (k in onList) {
+ v = onList[k];
+ addO('on', k, v);
+ }
+ s = _parent.selectAll(self).data(_data, _join);
+ e = s.enter().append(nodeType);
+ for (_j = 0, _len2 = enter.length; _j < _len2; _j++) {
+ a = enter[_j];
+ e[a.fn](a.a1, a.a2);
+ }
+ for (_k = 0, _len3 = preTrans.length; _k < _len3; _k++) {
+ a = preTrans[_k];
+ s[a.fn](a.a1, a.a2);
+ }
+ if (_transition && (_transition.duration != null)) {
+ t = s.transition();
+ t.duration(_transition.duration || 1000);
+ if (_transition.delay) {
+ t.delay(_transition.delay);
+ }
+ if (_transition.ease) {
+ t.ease(_transition.ease);
+ }
} else {
- enter.push({
- fn: fn,
- a1: k,
- a2: v.get()
- });
+ t = s;
}
- };
- if (text) {
- add1('text', text);
- }
- if (html) {
- add1('html', html);
- }
- for (k in attrList) {
- v = attrList[k];
- add2('attr', k, v);
- }
- for (k in styleList) {
- v = styleList[k];
- add2('style', k, v);
- }
- for (k in onList) {
- v = onList[k];
- addO('on', k, v);
- }
- s = _parent.selectAll(self).data(_data, _join);
- e = s.enter().append(nodeType);
- for (_j = 0, _len2 = enter.length; _j < _len2; _j++) {
- a = enter[_j];
- e[a.fn](a.a1, a.a2);
- }
- for (_k = 0, _len3 = preTrans.length; _k < _len3; _k++) {
- a = preTrans[_k];
- s[a.fn](a.a1, a.a2);
- }
- if (_transition && (_transition.duration != null)) {
- t = s.transition();
- t.duration(_transition.duration || 1000);
- if (_transition.delay) {
- t.delay(_transition.delay);
+ for (_l = 0, _len4 = postTrans.length; _l < _len4; _l++) {
+ a = postTrans[_l];
+ t[a.fn](a.a1, a.a2);
}
- if (_transition.ease) {
- t.ease(_transition.ease);
+ ex = s.exit().remove();
+ if (!(e.empty() && ex.empty())) {
+ out.set(s).notify();
}
} else {
- t = s;
- }
- for (_l = 0, _len4 = postTrans.length; _l < _len4; _l++) {
- a = postTrans[_l];
- t[a.fn](a.a1, a.a2);
- }
- ex = s.exit().remove();
- if (!(e.empty() && ex.empty())) {
+ s = _parent.selectAll(self).remove();
out.set(s).notify();
}
- } else {
- s = _parent.selectAll(self).remove();
- out.set(s).notify();
}
- }
- });
- return out;
-};
+ });
+ return out;
+ };
+})();
dvl.chain = function(f, h) {
var out;
f = dvl.wrapConstIfNeeded(f);
@@ -3021,986 +3041,362 @@ dvl.compare = function(acc, reverse) {
}
});
};
-default_compare_modes = ['up', 'down'];
-dvl.html.table2 = function(_arg) {
- var bodyCol, c, classStr, columns, comp, compare, compareList, compareMap, data, headerCol, parent, rowClass, rowLimit, sort, sortDir, sortOn, sortOnIndicator, table, _i, _len, _ref2, _ref3, _ref4;
- parent = _arg.parent, data = _arg.data, sort = _arg.sort, classStr = _arg.classStr, rowClass = _arg.rowClass, rowLimit = _arg.rowLimit, columns = _arg.columns;
- table = dvl.valueOf(parent).append('table').attr('class', classStr);
- sort = sort || {};
- sortOn = dvl.wrapVarIfNeeded(sort.on);
- sortDir = dvl.wrapVarIfNeeded(sort.dir);
- sortOnIndicator = dvl.wrapVarIfNeeded((_ref2 = sort.onIndicator) != null ? _ref2 : sortOn);
- headerCol = [];
- bodyCol = [];
- compareMap = {};
- compareList = [sortOn, sortDir];
- for (_i = 0, _len = columns.length; _i < _len; _i++) {
- c = columns[_i];
- if ((_ref3 = c.sortable) != null) {
- _ref3;
- } else {
- c.sortable = true;
- };
- if (c.sortable) {
- if (c.compare != null) {
- comp = dvl.wrapConstIfNeeded(c.compare);
+(function() {
+ var default_compare_modes;
+ default_compare_modes = ['up', 'down'];
+ dvl.html.table = function(_arg) {
+ var bodyCol, c, classStr, columns, comp, compare, compareList, compareMap, data, headerCol, parent, rowClass, rowLimit, sort, sortDir, sortOn, sortOnIndicator, table, _i, _len, _ref2, _ref3, _ref4;
+ parent = _arg.parent, data = _arg.data, sort = _arg.sort, classStr = _arg.classStr, rowClass = _arg.rowClass, rowLimit = _arg.rowLimit, columns = _arg.columns;
+ table = dvl.valueOf(parent).append('table').attr('class', classStr);
+ sort = sort || {};
+ sortOn = dvl.wrapVarIfNeeded(sort.on);
+ sortDir = dvl.wrapVarIfNeeded(sort.dir);
+ sortOnIndicator = dvl.wrapVarIfNeeded((_ref2 = sort.onIndicator) != null ? _ref2 : sortOn);
+ headerCol = [];
+ bodyCol = [];
+ compareMap = {};
+ compareList = [sortOn, sortDir];
+ for (_i = 0, _len = columns.length; _i < _len; _i++) {
+ c = columns[_i];
+ if ((_ref3 = c.sortable) != null) {
+ _ref3;
} else {
- comp = dvl.compare(c.value);
- }
- compareMap[c.id] = comp;
- compareList.push(comp);
- if (!((_ref4 = c.compareModes) != null ? _ref4[0] : void 0)) {
- c.compareModes = default_compare_modes;
- }
- }
- headerCol.push({
- id: c.id,
- title: c.title,
- classStr: c.classStr,
- tooltip: c.headerTooltip
- });
- bodyCol.push({
- id: c.id,
- "class": c.classStr,
- value: c.value,
- render: c.render,
- on: c.on
- });
- }
- compare = dvl.def(null, 'compare');
- dvl.register({
- listen: compareList,
- change: [compare],
- fn: function() {
- var cmp, oldCmp, _ref5, _sortDir, _sortOn;
- _sortOn = sortOn.get();
- _sortDir = sortDir.get();
- if (_sortOn != null) {
- cmp = (_ref5 = compareMap[_sortOn]) != null ? _ref5.get() : void 0;
- if (cmp && _sortDir === 'down') {
- oldCmp = cmp;
- cmp = function(a, b) {
- return oldCmp(b, a);
- };
+ c.sortable = true;
+ };
+ if (c.sortable) {
+ if (c.compare != null) {
+ comp = dvl.wrapConstIfNeeded(c.compare);
+ } else {
+ comp = dvl.compare(c.value);
}
- compare.set(cmp);
- } else {
- compare.set(null);
- }
- compare.notify();
- }
- });
- dvl.html.table2.header({
- parent: table,
- columns: headerCol,
- onClick: function(id) {
- var c, column, compareModes, _j, _len2;
- column = null;
- for (_j = 0, _len2 = columns.length; _j < _len2; _j++) {
- c = columns[_j];
- if (c.id === id) {
- column = c;
- break;
+ compareMap[c.id] = comp;
+ compareList.push(comp);
+ if (!((_ref4 = c.compareModes) != null ? _ref4[0] : void 0)) {
+ c.compareModes = default_compare_modes;
}
}
- if (!(column && column.sortable)) {
- return;
- }
- compareModes = column.compareModes;
- if (id === sortOn.get()) {
- sortDir.set(compareModes[(compareModes.indexOf(sortDir.get()) + 1) % compareModes.length]);
- dvl.notify(sortDir);
- } else {
- sortOn.set(id);
- sortDir.set(compareModes[0]);
- dvl.notify(sortOn, sortDir);
- }
- }
- });
- dvl.html.table2.body({
- parent: table,
- data: data,
- rowClass: rowClass,
- rowLimit: rowLimit,
- columns: bodyCol,
- compare: compare
- });
- return {};
-};
-dvl.html.table2.header = function(_arg) {
- var c, columns, listen, onClick, parent, thead, _i, _len;
- parent = _arg.parent, columns = _arg.columns, onClick = _arg.onClick;
- if (!parent) {
- throw 'there needs to be a parent';
- }
- thead = dvl.valueOf(parent).append('thead').append('tr');
- listen = [];
- for (_i = 0, _len = columns.length; _i < _len; _i++) {
- c = columns[_i];
- c.title = dvl.wrapConstIfNeeded(c.title);
- c.classStr = dvl.wrapConstIfNeeded(c.classStr);
- c.tooltip = dvl.wrapConstIfNeeded(c.tooltip);
- listen.push(c.title, c.classStr, c.tooltip);
- }
- dvl.register({
- name: 'head_render',
- listen: listen,
- fn: function() {
- var colSel;
- colSel = thead.selectAll('td').data(columns);
- colSel.enter().append('td');
- colSel.exit().remove();
- colSel.attr('class', function(c) {
- return c.classStr.get();
- }).attr('title', function(c) {
- return c.tooltip.get();
- }).text(function(c) {
- return c.title.get();
- }).on('click', function(c) {
- return onClick(c.id);
+ headerCol.push({
+ id: c.id,
+ title: c.title,
+ classStr: c.classStr,
+ tooltip: c.headerTooltip
+ });
+ bodyCol.push({
+ id: c.id,
+ "class": c.classStr,
+ value: c.value,
+ render: c.render,
+ on: c.on
});
}
- });
-};
-dvl.html.table2.body = function(_arg) {
- var c, change, columns, compare, data, k, listen, parent, render, rowClass, rowLimit, tbody, v, _i, _j, _len, _len2, _ref2;
- parent = _arg.parent, data = _arg.data, compare = _arg.compare, rowClass = _arg.rowClass, rowLimit = _arg.rowLimit, columns = _arg.columns;
- if (!parent) {
- throw 'there needs to be a parent';
- }
- if (!data) {
- throw 'there needs to be data';
- }
- tbody = dvl.valueOf(parent).append('tbody');
- compare = dvl.wrapConstIfNeeded(compare);
- if (rowClass != null) {
- rowClass = dvl.wrapConstIfNeeded(rowClass);
- }
- rowLimit = dvl.wrapConstIfNeeded(rowLimit);
- listen = [data, compare, rowClass, rowLimit];
- change = [];
- for (_i = 0, _len = columns.length; _i < _len; _i++) {
- c = columns[_i];
- c["class"] = dvl.wrapConstIfNeeded(c["class"]);
- c.value = dvl.wrapConstIfNeeded(c.value);
- listen.push(c["class"]);
- _ref2 = c.on;
- for (k in _ref2) {
- v = _ref2[k];
- v = dvl.wrapConstIfNeeded(v);
- listen.push(v);
- c.on[k] = v;
- }
- change.push(c.selection = dvl.def(null, "" + c.id + "_selection"));
- }
- dvl.register({
- name: 'body_render',
- listen: listen,
- change: change,
- fn: function() {
- var c, colSel, dataSorted, i, k, rowSel, sel, v, _compare, _data, _len2, _ref3, _rowClass, _rowLimit;
- _data = data.get();
- if (!_data) {
- tbody.selectAll('tr').remove();
- return;
- }
- dataSorted = _data;
- _compare = compare.get();
- if (_compare) {
- dataSorted = dataSorted.slice().sort(_compare);
- }
- _rowLimit = rowLimit.get();
- if (_rowLimit != null) {
- dataSorted = dataSorted.slice(0, _rowLimit);
- }
- rowSel = tbody.selectAll('tr').data(dataSorted);
- rowSel.enter().append('tr');
- rowSel.exit().remove();
- if (rowClass) {
- _rowClass = rowClass.get();
- rowSel.attr('class', _rowClass);
+ compare = dvl.def(null, 'compare');
+ dvl.register({
+ listen: compareList,
+ change: [compare],
+ fn: function() {
+ var cmp, oldCmp, _ref5, _sortDir, _sortOn;
+ _sortOn = sortOn.get();
+ _sortDir = sortDir.get();
+ if (_sortOn != null) {
+ cmp = (_ref5 = compareMap[_sortOn]) != null ? _ref5.get() : void 0;
+ if (cmp && _sortDir === 'down') {
+ oldCmp = cmp;
+ cmp = function(a, b) {
+ return oldCmp(b, a);
+ };
+ }
+ compare.set(cmp);
+ } else {
+ compare.set(null);
+ }
+ compare.notify();
}
- colSel = rowSel.selectAll('td').data(columns);
- colSel.enter().append('td');
- colSel.exit().remove();
- for (i = 0, _len2 = columns.length; i < _len2; i++) {
- c = columns[i];
- sel = tbody.selectAll("td:nth-child(" + (i + 1) + ")").data(dataSorted).attr('class', c["class"].get());
- _ref3 = c.on;
- for (k in _ref3) {
- v = _ref3[k];
- sel.on(k, v.get());
+ });
+ dvl.html.table.header({
+ parent: table,
+ columns: headerCol,
+ onClick: function(id) {
+ var c, column, compareModes, _j, _len2;
+ column = null;
+ for (_j = 0, _len2 = columns.length; _j < _len2; _j++) {
+ c = columns[_j];
+ if (c.id === id) {
+ column = c;
+ break;
+ }
+ }
+ if (!(column && column.sortable)) {
+ return;
+ }
+ compareModes = column.compareModes;
+ if (id === sortOn.get()) {
+ sortDir.set(compareModes[(compareModes.indexOf(sortDir.get()) + 1) % compareModes.length]);
+ dvl.notify(sortDir);
+ } else {
+ sortOn.set(id);
+ sortDir.set(compareModes[0]);
+ dvl.notify(sortOn, sortDir);
}
- c.selection.set(sel).notify();
}
+ });
+ dvl.html.table.body({
+ parent: table,
+ data: data,
+ rowClass: rowClass,
+ rowLimit: rowLimit,
+ columns: bodyCol,
+ compare: compare
+ });
+ return {};
+ };
+ dvl.html.table.header = function(_arg) {
+ var c, columns, listen, onClick, parent, thead, _i, _len;
+ parent = _arg.parent, columns = _arg.columns, onClick = _arg.onClick;
+ if (!parent) {
+ throw 'there needs to be a parent';
+ }
+ thead = dvl.valueOf(parent).append('thead').append('tr');
+ listen = [];
+ for (_i = 0, _len = columns.length; _i < _len; _i++) {
+ c = columns[_i];
+ c.title = dvl.wrapConstIfNeeded(c.title);
+ c.classStr = dvl.wrapConstIfNeeded(c.classStr);
+ c.tooltip = dvl.wrapConstIfNeeded(c.tooltip);
+ listen.push(c.title, c.classStr, c.tooltip);
}
- });
- for (_j = 0, _len2 = columns.length; _j < _len2; _j++) {
- c = columns[_j];
- render = typeof c.render !== 'function' ? dvl.html.table2.render[c.render || 'text'] : c.render;
- render.call(c, c.selection, c.value);
- }
-};
-dvl.html.table2.render = {
- text: function(selection, value) {
dvl.register({
- listen: [selection, value],
+ name: 'head_render',
+ listen: listen,
fn: function() {
- var _selection, _value;
- _selection = selection.get();
- _value = value.get();
- if ((_selection != null) && _value) {
- _selection.text(_value);
- }
+ var colSel;
+ colSel = thead.selectAll('td').data(columns);
+ colSel.enter().append('td');
+ colSel.exit().remove();
+ colSel.attr('class', function(c) {
+ return c.classStr.get();
+ }).attr('title', function(c) {
+ return c.tooltip.get();
+ }).text(function(c) {
+ return c.title.get();
+ }).on('click', function(c) {
+ return onClick(c.id);
+ });
}
});
- },
- html: function(selection, value) {
+ };
+ dvl.html.table.body = function(_arg) {
+ var c, change, columns, compare, data, k, listen, parent, render, rowClass, rowLimit, tbody, v, _i, _j, _len, _len2, _ref2;
+ parent = _arg.parent, data = _arg.data, compare = _arg.compare, rowClass = _arg.rowClass, rowLimit = _arg.rowLimit, columns = _arg.columns;
+ if (!parent) {
+ throw 'there needs to be a parent';
+ }
+ if (!data) {
+ throw 'there needs to be data';
+ }
+ tbody = dvl.valueOf(parent).append('tbody');
+ compare = dvl.wrapConstIfNeeded(compare);
+ if (rowClass != null) {
+ rowClass = dvl.wrapConstIfNeeded(rowClass);
+ }
+ rowLimit = dvl.wrapConstIfNeeded(rowLimit);
+ listen = [data, compare, rowClass, rowLimit];
+ change = [];
+ for (_i = 0, _len = columns.length; _i < _len; _i++) {
+ c = columns[_i];
+ c["class"] = dvl.wrapConstIfNeeded(c["class"]);
+ c.value = dvl.wrapConstIfNeeded(c.value);
+ listen.push(c["class"]);
+ _ref2 = c.on;
+ for (k in _ref2) {
+ v = _ref2[k];
+ v = dvl.wrapConstIfNeeded(v);
+ listen.push(v);
+ c.on[k] = v;
+ }
+ change.push(c.selection = dvl.def(null, "" + c.id + "_selection"));
+ }
dvl.register({
- listen: [selection, value],
+ name: 'body_render',
+ listen: listen,
+ change: change,
fn: function() {
- var _selection, _value;
- _selection = selection.get();
- _value = value.get();
- if ((_selection != null) && _value) {
- _selection.html(_value);
+ var c, colSel, dataSorted, i, k, rowSel, sel, v, _compare, _data, _len2, _ref3, _rowClass, _rowLimit;
+ _data = data.get();
+ if (!_data) {
+ tbody.selectAll('tr').remove();
+ return;
+ }
+ dataSorted = _data;
+ _compare = compare.get();
+ if (_compare) {
+ dataSorted = dataSorted.slice().sort(_compare);
+ }
+ _rowLimit = rowLimit.get();
+ if (_rowLimit != null) {
+ dataSorted = dataSorted.slice(0, _rowLimit);
+ }
+ rowSel = tbody.selectAll('tr').data(dataSorted);
+ rowSel.enter().append('tr');
+ rowSel.exit().remove();
+ if (rowClass) {
+ _rowClass = rowClass.get();
+ rowSel.attr('class', _rowClass);
+ }
+ colSel = rowSel.selectAll('td').data(columns);
+ colSel.enter().append('td');
+ colSel.exit().remove();
+ for (i = 0, _len2 = columns.length; i < _len2; i++) {
+ c = columns[i];
+ sel = tbody.selectAll("td:nth-child(" + (i + 1) + ")").data(dataSorted).attr('class', c["class"].get());
+ _ref3 = c.on;
+ for (k in _ref3) {
+ v = _ref3[k];
+ sel.on(k, v.get());
+ }
+ c.selection.set(sel).notify();
}
}
});
- },
- aLink: function(_arg) {
- var href;
- href = _arg.href;
- return function(selection, value) {
- dvl.bind({
- parent: selection,
- self: 'a.link',
- data: function(d) {
- return [d];
- },
- attr: {