cytoscape-node-html-label
Description
This extension provide ability adding labels for Cytoscape nodes. Simple example:
cyInstance.nodeHtmlLabel( [{ tpl: d => '<div>' + d + '</div>' }] );
Demo: https://kaluginserg.github.io/cytoscape-node-html-label/
Fitures
- optimised for high performance with high number nodes, for smooth panning and zooming.
- customizable any labels with different templates.
Dependencies
Usage instructions
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:
<script src="http://cytoscape.github.io/cytoscape.js/api/cytoscape.js-latest/cytoscape.min.js"></script>
<script src="cytoscape-node-html-label.js"></script>
RequireJs approach:
require()
the library as appropriate for your project:
CommonJS:
var cytoscape = require('cytoscape');
var nodeHtmlLabel = require('cytoscape-node-html-label');
nodeHtmlLabel( cytoscape );
AMD:
require(['cytoscape', 'cytoscape-node-html-label'], function( cytoscape, nodeHtmlLabel ){
nodeHtmlLabel( cytoscape );
});
API
nodeHtmlLabel parameter is an array of options:
cyInstance.nodeHtmlLabel(
[
{
query: 'node',
halign: 'center',
valign: 'center',
halignBox: 'center',
valignBox: 'center',
cssClass: '',
tpl: function(data){return '<span>' + data + '</span>';}
}
]
);
Example usage
Code example:
var cyInstance = cytoscape({
container: document.getElementById('cy'),
layout: {
name: 'random'
},
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 '<p class="cy-title__p1">' + data.id + '</p>' + '<p class="cy-title__p2">' + data.name + '</p>';
}
},
{
query: '.l2',
tpl: function(data) {
return '<p class="cy-title__p1">' + data.id + '</p>' + '<p class="cy-title__p2">' + data.name + '</p>';
}
}
]);
Demo here: https://kaluginserg.github.io/cytoscape-node-html-label/