summaryrefslogtreecommitdiff
path: root/app/components/graph/graph.tsx
blob: d41cfc7d21f086723fb7e3a1131f0154d19b1e8d (about) (plain)
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
import * as React from "react"
import { StyleProp, TextStyle, View, ViewStyle } from "react-native"
import { observer } from "mobx-react-lite"
import { color, typography } from "../../theme"
import { Text } from "../"
import { flatten } from "ramda"

import data from "../../data/miserables.json"
import genRandomTree from "../../data/randomdata";

import { ForceGraph2D, ForceGraph3D, ForceGraphVR, ForceGraphAR } from 'react-force-graph';
import  Slider  from '@react-native-community/slider';

const CONTAINER: ViewStyle = {
  justifyContent: "center",
}

const TEXT: TextStyle = {
  fontFamily: typography.primary,
  fontSize: 14,
  color: color.primary,
}

export interface GraphProps {
  /**
   * An optional style override useful for padding & margin.
   */
  style?: StyleProp<ViewStyle>
}

/**
 * Describe your component here
 */
export const Graph = observer(function Graph(props: GraphProps) {
  const { style } = props
  const styles = flatten([CONTAINER, style])

  //  const fgRef= React.useRef();


    const GROUPS=12;
    const gData = genRandomTree();

    const [visco, setVisco] = React.useState(0.4);

 // React.useEffect(()=> {
 //     const fg = fgRef.current;

 //     fg.d3Force('center', visco);
 // });

    return (
    <View>
    <Slider style={{position: "absolute", zIndex: 100, width: "20%", height: 40}}
        minimumValue={0}
        maximumValue={1}
        onValueChange={(value)=>{setVisco(value)}}
        value={visco}
    />
    <ForceGraph2D
   //   ref={fgRef}
      graphData={gData}
      nodeAutoColorBy={d => d.id%GROUPS}
      linkAutoColorBy={d => gData.nodes[d.source].id%GROUPS}
      linkColor={"#ffffff"}
      linkWidth={2}
      d3VelocityDecay={visco}
      />
    </View>
  )
})