Commit f7070d7b authored by Aron Carroll's avatar Aron Carroll

Re-use tabs in the heatmap plugin

This improves performance while scrolling as we're no longer destroying
and recreating every tab on each call to update.
parent 800c6cbf
...@@ -335,13 +335,22 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -335,13 +335,22 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
max = Math.max max, b.length max = Math.max max, b.length
# Update the data bindings # Update the data bindings
element = @element.empty() element = @element
# Update bucket pointers # Keep track of tabs to keep element creation to a minimum.
tabs = $.map @index, => @tabs ||= $([])
div = $('<div/>')
.appendTo(element) # Remove any extra tabs and update @tabs.
.addClass('heatmap-pointer') @tabs.slice(@buckets.length).remove()
@tabs = @tabs.slice(0, @buckets.length)
# Create any new tabs if needed.
$.each @buckets.slice(@tabs.length), =>
div = $('<div/>').appendTo(element)
@tabs.push(div[0])
div.addClass('heatmap-pointer')
# Creates highlights corresponding bucket when mouse is hovered # Creates highlights corresponding bucket when mouse is hovered
.on 'mousemove', (event) => .on 'mousemove', (event) =>
...@@ -379,9 +388,8 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -379,9 +388,8 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
annotations = @buckets[bucket].slice() annotations = @buckets[bucket].slice()
annotator.selectAnnotations annotations, annotator.selectAnnotations annotations,
(event.ctrlKey or event.metaKey), (event.ctrlKey or event.metaKey),
.get()
tabs = $(tabs) @tabs
.css 'margin-top', (d) => .css 'margin-top', (d) =>
if @isUpper(d) or @isLower(d) then '-9px' else '-8px' if @isUpper(d) or @isLower(d) then '-9px' else '-8px'
...@@ -402,8 +410,6 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -402,8 +410,6 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
if @dynamicBucket if @dynamicBucket
@annotator.updateViewer this._getDynamicBucket() @annotator.updateViewer this._getDynamicBucket()
@tabs = tabs
_getDynamicBucket: -> _getDynamicBucket: ->
top = window.pageYOffset top = window.pageYOffset
bottom = top + $(window).innerHeight() bottom = top + $(window).innerHeight()
......
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