Gathering detailed insights and metrics for cytoscape-popper
Gathering detailed insights and metrics for cytoscape-popper
Gathering detailed insights and metrics for cytoscape-popper
Gathering detailed insights and metrics for cytoscape-popper
npm install cytoscape-popper
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
97 Stars
153 Commits
23 Forks
18 Watching
4 Branches
33 Contributors
Updated on 06 Nov 2024
JavaScript (65.26%)
HTML (34.74%)
Cumulative downloads
Total Downloads
Last day
-7%
5,037
Compared to previous day
Last week
7%
27,211
Compared to previous week
Last month
6.2%
114,405
Compared to previous month
Last year
18.6%
1,250,958
Compared to previous year
Popper allows you to dynamically align a div, e.g. a tooltip, to another element in the page. This extension allows you to use any popper library on Cytoscape elements. This allows you to create DOM elements positioned on or around Cytoscape elements. It is useful for tooltips and overlays, for example.
Integration examples:
Since Popper.js
has become @floating-ui
(https://floating-ui.com/docs/migration) and the API has changed a lot it becomes harder to support both versions
(for example TippyJS, that supports only the previous version), so instead of depending on a specific external version
this extension allows users to use any Popper library with providing popperFactory
function during initializing.
See FloatingUI or Popper.js sections.
Download the library:
npm install cytoscape-popper
,bower install cytoscape-popper
, orImport the library as appropriate for your project:
ES import:
1import cytoscape from 'cytoscape'; 2import cytoscapePopper from 'cytoscape-popper'; 3 4function popperFactory(ref, content, opts) { 5 // See integration sections 6} 7 8cytoscape.use( cytoscapePopper(popperFactory) );
CommonJS require:
1let cytoscape = require('cytoscape');
2let cytoscapePopper = require('cytoscape-popper');
3
4function popperFactory(ref, content, opts) {
5 // See integration sections
6}
7
8cytoscape.use( cytoscapePopper(popperFactory) ); // register extension
AMD:
1require(['cytoscape', 'cytoscape-popper'], function( cytoscape, popper ){ 2 function popperFactory(ref, content, opts) { 3 // See integration sections 4 } 5 // register extension 6 popper(popperFactory)(cytoscape); 7});
This extension exposes popper()
and popperRef()
functions and provided popperFactory()
. These functions are defined for both the core and for elements, so you can call cy.popper()
or ele.popper()
for example.
Each function takes an options object, as follows:
cy.popper( options )
or ele.popper( options )
: Make a PopperInstance
for the specified core Cytoscape instance or the specified element. This is useful for positioning a div relative to or on top of a core instance or element.
cy.popperRef( options )
or ele.popperRef( options )
: Make a PopperInstance
for the specified core Cytoscape instance or the specified element. A Popper virtual element is useful only for positioning, as it represent the target rather than the content. This is useful for cases where you want to create a new Popper instance manually via Popper constructor createPopper()
or where you need to pass a popperRef
object to another library like Tippy.js.
options
content
: The HTML content of the popper. May be a DOM Element
reference or a function that returns one.renderedPosition
: A function that can be used to override the rendered Cytoscape position of the Popper target. This option is mandatory when using Popper on the core. For an element, the centre of its bounding box is used by default.renderedDimensions
: A function that can be used to override the rendered Cytoscape bounding box dimensions considered for the popper target (i.e. cy
or ele
). It defines only the effective width and height (bb.w
and bb.h
) of the Popper target. This option is more often useful for elements rather than for the core.popper
: The PopperOptions
object. These options are used in provided popperFactory
.1import cytoscape from 'cytoscape'; 2import cytoscapePopper from 'cytoscape-popper'; 3import { 4 computePosition, 5 flip, 6 shift, 7 limitShift, 8} from '@floating-ui/dom'; 9 10function popperFactory(ref, content, opts) { 11 // see https://floating-ui.com/docs/computePosition#options 12 const popperOptions = { 13 // matching the default behaviour from Popper@2 14 // https://floating-ui.com/docs/migration#configure-middleware 15 middleware: [ 16 flip(), 17 shift({limiter: limitShift()}) 18 ], 19 ...opts, 20 } 21 22 function update() { 23 computePosition(ref, content, popperOptions).then(({x, y}) => { 24 Object.assign(content.style, { 25 left: `${x}px`, 26 top: `${y}px`, 27 }); 28 }); 29 } 30 update(); 31 return { update }; 32} 33 34cytoscape.use(cytoscapePopper(popperFactory));
popper()
example1// create a basic popper on the first node 2let popper1 = cy.nodes()[0].popper({ 3 content: () => { 4 let div = document.createElement('div'); 5 6 div.innerHTML = 'Popper content'; 7 8 document.body.appendChild(div); 9 10 return div; 11 } 12}); 13 14// create a basic popper on the core with custom options 15let popper2 = cy.popper({ 16 content: () => { 17 let div = document.createElement('div'); 18 19 div.innerHTML = 'Popper content'; 20 21 document.body.appendChild(div); 22 23 return div; 24 }, 25 renderedPosition: () => ({ x: 100, y: 200 }), 26 popper: { 27 placement: 'bottom', 28 } // @flaoting-ui options (https://floating-ui.com/docs/middleware) 29});
popperRef()
example1// create a basic popper ref for the first node 2let popperRef1 = cy.nodes()[0].popperRef(); 3 4// create a basic popper ref on the core 5let popperRef2 = cy.popperRef({ 6 renderedPosition: () => ({ x: 200, y: 300 }) 7});
popper()
example1let node = cy.nodes().first(); 2 3let popper = node.popper({ 4 content: () => { 5 let div = document.createElement('div'); 6 7 div.innerHTML = 'Sticky Popper content'; 8 9 document.body.appendChild( div ); 10 11 return div; 12 } 13}); 14 15let update = () => { 16 popper.update(); 17}; 18 19node.on('position', update); 20 21cy.on('pan zoom resize', update);
1import cytoscape from 'cytoscape'; 2import cytoscapePopper from 'cytoscape-popper'; 3import { createPopper } from '@popperjs/core'; 4 5cytoscape.use(cytoscapePopper(createPopper));
popper()
example1// create a basic popper on the first node 2let popper1 = cy.nodes()[0].popper({ 3 content: () => { 4 let div = document.createElement('div'); 5 6 div.innerHTML = 'Popper content'; 7 8 document.body.appendChild(div); 9 10 return div; 11 }, 12 popper: {} // my popper options here 13}); 14 15// create a basic popper on the core 16let popper2 = cy.popper({ 17 content: () => { 18 let div = document.createElement('div'); 19 20 div.innerHTML = 'Popper content'; 21 22 document.body.appendChild(div); 23 24 return div; 25 }, 26 renderedPosition: () => ({ x: 100, y: 200 }), 27 popper: {} // my popper options here 28});
popperRef()
example1// create a basic popper ref for the first node 2let popperRef1 = cy.nodes()[0].popperRef(); 3 4// create a basic popper ref on the core 5let popperRef2 = cy.popperRef({ 6 renderedPosition: () => ({ x: 200, y: 300 }) 7});
popper()
example1let node = cy.nodes().first(); 2 3let popper = node.popper({ 4 content: () => { 5 let div = document.createElement('div'); 6 7 div.innerHTML = 'Sticky Popper content'; 8 9 document.body.appendChild( div ); 10 11 return div; 12 } 13}); 14 15let update = () => { 16 popper.update(); 17}; 18 19node.on('position', update); 20 21cy.on('pan zoom resize', update);
This extension can also be used to enable Tippy.js tooltip functionality with Cytoscape. Any version of Tippy that is compatible with Popper v2 is compatible with this extension.
1import cytoscape from 'cytoscape'; 2import popper from 'cytoscape-popper'; 3import tippy from 'tippy.js'; 4 5function tippyFactory(ref, content){ 6 // Since tippy constructor requires DOM element/elements, create a placeholder 7 var dummyDomEle = document.createElement('div'); 8 9 var tip = tippy( dummyDomEle, { 10 getReferenceClientRect: ref.getBoundingClientRect, 11 trigger: 'manual', // mandatory 12 // dom element inside the tippy: 13 content: content, 14 // your own preferences: 15 arrow: true, 16 placement: 'bottom', 17 hideOnClick: false, 18 sticky: "reference", 19 20 // if interactive: 21 interactive: true, 22 appendTo: document.body // or append dummyDomEle to document.body 23 } ); 24 25 return tip; 26} 27 28cytoscape.use(cytoscapePopper(tippyFactory));
The creation of many Tippy
instances at once has performance implications, especially for large graphs. Create each instance on demand, e.g. on tap
. Use destroy()
instead of hide()
where possible.
1let node = cy.nodes().first(); 2 3var tip = node.popper({ 4 content: () => { 5 let content = document.createElement('div'); 6 7 content.innerHTML = 'Tippy content'; 8 9 return content; 10 }, 11}); 12 13tip.show();
Refer to Tippy.js documentation for more details.
This extension exports empty PopperInstance
and PopperOptions
interfaces allows to extend them according to the final Popper implementation.
@floating-ui
example:
1import { ComputePositionConfig } from '@floating-ui/dom'; 2 3declare module 'cytoscape-popper' { 4 interface PopperOptions extends ComputePositionConfig { 5 } 6 interface PopperInstance { 7 update(): void; 8 } 9} 10
npm run test
: Run Mocha tests in ./test
npm run build
: Build ./src/**
into cytoscape-popper.js
npm run watch
: Automatically build on changes with live reloading (N.b. you must already have an HTTP server running)npm run dev
: Automatically build on changes with live reloading with webpack dev servernpm run lint
: Run eslint on the sourceN.b. all builds use babel, so modern ES features can be used in the src
.
This project is set up to automatically be published to npm and bower. To publish:
npm run build:release
git commit -am "Build for release"
npm version major|minor|patch
git push && git push --tags
npm publish .
bower register cytoscape-popper https://github.com/cytoscape/cytoscape.js-popper.git
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 5/14 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
48 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More