Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cy-node-html-label

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cy-node-html-label

Labels for cytoscape nodes

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

cytoscape-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.

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/

Features

  • optimised for high performance with high number nodes, for smooth panning and zooming.
  • customizable any labels with different templates.

Dependencies

  • Cytoscape.js ^3.0.0

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 ); // register extension

AMD:

require(['cytoscape', 'cytoscape-node-html-label'], function( cytoscape, nodeHtmlLabel ){
  nodeHtmlLabel( cytoscape ); // register extension
});

API

nodeHtmlLabel parameter is an array of options:

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 <div> container for every title
        tpl: function(data){return '<span>' + data + '</span>';} // your html template here
    }
]
    );

Example usage

Code example:

// 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' }
    ]
});

// set nodeHtmlLabel for your Cy instance
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>';
        }
    }
]);

// cyInstance.nodeHtmlLabel returns a `CytoscapeNodeHtmlLabel` 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.
});

// Requesting an update of a node label
cyInstance.nodeHtmlLabel().updateNodeLabel(cy.$id('a5'))

Demo here: https://kaluginserg.github.io/cytoscape-node-html-label/

how to build and develop:

  1. Run npm start
  2. Create change in src/cytoscape-node-html-label.ts
  3. When finished => npm run test
  4. Prepare js and min files: npm run build
  5. git commit Then, for version update and publish:
  6. Create new npm version: gulp patch, gulp feature or gulp release
  7. npm publish

Keywords

FAQs

Package last updated on 04 Sep 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc