Giter Club home page Giter Club logo

cytoscape.js-view-utilities's Introduction

cytoscape-view-utilities

Description

This Cytoscape.js extension provides miscellenaous view utilities such as hide/show, highlight, marquee zoom and free form selection, distributed under The MIT License.

Please cite the following paper when using this extension:

U. Dogrusoz , A. Karacelik, I. Safarli, H. Balci, L. Dervishi, and M. C. Siper, "Efficient methods and readily customizable libraries for managing complexity of large networks", PLoS ONE, 13(5): e0197238, 2018.

Demo

Click here (no undo) or here (undoable) for a demo

API

var instance = cy.viewUtilities(options)
@param options — If not provided, default options will be used. See the below section for default options. highlightStyles is array of objects. The objects should follow the format {node: ..., edge: ...}. selectStyles will be used if you want to override the highlighted styles when the objects are selected. lassoStyle will be used to override the lasso line style.
e.g

var options = {
  highlightStyles: [
    { node: { 'border-color': '#0b9bcd',  'border-width': 3 }, edge: {'line-color': '#0b9bcd', 'source-arrow-color': '#0b9bcd', 'target-arrow-color': '#0b9bcd', 'width' : 3} },
    { node: { 'border-color': '#04f06a',  'border-width': 3 }, edge: {'line-color': '#04f06a', 'source-arrow-color': '#04f06a', 'target-arrow-color': '#04f06a', 'width' : 3} },
  ],
  selectStyles: { 
    node: {'border-color': 'black', 'border-width': 3, 'background-color': 'lightgrey'}, 
    edge: {'line-color': 'black', 'source-arrow-color': 'black', 'target-arrow-color': 'black', 'width' : 3} 
  },
  setVisibilityOnHide: false, // whether to set visibility on hide/show
  setDisplayOnHide: true, // whether to set display on hide/show
  zoomAnimationDuration: 1500, // default duration for zoom animation speed
  neighbor: function(ele){
      return ele.closedNeighborhood();
  },
  neighborSelectTime: 500,
  lassoStyle: {lineColor: "#d67614", lineWidth: 3} // default lasso line color, dark orange, and default line width
  htmlElem4marqueeZoom: '', // should be string like `#cy` or `.cy`. `#cy` means get element with the ID 'cy'. `.cy` means the element with class 'cy' 
  marqueeZoomCursor: 'se-resize', // the cursor that should be used when marquee zoom is enabled. It can also be an image if a URL to an image is given
  isShowEdgesBetweenVisibleNodes: true // When showing elements, show edges if both source and target nodes become visible
};
var api = cy.viewUtilities(options);

instance.highlight(eles, idx = 0)
@param eles — a cytoscape.js collection (collection of elements) to be highlighted
@param idx — The index of the cytoscape.js style. If you don't specify it, the first style will be used.
Apply style class to the specified elements. Style class is specified with its index

instance.highlightNeighbors(eles, idx = 0)
@param eles — a cytoscape.js collection (collection of elements) to be highlighted
@param idx — The index of the cytoscape.js style. If you don't specify it, the first style will be used.
Highlights elements' neighborhood (based on the color option). Similar to the highlight function, either the elements and highlighting option can both be sent in the arguments. If only the elements are sent, then the default highlight color is used.

instance.removeHighlights(eles)
@param eles — elements to remove highlights
Remove highlights from eles.

instance.hide(eles)
@param eles — elements to hide
Hides given eles.

instance.show(eles)
@param eles — elements to show
Unhides given eles.

instance.showHiddenNeighbors(eles)
@param eles — elements to show hidden neighbors
Unhides hidden neigbors of given eles. Note that compound nodes are not respected as expected.

instance.zoomToSelected(eles)
@param eles — elements to zoom
Zoom to selected eles.

instance.enableMarqueeZoom(callback)
@param callback — is called at the end of the function
Enables marquee zoom. It is automatically called when CTRL+Shift keys are down.

