npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cytoscape-html-node

v2.2.0

Published

This extension allows for the creation of html in cytoscape nodes that can change based on zoom level.

Downloads

1,845

Readme

cytoscape-html-node

Description

This extension allows for the creation of html in cytoscape nodes that can change based on zoom level.

This extension was built as a use case of https://github.com/kaluginserg/cytoscape-node-html-label.

Dependencies

  • cytoscape: ^3.16.3
  • cytoscape-node-html-label: ^1.2.1

Usage instructions

Download the library:

  • via npm: npm install cytoscape-html-node
  • via direct download in the repository

Import the library as appropriate for your project:

ES import:

import cytoscape from 'cytoscape';
import { register as htmlnode } from 'cytoscape-html-node';

cytoscape.use(htmlnode);

CommonJS require:

let cytoscape = require('cytoscape');
let htmlnode = require('cytoscape-html-node');

cytoscape.use(htmlnode);

AMD:

require(['cytoscape', 'cytoscape-html-node'], function (cytoscape, htmlnode) {
  htmlnode(cytoscape);
});

API

Example

  • For a more detailed example, see example/src/example.js.
import cytoscape from 'cytoscape';
import { register as htmlnode } from 'cytoscape-html-node';

// register extensions
cytoscape.use(htmlnode);

let cy = cytoscape({
  container: document.getElementById('cy'),
  layout: {
    name: 'random',
  },
  style: [
    {
      selector: '.htmlNodeBaseStyle',
      style: {
        'background-color': 'lightgrey',
      },
    },
    {
      selector: '.htmlNodeAltStyle',
      style: {
        'background-color': 'darkblue',
      },
    },
  ],
  elements: [
    {
      group: 'nodes',
      data: {
        id: 'a1',
        shortSum: 'Short summary.',
        mediumSum: 'This a medium summary.',
        longSum: 'This is a much longer summary.',
      },
    },
    {
      group: 'nodes',
      data: {
        id: 'a2',
        shortSum: 'Short summary.',
        mediumSum: 'This a medium summary.',
        longSum: 'This is a much longer summary.',
      },
    },
    {
      group: 'nodes',
      data: {
        id: 'a3',
        shortSum: 'Short summary.',
        mediumSum: 'This a medium summary.',
        longSum: 'This is a much longer summary.',
      },
    },
    {
      group: 'nodes',
      data: {
        id: 'a4',
        shortSum: 'Short summary.',
        mediumSum: 'This a medium summary.',
        longSum: 'This is a much longer summary.',
      },
    },
  ],
});

const htmlnode = cy.htmlnode();

htmlnode.createHtmlNode(cytoscape, cy, {
  person: {
    query: "[type = 'person']",
    staticZoomLevel: 0.3,
    template: [
      {
        zoomRange: [0.3, 1],
        template: {
          html: `<div id="htmlLabel:#{data.id}">
                   <div class="largeFont">#{data.shortSum}</div>
                 </div>`,
          cssClass: 'htmlCard',
        },
      },
      {
        zoomRange: [1, 3],
        template: {
          html: `<div id="htmlLabel:#{data.id}">
                   <div class="mediumFont">#{data.mediumSum}</div>
                 </div>`,
          cssClass: 'htmlCard',
        },
      },
      {
        zoomRange: [3, 100],
        template: {
          html: `<div id="htmlLabel:#{data.id}" class="cardField">
                   <div class="smallFont">#{data.longSum}</div>
                 </div>`,
          cssClass: 'htmlCard',
        },
      },
    ],
  },

  event: {
    query: "[type = 'event']",
    template: [
      {
        zoomRange: [0.3, 1],
        template: {
          html: `<div id="htmlLabel:#{data.id}">
                   <div class="smallFont">#{data.shortEventInfo}</div>
                 </div>`,
          cssClass: 'htmlEvent',
        },
      },
      {
        zoomRange: [1, 3],
        template: {
          html: `<div id="htmlLabel:#{data.id}">
                   <div class="mediumFont">#{data.mediumEventInfo}</div>
                 </div>`,
          cssClass: 'htmlEvent',
        },
      },
      {
        zoomRange: [3, 100],
        template: {
          html: `<div id="htmlLabel:#{data.id}">
                   <div class="smallFont">#{data.longEventInfo}</div>
                 </div>`,
          cssClass: 'htmlEvent',
        },
      },
    ],
  },
});

Include the following css to use staticZoomLevel:

.html-node-notransition {
    -webkit-transition: none !important;
    -moz-transition: none !important;
    -o-transition: none !important;
    transition: none !important;
    -o-transform: none !important;
    -moz-transform: none !important;
    -ms-transform: none !important;
    -webkit-transform: none !important;
    transform: none !important;
}

Use information

  • The extension call should occur only once. All templates should be specified in that call, even if they are not immediately needed.

  • query: Accepts any cytoscape query. Specifies which node(s) template will apply to. Nodes added after the intial extension call that match the query will have html applied to them.

  • staticZoomLevel: Optionally specify a zoom level. When the cytoscape zoom level is greater than staticZoomLevel, the corresponding html has a static size.

  • htmlNodeBaseStyle: The style of the cytoscape node(s) when zoom has not passed the minimum zoomRange value.

  • htmlNodeAltStyle: The style of the cytoscape node(s) when zoom has passed the minimum zoomRange value.

  • zoomRange: The zoom range for which the template html is used. The values for each zoomRange within a query should be continuous with ascending values. The minimum value of all zoomRange within a query specifies when to toggle between altColor and defaultColor. The largest zoomRange should be arbitrarily large.

  • Cytoscape data can be accessed within html using #{data.prop} where prop is some cytoscape node data property.

  • The parent div should follow: <div id="htmlLabel:#{data.id}"></div>

Style suggestions

  • The width and height of the parent html-node div should be specified.

  • The parent html-node div should be centered.

  • Either content should not exceed the height of the parent html-node div or overflow should be managed.