Labels for cytoscape nodes
npm install cy-node-html-labelcytoscape-node-html-label
================================================================================
This project was forked off https://github.com/kaluginserg/cytoscape-node-html-label
I forked it off because the projected seemed abandoned, if the author comes back
I'll try to push my changes there.
This extension provide ability adding labels for Cytoscape nodes. Simple example:
cyInstance.nodeHtmlLabel( [{ tpl: d => '' + d + '' }] );
Demo: https://kaluginserg.github.io/cytoscape-node-html-label/
* Cytoscape.js ^3.0.0
Download the library:
* via npm: npm install cytoscape-node-html-label,
* via bower: bower install cytoscape-node-html-label, or
* via direct download in the repository (probably from a tag).
#### Plain HTML/JS has the extension registered for you automatically:
``html`
#### RequireJs approach:
require() the library as appropriate for your project:
CommonJS:
`js`
var cytoscape = require('cytoscape');
var nodeHtmlLabel = require('cytoscape-node-html-label');
nodeHtmlLabel( cytoscape ); // register extension
AMD:
`js`
require(['cytoscape', 'cytoscape-node-html-label'], function( cytoscape, nodeHtmlLabel ){
nodeHtmlLabel( cytoscape ); // register extension
});
nodeHtmlLabel parameter is an array of options:
` Code example: // set nodeHtmlLabel for your Cy instance ' + data.id + ' ' + data.name + ' ' + data.id + ' ' + data.name + ' // cyInstance.nodeHtmlLabel returns a // Requesting an update of a node label Demo here: https://kaluginserg.github.io/cytoscape-node-html-label/js
cyInstance.nodeHtmlLabel(
[
{
query: 'node', // cytoscape query selector
halign: 'center', // title vertical position. Can be 'left',''center, 'right'
valign: 'center', // title vertical position. Can be 'top',''center, 'bottom'
halignBox: 'center', // title vertical position. Can be 'left',''center, 'right'
valignBox: 'center', // title relative box vertical position. Can be 'top',''center, 'bottom'
cssClass: '', // any classes will be as attribute of container for every title
tpl: function(data){return '' + data + '';} // your html template here
}
]
);
``Example usage
jsCytoscapeNodeHtmlLabel
// create Cy instance
var cyInstance = cytoscape({
container: document.getElementById('cy'),
layout: {
name: 'random'
},
elements: [ // your cy elements
{ group: "nodes", data: { id: 'a1', name: 'a10' }, classes: 'l1' },
{ group: "nodes", data: { id: 'a1', name: 'a10' }, classes: 'l1' },
{ group: "nodes", data: { id: 'a1', name: 'a10' }, classes: 'l1' },
{ group: "nodes", data: { id: 'a5', name: 'a5' }, classes: 'l2' }
]
});
cyInstance.nodeHtmlLabel([{
query: '.l1',
valign: "top",
halign: "left",
valignBox: "top",
halignBox: "left",
tpl: function(data) {
return '
}
},
{
query: '.l2',
tpl: function(data) {
return '
}
}
]); instance, you will get the`
// same instance if calling on it more times.
// Listening for changes
cyInstance.on('nodehtml-create-or-update nodehtml-delete', function(event, data) {
// When created/updated data has the label, and you can get the html node with element.getNode()
// It also has isNew to know if it was created or updated.
// Target event is the cytoscape node associated to the label.
});
cyInstance.nodeHtmlLabel().updateNodeLabel(cy.$id('a5'))npm starthow to build and develop:
2) Run npm run test
2) Create change in src/cytoscape-node-html-label.ts
2) When finished => npm run build
2) Prepare js and min files: git commit
2) gulp patch
Then, for version update and publish:
2) Create new npm version: , gulp feature or gulp releasenpm publish`
2)