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 1 commit
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
26 changes: 21 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,
'titlePattern': '${structName}:${num}',
'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.setTitlePattern = function(newPattern) {
self.options['titlePattern'] = 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.getGetTitleText(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.getGetTitleText(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.getGetTitleText(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,19 @@ export function FornaContainer(element, passedOptions) {
self.updateStyle();
};

self.getGetTitleText = function (d) {
nickmelnikov82 marked this conversation as resolved.
Show resolved Hide resolved
var pattern = self.options['titlePattern'] || '';
var result = pattern;

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

keys.forEach(key => {
var fieldValue = d[key] || '';
result = result.replace(`\${${key}}`, fieldValue);
});
return result;
};

self.setSize();
}

Expand Down
Loading