Skip to content

Commit

Permalink
Added property for repositioning of nodes by dragging, fix potential …
Browse files Browse the repository at this point in the history
…issue where defaults for allowDraggingOfNodes and showLabels are not passed to Visceral initially. Remove code I forgot to remove
  • Loading branch information
brekelj1 committed Nov 21, 2016
1 parent 2f34a1c commit 040c0ff
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/vizceral.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -225,6 +227,7 @@ Vizceral.defaultProps = {
nodeContextSizeChanged: () => {},
matchesFound: () => {},
showLabels: true,
allowDraggingOfNodes: false,
styles: {},
traffic: {},
viewChanged: () => {},
Expand Down

0 comments on commit 040c0ff

Please sign in to comment.