Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add persistence #125

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

# Added
* [Persistence](https://dash.plotly.com/persistence)

### Changed
* Dash has been upgraded to 1.* in requirements.txt and tests/requirements.txt (#123)
* React/react-dom have been upgraded to 16.14+ (#117)
Expand Down
20 changes: 16 additions & 4 deletions dash_cytoscape/Cytoscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,26 @@ class attribute).
- filename (string; optional): Name for the file to be downloaded. Default: 'cyto'.
- imageData (string; optional): String representation of the image requested with generateImage. Null if no
image was requested yet or the previous request failed. Read-only.
- responsive (boolean; default False): Toggles intelligent responsive resize of Cytoscape graph with viewport size change"""
- responsive (boolean; default False): Toggles intelligent responsive resize of Cytoscape graph with viewport size change
- persistence (boolean | string | number; optional): Used to allow user interactions in this component to be persisted when
the component - or the page - is refreshed. If `persisted` is truthy and
hasn't changed from its previous value, any `persisted_props` that the
user has changed while using the app will keep those changes, as long as
the new prop value also matches what was given originally.
Used in conjunction with `persistence_type` and `persisted_props`.
- persisted_props (list of a value equal to: 'elements', 'stylesheet', 'layout's; optional): Properties whose user interactions will persist after refreshing the
component or the page.
- persistence_type (a value equal to: 'local', 'session', 'memory'; default 'local'): Where persisted user changes will be stored:
memory: only kept in memory, reset on page refresh.
local: window.localStorage, data is kept after the browser quit.
session: window.sessionStorage, data is cleared once the browser quit."""
@_explicitize_args
def __init__(self, id=Component.UNDEFINED, className=Component.UNDEFINED, style=Component.UNDEFINED, elements=Component.UNDEFINED, stylesheet=Component.UNDEFINED, layout=Component.UNDEFINED, pan=Component.UNDEFINED, zoom=Component.UNDEFINED, panningEnabled=Component.UNDEFINED, userPanningEnabled=Component.UNDEFINED, minZoom=Component.UNDEFINED, maxZoom=Component.UNDEFINED, zoomingEnabled=Component.UNDEFINED, userZoomingEnabled=Component.UNDEFINED, boxSelectionEnabled=Component.UNDEFINED, autoungrabify=Component.UNDEFINED, autolock=Component.UNDEFINED, autounselectify=Component.UNDEFINED, autoRefreshLayout=Component.UNDEFINED, tapNode=Component.UNDEFINED, tapNodeData=Component.UNDEFINED, tapEdge=Component.UNDEFINED, tapEdgeData=Component.UNDEFINED, mouseoverNodeData=Component.UNDEFINED, mouseoverEdgeData=Component.UNDEFINED, selectedNodeData=Component.UNDEFINED, selectedEdgeData=Component.UNDEFINED, generateImage=Component.UNDEFINED, imageData=Component.UNDEFINED, responsive=Component.UNDEFINED, **kwargs):
self._prop_names = ['id', 'className', 'style', 'elements', 'stylesheet', 'layout', 'pan', 'zoom', 'panningEnabled', 'userPanningEnabled', 'minZoom', 'maxZoom', 'zoomingEnabled', 'userZoomingEnabled', 'boxSelectionEnabled', 'autoungrabify', 'autolock', 'autounselectify', 'autoRefreshLayout', 'tapNode', 'tapNodeData', 'tapEdge', 'tapEdgeData', 'mouseoverNodeData', 'mouseoverEdgeData', 'selectedNodeData', 'selectedEdgeData', 'generateImage', 'imageData', 'responsive']
def __init__(self, id=Component.UNDEFINED, className=Component.UNDEFINED, style=Component.UNDEFINED, elements=Component.UNDEFINED, stylesheet=Component.UNDEFINED, layout=Component.UNDEFINED, pan=Component.UNDEFINED, zoom=Component.UNDEFINED, panningEnabled=Component.UNDEFINED, userPanningEnabled=Component.UNDEFINED, minZoom=Component.UNDEFINED, maxZoom=Component.UNDEFINED, zoomingEnabled=Component.UNDEFINED, userZoomingEnabled=Component.UNDEFINED, boxSelectionEnabled=Component.UNDEFINED, autoungrabify=Component.UNDEFINED, autolock=Component.UNDEFINED, autounselectify=Component.UNDEFINED, autoRefreshLayout=Component.UNDEFINED, tapNode=Component.UNDEFINED, tapNodeData=Component.UNDEFINED, tapEdge=Component.UNDEFINED, tapEdgeData=Component.UNDEFINED, mouseoverNodeData=Component.UNDEFINED, mouseoverEdgeData=Component.UNDEFINED, selectedNodeData=Component.UNDEFINED, selectedEdgeData=Component.UNDEFINED, generateImage=Component.UNDEFINED, imageData=Component.UNDEFINED, responsive=Component.UNDEFINED, persistence=Component.UNDEFINED, persisted_props=Component.UNDEFINED, persistence_type=Component.UNDEFINED, **kwargs):
self._prop_names = ['id', 'className', 'style', 'elements', 'stylesheet', 'layout', 'pan', 'zoom', 'panningEnabled', 'userPanningEnabled', 'minZoom', 'maxZoom', 'zoomingEnabled', 'userZoomingEnabled', 'boxSelectionEnabled', 'autoungrabify', 'autolock', 'autounselectify', 'autoRefreshLayout', 'tapNode', 'tapNodeData', 'tapEdge', 'tapEdgeData', 'mouseoverNodeData', 'mouseoverEdgeData', 'selectedNodeData', 'selectedEdgeData', 'generateImage', 'imageData', 'responsive', 'persistence', 'persisted_props', 'persistence_type']
self._type = 'Cytoscape'
self._namespace = 'dash_cytoscape'
self._valid_wildcard_attributes = []
self.available_properties = ['id', 'className', 'style', 'elements', 'stylesheet', 'layout', 'pan', 'zoom', 'panningEnabled', 'userPanningEnabled', 'minZoom', 'maxZoom', 'zoomingEnabled', 'userZoomingEnabled', 'boxSelectionEnabled', 'autoungrabify', 'autolock', 'autounselectify', 'autoRefreshLayout', 'tapNode', 'tapNodeData', 'tapEdge', 'tapEdgeData', 'mouseoverNodeData', 'mouseoverEdgeData', 'selectedNodeData', 'selectedEdgeData', 'generateImage', 'imageData', 'responsive']
self.available_properties = ['id', 'className', 'style', 'elements', 'stylesheet', 'layout', 'pan', 'zoom', 'panningEnabled', 'userPanningEnabled', 'minZoom', 'maxZoom', 'zoomingEnabled', 'userZoomingEnabled', 'boxSelectionEnabled', 'autoungrabify', 'autolock', 'autounselectify', 'autoRefreshLayout', 'tapNode', 'tapNodeData', 'tapEdge', 'tapEdgeData', 'mouseoverNodeData', 'mouseoverEdgeData', 'selectedNodeData', 'selectedEdgeData', 'generateImage', 'imageData', 'responsive', 'persistence', 'persisted_props', 'persistence_type']
self.available_wildcard_properties = []

_explicit_args = kwargs.pop('_explicit_args')
Expand Down
2 changes: 1 addition & 1 deletion dash_cytoscape/dash_cytoscape.dev.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash_cytoscape/dash_cytoscape.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash_cytoscape/dash_cytoscape_extra.dev.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash_cytoscape/dash_cytoscape_extra.min.js

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions dash_cytoscape/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,77 @@
"value": "false",
"computed": false
}
},
"persistence": {
"type": {
"name": "union",
"value": [
{
"name": "bool"
},
{
"name": "string"
},
{
"name": "number"
}
]
},
"required": false,
"description": "Used to allow user interactions in this component to be persisted when\nthe component - or the page - is refreshed. If `persisted` is truthy and\nhasn't changed from its previous value, any `persisted_props` that the\nuser has changed while using the app will keep those changes, as long as\nthe new prop value also matches what was given originally.\nUsed in conjunction with `persistence_type` and `persisted_props`."
},
"persisted_props": {
"type": {
"name": "arrayOf",
"value": {
"name": "enum",
"value": [
{
"value": "'elements'",
"computed": false
},
{
"value": "'stylesheet'",
"computed": false
},
{
"value": "'layout'",
"computed": false
}
]
}
},
"required": false,
"description": "Properties whose user interactions will persist after refreshing the\ncomponent or the page.",
"defaultValue": {
"value": "[]",
"computed": false
}
},
"persistence_type": {
"type": {
"name": "enum",
"value": [
{
"value": "'local'",
"computed": false
},
{
"value": "'session'",
"computed": false
},
{
"value": "'memory'",
"computed": false
}
]
},
"required": false,
"description": "Where persisted user changes will be stored:\nmemory: only kept in memory, reset on page refresh.\nlocal: window.localStorage, data is kept after the browser quit.\nsession: window.sessionStorage, data is cleared once the browser quit.",
"defaultValue": {
"value": "'local'",
"computed": false
}
}
}
}
Expand Down
48 changes: 46 additions & 2 deletions src/lib/components/Cytoscape.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,37 @@ Cytoscape.propTypes = {
/**
* Toggles intelligent responsive resize of Cytoscape graph with viewport size change
*/
responsive: PropTypes.bool
responsive: PropTypes.bool,

/**
* Used to allow user interactions in this component to be persisted when
* the component - or the page - is refreshed. If `persisted` is truthy and
* hasn't changed from its previous value, any `persisted_props` that the
* user has changed while using the app will keep those changes, as long as
* the new prop value also matches what was given originally.
* Used in conjunction with `persistence_type` and `persisted_props`.
*/
persistence: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.string,
PropTypes.number,
]),

/**
* Properties whose user interactions will persist after refreshing the
* component or the page.
*/
persisted_props: PropTypes.arrayOf(
PropTypes.oneOf(['elements', 'stylesheet', 'layout'])
),

/**
* Where persisted user changes will be stored:
* memory: only kept in memory, reset on page refresh.
* local: window.localStorage, data is kept after the browser quit.
* session: window.sessionStorage, data is cleared once the browser quit.
*/
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
};

Cytoscape.defaultProps = {
Expand All @@ -921,7 +951,21 @@ Cytoscape.defaultProps = {
generateImage: {},
imageData: null,
responsive: false,
elements: []
elements: [],
persisted_props: [],
persistence_type: 'local',
};

const defaultPersistenceTransform = {
extract: propValue => propValue,
apply: storedValue => storedValue,
};

Cytoscape.persistenceTransforms = {
elements: defaultPersistenceTransform,
stylesheet: defaultPersistenceTransform,
layout: defaultPersistenceTransform

}

export default Cytoscape;