summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2021-07-18 00:29:01 +0200
committerThomas F. K. Jorna <[email protected]>2021-07-18 00:29:01 +0200
commitecfd4f05bd32c3942580a5b01f021b2acdff4b54 (patch)
tree7597a3f85f616e3fd95579baf352a06a61201f2c /app
parent85ba3ce12f4e4f473d2ee2fb595854091baae803 (diff)
fixed not being able to save tweaks + formatting
Diffstat (limited to 'app')
-rw-r--r--app/components/graph/graph.tsx271
-rw-r--r--app/components/tweaks/tweaks.tsx6
-rw-r--r--app/screens/graph/graph-screen.tsx51
3 files changed, 154 insertions, 174 deletions
diff --git a/app/components/graph/graph.tsx b/app/components/graph/graph.tsx
index a129f62..ff41ea9 100644
--- a/app/components/graph/graph.tsx
+++ b/app/components/graph/graph.tsx
@@ -54,24 +54,25 @@ export const Graph = observer(function Graph(props: GraphProps): JSX.Element {
useEffect(() => {
const fg = fgRef.current
//fg.d3Force('center').strength(0.05);
- if(physics.gravityOn){
+ if (physics.gravityOn) {
fg.d3Force("x", d3.forceX().strength(physics.gravity));
fg.d3Force("y", d3.forceY().strength(physics.gravity));
- if (physics.threedim) {
- if(physics.galaxy){
- fg.d3Force("y", d3.forceY().strength(physics.gravity / 5));
- fg.d3Force("z", d3.forceZ().strength(physics.gravity / 5));
+ if (physics.threedim) {
+ if (physics.galaxy) {
+ fg.d3Force("y", d3.forceY().strength(physics.gravity / 5));
+ fg.d3Force("z", d3.forceZ().strength(physics.gravity / 5));
+ } else {
+ fg.d3Force("y", d3.forceY().strength(physics.gravity));
+ fg.d3Force("z", d3.forceZ().strength(physics.gravity));
+ }
} else {
- fg.d3Force("y", d3.forceY().strength(physics.gravity));
- fg.d3Force("z", d3.forceZ().strength(physics.gravity));
- } } else {
- fg.d3Force("z", null);
+ fg.d3Force("z", null);
};
} else {
fg.d3Force("x", null);
fg.d3Force("y", null);
- physics.threedim ? fg.d3Force("z", null) : null;
- };
+ physics.threedim ? fg.d3Force("z", null) : null;
+ };
fg.d3Force("link").strength(physics.linkStrength)
fg.d3Force("link").iterations(physics.linkIts)
physics.collision
@@ -81,13 +82,13 @@ export const Graph = observer(function Graph(props: GraphProps): JSX.Element {
})
// For the expandable version of the graph
- const rootId = 0
+ const rootId = 0
const nodesById = useMemo(() => {
const nodesById = Object.fromEntries(gData.nodes.map((node) => [node.id, node]))
// link parent/children
- gData.nodes.forEach((node) => {
+ gData.nodes.forEach((node) => {
node.collapsed = node.id !== rootId
node.childLinks = []
node.parentLink = []
@@ -119,63 +120,41 @@ export const Graph = observer(function Graph(props: GraphProps): JSX.Element {
* setPrunedTree(getPrunedTree())
* }, []);
*/
+ const [highlightNodes, setHighlightNodes] = useState(new Set());
+ const [highlightLinks, setHighlightLinks] = useState(new Set());
+ const [hoverNode, setHoverNode] = useState(null);
- // Highlight Graph
- /**
-/* const data = useMemo(() => {
-* // cross-link node objects
-* rando.links.forEach(link => {
-* const a = rando.nodes[link.source];
-* const b = rando.nodes[link.target];
-* !a.neighbors && (a.neighbors = []);
-* !b.neighbors && (b.neighbors = []);
-* a.neighbors.push(b);
-* b.neighbors.push(a);
-*
-* !a.links && (a.links = []);
-* !b.links && (b.links = []);
-* a.links.push(link);
-* b.links.push(link);
-* });
-*
-* return rando;
-* }, []);
- */
- const [highlightNodes, setHighlightNodes] = useState(new Set());
- const [highlightLinks, setHighlightLinks] = useState(new Set());
- const [hoverNode, setHoverNode] = useState(null);
-
- const updateHighlight = () => {
- setHighlightNodes(highlightNodes);
- setHighlightLinks(highlightLinks);
- };
+ const updateHighlight = () => {
+ setHighlightNodes(highlightNodes);
+ setHighlightLinks(highlightLinks);
+ };
- const handleNodeHover = node => {
- console.log("hover");
- highlightNodes.clear();
- highlightLinks.clear();
- if (node) {
- highlightNodes.add(node);
- node.neighbors.forEach(neighbor => highlightNodes.add(neighbor));
- node.links.forEach(link => highlightLinks.add(link));
- }
+ const handleNodeHover = node => {
+ console.log("hover");
+ highlightNodes.clear();
+ highlightLinks.clear();
+ if (node) {
+ highlightNodes.add(node);
+ node.neighbors.forEach(neighbor => highlightNodes.add(neighbor));
+ node.links.forEach(link => highlightLinks.add(link));
+ }
- setHoverNode(node || null);
- updateHighlight();
- };
+ setHoverNode(node || null);
+ updateHighlight();
+ };
- const handleLinkHover = link => {
- highlightNodes.clear();
- highlightLinks.clear();
+ const handleLinkHover = link => {
+ highlightNodes.clear();
+ highlightLinks.clear();
- if (link) {
- highlightLinks.add(link);
- highlightNodes.add(link.source);
- highlightNodes.add(link.target);
- }
+ if (link) {
+ highlightLinks.add(link);
+ highlightNodes.add(link.source);
+ highlightNodes.add(link.target);
+ }
- updateHighlight();
- };
+ updateHighlight();
+ };
/* const paintRing = useCallback((node, ctx) => {
* // add ring just for highlighted nodes
@@ -186,19 +165,19 @@ export const Graph = observer(function Graph(props: GraphProps): JSX.Element {
* }, [hoverNode]);
*/
- /* autoPauseRedraw={false}
- linkWidth={link => highlightLinks.has(link) ? 5 : 1}
- linkDirectionalParticles={4}
- linkDirectionalParticleWidth={link => highlightLinks.has(link) ? 4 : 0}
- nodeCanvasObjectMode={node => highlightNodes.has(node) ? 'before' : undefined}
- nodeCanvasObject={paintRing}
- onNodeHover={handleNodeHover}
- onLinkHover={handleLinkHover}
- nodeRelSize={NODE_R} */
+ /* autoPauseRedraw={false}
+linkWidth={link => highlightLinks.has(link) ? 5 : 1}
+linkDirectionalParticles={4}
+linkDirectionalParticleWidth={link => highlightLinks.has(link) ? 4 : 0}
+nodeCanvasObjectMode={node => highlightNodes.has(node) ? 'before' : undefined}
+nodeCanvasObject={paintRing}
+onNodeHover={handleNodeHover}
+onLinkHover={handleLinkHover}
+ nodeRelSize={NODE_R} */
- //nodeColor={(node) =>
- // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
- //}
+ //nodeColor={(node) =>
+ // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
+ //}
return (
<View>
{!physics.threedim ? (
@@ -209,68 +188,68 @@ export const Graph = observer(function Graph(props: GraphProps): JSX.Element {
//graphData={physics.collapse ? prunedTree : gData}
nodeAutoColorBy={physics.colorful ? "id" : undefined}
nodeColor={
- !physics.colorful ? (
+ !physics.colorful ? (
(node) => {
- if(highlightNodes.size === 0) {
- return "rgb(100, 100, 100, 1)"
- } else {
- return highlightNodes.has(node) ? "purple" : "rgb(50, 50, 50, 0.5)"
- }
- // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
+ if (highlightNodes.size === 0) {
+ return "rgb(100, 100, 100, 1)"
+ } else {
+ return highlightNodes.has(node) ? "purple" : "rgb(50, 50, 50, 0.5)"
+ }
+ // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
}) : undefined
}
linkAutoColorBy={physics.colorful ? "target" : undefined}
//linkAutoColorBy={(d) => gData.nodes[d.source].id % GROUPS}
linkColor={
- !physics.colorful ? (
- (link) => {
- if(highlightLinks.size === 0) {
- return "rgb(50, 50, 50, 0.8)"
- } else {
- return highlightLinks.has(link) ? "purple" : "rgb(50, 50, 50, 0.2)"
- }
- // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
+ !physics.colorful ? (
+ (link) => {
+ if (highlightLinks.size === 0) {
+ return "rgb(50, 50, 50, 0.8)"
+ } else {
+ return highlightLinks.has(link) ? "purple" : "rgb(50, 50, 50, 0.2)"
+ }
+ // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
}
- ) : undefined
- //highlightLinks.has(link) ? "purple" : "grey"
- // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
+ ) : undefined
+ //highlightLinks.has(link) ? "purple" : "grey"
+ // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
}
linkDirectionalParticles={physics.particles}
//onNodeClick={!physics.collapse ? null : handleNodeClick}
- nodeLabel={(node) => node.title}
+ nodeLabel={(node) => node.title}
//nodeVal ={(node)=> node.childLinks.length * 0.5 + 1}
//d3VelocityDecay={visco}
- linkWidth={link => highlightLinks.has(link) ? 3 * physics.linkWidth : physics.linkWidth}
+ linkWidth={link => highlightLinks.has(link) ? 3 * physics.linkWidth : physics.linkWidth}
linkOpacity={physics.linkOpacity}
nodeRelSize={physics.nodeRel}
nodeVal={node => highlightNodes.has(node) ? node.neighbors.length + 5 : node.neighbors.length + 3}
linkDirectionalParticleWidth={physics.particleWidth}
nodeCanvasObject={
- (node, ctx, globalScale) => {
- if(physics.labels) {
- if(globalScale > physics.labelScale || highlightNodes.has(node)) {
- const label = node.title.substring(0, Math.min(node.title.length, 30));
- const fontSize = 12/globalScale;
- ctx.font = `${fontSize}px Sans-Serif`;
- const textWidth = ctx.measureText(label).width;
- const bckgDimensions = [textWidth * 1.1, fontSize].map(n => n + fontSize * 0.5); // some padding
- const fadeFactor = Math.min(3*(globalScale - physics.labelScale)/physics.labelScale, 1);
+ (node, ctx, globalScale) => {
+ if (physics.labels) {
+ if (globalScale > physics.labelScale || highlightNodes.has(node)) {
+ const label = node.title.substring(0, Math.min(node.title.length, 30));
+ const fontSize = 12 / globalScale;
+ ctx.font = `${fontSize}px Sans-Serif`;
+ const textWidth = ctx.measureText(label).width;
+ const bckgDimensions = [textWidth * 1.1, fontSize].map(n => n + fontSize * 0.5); // some padding
+ const fadeFactor = Math.min(3 * (globalScale - physics.labelScale) / physics.labelScale, 1);
- ctx.fillStyle = 'rgba(20, 20, 20, ' +
- (highlightNodes.size === 0 ? .5 * fadeFactor : (highlightNodes.has(node) ? 0.5 : 0.15 * fadeFactor)) + ')';
- ctx.fillRect(node.x - bckgDimensions[0] / 2, node.y - bckgDimensions[1] / 2, ...bckgDimensions);
+ ctx.fillStyle = 'rgba(20, 20, 20, ' +
+ (highlightNodes.size === 0 ? .5 * fadeFactor : (highlightNodes.has(node) ? 0.5 : 0.15 * fadeFactor)) + ')';
+ ctx.fillRect(node.x - bckgDimensions[0] / 2, node.y - bckgDimensions[1] / 2, ...bckgDimensions);
- ctx.textAlign = 'center';
- ctx.textBaseline = 'middle';
- ctx.fillStyle = 'rgb(255, 255, 255, ' +
- (highlightNodes.size === 0 ? fadeFactor : (highlightNodes.has(node) ? 1 : 0.3 * fadeFactor)) + ')';
- ctx.fillText(label, node.x, node.y);
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'middle';
+ ctx.fillStyle = 'rgb(255, 255, 255, ' +
+ (highlightNodes.size === 0 ? fadeFactor : (highlightNodes.has(node) ? 1 : 0.3 * fadeFactor)) + ')';
+ ctx.fillText(label, node.x, node.y);
- node.__bckgDimensions = bckgDimensions; // to re-use in nodePointerAreaPaint
- };
- };
- }}
- nodeCanvasObjectMode={()=> 'after'}
+ node.__bckgDimensions = bckgDimensions; // to re-use in nodePointerAreaPaint
+ };
+ };
+ }}
+ nodeCanvasObjectMode={() => 'after'}
onNodeHover={physics.hover ? handleNodeHover : null}
//onLinkHover={physics.hover ? handleLinkHover : null}
d3AlphaDecay={physics.alphaDecay}
@@ -285,38 +264,38 @@ export const Graph = observer(function Graph(props: GraphProps): JSX.Element {
//graphData={physics.collapse ? prunedTree : gData}
nodeAutoColorBy={physics.colorful ? "id" : undefined}
nodeColor={
- !physics.colorful ? (
+ !physics.colorful ? (
(node) => {
- if(highlightNodes.size === 0) {
- return "rgb(100, 100, 100, 1)"
- } else {
- return highlightNodes.has(node) ? "purple" : "rgb(50, 50, 50, 0.5)"
- }
- // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
+ if (highlightNodes.size === 0) {
+ return "rgb(100, 100, 100, 1)"
+ } else {
+ return highlightNodes.has(node) ? "purple" : "rgb(50, 50, 50, 0.5)"
+ }
+ // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
}) : undefined
}
linkAutoColorBy={physics.colorful ? "target" : undefined}
//linkAutoColorBy={(d) => gData.nodes[d.source].id % GROUPS}
linkColor={
- !physics.colorful ? (
- (link) => {
- if(highlightLinks.size === 0) {
- return "rgb(50, 50, 50, 0.8)"
- } else {
- return highlightLinks.has(link) ? "purple" : "rgb(50, 50, 50, 0.2)"
- }
- // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
+ !physics.colorful ? (
+ (link) => {
+ if (highlightLinks.size === 0) {
+ return "rgb(50, 50, 50, 0.8)"
+ } else {
+ return highlightLinks.has(link) ? "purple" : "rgb(50, 50, 50, 0.2)"
+ }
+ // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
}
- ) : undefined
- //highlightLinks.has(link) ? "purple" : "grey"
- // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
+ ) : undefined
+ //highlightLinks.has(link) ? "purple" : "grey"
+ // !node.childLinks.length ? "green" : node.collapsed ? "red" : "yellow"
}
linkDirectionalParticles={physics.particles}
//onNodeClick={!physics.collapse ? null : handleNodeClick}
- nodeLabel={(node) => node.title}
+ nodeLabel={(node) => node.title}
//nodeVal ={(node)=> node.childLinks.length * 0.5 + 1}
//d3VelocityDecay={visco}
- linkWidth={link => highlightLinks.has(link) ? 3 * physics.linkWidth : physics.linkWidth}
+ linkWidth={link => highlightLinks.has(link) ? 3 * physics.linkWidth : physics.linkWidth}
linkOpacity={physics.linkOpacity}
nodeRelSize={physics.nodeRel}
nodeVal={node => highlightNodes.has(node) ? node.neighbors.length + 5 : node.neighbors.length + 3}
@@ -327,15 +306,15 @@ export const Graph = observer(function Graph(props: GraphProps): JSX.Element {
d3AlphaMin={physics.alphaTarget}
d3VelocityDecay={physics.velocityDecay}
nodeThreeObject={
- !physics.labels ? undefined
+ !physics.labels ? undefined
: ((node) => {
- console.log(node.title)
- const sprite = new SpriteText(node.title.substring(0, 30));
- console.log("didnt crash here 2")
- sprite.color = "#ffffff";
- sprite.textHeight = 8;
- return sprite;
- } )}
+ console.log(node.title)
+ const sprite = new SpriteText(node.title.substring(0, 30));
+ console.log("didnt crash here 2")
+ sprite.color = "#ffffff";
+ sprite.textHeight = 8;
+ return sprite;
+ })}
nodeThreeObjectExtend={true}
/>
)}
diff --git a/app/components/tweaks/tweaks.tsx b/app/components/tweaks/tweaks.tsx
index a67b723..d2b5bd1 100644
--- a/app/components/tweaks/tweaks.tsx
+++ b/app/components/tweaks/tweaks.tsx
@@ -44,7 +44,7 @@ export const Tweaks = observer(function Tweaks(props: TweaksProps): JSX.Element
<Text preset="fieldLabel" text="Gravity" />
<Switch style={{ width: "5", height: 20, marginVertical: 10 }}
value={physics.gravityOn}
- onValueChange={() => { setPhysics({ ...physics, gravityOn: !physics.gravityOn })}}
+ onValueChange={() => { setPhysics({ ...physics, gravityOn: !physics.gravityOn }) }}
/>
<Text preset="fieldLabel" text={"Gravity: " + physics.gravity} />
<Slider style={{ height: 40, width: "90%" }}
@@ -116,12 +116,12 @@ export const Tweaks = observer(function Tweaks(props: TweaksProps): JSX.Element
<Text preset="fieldLabel" text="Colorful" />
<Switch style={{ width: "5", height: 20, marginVertical: 10 }}
value={physics.colorful}
- onValueChange={() => { setPhysics({ ...physics, colorful: !physics.colorful })}}
+ onValueChange={() => { setPhysics({ ...physics, colorful: !physics.colorful }) }}
/>
<Text preset="fieldLabel" text="Hover highlight" />
<Switch style={{ width: "5", height: 20, marginVertical: 10 }}
value={physics.hover}
- onValueChange={() => { setPhysics({ ...physics, hover: !physics.hover })}}
+ onValueChange={() => { setPhysics({ ...physics, hover: !physics.hover }) }}
/>
<Text preset="fieldLabel" text={"Line Opacity: " + physics.linkOpacity} />
<Slider style={{ height: 40, width: "90%" }}
diff --git a/app/screens/graph/graph-screen.tsx b/app/screens/graph/graph-screen.tsx
index a33c6b1..ebca953 100644
--- a/app/screens/graph/graph-screen.tsx
+++ b/app/screens/graph/graph-screen.tsx
@@ -63,6 +63,7 @@ export const GraphScreen = observer(function GraphScreen() {
const value: string = await AsyncStorage.getItem("@physics");
if (value !== null) {
const valueJson = JSON.parse(value);
+ console.log(Object.keys(valueJson).length + " is not " + Object.keys(physicsInit).length)
if (Object.keys(valueJson).length === Object.keys(physicsInit).length) {
return valueJson;
} else { return physicsInit };
@@ -75,8 +76,9 @@ export const GraphScreen = observer(function GraphScreen() {
}
const storeData = async (value) => {
try {
- const jsonValue = JSON.stringify(value)
- await AsyncStorage.mergeItem("@physics", jsonValue)
+ let jsonVal = JSON.stringify(value)
+ console.log(jsonVal + " " + value);
+ await AsyncStorage.setItem("@physics", jsonVal)
} catch (e) {
console.log(e)
}
@@ -91,7 +93,6 @@ export const GraphScreen = observer(function GraphScreen() {
// set timer so the thing doesn't run every single slider tick
const timer = setTimeout(() => {
storeData(physics)
- const test = getData()
}, 1000)
return () => clearTimeout(timer)
}, [physics]);
@@ -101,31 +102,31 @@ export const GraphScreen = observer(function GraphScreen() {
const sanitizeGraph = (data, nodeIds: string[]) => {
const cleanLinks = [];
data.links.forEach((link) => {
- let target;
- let source;
+ let target;
+ let source;
for (let i = 0; i < nodeIds.length; i++) {
- let a = data.nodes[i];
- !a.neighbors && (a.neighbors = []);
- !a.links && (a.links = []);
- if (link.target === nodeIds[i]) {
- //let a = data.nodes[i];
- //!a.neighbors && (a.neighbors = []);
- //a.neighbors.push(a);
- a.links.push(link);
- target=[a, i];
+ let a = data.nodes[i];
+ !a.neighbors && (a.neighbors = []);
+ !a.links && (a.links = []);
+ if (link.target === nodeIds[i]) {
+ //let a = data.nodes[i];
+ //!a.neighbors && (a.neighbors = []);
+ //a.neighbors.push(a);
+ a.links.push(link);
+ target = [a, i];
cleanLinks.push(link);
- } else if (link.source === nodeIds[i]) {
- //let a = data.nodes[i];
- //!a.neighbors && (a.neighbors = []);
- //a.neighbors.push(a);
- a.links.push(link);
- source=[a, i];
- };
+ } else if (link.source === nodeIds[i]) {
+ //let a = data.nodes[i];
+ //!a.neighbors && (a.neighbors = []);
+ //a.neighbors.push(a);
+ a.links.push(link);
+ source = [a, i];
+ };
};
- if (target && source) {
- data.nodes[target[1]].neighbors.push(source[0]);
- data.nodes[source[1]].neighbors.push(target[0]);
- }
+ if (target && source) {
+ data.nodes[target[1]].neighbors.push(source[0]);
+ data.nodes[source[1]].neighbors.push(target[0]);
+ }
});
console.log(cleanLinks);
data.links = cleanLinks;