summaryrefslogtreecommitdiff
path: root/app/components/graph
diff options
context:
space:
mode:
Diffstat (limited to 'app/components/graph')
-rw-r--r--app/components/graph/graph.story.tsx15
-rw-r--r--app/components/graph/graph.tsx71
2 files changed, 86 insertions, 0 deletions
diff --git a/app/components/graph/graph.story.tsx b/app/components/graph/graph.story.tsx
new file mode 100644
index 0000000..e5385e6
--- /dev/null
+++ b/app/components/graph/graph.story.tsx
@@ -0,0 +1,15 @@
+import * as React from "react"
+import { storiesOf } from "@storybook/react-native"
+import { StoryScreen, Story, UseCase } from "../../../storybook/views"
+import { color } from "../../theme"
+import { Graph } from "./graph"
+
+storiesOf("Graph", module)
+ .addDecorator((fn) => <StoryScreen>{fn()}</StoryScreen>)
+ .add("Style Presets", () => (
+ <Story>
+ <UseCase text="Primary" usage="The primary.">
+ <Graph style={{ backgroundColor: color.error }} />
+ </UseCase>
+ </Story>
+ ))
diff --git a/app/components/graph/graph.tsx b/app/components/graph/graph.tsx
new file mode 100644
index 0000000..d41cfc7
--- /dev/null
+++ b/app/components/graph/graph.tsx
@@ -0,0 +1,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>
+ )
+})