Skip to content

Commit 061bd6b

Browse files
author
Melchior du Lac
committed
ENH: Adding panzoom as feature request from issue plotly#83
1 parent 29543d0 commit 061bd6b

19 files changed

+871
-46
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Dash = "1b08a953-4be3-4667-9a23-3db579824955"
99

1010
[compat]
1111
julia = "1.2"
12-
Dash = "0.1.3"
12+
Dash = "0.1.3, 1.0"

R/cytoCytoscape.R

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# AUTO GENERATED FILE - DO NOT EDIT
22

3+
#' @export
34
cytoCytoscape <- function(id=NULL, autoRefreshLayout=NULL, autolock=NULL, autoungrabify=NULL, autounselectify=NULL, boxSelectionEnabled=NULL, className=NULL, elements=NULL, generateImage=NULL, imageData=NULL, layout=NULL, maxZoom=NULL, minZoom=NULL, mouseoverEdgeData=NULL, mouseoverNodeData=NULL, pan=NULL, panningEnabled=NULL, responsive=NULL, selectedEdgeData=NULL, selectedNodeData=NULL, style=NULL, stylesheet=NULL, tapEdge=NULL, tapEdgeData=NULL, tapNode=NULL, tapNodeData=NULL, userPanningEnabled=NULL, userZoomingEnabled=NULL, zoom=NULL, zoomingEnabled=NULL) {
45

56
props <- list(id=id, autoRefreshLayout=autoRefreshLayout, autolock=autolock, autoungrabify=autoungrabify, autounselectify=autounselectify, boxSelectionEnabled=boxSelectionEnabled, className=className, elements=elements, generateImage=generateImage, imageData=imageData, layout=layout, maxZoom=maxZoom, minZoom=minZoom, mouseoverEdgeData=mouseoverEdgeData, mouseoverNodeData=mouseoverNodeData, pan=pan, panningEnabled=panningEnabled, responsive=responsive, selectedEdgeData=selectedEdgeData, selectedNodeData=selectedNodeData, style=style, stylesheet=stylesheet, tapEdge=tapEdge, tapEdgeData=tapEdgeData, tapNode=tapNode, tapNodeData=tapNodeData, userPanningEnabled=userPanningEnabled, userZoomingEnabled=userZoomingEnabled, zoom=zoom, zoomingEnabled=zoomingEnabled)

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ app.layout = html.Div([
7676

7777
Calling `cyto.load_extra_layouts()` also enables generating SVG images.
7878

79+
### Panzoom
80+
81+
This version contains the [panzoom](https://github.com/cytoscape/cytoscape.js-panzoom) extension to the dash cytoscape app. Note that you still need to add "Font Awesome" to your app's `external_stylesheets`. For example:
82+
83+
```
84+
{
85+
'href': 'https://use.fontawesome.com/releases/v5.8.1/css/all.css',
86+
'rel': 'stylesheet',
87+
'integrity': 'sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf',
88+
'crossorigin': 'anonymous'
89+
},
90+
```
7991

8092
## Getting Started in R
8193

dash_cytoscape/dash_cytoscape.dev.js

+78-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_cytoscape/dash_cytoscape.min.js

+49-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_cytoscape/dash_cytoscape_extra.dev.js

+78-1
Large diffs are not rendered by default.

dash_cytoscape/dash_cytoscape_extra.min.js

+52-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_cytoscape/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"cytoscape-klay": "^3.1.2",
3838
"cytoscape-spread": "^3.0.0",
3939
"cytoscape-svg": "0.2.0",
40+
"cytoscape-panzoom": "^2.5.3",
4041
"lodash": "^4.17.11",
4142
"ramda": "^0.25.0",
4243
"react": "^16.14.0",

deps/dash_cytoscape.dev.js

+78-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps/dash_cytoscape.min.js

+49-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps/dash_cytoscape_extra.dev.js

+78-1
Large diffs are not rendered by default.

deps/dash_cytoscape_extra.min.js

+52-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/deps/dash_cytoscape.dev.js

+78-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/deps/dash_cytoscape.min.js

+49-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/deps/dash_cytoscape_extra.dev.js

+78-1
Large diffs are not rendered by default.

inst/deps/dash_cytoscape_extra.min.js

+52-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+44-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"cytoscape-klay": "^3.1.2",
3838
"cytoscape-spread": "^3.0.0",
3939
"cytoscape-svg": "0.2.0",
40+
"cytoscape-panzoom": "^2.5.3",
4041
"lodash": "^4.17.11",
4142
"ramda": "^0.25.0",
4243
"react": "^16.14.0",

src/lib/components/Cytoscape.react.js

+40-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ import React, {Component} from 'react';
66
import PropTypes from 'prop-types';
77
import CytoscapeComponent from 'react-cytoscapejs';
88
import _ from 'lodash';
9+
import CytoscapeJS from 'cytoscape';
10+
import panzoom from 'cytoscape-panzoom';
11+
import "cytoscape-panzoom/cytoscape.js-panzoom.css";
12+
13+
CytoscapeJS.use(panzoom)
914

1015
import CyResponsive from '../cyResponsive.js';
1116

17+
1218
/**
1319
A Component Library for Dash aimed at facilitating network visualization in
1420
Python, wrapped around [Cytoscape.js](http://js.cytoscape.org/).
@@ -20,7 +26,7 @@ class Cytoscape extends Component {
2026
this.handleCy = this.handleCy.bind(this);
2127
this._handleCyCalled = false;
2228
this.handleImageGeneration = this.handleImageGeneration.bind(this);
23-
this.cyResponsiveClass = false;
29+
this.cyResponsiveClass = false;
2430
}
2531

2632
generateNode(event) {
@@ -150,6 +156,7 @@ class Cytoscape extends Component {
150156
return edgeObject;
151157
}
152158

159+
153160
handleCy(cy) {
154161
// If the cy pointer has not been modified, and handleCy has already
155162
// been called before, than we don't run this function.
@@ -160,6 +167,7 @@ class Cytoscape extends Component {
160167
window.cy = cy;
161168
this._handleCyCalled = true;
162169

170+
163171
// ///////////////////////////////////// CONSTANTS /////////////////////////////////////////
164172
const SELECT_THRESHOLD = 100;
165173

@@ -279,6 +287,36 @@ class Cytoscape extends Component {
279287

280288
this.cyResponsiveClass = new CyResponsive(cy);
281289
this.cyResponsiveClass.toggle(this.props.responsive);
290+
291+
// the default values of each option are outlined below:
292+
var defaultZoomControls = {
293+
zoomFactor: 0.05, // zoom factor per zoom tick
294+
zoomDelay: 45, // how many ms between zoom ticks
295+
minZoom: 0.1, // min zoom level
296+
maxZoom: 10, // max zoom level
297+
fitPadding: 50, // padding when fitting
298+
panSpeed: 10, // how many ms in between pan ticks
299+
panDistance: 10, // max pan distance per tick
300+
panDragAreaSize: 75, // the length of the pan drag box in which the vector for panning is calculated (bigger = finer control of pan speed and direction)
301+
panMinPercentSpeed: 0.25, // the slowest speed we can pan by (as a percent of panSpeed)
302+
panInactiveArea: 8, // radius of inactive area in pan drag box
303+
panIndicatorMinOpacity: 0.5, // min opacity of pan indicator (the draggable nib); scales from this to 1.0
304+
zoomOnly: false, // a minimal version of the ui only with zooming (useful on systems with bad mousewheel resolution)
305+
fitSelector: undefined, // selector of elements to fit
306+
animateOnFit: function(){ // whether to animate on fit
307+
return false;
308+
},
309+
fitAnimationDuration: 1000, // duration of animation on fit
310+
311+
// icon class names
312+
sliderHandleIcon: 'fa fa-minus',
313+
zoomInIcon: 'fa fa-plus',
314+
zoomOutIcon: 'fa fa-minus',
315+
resetIcon: 'fa fa-expand'
316+
};
317+
318+
// add the panzoom control
319+
cy.panzoom(defaultZoomControls);
282320
}
283321

284322
handleImageGeneration(imageType, imageOptions, actionsToPerform, fileName) {
@@ -451,6 +489,7 @@ class Cytoscape extends Component {
451489
this.cyResponsiveClass.toggle(responsive);
452490
}
453491

492+
454493
return (
455494
<CytoscapeComponent
456495
id={id}

0 commit comments

Comments
 (0)