Skip to content

Commit 4c6c8ee

Browse files
committed
Added user configuration of tweening precision
Resolves #44.
1 parent 9d6bd6d commit 4c6c8ee

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

src/Graph.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class Graph extends React.Component {
133133
.fit(fit)
134134
.tweenPaths(this.props.tweenPaths)
135135
.tweenShapes(this.props.tweenShapes)
136+
.tweenPrecision(this.props.tweenPrecision)
136137
.dot(this.props.dotSrc, this.handleDotLayoutReady.bind(this))
137138
.render(this.handleRenderGraphReady.bind(this));
138139
}

src/SettingsDialog.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import DialogContentText from '@material-ui/core/DialogContentText';
99
import DialogTitle from '@material-ui/core/DialogTitle';
1010
import FormGroup from '@material-ui/core/FormGroup';
1111
import FormControlLabel from '@material-ui/core/FormControlLabel';
12+
import FormLabel from '@material-ui/core/FormLabel';
13+
import RadioGroup from '@material-ui/core/RadioGroup';
14+
import Radio from '@material-ui/core/Radio';
1215
import Switch from '@material-ui/core/Switch';
1316
import Input from '@material-ui/core/Input';
1417
import InputAdornment from '@material-ui/core/InputAdornment';
@@ -44,6 +47,20 @@ const styles = theme => ({
4447
display: 'flex',
4548
justifyContent: 'space-between',
4649
},
50+
group: {
51+
marginTop: theme.spacing.unit * 1,
52+
marginLeft: theme.spacing.unit * 0,
53+
},
54+
tweenPrecisionAbsoluteInput: {
55+
marginTop: theme.spacing.unit * 1,
56+
marginLeft: theme.spacing.unit * 1.5,
57+
width: '6.9em',
58+
},
59+
tweenPrecisionRelativeInput: {
60+
marginTop: theme.spacing.unit * 1,
61+
marginLeft: theme.spacing.unit * 1.5,
62+
width: '4.8em',
63+
},
4764
holdOffInput: {
4865
width: '7.6em',
4966
},
@@ -77,6 +94,22 @@ class SettingsDialog extends React.Component {
7794
this.props.onTweenShapesSwitchChange(event.target.checked);
7895
};
7996

97+
handleTweenPrecisionChange = (event) => {
98+
let tweenPrecision = event.target.value;
99+
if (event.target.value === 'absolute' || tweenPrecision > 1) {
100+
tweenPrecision = Math.max(Math.ceil(tweenPrecision), 1);
101+
}
102+
this.props.onTweenPrecisionChange(tweenPrecision.toString() + (this.props.tweenPrecision.includes('%') ? '%': ''));
103+
};
104+
105+
handleTweenPrecisionIsRelativeRadioChange = (event) => {
106+
let tweenPrecision = +this.props.tweenPrecision.split('%')[0];
107+
if (event.target.value === 'absolute' || tweenPrecision > 1) {
108+
tweenPrecision = Math.max(Math.ceil(tweenPrecision), 1);
109+
}
110+
this.props.onTweenPrecisionChange(tweenPrecision.toString() + (event.target.value === 'relative' ? '%': ''));
111+
};
112+
80113
handleHoldOffChange = (event) => {
81114
this.props.onHoldOffChange(event.target.value);
82115
};
@@ -91,6 +124,13 @@ class SettingsDialog extends React.Component {
91124

92125
render() {
93126
const { classes } = this.props;
127+
const tweenPrecisionIsRelative = this.props.tweenPrecision.includes('%');
128+
const tweenPrecision = +this.props.tweenPrecision.split('%')[0];
129+
const tweenPrecisionType = tweenPrecisionIsRelative ? 'relative' : 'absolute';
130+
const tweenPrecisionUnit = tweenPrecisionIsRelative ? '%' : 'points';
131+
const enableTweenPrecisionSetting = this.props.tweenPaths || this.props.tweenShapes;
132+
const tweenPrecisionStep = (tweenPrecisionIsRelative && tweenPrecision <= 1) ? 0.1 : 1;
133+
const tweenPrecisionInputClass = tweenPrecisionIsRelative ? classes.tweenPrecisionRelativeInput : classes.tweenPrecisionAbsoluteInput;
94134
return (
95135
<div>
96136
<Dialog
@@ -172,6 +212,45 @@ class SettingsDialog extends React.Component {
172212
label="Enable shape tweening during transitions"
173213
/>
174214
</FormGroup>
215+
<FormControl component="fieldset" className={classes.formControl}>
216+
<FormLabel component="legend">Tweening precision</FormLabel>
217+
<RadioGroup
218+
name="tweenPrecision"
219+
className={classes.group}
220+
value={tweenPrecisionType}
221+
onChange={this.handleTweenPrecisionIsRelativeRadioChange}
222+
>
223+
<FormControlLabel
224+
className={classes.formControlLabel}
225+
value="absolute"
226+
disabled={!enableTweenPrecisionSetting}
227+
control={<Radio />}
228+
label="Absolute"
229+
/>
230+
<FormControlLabel
231+
className={classes.formControlLabel}
232+
value="relative"
233+
disabled={!enableTweenPrecisionSetting}
234+
control={<Radio />}
235+
label="Relative"
236+
/>
237+
</RadioGroup>
238+
<Input
239+
className={tweenPrecisionInputClass}
240+
id="tween-precision"
241+
type="number"
242+
value={tweenPrecision}
243+
disabled={!enableTweenPrecisionSetting}
244+
onChange={this.handleTweenPrecisionChange}
245+
endAdornment={<InputAdornment position="end"> {tweenPrecisionUnit} </InputAdornment>}
246+
inputProps={{
247+
'aria-label': 'tweenPrecision',
248+
min: tweenPrecisionStep,
249+
max: tweenPrecisionIsRelative ? 100 : 999,
250+
step: tweenPrecisionStep,
251+
}}
252+
/>
253+
</FormControl>
175254
</DialogContent>
176255
<DialogTitle id="form-dialog-title">Text Editor</DialogTitle>
177256
<DialogContent classes={{root: classes.root}}>

src/pages/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Index extends React.Component {
5656
fitGraph : localStorage.getItem('fitGraph') === 'true',
5757
tweenPaths : localStorage.getItem('tweenPaths') !== 'false',
5858
tweenShapes : localStorage.getItem('tweenShapes') !== 'false',
59+
tweenPrecision : localStorage.getItem('tweenPrecision') || '1%',
5960
engine : localStorage.getItem('engine') || 'dot',
6061
defaultNodeAttributes: JSON.parse(localStorage.getItem('defaultNodeAttributes')) || {},
6162
defaultEdgeAttributes: JSON.parse(localStorage.getItem('defaultEdgeAttributes')) || {},
@@ -194,6 +195,12 @@ class Index extends React.Component {
194195
});
195196
}
196197

198+
handleTweenPrecisionChange = (tweenPrecision) => {
199+
this.setPersistentState({
200+
tweenPrecision: tweenPrecision,
201+
});
202+
}
203+
197204
handleHoldOffChange = (holdOff) => {
198205
this.setPersistentState({
199206
holdOff: holdOff,
@@ -415,10 +422,12 @@ class Index extends React.Component {
415422
fitGraph={this.state.fitGraph}
416423
tweenPaths={this.state.tweenPaths}
417424
tweenShapes={this.state.tweenShapes}
425+
tweenPrecision={this.state.tweenPrecision}
418426
onEngineSelectChange={this.handleEngineSelectChange}
419427
onFitGraphSwitchChange={this.handleFitGraphSwitchChange}
420428
onTweenPathsSwitchChange={this.handleTweenPathsSwitchChange}
421429
onTweenShapesSwitchChange={this.handleTweenShapesSwitchChange}
430+
onTweenPrecisionChange={this.handleTweenPrecisionChange}
422431
holdOff={this.state.holdOff}
423432
onHoldOffChange={this.handleHoldOffChange}
424433
fontSize={this.state.fontSize}
@@ -492,6 +501,7 @@ class Index extends React.Component {
492501
fit={this.state.fitGraph}
493502
tweenPaths={this.state.tweenPaths}
494503
tweenShapes={this.state.tweenShapes}
504+
tweenPrecision={this.state.tweenPrecision}
495505
defaultNodeAttributes={this.state.defaultNodeAttributes}
496506
defaultEdgeAttributes={this.state.defaultEdgeAttributes}
497507
onTextChange={this.handleTextChange}

0 commit comments

Comments
 (0)