Commit 94a56244 authored by Aron Carroll's avatar Aron Carroll

Merge pull request #1767 from hypothesis/rename-heatmap

Rename Heatmap -> BucketBar.
parents 80f00721 8e7da1e4
...@@ -2,7 +2,7 @@ var Klass = window.Annotator.Host; ...@@ -2,7 +2,7 @@ var Klass = window.Annotator.Host;
var docs = 'https://github.com/hypothesis/h/blob/master/README.rst#customized-embedding'; var docs = 'https://github.com/hypothesis/h/blob/master/README.rst#customized-embedding';
var options = { var options = {
app: jQuery('link[type="application/annotator+html"]').attr('href'), app: jQuery('link[type="application/annotator+html"]').attr('href'),
Heatmap: {container: '.annotator-frame'}, BucketBar: {container: '.annotator-frame'},
Toolbar: {container: '.annotator-frame'} Toolbar: {container: '.annotator-frame'}
}; };
......
...@@ -141,10 +141,10 @@ class Annotator.Guest extends Annotator ...@@ -141,10 +141,10 @@ class Annotator.Guest extends Annotator
.bind('onEditorSubmit', this.onEditorSubmit) .bind('onEditorSubmit', this.onEditorSubmit)
.bind('setDynamicBucketMode', (ctx, value) => .bind('setDynamicBucketMode', (ctx, value) =>
return unless @plugins.Heatmap return unless @plugins.BucketBar
return if @plugins.Heatmap.dynamicBucket is value return if @plugins.BucketBar.dynamicBucket is value
@plugins.Heatmap.dynamicBucket = value @plugins.BucketBar.dynamicBucket = value
if value then @plugins.Heatmap._update() if value then @plugins.BucketBar._update()
) )
.bind('focusAnnotations', (ctx, tags=[]) => .bind('focusAnnotations', (ctx, tags=[]) =>
...@@ -185,10 +185,6 @@ class Annotator.Guest extends Annotator ...@@ -185,10 +185,6 @@ class Annotator.Guest extends Annotator
this.publish 'setVisibleHighlights', state this.publish 'setVisibleHighlights', state
) )
.bind('updateHeatmap', =>
@plugins.Heatmap._scheduleUpdate()
)
_setupWrapper: -> _setupWrapper: ->
@wrapper = @element @wrapper = @element
.on 'click', (event) => .on 'click', (event) =>
...@@ -290,7 +286,7 @@ class Annotator.Guest extends Annotator ...@@ -290,7 +286,7 @@ class Annotator.Guest extends Annotator
# toggle: should this toggle membership in an existing selection? # toggle: should this toggle membership in an existing selection?
selectAnnotations: (annotations, toggle) => selectAnnotations: (annotations, toggle) =>
# Switch off dynamic mode; we are going to "Selection" scope # Switch off dynamic mode; we are going to "Selection" scope
@plugins.Heatmap.dynamicBucket = false @plugins.BucketBar.dynamicBucket = false
if toggle if toggle
# Tell sidebar to add these annotations to the sidebar # Tell sidebar to add these annotations to the sidebar
......
...@@ -42,9 +42,9 @@ class Annotator.Host extends Annotator.Guest ...@@ -42,9 +42,9 @@ class Annotator.Host extends Annotator.Guest
this.setTool('comment') this.setTool('comment')
this.setVisibleHighlights(!!options.showHighlights) this.setVisibleHighlights(!!options.showHighlights)
if @plugins.Heatmap? if @plugins.BucketBar?
this._setupDragEvents() this._setupDragEvents()
@plugins.Heatmap.element.on 'click', (event) => @plugins.BucketBar.element.on 'click', (event) =>
if @frame.hasClass 'annotator-collapsed' if @frame.hasClass 'annotator-collapsed'
this.showFrame() this.showFrame()
...@@ -118,7 +118,7 @@ class Annotator.Host extends Annotator.Guest ...@@ -118,7 +118,7 @@ class Annotator.Host extends Annotator.Guest
@drag.enabled = false @drag.enabled = false
@drag.last = null @drag.last = null
for handle in [@plugins.Heatmap.element[0], @plugins.Toolbar.buttons[0]] for handle in [@plugins.BucketBar.element[0], @plugins.Toolbar.buttons[0]]
handle.draggable = true handle.draggable = true
handle.addEventListener 'dragstart', dragStart handle.addEventListener 'dragstart', dragStart
handle.addEventListener 'dragend', dragEnd handle.addEventListener 'dragend', dragEnd
......
$ = Annotator.$ $ = Annotator.$
class Annotator.Plugin.Heatmap extends Annotator.Plugin class Annotator.Plugin.BucketBar extends Annotator.Plugin
# prototype constants # prototype constants
BUCKET_THRESHOLD_PAD: 30 BUCKET_THRESHOLD_PAD: 30
BUCKET_SIZE: 16 BUCKET_SIZE: 16
# heatmap svg skeleton # svg skeleton
html: """ html: """
<div class="annotator-heatmap"> <div class="annotator-bucket-bar">
<div class="annotator-heatmap-bar"></div>
</div> </div>
""" """
...@@ -97,7 +96,7 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -97,7 +96,7 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
addEventListener "docPageScrolling", this._scheduleUpdate addEventListener "docPageScrolling", this._scheduleUpdate
# Update the heatmap sometimes soon # Update sometime soon
_scheduleUpdate: => _scheduleUpdate: =>
return if @_updatePending return if @_updatePending
@_updatePending = true @_updatePending = true
...@@ -200,7 +199,7 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -200,7 +199,7 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
$.merge above, this._collectVirtualAnnotations 0, currentPage-1 $.merge above, this._collectVirtualAnnotations 0, currentPage-1
$.merge below, this._collectVirtualAnnotations currentPage+1, lastPage $.merge below, this._collectVirtualAnnotations currentPage+1, lastPage
# Construct control points for the heatmap # Construct indicator points
points = highlights.reduce (points, hl, i) => points = highlights.reduce (points, hl, i) =>
d = hl.annotation d = hl.annotation
x = hl.getTop() - defaultView.pageYOffset x = hl.getTop() - defaultView.pageYOffset
...@@ -312,7 +311,7 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -312,7 +311,7 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
@tabs.push(div[0]) @tabs.push(div[0])
div.addClass('heatmap-pointer') div.addClass('annotator-bucket-indicator')
# Creates highlights corresponding bucket when mouse is hovered # Creates highlights corresponding bucket when mouse is hovered
# TODO: This should use event delegation on the container. # TODO: This should use event delegation on the container.
......
...@@ -103,5 +103,5 @@ class Annotator.Plugin.Toolbar extends Annotator.Plugin ...@@ -103,5 +103,5 @@ class Annotator.Plugin.Toolbar extends Annotator.Plugin
else else
height = 35 height = 35
this.toolbar.css("min-height", "") this.toolbar.css("min-height", "")
this.annotator.plugins.Heatmap?.BUCKET_THRESHOLD_PAD = height this.annotator.plugins.BucketBar?.BUCKET_THRESHOLD_PAD = height
this.annotator.plugins.Heatmap?._update(); this.annotator.plugins.BucketBar?._update();
...@@ -128,14 +128,6 @@ class Hypothesis extends Annotator ...@@ -128,14 +128,6 @@ class Hypothesis extends Annotator
options.origin = '*' options.origin = '*'
provider = Channel.build options provider = Channel.build options
# Dodge toolbars [DISABLE]
#@provider.getMaxBottom (max) =>
# @element.css('margin-top', "#{max}px")
# @element.find('.topbar').css("top", "#{max}px")
# @element.find('#gutter').css("margin-top", "#{max}px")
# @plugins.Heatmap.BUCKET_THRESHOLD_PAD += max
provider
.bind('publish', (ctx, args...) => this.publish args...) .bind('publish', (ctx, args...) => this.publish args...)
......
...@@ -55,13 +55,13 @@ $negative: #d11c2b; ...@@ -55,13 +55,13 @@ $negative: #d11c2b;
$neutral: #0171ba; $neutral: #0171ba;
//OTHER VARIABLES //OTHER VARIABLES
$bucket-bar-width: 22px;
$highlight-color: rgba(255, 255, 60, 0.3); $highlight-color: rgba(255, 255, 60, 0.3);
$highlight-color-second: rgba(206, 206, 60, 0.4); $highlight-color-second: rgba(206, 206, 60, 0.4);
$highlight-color-third: rgba(192, 192, 49, 0.4); $highlight-color-third: rgba(192, 192, 49, 0.4);
$highlight-color-focus: rgba(192, 236, 253, 0.5); $highlight-color-focus: rgba(192, 236, 253, 0.5);
$score-width: 40px; $score-width: 40px;
$score-height: $score-width; $score-height: $score-width;
$heatmap-width: 22px;
$input-border-radius: 2px; $input-border-radius: 2px;
/* Style input placeholders */ /* Style input placeholders */
......
.heatmap-pointer { .annotator-bucket-bar {
background: hsla(0, 0, 0, .1);
cursor: ew-resize;
position: absolute;
height: 100%;
width: $bucket-bar-width;
left: -($bucket-bar-width);
}
.annotator-bucket-indicator {
@include box-sizing(border-box); @include box-sizing(border-box);
background: $white; background: $white;
border: solid 1px $gray-lighter; border: solid 1px $gray-lighter;
......
...@@ -72,32 +72,6 @@ $base-font-size: 14px; ...@@ -72,32 +72,6 @@ $base-font-size: 14px;
} }
//HEATMAP STUFF////////////////////////////////
.annotator-frame {
.annotator-heatmap {
cursor: ew-resize;
position: absolute;
overflow: hidden;
height: 100%;
width: $heatmap-width + 18px;
left: -($heatmap-width + 18px);
}
.annotator-heatmap-bar {
@include stretch-y;
background: hsla(0, 0, 0, .1);
border-left: solid 1px $gray-lighter;
height: 100%;
left: 18px;
width: $heatmap-width;
}
}
.annotator-frame {
@import 'pointers';
}
//HIGHLIGHTS//////////////////////////////// //HIGHLIGHTS////////////////////////////////
.annotator-hl { .annotator-hl {
&::-moz-selection { &::-moz-selection {
...@@ -131,6 +105,7 @@ $base-font-size: 14px; ...@@ -131,6 +105,7 @@ $base-font-size: 14px;
// Sidebar // Sidebar
.annotator-frame { .annotator-frame {
@import 'reset'; @import 'reset';
@import 'bucket-bar';
@include nested-reset; @include nested-reset;
@include reset-box-model; @include reset-box-model;
@include user-select(none); @include user-select(none);
...@@ -178,7 +153,7 @@ $base-font-size: 14px; ...@@ -178,7 +153,7 @@ $base-font-size: 14px;
//CONTROLBAR STUFF//////////////////////////////// //CONTROLBAR STUFF////////////////////////////////
.annotator-frame .annotator-toolbar { .annotator-frame .annotator-toolbar {
position: absolute; position: absolute;
left: -($heatmap-width + 18px - 7px); left: -($bucket-bar-width + 18px - 7px);
width: 37px; width: 37px;
z-index: 2; z-index: 2;
......
...@@ -48,7 +48,7 @@ module.exports = function(config) { ...@@ -48,7 +48,7 @@ module.exports = function(config) {
'h/static/scripts/helpers.js', 'h/static/scripts/helpers.js',
'h/static/scripts/session.js', 'h/static/scripts/session.js',
'h/static/scripts/hypothesis.js', 'h/static/scripts/hypothesis.js',
'h/static/scripts/plugin/heatmap.js', 'h/static/scripts/plugin/bucket-bar.js',
'h/static/scripts/vendor/sinon.js', 'h/static/scripts/vendor/sinon.js',
'h/static/scripts/vendor/chai.js', 'h/static/scripts/vendor/chai.js',
'h/static/scripts/hypothesis.js', 'h/static/scripts/hypothesis.js',
......
assert = chai.assert assert = chai.assert
sinon.assert.expose(assert, prefix: '') sinon.assert.expose(assert, prefix: '')
describe 'Annotator.Heatmap', -> describe 'Annotator.BucketBar', ->
createHeatmap = (options) -> createBucketBar = (options) ->
element = document.createElement('div') element = document.createElement('div')
new Annotator.Plugin.Heatmap(element, options || {}) new Annotator.Plugin.BucketBar(element, options || {})
# Yes this is testing a private method. Yes this is bad practice, but I'd # Yes this is testing a private method. Yes this is bad practice, but I'd
# rather test this functionality in a private method than not test it at all. # rather test this functionality in a private method than not test it at all.
describe '_buildTabs', -> describe '_buildTabs', ->
setup = (tabs) -> setup = (tabs) ->
heatmap = createHeatmap() bucketBar = createBucketBar()
heatmap.tabs = tabs bucketBar.tabs = tabs
heatmap.buckets = [['AN ANNOTATION?']] bucketBar.buckets = [['AN ANNOTATION?']]
heatmap.index = [ bucketBar.index = [
0, 0,
heatmap.BUCKET_THRESHOLD_PAD - 12, bucketBar.BUCKET_THRESHOLD_PAD - 12,
heatmap.BUCKET_THRESHOLD_PAD + heatmap.BUCKET_SIZE + 6 bucketBar.BUCKET_THRESHOLD_PAD + bucketBar.BUCKET_SIZE + 6
] ]
heatmap bucketBar
it 'creates a tab with a title', -> it 'creates a tab with a title', ->
tab = $('<div />') tab = $('<div />')
heatmap = setup(tab) bucketBar = setup(tab)
heatmap._buildTabs() bucketBar._buildTabs()
assert.equal(tab.attr('title'), 'Show one annotation') assert.equal(tab.attr('title'), 'Show one annotation')
it 'creates a tab with a pluralized title', -> it 'creates a tab with a pluralized title', ->
tab = $('<div />') tab = $('<div />')
heatmap = setup(tab) bucketBar = setup(tab)
heatmap.buckets[0].push('Another Annotation?') bucketBar.buckets[0].push('Another Annotation?')
heatmap._buildTabs() bucketBar._buildTabs()
assert.equal(tab.attr('title'), 'Show 2 annotations') assert.equal(tab.attr('title'), 'Show 2 annotations')
it 'sets the tab text to the number of annotations', -> it 'sets the tab text to the number of annotations', ->
tab = $('<div />') tab = $('<div />')
heatmap = setup(tab) bucketBar = setup(tab)
heatmap.buckets[0].push('Another Annotation?') bucketBar.buckets[0].push('Another Annotation?')
heatmap._buildTabs() bucketBar._buildTabs()
assert.equal(tab.text(), '2') assert.equal(tab.text(), '2')
it 'sets the tab text to the number of annotations', -> it 'sets the tab text to the number of annotations', ->
tab = $('<div />') tab = $('<div />')
heatmap = setup(tab) bucketBar = setup(tab)
heatmap.buckets[0].push('Another Annotation?') bucketBar.buckets[0].push('Another Annotation?')
heatmap._buildTabs() bucketBar._buildTabs()
assert.equal(tab.text(), '2') assert.equal(tab.text(), '2')
it 'adds the class "upper" if the annotation is at the top', -> it 'adds the class "upper" if the annotation is at the top', ->
tab = $('<div />') tab = $('<div />')
heatmap = setup(tab) bucketBar = setup(tab)
sinon.stub(heatmap, 'isUpper').returns(true) sinon.stub(bucketBar, 'isUpper').returns(true)
heatmap._buildTabs() bucketBar._buildTabs()
assert.equal(tab.hasClass('upper'), true) assert.equal(tab.hasClass('upper'), true)
it 'removes the class "upper" if the annotation is not at the top', -> it 'removes the class "upper" if the annotation is not at the top', ->
tab = $('<div />').addClass('upper') tab = $('<div />').addClass('upper')
heatmap = setup(tab) bucketBar = setup(tab)
sinon.stub(heatmap, 'isUpper').returns(false) sinon.stub(bucketBar, 'isUpper').returns(false)
heatmap._buildTabs() bucketBar._buildTabs()
assert.equal(tab.hasClass('upper'), false) assert.equal(tab.hasClass('upper'), false)
it 'adds the class "lower" if the annotation is at the top', -> it 'adds the class "lower" if the annotation is at the top', ->
tab = $('<div />') tab = $('<div />')
heatmap = setup(tab) bucketBar = setup(tab)
sinon.stub(heatmap, 'isLower').returns(true) sinon.stub(bucketBar, 'isLower').returns(true)
heatmap._buildTabs() bucketBar._buildTabs()
assert.equal(tab.hasClass('lower'), true) assert.equal(tab.hasClass('lower'), true)
it 'removes the class "lower" if the annotation is not at the top', -> it 'removes the class "lower" if the annotation is not at the top', ->
tab = $('<div />').addClass('lower') tab = $('<div />').addClass('lower')
heatmap = setup(tab) bucketBar = setup(tab)
sinon.stub(heatmap, 'isLower').returns(false) sinon.stub(bucketBar, 'isLower').returns(false)
heatmap._buildTabs() bucketBar._buildTabs()
assert.equal(tab.hasClass('lower'), false) assert.equal(tab.hasClass('lower'), false)
it 'reveals the tab if there are annotations in the bucket', -> it 'reveals the tab if there are annotations in the bucket', ->
tab = $('<div />') tab = $('<div />')
heatmap = setup(tab) bucketBar = setup(tab)
heatmap._buildTabs() bucketBar._buildTabs()
assert.equal(tab.css('display'), '') assert.equal(tab.css('display'), '')
it 'hides the tab if there are no annotations in the bucket', -> it 'hides the tab if there are no annotations in the bucket', ->
tab = $('<div />') tab = $('<div />')
heatmap = setup(tab) bucketBar = setup(tab)
heatmap.buckets = [] bucketBar.buckets = []
heatmap._buildTabs() bucketBar._buildTabs()
assert.equal(tab.css('display'), 'none') assert.equal(tab.css('display'), 'none')
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