Calculate annotations weight and add weight css classes for color intensity

This commit is contained in:
Amaia Castro
2017-03-02 14:10:44 +01:00
parent 5f61e9f270
commit 854d51dd8e
4 changed files with 42 additions and 1 deletions

View File

@@ -153,6 +153,26 @@ App.LegislationAnnotatable =
return
), 100)
propotionalWeight: (v, max) ->
Math.floor(v*5/(max+1)) + 1
addWeightClasses: ->
annotationsLoaded: (annotations) ->
return if annotations.length == 0
weights = annotations.map (ann) -> ann.weight
max_weight = Math.max.apply(null, weights)
last_annotation = annotations[annotations.length - 1]
checkExist = setInterval((->
if $("span[data-annotation-id='" + last_annotation.id + "']").length
for annotation in annotations
ann_weight = App.LegislationAnnotatable.propotionalWeight(annotation.weight, max_weight)
el = $("span[data-annotation-id='" + annotation.id + "']")
el.addClass('weight-' + ann_weight)
clearInterval checkExist
return
), 100)
initialize: ->
$(document).off("renderLegislationAnnotation").on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments)
$(document).off('click', '[data-annotation-id]').on('click', '[data-annotation-id]', App.LegislationAnnotatable.onClick)
@@ -184,6 +204,7 @@ App.LegislationAnnotatable =
editorExtensions: [App.LegislationAnnotatable.editorExtension]
})
.include(App.LegislationAnnotatable.scrollToAnchor)
.include(App.LegislationAnnotatable.addWeightClasses)
.include(annotator.storage.http, { prefix: base_url, urls: { search: "/annotations/search" } })
App.LegislationAnnotatable.app.start().then ->

View File

@@ -103,6 +103,22 @@
background: rgba(255, 255, 10, 0.2);
}
.annotator-hl.weight-1 {
background: rgba(255, 255, 10, 0.2);
}
.annotator-hl.weight-2 {
background: rgba(255, 255, 10, 0.4);
}
.annotator-hl.weight-3 {
background: rgba(255, 255, 10, 0.6);
}
.annotator-hl.weight-4 {
background: rgba(255, 255, 10, 0.8);
}
.annotator-hl.weight-5 {
background: rgba(255, 255, 10, 1);
}
.current-annotation {
text-decoration: underline;
}