UNPKG

cytoscape-popper

Version:
147 lines (114 loc) 2.88 kB
<!DOCTYPE> <html> <head> <title>cytoscape-popper + TippyJS demo</title> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1"> <script src="https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script> <!-- for testing with local version of cytoscape.js --> <!--<script src="../cytoscape.js/build/cytoscape.js"></script>--> <script src="https://unpkg.com/@popperjs/core@2"></script> <script src="cytoscape-popper.js"></script> <script src="https://unpkg.com/tippy.js@6"></script> <style> body { font-family: helvetica neue, helvetica, liberation sans, arial, sans-serif; font-size: 14px } #cy { position: absolute; left: 0; top: 0; bottom: 0; right: 0; z-index: 1; } h1 { opacity: 0.5; font-size: 1em; font-weight: bold; } /* makes sticky faster; disable if you want animated tippies */ .tippy-popper { transition: none !important; } </style> <script> function tippyFactory(ref, content){ // Since tippy constructor requires DOM element/elements, create a placeholder var dummyDomEle = document.createElement('div'); var tip = tippy( dummyDomEle, { getReferenceClientRect: ref.getBoundingClientRect, trigger: 'manual', // mandatory // dom element inside the tippy: content: content, // your own preferences: arrow: true, placement: 'bottom', hideOnClick: false, sticky: "reference", // if interactive: interactive: true, appendTo: document.body // or append dummyDomEle to document.body } ); return tip; } document.addEventListener('DOMContentLoaded', function () { cytoscape.use(cytoscapePopper(tippyFactory)); var cy = window.cy = cytoscape({ container: document.getElementById('cy'), style: [ { selector: 'node', style: { 'content': 'data(id)' } }, { selector: 'edge', style: { 'curve-style': 'bezier', 'target-arrow-shape': 'triangle' } } ], elements: { nodes: [ { data: { id: 'a' } }, { data: { id: 'b' } } ], edges: [ { data: { id: 'ab', source: 'a', target: 'b' } } ] }, layout: { name: 'grid' } }); var a = cy.getElementById('a'); var b = cy.getElementById('b'); var ab = cy.getElementById('ab'); var makeContent = function(text){ var div = document.createElement('div'); div.innerHTML = text; return div; }; var tippyA = a.popper({ content: makeContent('foo'), }); tippyA.show(); var tippyB = b.popper({ content: makeContent('bar'), }); tippyB.show(); var tippyAB = ab.popper({ content: makeContent('baz'), }); tippyAB.show(); }); </script> </head> <body> <h1>cytoscape-popper + TippyJS demo</h1> <div id="cy"></div> </body> </html>