From 7aa007f158a52b41494049a1202938fc97813ec1 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Fri, 23 Jul 2021 15:20:02 +0200 Subject: added theme tracking --- pages/index.tsx | 498 +++++++++++++++++++++++++++----------------------------- 1 file changed, 242 insertions(+), 256 deletions(-) (limited to 'pages/index.tsx') diff --git a/pages/index.tsx b/pages/index.tsx index 3200bb9..5dfce8d 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -10,6 +10,7 @@ import { OrgRoamGraphReponse, OrgRoamLink, OrgRoamNode } from '../api' import { GraphData, NodeObject } from 'force-graph' import { useWindowSize } from '@react-hook/window-size' +import { Scrollbars } from 'react-custom-scrollbars-2' import { Accordion, @@ -44,6 +45,7 @@ import { MenuOptionGroup, MenuItemOption, Flex, + useTheme, } from '@chakra-ui/react' import { InfoOutlineIcon, RepeatClockIcon, ChevronDownIcon, SettingsIcon } from '@chakra-ui/icons' @@ -97,33 +99,6 @@ const initialPhysics = { highlightLinkSize: 2, } -const initialTheme = { - base1: '#1c1f24', - base2: '#21272d', - base3: '#23272e', - base4: '#484854', - base5: '#62686E', - base6: '#757B80', - base7: '#9ca0a4', - base8: '#DFDFDF', - bg: '#242730', - 'bg-alt': '#2a2e38', - blue: '#51afef', - cyan: '#5cEfFF', - 'dark-blue': '#1f5582', - 'dark-cyan': '#6A8FBF', - fg: '#bbc2cf', - 'fg-alt': '#5D656B', - green: '#7bc275', - grey: '#484854', - magenta: '#C57BDB', - orange: '#e69055', - red: '#ff665c', - teal: '#4db5bd', - violet: '#a991f1', - yellow: '#FCCE7B', -} - export default function Home() { // only render on the client const [showPage, setShowPage] = useState(false) @@ -140,7 +115,7 @@ export default function Home() { export function GraphPage() { const [physics, setPhysics] = usePersistantState('physics', initialPhysics) - const [theme, setTheme] = useState(initialTheme) + // const [theme, setTheme] = useState(initialTheme) const [graphData, setGraphData] = useState(null) const [emacsNodeId, setEmacsNodeId] = useState(null) @@ -154,11 +129,11 @@ export function GraphPage() { const emacsNodeId = e.data setEmacsNodeId(emacsNodeId) }) - fetch('http://localhost:35901/theme') - .then((res) => res.json()) - .then((emacsTheme) => { - setTheme(emacsTheme) - }) + /* fetch('http://localhost:35901/theme') + * .then((res) => res.json()) + * .then((emacsTheme) => { + * setTheme(emacsTheme) + * }) */ fetch('http://localhost:35901/graph') .then((res) => res.json()) .then((orgRoamGraphData: OrgRoamGraphReponse) => { @@ -256,7 +231,14 @@ export const SliderWithInfo = ({ {label} {infoText && } - + @@ -285,13 +267,22 @@ export const EnableSection = (props: EnableSectionProps) => { {label} {infoText && } - + {value && children} ) } +/* style={{ + * position: "absolute", + * zIndex: 2000, + * width: 400, + * maxHeight: "70%", + * background: "alt.100", + * marginTop: "2%", + * marginLeft: "2%" + * }} */ export interface TweakProps { physics: typeof initialPhysics setPhysics: any @@ -304,13 +295,14 @@ export const Tweaks = function (props: TweakProps) { @@ -318,224 +310,228 @@ export const Tweaks = function (props: TweakProps) { aria-label="Reset Defaults" icon={} onClick={() => setPhysics(initialPhysics)} + colorScheme="purple" /> - - - - - - Physics - - setPhysics({ ...physics, enabled: !physics.enabled })} - isChecked={physics.enabled} - /> - - - } - align="stretch" - > - setPhysics({ ...physics, gravityOn: !physics.gravityOn })} - > - setPhysics({ ...physics, gravity: v / 10 })} - /> - - setPhysics({ ...physics, charge: -100 * value })} - label="Repulsive Force" + + + + + + + Physics + + setPhysics({ ...physics, enabled: !physics.enabled })} + isChecked={physics.enabled} + colorScheme="purple" /> - setPhysics({ ...physics, collision: !physics.collision })} + + + } + align="stretch" > + setPhysics({ ...physics, gravityOn: !physics.gravityOn })} + > + setPhysics({ ...physics, gravity: v / 10 })} + /> + setPhysics({ ...physics, collisionStrength: value / 10 })} - label="Strength" + value={-physics.charge / 100} + onChange={(value) => setPhysics({ ...physics, charge: -100 * value })} + label="Repulsive Force" /> - - setPhysics({ ...physics, linkStrength: value / 5 })} - label="Link Force" - /> - setPhysics({ ...physics, linkIts: value })} - min={0} - max={6} - step={1} - infoText="How many links down the line the physics of a single node affects (Slow)" - /> - setPhysics({ ...physics, velocityDecay: value / 10 })} - /> - - - - - - Advanced - - - - } - align="stretch" - > - setPhysics({ ...physics, iterations: v })} - infoText="Number of times the physics simulation iterates per simulation step" - /> - setPhysics({ ...physics, alphaDecay: value / 50 })} - /> - - - - - - {/* */} - - - - - - Visual - - - } - align="stretch" - > - setPhysics({ ...physics, nodeRel: value })} - /> - setPhysics({ ...physics, linkWidth: value })} - /> - setPhysics({ ...physics, labels: !physics.labels })} - > + setPhysics({ ...physics, collision: !physics.collision })} + > + setPhysics({ ...physics, collisionStrength: value / 10 })} + label="Strength" + /> + setPhysics({ ...physics, labelScale: value / 5 })} + value={physics.linkStrength * 5} + onChange={(value) => setPhysics({ ...physics, linkStrength: value / 5 })} + label="Link Force" /> - - setPhysics({ ...physics, particles: !physics.particles })} - > setPhysics({ ...physics, linkIts: value })} + min={0} + max={6} step={1} - onChange={(value) => setPhysics({ ...physics, particlesNumber: value })} + infoText="How many links down the line the physics of a single node affects (Slow)" /> setPhysics({ ...physics, particleWidth: value })} + label="Viscosity" + value={physics.velocityDecay * 10} + onChange={(value) => setPhysics({ ...physics, velocityDecay: value / 10 })} /> - - setPhysics({ ...physics, highlight: !physics.highlight })} - value={physics.highlight} + + + + + + Advanced + + + + } + align="stretch" + > + setPhysics({ ...physics, iterations: v })} + infoText="Number of times the physics simulation iterates per simulation step" + /> + setPhysics({ ...physics, alphaDecay: value / 50 })} + /> + + + + + + {/* */} + + + + + + Visual + + + } + align="stretch" > setPhysics({ ...physics, highlightLinkSize: value })} + label="Node size" + value={physics.nodeRel} + onChange={(value) => setPhysics({ ...physics, nodeRel: value })} /> setPhysics({ ...physics, highlightNodeSize: value })} + label="Link width" + value={physics.linkWidth} + onChange={(value) => setPhysics({ ...physics, linkWidth: value })} /> - - Highlight node color - - - Highlight link color - - - - - - - - - Behavior - - - } - align="stretch" - > - - Hover Higlight - - }> - {physics.hover} - - - Off - On - - - - - Click - - - Double-click - - - - - + setPhysics({ ...physics, labels: !physics.labels })} + > + setPhysics({ ...physics, labelScale: value / 5 })} + /> + + setPhysics({ ...physics, particles: !physics.particles })} + > + setPhysics({ ...physics, particlesNumber: value })} + /> + setPhysics({ ...physics, particleWidth: value })} + /> + + setPhysics({ ...physics, highlight: !physics.highlight })} + value={physics.highlight} + > + setPhysics({ ...physics, highlightLinkSize: value })} + /> + setPhysics({ ...physics, highlightNodeSize: value })} + /> + + Highlight node color + + + Highlight link color + + + + + + + + + Behavior + + + } + align="stretch" + > + + Hover Higlight + + }> + {physics.hover} + + + Off + On + + + + + Click + + + Double-click + + + + + + ) } @@ -681,37 +677,27 @@ export const Graph = function (props: GraphProps) { return } + const theme = useTheme() + console.log(theme) const graphCommonProps: ComponentPropsWithoutRef = { graphData: scopedGraphData, width: windowWidth, height: windowHeight, - backgroundColor: '#242730', + backgroundColor: theme.white, nodeLabel: (node) => (node as OrgRoamNode).title, nodeColor: (node) => { if (!physics.colorful) { if (Object.keys(highlightedNodes).length === 0) { return 'rgb(100, 100, 100)' } - return highlightedNodes[node.id!] ? '#a991f1' : 'rgb(50, 50, 50)' + return highlightedNodes[node.id!] ? theme.blue['500'] : 'rgb(50, 50, 50)' } - const palette = [ - '#ff665c', - '#e69055', - '#7bc275', - '#4db5bd', - '#FCCE7B', - '#51afef', - '#1f5582', - '#C57BDB', - '#a991f1', - '#5cEfFF', - '#6A8FBF', - ] - - return palette[ - numbereWithinRange(linksByNodeId[node.id!]?.length ?? 0, 0, palette.length - 1) - ] + const palette = ['pink', 'purple', 'blue', 'cyan', 'teal', 'green', 'yellow', 'orange', 'red'] + + return theme.colors[ + palette[numbereWithinRange(linksByNodeId[node.id!]?.length ?? 0, 0, palette.length - 1)] + ][500] }, nodeRelSize: physics.nodeRel, nodeVal: (node) => { @@ -778,7 +764,7 @@ export const Graph = function (props: GraphProps) { (link.source as NodeObject).id! === centralHighlightedNode?.id! || (link.target as NodeObject).id! === centralHighlightedNode?.id! - return linkIsHighlighted ? '#a991f1' : '#666666' + return linkIsHighlighted ? theme.colors.purple[500] : theme.colors.gray[400] }, linkWidth: (link) => { return physics.linkWidth -- cgit v1.2.3