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 aabad71
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type Message = 'dispatchAsynchError' | 'collectionLoaded' | 'requestRende
| 'svgWidth' | 'configurationUpdated' | 'newSourceData' | 'init' | 'click'
| 'contextmenu' | 'isReloadOkay' | 'spanAndAttributeTypesLoaded'
| 'keydown' | 'dragstart' | 'mousedown' | 'mouseup' | 'mousemove'
| 'displaySpanComment' | 'displayArcComment' | 'displaySentComment' | 'hideComment'
| 'displaySpanComment' | 'displayArcComment' | 'displaySentComment'
| '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 @@ -3788,7 +3788,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 @@ -55,25 +55,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 Down Expand Up @@ -167,137 +158,6 @@ export class VisualizerUI {
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
*/
Expand Down Expand Up @@ -370,8 +230,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 aabad71

Please sign in to comment.