Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Allow user to specify hoverinfo #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions app/scripts/fornac.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function FornaContainer(element, passedOptions) {
'layout': 'standard-polygonal',
'allowPanningAndZooming': true,
'transitionDuration': 500,
'hoverPattern': '',
'resizeSvgOnResize': true //change the size of the svg when resizing the container
//sometimes its beneficial to turn this off, especially when
//performance is an issue
Expand Down Expand Up @@ -760,6 +761,10 @@ export function FornaContainer(element, passedOptions) {
}
};

self.setHoverPattern = function(newPattern) {
self.options['hoverPattern'] = newPattern || '';
}

function mousedown() {

}
Expand Down Expand Up @@ -1511,7 +1516,7 @@ export function FornaContainer(element, passedOptions) {
.append('svg:title')
.text(function(d) {
if (d.nodeType == 'nucleotide') {
return d.structName + ':' + d.num;
return self.getTitleText(d)
} else {
return '';
}
Expand All @@ -1524,7 +1529,7 @@ export function FornaContainer(element, passedOptions) {
.append('svg:title')
.text(function(d) {
if (d.nodeType == 'nucleotide') {
return d.structName + ':' + d.num;
return self.getTitleText(d)
} else {
return '';
}
Expand All @@ -1549,7 +1554,7 @@ export function FornaContainer(element, passedOptions) {
labelsEnter.append('svg:title')
.text(function(d) {
if (d.nodeType == 'nucleotide') {
return d.structName + ':' + d.num;
return self.getTitleText(d)
} else {
return '';
}
Expand All @@ -1561,13 +1566,11 @@ export function FornaContainer(element, passedOptions) {

var nodeTooltip = function(d) {
nodeTooltips = {};

nodeTooltips.nucleotide = d.num;
nodeTooltips.label = '';
nodeTooltips.pseudo = '';
nodeTooltips.middle = '';
nodeTooltips.protein = d.structName;

return nodeTooltips[d.nodeType];
};

Expand Down Expand Up @@ -1654,6 +1657,31 @@ export function FornaContainer(element, passedOptions) {
self.updateStyle();
};

self.getTitleText = function (d) {
var pattern = self.getHoverPattern(d)
var result = pattern;

var keys = pattern.split('${').slice(1).map(elem => elem.split('}')[0])

keys.forEach(key => {
var fieldValue = d[key];

if (!fieldValue) {
console.warn(`The property ${key} isn't correct node property`)
fieldValue = ''
}
result = result.replace(`\${${key}}`, fieldValue);
});
return result;
};

self.getHoverPattern = function(d) {
var structNameIsPresent = d['structName'] && d['structName'] !== 'empty'
var defaultPattern = structNameIsPresent ? '${structName}:${num}' : '${nodeType}:${num}'
var patternIsPresent = self.options['hoverPattern'] && self.options['hoverPattern'].length > 0
return patternIsPresent ? self.options['hoverPattern'] : defaultPattern;
}

self.setSize();
}

Expand Down
Loading