https://github.com/cytoscape/cytoscape.js-popper
A wrapper for Popper.js that lets you position divs relative to Cytoscape elements
Science Score: 33.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
✓Academic publication links
Links to: zenodo.org -
✓Committers with academic emails
3 of 11 committers (27.3%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.5%) to scientific vocabulary
Keywords from Contributors
Repository
A wrapper for Popper.js that lets you position divs relative to Cytoscape elements
Basic Info
Statistics
- Stars: 104
- Watchers: 17
- Forks: 23
- Open Issues: 3
- Releases: 0
Metadata Files
README.md
cytoscape-popper
Description
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: - Floating UI - demo, usage - Popper.js@2 - demo, usage - Tippy.JS - demo, usage
Migration from v2
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.
Dependencies
- Cytoscape.js ^3.2.0
Usage instructions
Download the library:
* via npm: npm install cytoscape-popper,
* via bower: bower install cytoscape-popper, or
* via direct download in the repository (probably from a tag).
Import the library as appropriate for your project:
ES import:
```js import cytoscape from 'cytoscape'; import cytoscapePopper from 'cytoscape-popper';
function popperFactory(ref, content, opts) { // See integration sections }
cytoscape.use( cytoscapePopper(popperFactory) ); ```
CommonJS require:
```js let cytoscape = require('cytoscape'); let cytoscapePopper = require('cytoscape-popper');
function popperFactory(ref, content, opts) { // See integration sections }
cytoscape.use( cytoscapePopper(popperFactory) ); // register extension ```
AMD:
js
require(['cytoscape', 'cytoscape-popper'], function( cytoscape, popper ){
function popperFactory(ref, content, opts) {
// See integration sections
}
// register extension
popper(popperFactory)(cytoscape);
});
API
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.
optionscontent: The HTML content of the popper. May be a DOMElementreference 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.cyorele). It defines only the effective width and height (bb.wandbb.h) of the Popper target. This option is more often useful for elements rather than for the core.popper: ThePopperOptionsobject. These options are used in providedpopperFactory.
Usage with @floating-ui
Initializing
``` js import cytoscape from 'cytoscape'; import cytoscapePopper from 'cytoscape-popper'; import { computePosition, flip, shift, limitShift, } from '@floating-ui/dom';
function popperFactory(ref, content, opts) { // see https://floating-ui.com/docs/computePosition#options const popperOptions = { // matching the default behaviour from Popper@2 // https://floating-ui.com/docs/migration#configure-middleware middleware: [ flip(), shift({limiter: limitShift()}) ], ...opts, }
function update() {
computePosition(ref, content, popperOptions).then(({x, y}) => {
Object.assign(content.style, {
left: ${x}px,
top: ${y}px,
});
});
}
update();
return { update };
}
cytoscape.use(cytoscapePopper(popperFactory)); ```
popper() example
``` js
// 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;
} });
// create a basic popper on the core with custom options 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: { placement: 'bottom', } // @flaoting-ui options (https://floating-ui.com/docs/middleware) }); ```
popperRef() example
``` js // create a basic popper ref for the first node let popperRef1 = cy.nodes()[0].popperRef();
// create a basic popper ref on the core let popperRef2 = cy.popperRef({ renderedPosition: () => ({ x: 200, y: 300 }) }); ```
Sticky popper() example
```js let 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.update(); };
node.on('position', update);
cy.on('pan zoom resize', update); ```
Usage with Popper.js (deprecated)
Initializing
``` js import cytoscape from 'cytoscape'; import cytoscapePopper from 'cytoscape-popper'; import { createPopper } from '@popperjs/core';
cytoscape.use(cytoscapePopper(createPopper)); ```
popper() example
``` js
// 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
``` js // create a basic popper ref for the first node let popperRef1 = cy.nodes()[0].popperRef();
// create a basic popper ref on the core let popperRef2 = cy.popperRef({ renderedPosition: () => ({ x: 200, y: 300 }) }); ```
Sticky popper() example
```js let 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.update(); };
node.on('position', update);
cy.on('pan zoom resize', update); ```
Usage with Tippy.js
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.
Initializing
```js import cytoscape from 'cytoscape'; import popper from 'cytoscape-popper'; import tippy from 'tippy.js';
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; }
cytoscape.use(cytoscapePopper(tippyFactory));
``
The creation of manyTippyinstances at once has performance implications, especially for large graphs. Create each instance on demand, e.g. ontap. Use [destroy()](https://atomiks.github.io/tippyjs/v6/methods/#destroy) instead ofhide()` where possible.
```js let node = cy.nodes().first();
var tip = node.popper({ content: () => { let content = document.createElement('div');
content.innerHTML = 'Tippy content';
return content;
}, });
tip.show(); ```
Refer to Tippy.js documentation for more details.
Typescript
This extension exports empty PopperInstance and PopperOptions interfaces allows to extend them according to the final Popper implementation.
@floating-ui example:
```ts
import { ComputePositionConfig } from '@floating-ui/dom';
declare module 'cytoscape-popper' { interface PopperOptions extends ComputePositionConfig { } interface PopperInstance { update(): void; } }
```
Build targets
npm run test: Run Mocha tests in./testnpm run build: Build./src/**intocytoscape-popper.jsnpm 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 source
N.b. all builds use babel, so modern ES features can be used in the src.
Publishing instructions
This project is set up to automatically be published to npm and bower. To publish:
- Build the extension :
npm run build:release - Commit the build :
git commit -am "Build for release" - Bump the version number and tag:
npm version major|minor|patch - Push to origin:
git push && git push --tags - Publish to npm:
npm publish . - If publishing to bower for the first time, you'll need to run
bower register cytoscape-popper https://github.com/cytoscape/cytoscape.js-popper.git - Make a new release for Zenodo.
Owner
- Name: Cytoscape Consortium
- Login: cytoscape
- Kind: organization
- Website: http://www.cytoscape.org/
- Repositories: 153
- Profile: https://github.com/cytoscape
GitHub Events
Total
- Watch event: 6
- Delete event: 7
- Issue comment event: 14
- Pull request event: 12
- Create event: 8
Last Year
- Watch event: 6
- Delete event: 7
- Issue comment event: 14
- Pull request event: 12
- Create event: 8
Committers
Last synced: 11 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Harsh Mistry | h****y@u****a | 73 |
| Max Franz | m****z@g****m | 44 |
| Atrue | w****u@g****m | 7 |
| Linda Parsons | l****h@g****m | 3 |
| dsabsay | d****y@g****m | 2 |
| dependabot[bot] | 4****] | 2 |
| Dylan Fong | d****g@u****a | 2 |
| adamstruck | s****a@o****u | 1 |
| Jean Zombie | 2****e | 1 |
| Ivan | r****t@g****m | 1 |
| Thorsten | t****n@v****e | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 10 months ago
All Time
- Total issues: 37
- Total pull requests: 70
- Average time to close issues: about 1 month
- Average time to close pull requests: about 2 months
- Total issue authors: 25
- Total pull request authors: 10
- Average comments per issue: 1.46
- Average comments per pull request: 1.96
- Merged pull requests: 14
- Bot issues: 0
- Bot pull requests: 57
Past Year
- Issues: 1
- Pull requests: 10
- Average time to close issues: about 17 hours
- Average time to close pull requests: about 2 months
- Issue authors: 1
- Pull request authors: 1
- Average comments per issue: 1.0
- Average comments per pull request: 0.9
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 10
Top Authors
Issue Authors
- maxkfranz (13)
- Nawarius (1)
- pieartsy (1)
- gokhanckgz (1)
- git4anjali (1)
- TonyIvanova (1)
- amouro (1)
- dependabot[bot] (1)
- vedant-g (1)
- surfjedi (1)
- marimeireles (1)
- jmazzitelli (1)
- littleblackfish (1)
- adamstruck (1)
- hmtinc (1)
Pull Request Authors
- dependabot[bot] (67)
- hmtinc (5)
- Atrue (2)
- rasca (2)
- DocVolz (1)
- adamstruck (1)
- dsabsay (1)
- thehappydinoa (1)
- lcparsons (1)
- Jean-Zombie (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 4
-
Total downloads:
- npm 162,499 last-month
- Total docker downloads: 156
-
Total dependent packages: 37
(may contain duplicates) -
Total dependent repositories: 302
(may contain duplicates) - Total versions: 24
- Total maintainers: 5
npmjs.org: cytoscape-popper
A Cytoscape.js extension for Popper.js
- Homepage: https://github.com/cytoscape/cytoscape.js-popper
- License: MIT
-
Latest release: 4.0.1
published almost 2 years ago
Rankings
Maintainers (5)
bower.io: cytoscape-popper
A Cytoscape.js extension for Popper.js
- License: MIT
-
Latest release: v4.0.0
published over 2 years ago
Rankings
repo1.maven.org: org.webjars.npm:github-com-cytoscape-cytoscape-js-popper
WebJar for cytoscape-popper
- Homepage: http://webjars.org
- Documentation: https://appdoc.app/artifact/org.webjars.npm/github-com-cytoscape-cytoscape-js-popper/
- License: MIT
-
Latest release: 1.0.4
published about 7 years ago
Rankings
repo1.maven.org: org.webjars.npm:cytoscape-popper
WebJar for cytoscape-popper
- Homepage: https://www.webjars.org
- Documentation: https://appdoc.app/artifact/org.webjars.npm/cytoscape-popper/
- License: MIT
-
Latest release: 2.0.0
published over 5 years ago
Rankings
Dependencies
- cytoscape ^3.2.0
- 1103 dependencies
- babel-core ^6.24.1 development
- babel-loader ^7.0.0 development
- babel-preset-env ^1.5.1 development
- camelcase ^4.1.0 development
- chai 4.0.2 development
- cpy-cli ^1.0.1 development
- cross-env ^5.0.0 development
- eslint ^4.18.2 development
- gh-pages ^1.0.0 development
- mocha 3.4.2 development
- npm-run-all ^4.1.2 development
- rimraf ^2.6.2 development
- update ^0.7.4 development
- updater-license ^1.0.0 development
- webpack ^2.6.1 development
- webpack-dev-server ^2.4.5 development
- @popperjs/core ^2.0.0