Skip to content

Commit

Permalink
#4550 - Clean up code
Browse files Browse the repository at this point in the history
- Remove unused and deprecated old brat comment popup code
  • Loading branch information
reckart committed Feb 24, 2024
1 parent 4291e36 commit 09a133d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export type Message = 'dispatchAsynchError' | 'collectionLoaded' | 'requestRende
| 'svgWidth' | 'configurationUpdated' | 'newSourceData' | 'init' | 'click'
| 'contextmenu' | 'isReloadOkay' | 'spanAndAttributeTypesLoaded'
| 'keydown' | 'dragstart' | 'mousedown' | 'mouseup' | 'mousemove'
| 'displaySpanComment' | 'displayArcComment' | 'displaySentComment' | 'hideComment'
| 'resize' | 'displaySpanButtons' | 'configurationChanged'
| 'mouseover' | 'mouseout' | 'dblclick' | 'keypress' | 'touchstart' | 'touchend'
| 'collectionChanged' | 'renderData' | 'renderDataPatch' | 'triggerRender'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3555,14 +3555,6 @@ export class Visualizer {
evt.target.dispatchEvent(new AnnotationOverEvent(fakeSpan, evt.originalEvent))
}

this.dispatcher.post('displaySpanComment', [
evt, target, id, span.type, span.attributeText,
span.text,
span.hovertext,
span.comment && span.comment.text,
span.comment && span.comment.type
])

if (span.actionButtons) {
this.dispatcher.post('displaySpanButtons', [evt, target])
}
Expand Down Expand Up @@ -3702,14 +3694,6 @@ export class Visualizer {
}

const originSpanType = this.data.spans[originSpanId].type || ''
const targetSpanType = this.data.spans[targetSpanId].type || ''

this.dispatcher.post('displayArcComment', [
evt, target, symmetric, arcId,
originSpanId, originSpanType, role,
targetSpanId, targetSpanType,
commentText, commentType
])