instance.disableMarqueeZoom()
Disables marquee zoom. It is automatically called when CTRL+Shift keys are up.

instance.enableLassoMode(callback)
@param callback — is called at the end of the function
Enables lasso tool.

instance.disableLassoMode()
Disables lasso tool.

instance.getHighlightStyles()
Returns current highlightStyles which is an array of objects like below

[
  { node: { 'border-color': '#0b9bcd',  'border-width': 3 }, edge: {'line-color': '#0b9bcd', 'source-arrow-color': '#0b9bcd', 'target-arrow-color': '#0b9bcd', 'width' : 3} },
  { node: { 'border-color': '#bf0603',  'border-width': 3 }, edge: {'line-color': '#bf0603', 'source-arrow-color': '#bf0603', 'target-arrow-color': '#bf0603', 'width' : 3} },
],

instance.getAllHighlightClasses()
Returns all currently used cytoscape.js style classes

instance.changeHighlightStyle(idx, nodeStyle, edgeStyle)
@param idx — index of the style that is going to be changed
@param nodeStyle — cytoscape style for nodes
@param edgeStyle — cytoscape style for edges
Changes the style specified with idx.

instance.addHighlightStyle(nodeStyle, edgeStyle)
@param nodeStyle — cytoscape style for nodes
@param edgeStyle — cytoscape style for edges
Adds a new style to the highlightStyles array.

instance.removeHighlightStyle(styleIdx): void
@param styleIdx — index of the style to delete (0 based)
Removes the style from highlightStyles array.

instance.changeLassoStyle(styleObj)
@param styleObj — lasso line style object with lineColor and/or lineWidth properties

Default Options

var options = {
  highlightStyles: [],
  selectStyles: {},
  setVisibilityOnHide: false, // whether to set visibility on hide/show
  setDisplayOnHide: true, // whether to set display on hide/show
  zoomAnimationDuration: 1500, // default duration for zoom animation speed
  neighbor: function (ele) { // return desired neighbors of tapheld element
    return false;
  },
  neighborSelectTime: 500, // ms, time to taphold to select desired neighbors in addition to the taphold event detect time by cytoscape
  lassoStyle: {lineColor: "#d67614", lineWidth: 3} // default lasso line color, dark orange, and default line width
};

Default Undo-Redo Actions

ur.do("highlight", args)

ur.do("highlightNeighbors", args) ur.do("highlightNeighbours", args)

ur.do("removeHighlights")

ur.do("hide", eles)

ur.do("show", eles)

Dependencies

  • Cytoscape.js ^3.2.0
  • Geometric.js ^2.2.3
  • cytoscape-undo-redo.js ^1.0.8 (optional)

Usage instructions

Download the library:

  • via npm: npm install cytoscape-view-utilities ,
  • via bower: bower install cytoscape-view-utilities , or
  • via direct download in the repository (probably from a tag).

require() the library as appropriate for your project:

CommonJS:

var cytoscape = require('cytoscape');
var viewUtilities = require('cytoscape-view-utilities');

viewUtilities(cytoscape); // register extension

AMD:

require(['cytoscape', 'cytoscape-view-utilities'], function(cytoscape, view - utilities) {
    view - utilities(cytoscape); // register extension
});

Plain HTML/JS has the extension registered for you automatically, because no require() is needed.

