11import snarkdown from 'snarkdown' ;
2+ import tippy from 'tippy.js' ;
3+ import { getTippyConfig } from '../lib' ;
4+ import { tippyLightCss } from './tippy-styles' ;
25
36const PVJS_URL = 'https://cdn.jsdelivr.net/npm/@wikipathways/pvjs@5.0.1/dist/pvjs.vanilla.js' ;
47const 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 */
296302export 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}
0 commit comments