Skip to content

Commit c9a0f0c

Browse files
committed
Show customizable tooltip on pathway gene node hover
1 parent ccd6d1b commit c9a0f0c

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

src/js/kit/pathway-viewer.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import snarkdown from 'snarkdown';
2+
import tippy from 'tippy.js';
3+
import {getTippyConfig} from '../lib';
4+
import { tippyLightCss } from './tippy-styles';
25

36
const PVJS_URL = 'https://cdn.jsdelivr.net/npm/@wikipathways/pvjs@5.0.1/dist/pvjs.vanilla.js';
47
const SVGPANZOOM_URL = 'https://cdn.jsdelivr.net/npm/svg-pan-zoom@3.5.0/dist/svg-pan-zoom.min.js';
@@ -292,12 +295,16 @@ function addFooter(pathwayJson, pathwayContainer) {
292295
pathwayContainer.insertAdjacentHTML('beforeEnd', footer);
293296
}
294297

298+
function addPathwayNodeListeners() {
299+
}
300+
295301
/** Fetch and render WikiPathways diagram for given pathway ID */
296302
export async function drawPathway(
297303
pwId, sourceGene, destGene,
298304
outerSelector='#_ideogramOuterWrap',
299305
dimensions={height: 440, width: 900},
300306
showClose=true,
307+
nodeHoverFn,
301308
retryAttempt=0
302309
) {
303310
const pvjsScript = document.querySelector(`script[src="${PVJS_URL}"]`);
@@ -318,7 +325,8 @@ export async function drawPathway(
318325
setTimeout(() => {
319326
drawPathway(
320327
pwId, sourceGene, destGene,
321-
outerSelector, dimensions, showClose, retryAttempt++
328+
outerSelector, dimensions, showClose, nodeHoverFn,
329+
retryAttempt++
322330
);
323331
}, 250);
324332
return;
@@ -396,4 +404,27 @@ export async function drawPathway(
396404
// Notify listeners of event completion
397405
const ideogramPathwayEvent = new CustomEvent('ideogramDrawPathway', {detail});
398406
document.dispatchEvent(ideogramPathwayEvent);
407+
408+
const css =
409+
`<style>
410+
${tippyLightCss}
411+
</style>`;
412+
pvjsContainer.insertAdjacentHTML('afterBegin', css);
413+
414+
pathwayContainer.querySelectorAll('g.GeneProduct').forEach(g => {
415+
const geneName = g.getAttribute('name');
416+
let tooltipContent = geneName;
417+
g.addEventListener('mouseover', (event) => {
418+
if (nodeHoverFn) {
419+
tooltipContent = nodeHoverFn(geneName);
420+
g.setAttribute('data-tippy-content', tooltipContent);
421+
tippy('g.GeneProduct[data-tippy-content]', tippyConfig);
422+
}
423+
});
424+
425+
g.setAttribute(`data-tippy-content`, tooltipContent);
426+
});
427+
428+
const tippyConfig = getTippyConfig();
429+
tippy('g.GeneProduct[data-tippy-content]', tippyConfig);
399430
}

src/js/kit/related-genes.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,12 @@ function addPathwayListeners(ideo) {
16571657
// const pathwayName = target.getAttribute('data-pathway-name');
16581658
// const pathway = {id: pathwayId, name: pathwayName};
16591659
// plotPathwayGenes(searchedGene, pathway, ideo);
1660-
drawPathway(pathwayId, searchedGene, interactingGene);
1660+
function nodeHoverFn(geneName) {
1661+
console.log('in nodeHoverFn')
1662+
return '<div>ok ' + geneName + '</div><div>1234</div>';
1663+
}
1664+
drawPathway(pathwayId, searchedGene, interactingGene,
1665+
undefined, undefined, undefined, nodeHoverFn);
16611666
event.stopPropagation();
16621667
});
16631668
});

0 commit comments

Comments
 (0)