|
| 1 | +import React, { PropTypes, Component } from 'react'; |
| 2 | +import * as themes from 'redux-devtools/lib/react/themes'; |
| 3 | +import visualizer from 'd3-state-visualizer'; |
| 4 | + |
| 5 | +const styles = { |
| 6 | + container: { |
| 7 | + fontFamily: 'monaco, Consolas, Lucida Console, monospace', |
| 8 | + position: 'relative', |
| 9 | + overflowY: 'hidden', |
| 10 | + width: '100%', |
| 11 | + height: '100%', |
| 12 | + minWidth: 300 |
| 13 | + } |
| 14 | +}; |
| 15 | + |
| 16 | +export default class ChartMonitor extends Component { |
| 17 | + constructor(props) { |
| 18 | + super(props); |
| 19 | + } |
| 20 | + |
| 21 | + static propTypes = { |
| 22 | + computedStates: PropTypes.array.isRequired, |
| 23 | + currentStateIndex: PropTypes.number.isRequired, |
| 24 | + monitorState: PropTypes.object.isRequired, |
| 25 | + stagedActions: PropTypes.array.isRequired, |
| 26 | + skippedActions: PropTypes.object.isRequired, |
| 27 | + reset: PropTypes.func.isRequired, |
| 28 | + commit: PropTypes.func.isRequired, |
| 29 | + rollback: PropTypes.func.isRequired, |
| 30 | + sweep: PropTypes.func.isRequired, |
| 31 | + toggleAction: PropTypes.func.isRequired, |
| 32 | + jumpToState: PropTypes.func.isRequired, |
| 33 | + setMonitorState: PropTypes.func.isRequired, |
| 34 | + select: PropTypes.func.isRequired, |
| 35 | + visibleOnLoad: PropTypes.bool |
| 36 | + }; |
| 37 | + |
| 38 | + static defaultProps = { |
| 39 | + select: (state) => state, |
| 40 | + monitorState: { isVisible: true }, |
| 41 | + theme: 'nicinabox', |
| 42 | + visibleOnLoad: true |
| 43 | + }; |
| 44 | + |
| 45 | + componentWillReceiveProps() { |
| 46 | + } |
| 47 | + |
| 48 | + componentDidUpdate() { |
| 49 | + } |
| 50 | + |
| 51 | + componentWillMount() { |
| 52 | + let visibleOnLoad = this.props.visibleOnLoad; |
| 53 | + const { monitorState } = this.props; |
| 54 | + this.props.setMonitorState({ |
| 55 | + ...monitorState, |
| 56 | + isVisible: visibleOnLoad |
| 57 | + }); |
| 58 | + } |
| 59 | + |
| 60 | + render() { |
| 61 | + const { monitorState, computedStates } = this.props; |
| 62 | + |
| 63 | + let theme; |
| 64 | + if (typeof this.props.theme === 'string') { |
| 65 | + if (typeof themes[this.props.theme] !== 'undefined') { |
| 66 | + theme = themes[this.props.theme]; |
| 67 | + } else { |
| 68 | + console.warn('DevTools theme ' + this.props.theme + ' not found, defaulting to nicinabox'); |
| 69 | + theme = themes.nicinabox; |
| 70 | + } |
| 71 | + } else { |
| 72 | + theme = this.props.theme; |
| 73 | + } |
| 74 | + if (!monitorState.isVisible) { |
| 75 | + return null; |
| 76 | + } |
| 77 | + |
| 78 | + const style = { |
| 79 | + width: '100%', |
| 80 | + height: '100%', |
| 81 | + node: { |
| 82 | + colors: { |
| 83 | + 'default': theme.base0B, |
| 84 | + collapsed: theme.base0B, |
| 85 | + parent: theme.base0E |
| 86 | + }, |
| 87 | + radius: 7 |
| 88 | + }, |
| 89 | + text: { |
| 90 | + colors: { |
| 91 | + 'default': theme.base0D, |
| 92 | + hover: theme.base06 |
| 93 | + } |
| 94 | + } |
| 95 | + }; |
| 96 | + |
| 97 | + const TreeChart = visualizer.components.TreeChart; |
| 98 | + |
| 99 | + return ( |
| 100 | + <div style={{...styles.container, backgroundColor: theme.base00}}> |
| 101 | + <TreeChart |
| 102 | + state={computedStates[computedStates.length - 1].state} |
| 103 | + id='todosState' |
| 104 | + aspectRatio={0.5} |
| 105 | + isSorted={false} |
| 106 | + heightBetweenNodesCoeff={1} |
| 107 | + widthBetweenNodesCoeff={1.3} |
| 108 | + tooltipOptions={{ offset: {left: 30, top: 10}, indentationSize: 2}} |
| 109 | + style={style} |
| 110 | + /> |
| 111 | + </div> |
| 112 | + ); |
| 113 | + } |
| 114 | +} |
0 commit comments