Skip to content

Commit e1742d1

Browse files
fix(statevis): do not allow drag when minimized
refactor(statevis): refactor components
1 parent 95ad3a1 commit e1742d1

File tree

11 files changed

+417
-282
lines changed

11 files changed

+417
-282
lines changed

src/state/stateVisualizer.tsx

Lines changed: 0 additions & 270 deletions
This file was deleted.

src/statevis/Controls.tsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { h, Component } from 'preact';
2+
import { StateSelector } from '../selector/StateSelector';
3+
import { RENDERER_PRESETS, DEFAULT_RENDERER } from './renderers';
4+
import { Renderer } from './interface';
5+
import { UIRouter } from '@uirouter/core';
6+
7+
export interface IControlsProps {
8+
router: UIRouter;
9+
onRendererChange: (renderer: Renderer) => void;
10+
onMinimize: () => void;
11+
}
12+
13+
export interface IControlsState {
14+
renderer: Renderer;
15+
presetName: string;
16+
}
17+
18+
declare function require(string): string;
19+
const imgChevron = require('../../images/16/chevron-down.png');
20+
21+
export class Controls extends Component<IControlsProps, IControlsState> {
22+
state = {
23+
renderer: DEFAULT_RENDERER,
24+
presetName: 'Tree',
25+
}
26+
27+
componentDidMount() {
28+
this.props.onRendererChange(this.state.renderer);
29+
}
30+
31+
handleZoom(event: Event) {
32+
let el = event.target;
33+
let value = parseFloat(el['value']);
34+
let renderer = { ...this.state.renderer, zoom: value };
35+
this.setState({ renderer });
36+
this.props.onRendererChange(renderer);
37+
}
38+
39+
handleLayout(event: Event) {
40+
let presetName = event.target['value'];
41+
let settings = RENDERER_PRESETS[presetName];
42+
let renderer = { ...this.state.renderer, ...settings };
43+
this.setState({ renderer, presetName });
44+
this.props.onRendererChange(renderer);
45+
}
46+
47+
render() {
48+
const zoomLevels = [2.0, 1.5, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3];
49+
50+
return (
51+
<div className="uirStateVisControls">
52+
<div>Current State: <StateSelector router={this.props.router} /></div>
53+
<div>
54+
<select onChange={this.handleLayout.bind(this)} value={this.state.presetName} style={{ maxWidth: 100 }}>
55+
{Object.keys(RENDERER_PRESETS).map(preset =>
56+
<option value={preset}>{preset}</option>
57+
)}
58+
</select>
59+
60+
<select onChange={this.handleZoom.bind(this)} value={this.state.renderer.zoom + ''} style={{ maxWidth: 100 }}>
61+
{zoomLevels.map(level =>
62+
<option value={level + ""}>{level}x</option>
63+
)}
64+
</select>
65+
66+
</div>
67+
68+
<button onClick={this.props.onMinimize}>
69+
<img src={imgChevron} style={{ cursor: 'pointer' }} />
70+
</button>
71+
</div>
72+
)
73+
}
74+
}

0 commit comments

Comments
 (0)