Permalink
Browse files

add thumb events to legacy plugins

  • Loading branch information...
1 parent 700d59f commit a7eb9cd59fd92310f018cb53b4537ef62daf1225 @WardCunningham committed Jan 7, 2013
Showing with 95 additions and 15 deletions.
  1. +27 −8 client/plugins/chart/chart.coffee
  2. +35 −4 client/plugins/chart/chart.js
  3. +12 −1 client/plugins/line/line.coffee
  4. +21 −2 client/plugins/line/line.js
@@ -7,16 +7,35 @@ formatTime = (time) ->
mi = (if d.getMinutes() < 10 then "0" else "") + d.getMinutes()
"#{h}:#{mi} #{am}<br>#{d.getDate()} #{mo} #{d.getFullYear()}"
+display = (div, data) ->
+ [time, sample] = data
+ div.find('p:first').text sample.toFixed(1)
+ div.find('p:last').html formatTime(time)
+
+findData = (item, thumb) ->
+ for data in item.data
+ return data if data[0] is thumb
+ null
+
window.plugins.chart =
emit: (div, item) ->
chartElement = $('<p />').addClass('readout').appendTo(div).text(item.data.last().last())
captionElement = $('<p />').html(wiki.resolveLinks(item.caption)).appendTo(div)
bind: (div, item) ->
- div.find('p:first').mousemove (e) ->
- return unless (data = item.data[Math.floor(item.data.length * e.offsetX / e.target.offsetWidth)])?
- [time, sample] = data
- $(e.target).text sample.toFixed(1)
- $(e.target).siblings("p").last().html formatTime(time)
- .dblclick ->
- wiki.dialog "JSON for #{item.caption}", $('<pre/>').text(JSON.stringify(item.data, null, 2))
-
+
+ lastThumb = null
+
+ div.find('p:first')
+ .mousemove (e) ->
+ return unless (data = item.data[Math.floor(item.data.length * e.offsetX / e.target.offsetWidth)])?
+ [time, sample] = data
+ return if time == lastThumb || null == (lastThumb = time)
+ display div, data
+ div.trigger('thumb', +time)
+ .dblclick ->
+ wiki.dialog "JSON for #{item.caption}", $('<pre/>').text(JSON.stringify(item.data, null, 2))
+
+ $('.main').on 'thumb', (evt, thumb) ->
+ if thumb != lastThumb and (data = findData item, thumb)
+ lastThumb = thumb
+ display div, data

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -29,6 +29,15 @@ window.plugins.line =
x = d3.time.scale().domain(extent (p)->p.x).range([ 0, w ])
y = d3.scale.linear().domain(extent (p)->p.y).range([ h, 0 ])
+ lastThumb = null
+
+ $('.main').bind 'thumb', (e, thumb) ->
+ return if thumb is lastThumb
+ lastThumb = thumb
+ d3.selectAll("circle.line")
+ .attr('r', (d) -> if d.x.getTime() is thumb then 8 else 3.5)
+
+
vis = d3.select(div.get(0))
.data([ data ])
.append("svg:svg")
@@ -80,4 +89,6 @@ window.plugins.line =
.enter()
.append("svg:circle")
.attr("class", "line")
- .attr("cx", (d) -> x(d.x)).attr("cy", (d) -> y(d.y)).attr("r", 3.5)
+ .attr("cx", (d) -> x(d.x)).attr("cy", (d) -> y(d.y)).attr("r", 3.5)
+ .on('mouseover', (d) -> div.trigger('thumb', lastThumb = d.x.getTime()); d3.select(this).attr('r', 8))
+ .on('mouseout', -> d3.select(this).attr('r', 3.5))

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit a7eb9cd

Please sign in to comment.