Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
cytoscape-popper
Advanced tools
A Cytoscape.js extension for integrating Popper.js (demo) (tippy demo)
Popper.js allows you to dynamically align a div, e.g. a tooltip, to another element in the page. This extension allows you to use Popper.js 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.
Download the library:
npm install cytoscape-popper
,bower install cytoscape-popper
, orImport the library as appropriate for your project:
ES import:
import cytoscape from 'cytoscape';
import popper from 'cytoscape-popper';
cytoscape.use( popper );
CommonJS require:
let cytoscape = require('cytoscape');
let popper = require('cytoscape-popper');
cytoscape.use( popper ); // register extension
AMD:
require(['cytoscape', 'cytoscape-popper'], function( cytoscape, popper ){
popper( cytoscape ); // register extension
});
Plain HTML/JS has the extension registered for you automatically, because no require()
is needed.
This extension exposes two functions, popper()
and popperRef()
. 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 )
: Get a Popper object 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 )
: Get a Popper reference object for the specified core Cytoscape instance or the specified element. A Popper reference object 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()
manually 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 Popper options object. You may use this to override Popper options.popper()
example// create a basic popper on the first node
let popper1 = cy.nodes()[0].popper({
content: () => {
let div = document.createElement('div');
div.innerHTML = 'Popper content';
document.body.appendChild(div);
return div;
},
popper: {} // my popper options here
});
// create a basic popper on the core
let popper2 = cy.popper({
content: () => {
let div = document.createElement('div');
div.innerHTML = 'Popper content';
document.body.appendChild(div);
return div;
},
renderedPosition: () => ({ x: 100, y: 200 }),
popper: {} // my popper options here
});
popperRef()
example// create a basic popper ref for the first node
let popperRef1 = cy.nodes()[0].popperRef();
// create a basic popper on the core
let popperRef2 = cy.popperRef({
renderedPosition: () => ({ x: 200, y: 300 })
});
popper()
examplelet node = cy.nodes().first();
let popper = node.popper({
content: () => {
let div = document.createElement('div');
div.innerHTML = 'Sticky Popper content';
document.body.appendChild( div );
return div;
}
});
let update = () => {
popper.scheduleUpdate();
};
node.on('position', update);
cy.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 v1 is compatible with this extension. As of this writing, the latest compatible version of Tippy.js is v5.2.1.
:warning: Tippy.js v6+ is not compatible with Popper v1 (see this). As such, the latest (major) version of Tippy you can use is v5.
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.
let node = cy.nodes().first();
let ref = node.popperRef(); // used only for positioning
// unfortunately, a dummy element must be passed as tippy only accepts a dom element as the target
// https://github.com/atomiks/tippyjs/issues/661
let dummyDomEle = document.createElement('div');
// using tippy@^5.2.1
let tip = new Tippy(dummyDomEle, { // tippy options:
// mandatory:
trigger: 'manual', // call show() and hide() yourself
lazy: false, // needed for onCreate()
onCreate: instance => { instance.popperInstance.reference = ref; }, // needed for `ref` positioning
// your custom options follow:
content: () => {
let content = document.createElement('div');
content.innerHTML = 'Tippy content';
return content;
}
});
tip.show();
Refer to Tippy.js documentation for more details.
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
FAQs
A Cytoscape.js extension for Popper.js
The npm package cytoscape-popper receives a total of 20,057 weekly downloads. As such, cytoscape-popper popularity was classified as popular.
We found that cytoscape-popper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.