From 040c0ffcf5d209495c1e849befa046f0142bbb5c Mon Sep 17 00:00:00 2001 From: brekelmj Date: Tue, 22 Nov 2016 09:41:06 +1100 Subject: [PATCH] Added property for repositioning of nodes by dragging, fix potential issue where defaults for allowDraggingOfNodes and showLabels are not passed to Visceral initially. Remove code I forgot to remove --- src/vizceral.jsx | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/vizceral.jsx b/src/vizceral.jsx index 42b9162..99cf836 100644 --- a/src/vizceral.jsx +++ b/src/vizceral.jsx @@ -4,19 +4,6 @@ import { isEqual, some } from 'lodash'; import React from 'react'; // eslint-disable-line import/no-unresolved, import/no-extraneous-dependencies import VizceralGraph from 'vizceral'; -const Console = console; -const Double_nan = 0/0; -const hasOwnPropFunc = Object.prototype.hasOwnProperty; -const isFiniteAfterCoerceToNumber = isFinite; - -function isArray(value) { - return Object.prototype.toString.call(value) === "[object Array]"; -} - -function isFiniteDouble(value) { - return typeof value === "number" && isFiniteAfterCoerceToNumber(value); -} - function getPerformanceNow() { let g = window; if (g != null) { @@ -65,6 +52,7 @@ function getPerformanceNow() { * ## Props */ class Vizceral extends React.Component { + componentDidMount () { this.vizceral = new VizceralGraph(this.refs.vizCanvas); this.updateStyles(this.props.styles); @@ -76,6 +64,13 @@ class Vizceral extends React.Component { this.vizceral.on('matchesFound', this.props.matchesFound); this.vizceral.on('viewUpdated', this.props.viewUpdated); + // Pass our defaults to Vizceral in the case that it has different defaults. + this.vizceral.setOptions({ + allowDraggingOfNodes: this.props.allowDraggingOfNodes, + showLabels: this.props.showLabels + }); + + if (!isEqual(this.props.filters, Vizceral.defaultProps.filters)) { this.vizceral.setFilters(this.props.filters); } @@ -101,7 +96,6 @@ class Vizceral extends React.Component { if (!isEqual(nextProps.styles, this.props.styles)) { this.updateStyles(nextProps.styles); } - if (!isEqual(nextProps.view, this.props.view) || !isEqual(nextProps.objectToHighlight, this.props.objectToHighlight)) { this.vizceral.setView(nextProps.view, nextProps.objectToHighlight); @@ -110,8 +104,12 @@ class Vizceral extends React.Component { if (!isEqual(nextProps.filters, this.props.filters)) { this.vizceral.setFilters(nextProps.filters); } - if (!isEqual(nextProps.showLabels, this.props.showLabels)) { - this.vizceral.setOptions({ showLabels: nextProps.showLabels }); + if (!isEqual(nextProps.showLabels, this.props.showLabels) || + !isEqual(nextProps.allowDraggingOfNodes, this.props.allowDraggingOfNodes)) { + this.vizceral.setOptions({ + allowDraggingOfNodes: nextProps.allowDraggingOfNodes, + showLabels: nextProps.showLabels + }); } if (!isEqual(nextProps.modes, this.props.modes)) { this.vizceral.setModes(nextProps.modes); @@ -197,6 +195,10 @@ Vizceral.propTypes = { * Whether or not to show labels on the nodes. */ showLabels: React.PropTypes.bool, + /** + * Nodes can be repositioned through dragging if and only if this is true. + */ + allowDraggingOfNodes: React.PropTypes.bool, /** * Styles to override default properties. */ @@ -225,6 +227,7 @@ Vizceral.defaultProps = { nodeContextSizeChanged: () => {}, matchesFound: () => {}, showLabels: true, + allowDraggingOfNodes: false, styles: {}, traffic: {}, viewChanged: () => {},