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

Feature/interactive_physical_layout #4

Merged
merged 8 commits into from
Nov 22, 2016
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# System
.DS_Store

# IDE config
.idea

# Generated
/.jshintignore
/.jshintrc
Expand Down
47 changes: 39 additions & 8 deletions src/vizceral.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ import { isEqual, some } from 'lodash';
import React from 'react'; // eslint-disable-line import/no-unresolved, import/no-extraneous-dependencies
import VizceralGraph from 'vizceral';

function getPerformanceNow() {
let g = window;
if (g != null) {
let perf = g.performance;
if (perf != null) {
try {
let perfNow = perf.now();
if (typeof perfNow === "number") {
return perfNow;
}
} catch (e) {
}
}
}
return null;
}

/**
* ![](https://raw.githubusercontent.com/Netflix/vizceral/master/logo.png)
*
Expand All @@ -19,6 +36,7 @@ import VizceralGraph from 'vizceral';
* <Vizceral traffic={this.state.trafficData}
* view={this.state.currentView}
* showLabels={this.state.displayOptions.showLabels}
* physicsOptions={this.state.physicsOptions}
* filters={this.state.filters}
* viewChanged={this.viewChanged}
* objectHighlighted={this.objectHighlighted}
Expand All @@ -34,6 +52,7 @@ import VizceralGraph from 'vizceral';
* ## Props
*/
class Vizceral extends React.Component {

componentDidMount () {
this.vizceral = new VizceralGraph(this.refs.vizCanvas);
this.updateStyles(this.props.styles);
Expand All @@ -45,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 @@ -60,8 +86,8 @@ class Vizceral extends React.Component {
setTimeout(() => {
this.vizceral.setView(this.props.view || Vizceral.defaultProps.view, this.props.objectToHighlight);
this.vizceral.updateData(this.props.traffic);

this.vizceral.animate();
let perfNow = getPerformanceNow();
this.vizceral.animate(perfNow === null ? 0 : perfNow);
this.vizceral.updateBoundingRectCache();
}, 0);
}
Expand All @@ -70,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 @@ -79,11 +104,13 @@ 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 All @@ -95,7 +122,6 @@ class Vizceral extends React.Component {
if (nextProps.match !== this.props.match) {
this.vizceral.findNodes(nextProps.match);
}

// If the data does not have an updated field, just assume it's modified now
// This also solves the case between data updates
nextProps.traffic.updated = nextProps.traffic.updated || Date.now();
Expand Down Expand Up @@ -169,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 @@ -197,6 +227,7 @@ Vizceral.defaultProps = {
nodeContextSizeChanged: () => {},
matchesFound: () => {},
showLabels: true,
allowDraggingOfNodes: false,
styles: {},
traffic: {},
viewChanged: () => {},
Expand Down