-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlanetaryParameters.jsx
302 lines (277 loc) · 9.45 KB
/
PlanetaryParameters.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
import React from 'react';
import PropTypes from 'prop-types';
import { PlanetTypes } from './enums.jsx';
import NumberInputField from './Inputs/NumberInputField.jsx';
/**
* Enumerated type, for each of the planets found in the drop-down menus.
* You can use these for keys in switch statements or in objects.
*/
const planet = {
VENUS: 1,
/**MARS: 2,
JUPITER: 3,
SATURN: 4,*/
}
/**
* Predefined data values for the planets.
*/
const planetPresets = {
/**[planet.JUPITER]: {
epicycleSize: 0.19,
eccentricity: 0.05,
motionRate: 0.08,
apogeeAngle: 152.2,
planetType: PlanetTypes.SUPERIOR,
}, */
[planet.VENUS]: {
epicycleSize: 0.72,
eccentricity: 0.02,
motionRate: 1.60,
apogeeAngle: 46.2,
planetType: PlanetTypes.INFERIOR,
}
/**[planet.MARS]: {
epicycleSize: 0.66,
eccentricity: 0.10,
motionRate: 0.52,
apogeeAngle: 106.7,
planetType: PlanetTypes.SUPERIOR,
},
[planet.SATURN]: {
epicycleSize: 0.11,
eccentricity: 0.06,
motionRate: 0.03,
apogeeAngle: 224.2,
planetType: PlanetTypes.SUPERIOR,
}*/
}
/**
* PlanetaryParameters is a GUI interface that controls the
* variables used to alter the orbit drawings in the OrbitView.
*/
export default class PlanetaryParameters extends React.Component {
constructor(props) {
super(props);
this.handlePresetSelection = this.handlePresetSelection.bind(this);
this.handleSingleVariableChange = this.handleSingleVariableChange.bind(this);
this.handleChange = this.handleChange.bind(this);
}
render() {
return (
<React.Fragment>
<h2> Planetary Parameters</h2>
<PlanetPresetSelection
onSubmit={this.handlePresetSelection}
/>
<fieldset>
<legend>Parameters</legend>
<SingleVariableControl
name="epicycleSize"
displayName="Epicycle Size"
min={0}
max={1}
step={0.01}
decimals={2}
value={this.props.params.epicycleSize}
onChange={this.handleSingleVariableChange}
/>
<SingleVariableControl
name="eccentricity"
displayName="Eccentricity"
min={0.00}
max={0.50}
step={0.01}
decimals={2}
value={this.props.params.eccentricity}
onChange={this.handleSingleVariableChange}
/>
<SingleVariableControl
name="motionRate"
displayName="Motion Rate"
min={0.00}
max={4.50}
step={0.05}
decimals={2}
value={this.props.params.motionRate}
onChange={this.handleSingleVariableChange}
/>
<br/>
<SingleVariableControl
name="apogeeAngle"
displayName="Apogee Angle"
min={0.0}
max={360.0}
step={3.6}
decimals={1}
value={this.props.params.apogeeAngle}
onChange={this.handleSingleVariableChange}
/>
</fieldset>
<fieldset>
<legend>Planet Type</legend>
<div className="custom-control custom-radio custom-control-inline">
<input
type="radio"
name="planetType"
id="planetTypeRadio2"
value={PlanetTypes.INFERIOR}
checked={this.props.params.planetType === PlanetTypes.INFERIOR}
onChange={this.handleRadioBoxes.bind(this)}
className="custom-control-input"
/>
<label htmlFor="planetTypeRadio2" className="custom-control-label">Inferior</label>
</div>
</fieldset>
</React.Fragment>
)
}
handlePresetSelection(planetName) {
let newParams = planetPresets[planet[planetName]];
this.props.onChange(newParams);
}
handleChange(newParams) {
this.props.onChange(newParams);
}
handleSingleVariableChange(key, value) {
this.props.onChange({
...this.props.params,
[key]: value
});
}
handleRadioBoxes(event) {
this.props.onChange({
...this.props.params,
[event.target.name]: Number.parseInt(event.target.value)
});
}
}
PlanetaryParameters.propTypes = {
onChange: PropTypes.func.isRequired,
params: PropTypes.exact({
epicycleSize: PropTypes.number.isRequired,
eccentricity: PropTypes.number.isRequired,
motionRate: PropTypes.number.isRequired,
apogeeAngle: PropTypes.number.isRequired,
planetType: PropTypes.number.isRequired,
}).isRequired,
}
/**
* A Drop Down Menu interface to select a planet by name. The entries in the
* menu are automatically created from the planetPresets variable, so that
* they can that preset data can be modified all in one place.
*/
class PlanetPresetSelection extends React.Component {
constructor(props) {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
this.state = { value: 'VENUS' }
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
event.preventDefault();
this.props.onSubmit(this.state.value);
}
render() {
const planetNameArray = Object.keys(planet);
const planetOptionList = planetNameArray.map((name)=> {
let displayName = name[0] + name.substr(1).toLowerCase();
return (
<option key={name} value={name}>{displayName}</option>
);
});
return (
<form onSubmit={this.handleSubmit} className="form-inline">
<label>
PRESETS:
<select value={this.state.value} onChange={this.handleChange} className="form-control form-control-sm">
{planetOptionList}
</select>
</label>
<input type="submit" value="OK" className="btn btn-primary"/>
</form>
);
}
}
PlanetPresetSelection.propTypes = {
onSubmit: PropTypes.func,
}
/**
* A Single Variable Control is a combination of both a number input box and a
* slider. It can be used to adjust a single "planetary parameter" at a time.
* @extends React
*/
class SingleVariableControl extends React.Component {
constructor(props) {
super(props);
}
render() {
const value = Number.parseFloat(this.props.value).toFixed(this.props.decimals);
return (
<label>
{this.props.displayName}
<NumberInputField
type="number"
name={this.props.name}
min={this.props.min}
max={this.props.max}
step={this.props.step}
onNewValue={this.handleNewValue.bind(this)}
value={this.props.value}
decimals={this.props.decimals}
/>
<input
type="range"
name={this.props.name}
min={this.props.min}
max={this.props.max}
step={this.props.step}
onChange={this.handleChange.bind(this)}
value={value}
/>
</label>
)
}
handleNewValue(value) {
let name = this.props.name;
value = this.convertEntryToValidNumber(value);
this.props.onChange(name, value);
}
handleChange(event) {
let name = this.props.name;
let value = this.convertEntryToValidNumber(event.target.value);
this.props.onChange(name, value);
}
/**
* Converts string into a number, and ensures that it is within the valid
* range of numbers, using the "min" and "max" provided by the props passed
* to this component.
* @param {String} value The direct input string from user.
* @return {Number} The validated number output
*/
convertEntryToValidNumber(value) {
let type = typeof(value);
if (isNaN(value) || type !== 'string' && type !== 'number') {
return this.props.min;
}
value = Number.parseFloat(value);
value = Math.min(this.props.max, value);
value = Math.max(this.props.min, value);
return value;
}
}
SingleVariableControl.propTypes = {
name: PropTypes.string,
min: PropTypes.number,
max: PropTypes.number,
step: PropTypes.number,
value: PropTypes.number,
decimals: PropTypes.number,
onChange: PropTypes.func,
displayName: PropTypes.string,
}