Build targets

  • npm run build : Build ./src/** into cytoscape-view-utilities.js in production environment and minimize the file.
  • npm run build:dev : Build ./src/** into cytoscape-view-utilities.js in development environment without minimizing the file.

Publishing instructions

This project is set up to automatically be published to npm and bower. To publish:

  1. Build the extension : npm run build
  2. Commit the build : git commit -am "Build for release"
  3. Bump the version number and tag: npm version major|minor|patch
  4. Push to origin: git push && git push --tags
  5. Publish to npm: npm publish .
  6. If publishing to bower for the first time, you'll need to run bower register cytoscape-view-utilities https://github.com/iVis-at-Bilkent/view-utilities.git

Team

Alumni

cytoscape.js-view-utilities's People

Contributors

canbax avatar hasanbalci avatar herencalik avatar kaansancak avatar kinimesi avatar metincansiper avatar mobizaman avatar mrsfy avatar msalihaltun avatar nasimsaleh avatar rumeysaozaydin avatar ugurdogrusoz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cytoscape.js-view-utilities's Issues

Marquee zoom in demo

From @canbax: The way marquee zoom is exposed in the demo is confusing. You click on it, it enables the marquee zoom, and when you actually perform the zoom it's automatically disabled without any feedback to the user.

Perhaps we can make this a checkbox, which enables marquee zoom on set and when the user actually performs a marquee zoom we can reset this checkbox (since the marquee zoom action automatically disables marquee zoom).

Undo problem emerging after multiple highlights

In undoable demo file,
I highlghted the neighbours of Jerry and get the following screen,

highlight_neighbours_jerry

Then I highlighted the neighbours of Kramer and get the following screen,

highlight_neighbours_krammer

Finally I performed an undo operation and get the following result,

undo_after_highlights

I think that something must be wrong with undo operation performed after multiple times highlights.

Dependency update

Let's update Cytoscape.js dependency as ^3.2.0 instead of ^2.7.0 both in README and package.json. This is required if user wants to apply cose-bilkent layout as post-processing.

Also, let's use the latest version of the cose-bilkent in the demo files.

Support for defining multiple highlighting styles

User should be able to define up to four different highlighting styles for nodes and edges in options. Let's name those options as "highlighted" (the current one), "highlighted2", "highlighted3" and "highlighted4". After user defined different styles, a sample usage should be as follows:

var instance = cy.viewUtilities(options); 
instance.highlight(eles, "highlighted2");

If user doesn't define the second parameter in the above example that indicates the highlighting style, then the style in "highlighted" should be used as default.

Remove selected highlights action removes all highlights in undoable demos

In both undoable demo at master and undoable demo at unstable, using the "Remove Selected Highlights" action removes all highlights, given that some element is selected.

Steps to reproduce:

  • Open either undoable demo.
  • Highlight any element(s).
  • Select any element(s), highlighted or otherwise.
  • Click "Remove Selected Highlights".

Expected: Selected elements have their highlights removed.
Result: All highlights are removed.

This problem doesn't happen in non-undoable demo at master or non-undoable demo at unstable. Probably an issue with undo actions for removing highlights.

Buggy behavior in marquee zoom

It seems that there is a bug in marquee zoom. Normally, it should work either by calling enableMarqueeZoom function via a button and then SHIFT+drag or directly CTRL+SHIFT+drag where CTRL+SHIFT automatically calls enableMarqueeZoom function. Currently, the first approach is not working sometimes. Buggy behavior can be seen in demo with a few consecutive marquee zoom tries.

Namespacing

This extension should really follow the convention that it returns an object with its API, and only registers a single function per core and per collection with the same name as the extension.

e.g.

cy.viewutil().search(...);

cy.$('#foo').viewutil().highlight();

Otherwise, your extension can collide with other extensions or new APIs added to the core.

Demo improvements

Let's please (in both demo apps):

  • Make sure "Update Color" and "Add Color" buttons fit in one line
  • When a new Higlight color is added, can we assign a random distinct color (currently we use the same color over and over again)

Error when initialising

Hello - if I initialise with non empty highlightStyles and selectStyles, I get the following error:

TypeError: Cannot read property 'selector' of undefined

Screen Shot 2021-08-06 at 5 58 10 pm

If I initialise with empty highlightStyles and selectStyles it initialises OK.

Here is some test code that shows options that work and options that do not work:

import cytoscape from "cytoscape";
import viewUtilities from "cytoscape-view-utilities";
viewUtilities(cytoscape); // register extension
const cy = cytoscape()
const optionsWorking = {
    highlightStyles: [],
    selectStyles: {},
};
const optionsNotWorking = {
    highlightStyles: [
        {node: {'border-color': '#0b9bcd', 'border-width': 3},
            edge: {
                'line-color': '#0b9bcd',
                'source-arrow-color': '#0b9bcd',
                'target-arrow-color': '#0b9bcd',
                'width': 3
            }
        },
        {node: {'border-color': '#04f06a', 'border-width': 3},
            edge: {
                'line-color': '#04f06a',
                'source-arrow-color': '#04f06a',
                'target-arrow-color': '#04f06a',
                'width': 3
            }
        },
    ],
    selectStyles: {
        node: {'border-color': 'black', 'border-width': 3, 'background-color': 'lightgrey'},
        edge: {'line-color': 'black', 'source-arrow-color': 'black', 'target-arrow-color': 'black', 'width': 3}
    },
};

let api = cy.viewUtilities(optionsWorking);

export default cy;

Can anyone suggest please what might be the issue?

thanks!

demo.html throws "ReferenceError: cytoscape is not defined"

After a fresh clone, opening demo.html in Firefox 54 throws the following errors:

The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.  demo.html
ReferenceError: cytoscape is not defined[Learn More]  demo.html:42:21
	<anonymous> file:///tmp/cytoscape.js-view-utilities/demo.html:42:21

I think the problem is that this import does not exist: http://cytoscape.github.io/cytoscape.js/api/cytoscape.js-latest/cytoscape.min.js

I could get it to work by replacing the link with https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.1.2/cytoscape.min.js.

Show operation in demo

There is a problem in the demo of show operation. I think it isn't related with the show operation itself, but we are missing some elements to show again in the demo.
ezgif com-video-to-gif

Marqueue zoom shortcut

The shortcut was implemented in Newt but view utilities extension is a more logical place to have this feature. Basically the shortcut works as Marqueue zoom but instead of clicking to activate marqueue zoom and then shift+darg, Simply ctrl+shift+drag would do the job.

Can not change settings

I want to change highlight border-width based on user input. I set default at the first time.

let options = { node: { highlighted: C.HIGHLIGHTED_NODE_1, highlighted2: C.HIGHLIGHTED_NODE_2, highlighted3: C.HIGHLIGHTED_NODE_3, // options object has some other properties ... cy.viewUtilities(options)

I change options.node.hightlighted3 and then I call cy.viewUtilities(options) again but I see settings did not changed

Update README

Let's update the readme for this extension. Specifically the animated image should show:

  • highlight facilities
  • hide/show
  • marquee zoom
  • lasso tool

Restricting functionality to selected elements only

Is it possible to restrict which nodes can be candidate for view-utilities functionality.
For example I only want parent nodes to be able to hide or show with js-view-utilities
functionality

Similar functionality is provided with -node-resize plugin with which one is able to apply controls over desired nodes only

// https://github.com/iVis-at-Bilkent/cytoscape.js-node-resize provides 
isNoControlsMode: function (node) { return node.is(".noControlsMode") }, // no controls - do not draw grapples

Graph disappears on zoom

Reported by @kaansancak:
Select a rectangle around a single node. After first zoom, select a similar rectangle (around the same node), sometimes graph disappears.

Double click unhides all levels of neighbors

Double clicking on a node with hidden neighbors would unhide only the first level neighbors but now unhides them all (see the animated demo).
Another problem is that when those nodes are unhidden, they won't get deselected.

Choice of highlight color

  • 1. Let's please update the undoable demo as well.
    Let's do the following in both demos:
  • 2. Let's rename "Highlight Elements" to "Highlight Selected"
  • 3.Let's leave some space before "Highlight Selected"
  • 4. We also need to update the README (changes in the API)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.