if (arcId) {
if (evt.target) {
Expand Down Expand Up @@ -3758,8 +3742,6 @@ export class Visualizer {
fakeSpan.layer = { id: 0, name: Util.spanDisplayForm(this.entityTypes, comment.type) }
evt.target.dispatchEvent(new AnnotationOverEvent(fakeSpan, evt.originalEvent))
}

this.dispatcher.post('displaySentComment', [evt, comment.text, comment.type])
}
}
}
Expand Down Expand Up @@ -3788,7 +3770,6 @@ export class Visualizer {

const target = evt.target
target.classList.remove('badTarget')
this.dispatcher.post('hideComment')

if (this.highlight) {
this.highlight.map(h => h.remove())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ import type { Dispatcher } from '../dispatcher/Dispatcher'

import { INSTANCE as Configuration } from '../configuration/Configuration'

import { INSTANCE as Util } from '../util/Util'
import { DocumentData } from '../visualizer/DocumentData'
import { RelationTypeDto, EntityTypeDto, VID, CommentType } from '../protocol/Protocol'
import { RelationTypeDto, EntityTypeDto, VID } from '../protocol/Protocol'
import { DiamAjax, Offsets } from '@inception-project/inception-js-api'
import { Entity } from '../visualizer/Entity'
import { AttributeType } from '../visualizer/AttributeType'
Expand All @@ -55,25 +54,16 @@ export class VisualizerUI {

private dispatcher: Dispatcher

private commentPopup: JQuery
private commentDisplayed = false
private displayCommentTimer: number | undefined = undefined

private ajax: DiamAjax

constructor (dispatcher: Dispatcher, ajax: DiamAjax) {
console.debug('Setting up brat visualizer-ui module...')

this.ajax = ajax
this.commentPopup = $('#commentpopup')
this.dispatcher = dispatcher
this.dispatcher
.on('init', this, this.init)
.on('dataReady', this, this.rememberData)
// .on('displaySpanComment', this, this.displaySpanComment)
// .on('displayArcComment', this, this.displayArcComment)
// .on('displaySentComment', this, this.displaySentComment)
.on('hideComment', this, this.hideComment)
.on('resize', this, this.onResize)
.on('spanAndAttributeTypesLoaded', this, this.spanAndAttributeTypesLoaded)
.on('doneRendering', this, this.onDoneRendering)
Expand All @@ -84,231 +74,6 @@ export class VisualizerUI {
.on('contextmenu', this, this.contextMenu)
}

/* START comment popup - related */

/**
* @deprecated To be replaced with the new Popover component
*/
adjustToCursor (evt: MouseEvent, element, offset, top, right) {
// get the real width, without wrapping
element.css({ left: 0, top: 0 })
const screenWidth = $(window).width()
// FIXME why the hell is this 22 necessary?!?
const elementHeight = element.height() + 22
const elementWidth = element.width() + 22
let x, y
offset = offset || 0
if (top) {
y = evt.clientY - elementHeight - offset
if (y < 0) { top = false }
}
if (!top) {
y = evt.clientY + offset
}
if (right) {
x = evt.clientX + offset
if (x >= screenWidth - elementWidth) { right = false }
}
if (!right) {
x = evt.clientX - elementWidth - offset
}
if (y < 0) { y = 0 }
if (x < 0) { x = 0 }
element.css({ top: y, left: x })
}

/**
* @deprecated To be replaced with the new Popover component
*/
displaySentComment (evt: MouseEvent, commentText: string, commentType: CommentType) {
this.displayComment(evt, '', commentText, commentType)
}

/**
* @deprecated To be replaced with the new Popover component
*/
displayComment (evt: MouseEvent, comment: string, commentText: string, commentType: CommentType, immediately?: boolean) {
let idtype = ''
if (commentType) {
// label comment by type, with special case for default note type
let commentLabel: string
if (commentType === 'AnnotatorNotes') {
commentLabel = '<b>Note:</b> '
} else {
commentLabel = '<b>' + Util.escapeHTML(commentType) + ':</b> '
}
comment += '<hr/>'
comment += commentLabel + Util.escapeHTMLwithNewlines(commentText)
idtype = 'comment_' + commentType
}
this.commentPopup[0].className = idtype
this.commentPopup.html(comment)
this.adjustToCursor(evt, this.commentPopup, 10, true, true)
clearTimeout(this.displayCommentTimer)
/* slight "tooltip" delay to allow highlights to be seen
before the popup obstructs them. */
this.displayCommentTimer = setTimeout(() => {
this.commentPopup.show()
this.commentDisplayed = true
}, immediately ? 0 : 500)
}

// to avoid clobbering on delayed response
commentPopupNormInfoSeqId = 0

/**
* @deprecated To be replaced with the new Popover component
*/
compareLazyDetails (a, b) {
// images at the top
if (a[0].toLowerCase() === '<img>') return -1
if (b[0].toLowerCase() === '<img>') return 1
// otherwise stable
return Util.cmp(a[2], b[2])
}

/**
* @deprecated To be replaced with the new Popover component
*/
displaySpanComment (evt, target, spanId, spanType, mods, spanText, hoverText,
commentText, commentType) {
const immediately = false
let comment = ('<div><span class="comment_type_id_wrapper">' +
'<span class="comment_type">' + Util.escapeHTML(Util.spanDisplayForm(this.spanTypes, spanType)) + '</span>' + ' ' +
'<span class="comment_id">' + 'ID:' + Util.escapeHTML(spanId) + '</span></span>')
if (mods.length) {
comment += '<div>' + Util.escapeHTML(mods.join(', ')) + '</div>'
}

comment += '</div>'

if (hoverText != null) {
comment += ('<div class="comment_text">' + Util.escapeHTML(hoverText) + '</div>')
} else if (spanText) {
comment += ('<div class="comment_text">"' + Util.escapeHTML(spanText) + '"</div>')
}

comment += '<div id="lazy_details_drop_point"></div>'

// display initial comment HTML
this.displayComment(evt, comment, commentText, commentType, immediately)

// initiate AJAX calls for the normalization data to query
this.initiateNormalizationAjaxCall(spanId, spanType)
}

/**
* @deprecated To be replaced with the new Popover component
*/
displayArcComment (evt, target, symmetric, arcId, originSpanId, originSpanType,
role, targetSpanId, targetSpanType, commentText, commentType) {
if (!this.data) return
const arcRole = target.attr('data-arc-role')
// in arrowStr, &#8212 == mdash, &#8594 == Unicode right arrow
const arrowStr = symmetric ? '&#8212;' : '&#8594;'
const arcDisplayForm = Util.arcDisplayForm(this.spanTypes, this.data.spans[originSpanId].type, arcRole, this.relationTypesHash)
let comment = ''
comment += ('<span class="comment_type_id_wrapper">' +
'<span class="comment_type">' + Util.escapeHTML(Util.spanDisplayForm(this.spanTypes, originSpanType)) + ' ' + arrowStr + ' ' + Util.escapeHTML(arcDisplayForm) + ' ' + arrowStr + ' ' + Util.escapeHTML(Util.spanDisplayForm(this.spanTypes, targetSpanType)) + '</span>' +
'<span class="comment_id">' + (arcId ? 'ID:' + arcId : Util.escapeHTML(originSpanId) + arrowStr + Util.escapeHTML(targetSpanId)) + '</span>' +
'</span>')
comment += ('<div class="comment_text">' + Util.escapeHTML('"' + this.data.spans[originSpanId].text + '"') + arrowStr + Util.escapeHTML('"' + this.data.spans[targetSpanId].text + '"') + '</div>')
comment += '<div id="lazy_details_drop_point"></div>'

this.displayComment(evt, comment, commentText, commentType)

// initiate AJAX calls for the normalization data to query
this.initiateNormalizationAjaxCall(arcId, arcRole)
}

/**
* @deprecated To be replaced with the new Popover component
*/
initiateNormalizationAjaxCall (id: VID, type: number) {
this.ajax.loadLazyDetails(id, type).then(detailGroups => {
// extend comment popup with normalization data
let norminfo = ''

for (const group of detailGroups) {
const details = group.details
// flatten outer (name, attr, info) array (idx for sort)
let infos: [string, string, number][] = []
let idx = 0
for (let j = 0; j < details.length; j++) {
infos.push([details[j].label, details[j].value, idx++])
}

// sort, prioritizing images (to get floats right)
infos = infos.sort(this.compareLazyDetails)

// generate HTML
if (group.title) {
norminfo += `<hr/>
<span class="comment_id">${group.title}</span>
<br/>`
}

for (let i = 0; i < infos.length; i++) {
const label = infos[i][0] as string
let value = infos[i][1] as string
if (label && value) {
// special treatment for some label values
if (label.toLowerCase() === '<img>') {
norminfo += `<img class="norm_info_img" crossorigin src="${value}"/>`
} else {
// normal, as text max length restriction
if (value.length > 300) {
value = value.substr(0, 300) + ' ...'
}

norminfo += `<span class="norm_info_label">${Util.escapeHTML(label)}</span>
<span class="norm_info_value">: ${Util.escapeHTML(value)?.replace(/\n/g, '<br/>')}</span>
<br/>`
}
}
}
}

const drop = $('#lazy_details_drop_point')
if (drop) {
drop.html(norminfo)
} else {
console.log('Lazy details drop point not found!') // TODO XXX
}
})
}

/**
* @deprecated To be replaced with the new Popover component
*/
hideComment () {
clearTimeout(this.displayCommentTimer)
if (this.commentDisplayed) {
// BEGIN WEBANNO EXTENSION - #1610 - Improve brat visualization interaction performance
// - Show/hide comments immediately instead of using an animation to avoid costly reflows
/*
commentPopup.stop(true, true).fadeOut(0, function() {
commentDisplayed = false;
});
*/
this.commentPopup.hide()
this.commentDisplayed = false
// END WEBANNO EXTENSION - #1610 - Improve brat visualization interaction performance
}
clearTimeout(this.displayButtonsTimer)
}

/**
* @deprecated To be replaced with the new Popover component
*/
onMouseMove (evt: MouseEvent) {
if (this.commentDisplayed) {
this.adjustToCursor(evt, this.commentPopup, 10, true, true)
}
}

/* END comment popup - related */

// BEGIN WEBANNO EXTENSION - #1697 - Explicit UI for accepting/recejcting recommendations
displayButtonsTimer: number | undefined = undefined
buttonsShown = false
Expand Down Expand Up @@ -370,8 +135,6 @@ export class VisualizerUI {
width: acceptBtn.width() * 2 + spanWidth
})
.mouseleave(this.hideSpanButtons)
// hide the buttons when comments are hidden (i.e. mouse left the span)
this.dispatcher.on('hideComment', this, this.hideSpanButtons)

clearTimeout(this.displayButtonsTimer)
this.displayButtonsTimer = setTimeout(() => {
Expand Down

0 comments on commit 09a133d

Please sign in to comment.