const React = require('react'); const tweenState = require('react-tween-state'); const AppActions = require('../actions/app-actions'); const NodeColorMixin = require('../mixins/node-color-mixin'); const Node = React.createClass({ mixins: [ NodeColorMixin, tweenState.Mixin ], getInitialState: function() { return { x: 0, y: 0 }; }, componentWillMount: function() { // initial node position when rendered the first time this.setState({ x: this.props.dx, y: this.props.dy }); }, componentWillReceiveProps: function(nextProps) { // animate node transition to next position this.tweenState('x', { easing: tweenState.easingTypes.easeInOutQuad, duration: 500, endValue: nextProps.dx }); this.tweenState('y', { easing: tweenState.easingTypes.easeInOutQuad, duration: 500, endValue: nextProps.dy }); }, render: function() { const transform = 'translate(' + this.getTweeningValue('x') + ',' + this.getTweeningValue('y') + ')'; const scale = this.props.scale; const textOffsetX = 0; const textOffsetY = scale(0.5) + 18; const isPseudo = !!this.props.pseudo; const color = isPseudo ? '' : this.getNodeColor(this.props.label); const onClick = isPseudo ? null : this.props.onClick; const onMouseEnter = isPseudo ? null : this.handleMouseEnter; const onMouseLeave = isPseudo ? null : this.handleMouseLeave; const classNames = ['node']; if (this.props.highlighted) { classNames.push('highlighted'); } if (this.props.pseudo) { classNames.push('pseudo'); } return ( {this.props.highlighted && } {this.props.label} {this.props.subLabel} ); }, handleMouseEnter: function(ev) { AppActions.enterNode(ev.currentTarget.id); }, handleMouseLeave: function(ev) { AppActions.leaveNode(ev.currentTarget.id); } }); module.exports = Node;