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

Commit

Permalink
Merge pull request #1 from nickmelnikov82/allow-users-to-set-hoverinf…
Browse files Browse the repository at this point in the history
…o-config

Allow user to specify hoverinfo
  • Loading branch information
HammadTheOne authored Sep 24, 2021
2 parents 6b1b847 + f32b3e8 commit 794ebd4
Show file tree
Hide file tree
Showing 4 changed files with 475 additions and 417 deletions.
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

0 comments on commit 794ebd4

Please sign in to comment.