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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
import * as React from "react"
import { ScrollView, StyleProp, Switch, TextStyle, TouchableOpacity, View, ViewStyle, StyleSheet, Button } from "react-native"
import { observer } from "mobx-react-lite"
import { color, typography } from "../../theme"
import { Text } from "../"
import { flatten } from "ramda"
import Slider from "@react-native-community/slider"
import { useState } from "react"
import Accordion from 'react-native-collapsible/Accordion'
import * as Animatable from 'react-native-animatable'
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
const CONTAINER: ViewStyle = {
justifyContent: "center",
}
const TEXT: TextStyle = {
fontFamily: typography.primary,
fontSize: 14,
color: color.primary,
}
export interface TweaksProps {
/**
* An optional style override useful for padding & margin.
*/
style?: StyleProp<ViewStyle>
physics
setPhysics
}
/**
* Describe your component here
*/
export const Tweaks = observer(function Tweaks(props: TweaksProps): JSX.Element {
const { style, physics, setPhysics } = props
// const styles = flatten([CONTAINER, style])
const content = [
{
title: "Physics",
content:
<View>
<Text preset="fieldLabel" text={"Repulsive force: " + physics.charge} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={-400}
maximumValue={100}
onValueChange={(value) => { setPhysics({ ...physics, charge: value }) }}
value={physics.charge}
step={1} />
<Text preset="fieldLabel" text={"Link Force: " + physics.linkStrength} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={-2}
maximumValue={2}
onValueChange={(value) => { setPhysics({ ...physics, linkStrength: value }) }}
value={physics.linkStrength}
step={0.1}
/>
<Text preset="fieldLabel" text={"'Link Iterations': " + physics.linkIts} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={1}
maximumValue={10}
onValueChange={(value) => { setPhysics({ ...physics, linkIts: value }) }}
value={physics.linkIts}
step={1} />
<Text preset="fieldLabel" text="Collision" />
<Switch style={{ width: "5", height: 20, marginVertical: 10 }}
value={physics.collision}
onValueChange={() => { setPhysics({ ...physics, collision: !physics.collision }) }}
/>
</View>,
},
{
title: 'Visual',
content:
<View>
<Text preset="fieldLabel" text={"Line Opacity: " + physics.linkOpacity} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={0}
maximumValue={1}
onValueChange={(value) => { setPhysics({ ...physics, linkOpacity: value }) }}
value={physics.linkOpacity}
step={.01} />
<Text preset="fieldLabel" text={"Line width: " + physics.linkWidth} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={.1}
maximumValue={10}
onValueChange={(value) => { setPhysics({ ...physics, linkWidth: value }) }}
value={physics.linkWidth}
step={0.1} />
<Text preset="fieldLabel" text={"Node size: " + physics.nodeRel} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={1}
maximumValue={10}
onValueChange={(value) => { setPhysics({ ...physics, nodeRel: value }) }}
value={physics.nodeRel}
step={.01} />
<Text preset="fieldLabel" text={"Particles: " + physics.particles} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={0}
maximumValue={10}
onValueChange={(value) => { setPhysics({ ...physics, particles: value }) }}
value={physics.particles}
step={1} />
<Text preset="fieldLabel" text={"Particle Size: " + physics.particleWidth} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={1}
maximumValue={10}
onValueChange={(value) => { setPhysics({ ...physics, particleWidth: value }) }}
value={physics.particleWidth}
step={.1} />
<Text preset="fieldLabel" text="Labels" />
<Switch style={{ width: "5", height: 20, marginVertical: 10 }}
value={physics.labels}
onValueChange={() => { setPhysics({ ...physics, labels: !physics.labels }) }}
/>
<Text preset="fieldLabel" text={"Scale when labels become visible: " + physics.labelScale} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={0.1}
maximumValue={5}
onValueChange={(value) => { setPhysics({ ...physics, labelScale: value }) }}
value={physics.labelScale}
step={.1} />
</View>,
},
{
title: 'Modes',
content:
<View>
<Text preset="fieldLabel" text="Expandable Graph" />
<Switch style={{ width: "5", height: 20, marginVertical: 10 }}
value={physics.collapse}
onValueChange={() => { setPhysics({ ...physics, collapse: !physics.collapse }) }}
/>
<Text preset="fieldLabel" text="3D" />
<Switch style={{ width: "5", height: 20, marginVertical: 10 }}
value={physics.threedim}
onValueChange={() => { setPhysics({ ...physics, threedim: !physics.threedim }) }}
/>
</View>
},
];
const [activeSections, setActiveSections] = useState([]);
const setSections = (sections) => {
setActiveSections(
sections.includes(undefined) ? [] : sections
);
};
const renderHeader = (section, _, isActive) => {
return (
<Animatable.View
duration={400}
style={[styles.header, isActive ? styles.active : styles.inactive]}
transition="backgroundColor"
>
<Text style={styles.headerText}>{section.title}</Text>
</Animatable.View>
);
};
const renderContent = (section, _, isActive) => {
return (
<Animatable.View
duration={400}
style={[styles.content, isActive ? styles.active : styles.inactive]}
transition="backgroundColor"
>
{section.content}
</Animatable.View>
);
}
const [tweaks, setTweaks] = useState(true);
if (true) {
if (tweaks) {
return (
<View style={styles.container}>
<View style={{ height: 30, width: "100%", backgroundColor: "rgb(20,20,20)" }}>
<TouchableOpacity style={{ width: 30, color: "#ffffff", textAlign: "center", marginLeft: "auto", padding: 5 }}
onPress={() => { setTweaks(false) }}>
<Icon name="close-circle" color="#ffffff" size={20} />
</TouchableOpacity>
</View>
<ScrollView>
<Accordion
activeSections={activeSections}
sections={content}
touchAbleComponent={TouchableOpacity}
expandMultiple={true}
renderHeader={renderHeader}
renderContent={renderContent}
duration={200}
onChange={setSections}
renderAsFlatList={false}
/>
</ScrollView>
</View>
);
} else {
return (
<TouchableOpacity
onPress={() => { setTweaks(true) }}
style={{ position: "absolute", top: 50, left: 50, width: 30, color: "#ffffff", zIndex: 100 }}>
<Icon name="cog" color="#ffffff" size={30} />
</TouchableOpacity>
)
}
} else {
return (
<View style={{ position: "absolute", top: "5%", left: "5%", zIndex: 100, width: 300, backgroundColor: "#000000", padding: 20 }}>
<Text preset="bold" text="Physics" />
<Text preset="fieldLabel" text={"Repulsive force: " + physics.charge} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={-400}
maximumValue={100}
onValueChange={(value) => { setPhysics({ ...physics, charge: value }) }}
value={physics.charge}
step={1} />
<Text preset="fieldLabel" text={"Link Force: " + physics.linkStrength} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={0}
maximumValue={2}
onValueChange={(value) => { setPhysics({ ...physics, linkStrength: value }) }}
value={physics.linkStrength}
step={0.1}
/>
<Text preset="fieldLabel" text={"'Link Iterations': " + physics.linkIts} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={1}
maximumValue={10}
onValueChange={(value) => { setPhysics({ ...physics, linkIts: value }) }}
value={physics.linkIts}
step={1} />
<Text preset="fieldLabel" text="Collision" />
<Switch style={{ width: "5", height: 20, marginVertical: 10 }}
value={physics.collision}
onValueChange={() => { setPhysics({ ...physics, collision: !physics.collision }) }}
/>
<Text preset="bold" text="Visual" />
<Text preset="fieldLabel" text={"Particles: " + physics.particles} />
<Slider style={{ height: 40, width: "90%" }}
minimumValue={0}
maximumValue={5}
onValueChange={(value) => { setPhysics({ ...physics, particles: value }) }}
value={physics.particles}
step={1} />
<Text preset="bold" text="Modes" />
<Text preset="fieldLabel" text="Expandable Graph" />
<Switch style={{ width: "5", height: 20, marginVertical: 10 }}
value={physics.collapse}
onValueChange={() => { setPhysics({ ...physics, collapse: !physics.collapse }) }}
/>
<Text preset="fieldLabel" text="3D" />
<Switch style={{ width: "5", height: 20, marginVertical: 10 }}
value={physics.threedim}
onValueChange={() => { setPhysics({ ...physics, threedim: !physics.threedim }) }}
/>
</View>
);
}
})
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'rgb(20,20,20)',
position: "absolute",
zIndex: 100,
left: 50,
top: 50,
width: 250,
borderRadius: 5,
borderStyle: "solid",
maxHeight: "70%",
paddingBottom: 20,
},
title: {
textAlign: 'left',
fontSize: 22,
fontWeight: '300',
marginBottom: 20,
paddingLeft: 20,
},
header: {
backgroundColor: '#111111',
padding: 10,
paddingBottom: 20,
textAlign: "left",
},
headerText: {
textAlign: 'left',
paddingLeft: 30,
fontSize: 16,
fontWeight: '500',
},
content: {
padding: 20,
paddingLeft: 60,
backgroundColor: '#000000',
},
active: {
backgroundColor: 'rgba(0,0,0,1)',
},
inactive: {
backgroundColor: 'rgba(20,20,20,1)',
},
selectors: {
marginBottom: 10,
flexDirection: 'row',
justifyContent: 'center',
},
selector: {
backgroundColor: '#111111',
padding: 10,
},
activeSelector: {
fontWeight: 'bold',
},
selectTitle: {
fontSize: 14,
fontWeight: '500',
padding: 10,
},
multipleToggle: {
flexDirection: 'row',
justifyContent: 'center',
marginVertical: 30,
alignItems: 'center',
},
multipleToggle__title: {
fontSize: 16,
marginRight: 8,
},
});
|