Commit 6afff414 authored by Aron Carroll's avatar Aron Carroll

WIP update heatmap plugin to work without d3

parent f3b769b1
...@@ -50,7 +50,6 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -50,7 +50,6 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
$(element).append @element $(element).append @element
pluginInit: -> pluginInit: ->
return unless d3?
this._maybeRebaseUrls() this._maybeRebaseUrls()
events = [ events = [
...@@ -349,56 +348,22 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -349,56 +348,22 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
if bucket.length if bucket.length
start = @buckets[i-1]?.length and ((@buckets[i-1].length + bucket.length) / 2) or 1e-6 start = @buckets[i-1]?.length and ((@buckets[i-1].length + bucket.length) / 2) or 1e-6
end = @buckets[i+1]?.length and ((@buckets[i+1].length + bucket.length) / 2) or 1e-6 end = @buckets[i+1]?.length and ((@buckets[i+1].length + bucket.length) / 2) or 1e-6
curve = d3.scale.pow().exponent(.1)
.domain([0, .5, 1])
.range([
[offsets[0], i, 0, start]
[d3.mean(offsets), i, .5, bucket.length]
[offsets[1], i, 1, end]
])
.interpolate(d3.interpolateArray)
curve(v) for v in d3.range(0, 1, .05)
else else
[ [offsets[0], i, 0, 1e-6] [ [offsets[0], i, 0, 1e-6]
[offsets[1], i, 1, 1e-6] ] [offsets[1], i, 1, 1e-6] ]
# Update the data bindings # Update the data bindings
element = d3.select(@element[0]) element = @element.empty()
# Update gradient stops
opacity = d3.scale.pow().domain([0, max]).range([.1, .6]).exponent(2)
stops = element
.select('#heatmap-gradient')
.selectAll('stop')
.data(stopData, (d) => d)
stops.enter().append('stop')
stops.exit().remove()
stops.order()
.attr('offset', (v) => v[0] / $(window).height())
.attr('stop-color', (v) =>
if max == 0 then this._colorize(1e-6) else this._colorize(v[3] / max))
.attr('stop-opacity', (v) ->
if max == 0 then .1 else opacity(v[3]))
# Update bucket pointers # Update bucket pointers
tabs = element tabs = $.map stopData, =>
.selectAll('div.heatmap-pointer') div = $('<div/>')
.appendTo(element)
.data => .addClass('heatmap-pointer')
buckets = []
@index.forEach (b, i) =>
if @buckets[i].length > 0 or @isUpper(i) or @isLower(i)
buckets.push i
@bucketIndices = buckets
buckets
tabs.enter().append('div')
.classed('heatmap-pointer', true)
# Creates highlights corresponding bucket when mouse is hovered # Creates highlights corresponding bucket when mouse is hovered
.on 'mousemove', (bucket) => .on 'mousemove', (event) =>
bucket = @tabs.index(event.currentTarget)
for hl in @annotator.getHighlights() for hl in @annotator.getHighlights()
if hl.annotation in @buckets[bucket] if hl.annotation in @buckets[bucket]
hl.setActive true, true hl.setActive true, true
...@@ -415,8 +380,9 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -415,8 +380,9 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
@annotator.publish "finalizeHighlights" @annotator.publish "finalizeHighlights"
# Does one of a few things when a tab is clicked depending on type # Does one of a few things when a tab is clicked depending on type
.on 'click', (bucket) => .on 'click', (event) =>
d3.event.stopPropagation() bucket = @tabs.index(event.currentTarget)
event.stopPropagation()
pad = defaultView.innerHeight * .2 pad = defaultView.innerHeight * .2
# If it's the upper tab, scroll to next anchor above # If it's the upper tab, scroll to next anchor above
...@@ -428,28 +394,28 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -428,28 +394,28 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
@dynamicBucket = true @dynamicBucket = true
@_jumpMinMax @buckets[bucket], "down" @_jumpMinMax @buckets[bucket], "down"
else else
d3.event.stopPropagation()
annotations = @buckets[bucket].slice() annotations = @buckets[bucket].slice()
annotator.selectAnnotations annotations, annotator.selectAnnotations annotations,
(d3.event.ctrlKey or d3.event.metaKey), (d3.event.ctrlKey or d3.event.metaKey),
.get()
tabs.exit().remove() tabs = $(tabs)
.css 'margin-top', (d) =>
tabs
.style 'margin-top', (d) =>
if @isUpper(d) or @isLower(d) then '-9px' else '-8px' if @isUpper(d) or @isLower(d) then '-9px' else '-8px'
.style 'top', (d) => .css 'top', (d) =>
"#{(@index[d] + @index[d+1]) / 2}px" "#{(@index[d] + @index[d+1]) / 2}px"
.html (d) => .html (d) =>
return unless @buckets[d]
"<div class='label'>#{@buckets[d].length}</div>" "<div class='label'>#{@buckets[d].length}</div>"
.classed('upper', @isUpper) .toggleClass('upper', @isUpper)
.classed('lower', @isLower) .toggleClass('lower', @isLower)
.style 'display', (d) => .css 'display', (d) =>
if (@buckets[d].length is 0) then 'none' else '' bucket = @buckets[d]
if (!bucket or bucket.length is 0) then 'none' else ''
if @dynamicBucket if @dynamicBucket
@annotator.updateViewer this._getDynamicBucket() @annotator.updateViewer this._getDynamicBucket()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment