From 5b750a8bc321a40f26ce18c8d3d8fb8f4106359a Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Sun, 8 Aug 2021 23:48:37 +0200 Subject: feat: much smoother local mode --- components/config.ts | 6 +- components/tweaks.tsx | 193 +++++++++++++++++++++++++++----------------------- 2 files changed, 107 insertions(+), 92 deletions(-) (limited to 'components') diff --git a/components/config.ts b/components/config.ts index 2636b73..b48cbe4 100644 --- a/components/config.ts +++ b/components/config.ts @@ -20,15 +20,16 @@ export const initialPhysics = { collision: true, collisionStrength: 20, centering: true, - centeringStrength: 0.05, + centeringStrength: 0.2, linkStrength: 0.3, linkIts: 1, - alphaDecay: 0.1, + alphaDecay: 0.05, alphaTarget: 0, alphaMin: 0, velocityDecay: 0.25, gravity: 0.3, gravityOn: true, + gravityLocal: false, } export const initialFilter = { @@ -117,6 +118,7 @@ export const initialMouse = { highlight: 'hover', local: 'click', follow: 'double', + context: 'right', } export const colorList = [ diff --git a/components/tweaks.tsx b/components/tweaks.tsx index cc8b81e..26f1b60 100644 --- a/components/tweaks.tsx +++ b/components/tweaks.tsx @@ -45,7 +45,7 @@ import { } from '@chakra-ui/react' import { CUIAutoComplete } from 'chakra-ui-autocomplete' -import React, { useState, useContext, useEffect } from 'react' +import React, { useState, useContext, useEffect, useCallback } from 'react' import Scrollbars from 'react-custom-scrollbars-2' import { initialPhysics, @@ -58,6 +58,7 @@ import { } from './config' import { ThemeContext } from '../util/themecontext' +import { usePersistantState } from '../util/persistant-state' export interface TweakProps { physics: typeof initialPhysics @@ -95,9 +96,16 @@ export const Tweaks = (props: TweakProps) => { tagColors, setTagColors, } = props - const [showTweaks, setShowTweaks] = useState(true) + const [showTweaks, setShowTweaks] = usePersistantState('showTweaks', false) const { highlightColor, setHighlightColor } = useContext(ThemeContext) + const setVisualsCallback = useCallback((val) => setVisuals(val), []) + const setPhysicsCallback = useCallback((val: number, phys: string, scale: number) => { + setPhysics((curr: typeof initialPhysics) => { + return { ...curr, [phys]: val / scale } + }) + }, []) + return !showTweaks ? ( { position="relative" boxShadow="xl" maxH={0.92 * globalThis.innerHeight} + marginBottom={10} > { Orphans { - setFilter({ ...filter, orphans: !filter.orphans }) + setFilter((curr: typeof initialFilter) => { + return { ...curr, orphans: !curr.orphans } + }) }} isChecked={filter.orphans} > @@ -298,15 +309,26 @@ export const Tweaks = (props: TweakProps) => { value={physics.gravityOn} onChange={() => setPhysics({ ...physics, gravityOn: !physics.gravityOn })} > + + Also in local + { + setPhysics((curr: typeof initialPhysics) => { + return { ...curr, gravityLocal: !curr.gravityLocal } + }) + }} + isChecked={physics.gravityLocal} + > + setPhysics({ ...physics, gravity: v / 10 })} + onChange={(v: number) => setPhysicsCallback(v, 'gravity', 10)} /> setPhysics({ ...physics, charge: -100 * value })} + onChange={(v) => setPhysicsCallback(v, 'gravity', -1 / 100)} label="Repulsive Force" /> { > setPhysics({ ...physics, collisionStrength: value * 5 })} + onChange={(v) => setPhysicsCallback(v, 'collisionStrength', 1 / 5)} label="Collision Radius" infoText="Easy with this one, high values can lead to a real jiggly mess" /> setPhysics({ ...physics, linkStrength: value / 5 })} + onChange={(v) => setPhysicsCallback(v, 'linkStrength', 5)} label="Link Force" /> setPhysics({ ...physics, linkIts: value })} + onChange={(v) => setPhysicsCallback(v, 'linkIts', 1)} min={0} max={6} step={1} @@ -339,7 +361,7 @@ export const Tweaks = (props: TweakProps) => { setPhysics({ ...physics, velocityDecay: value / 10 })} + onChange={(v) => setPhysicsCallback(v, 'velocityDecay', 10)} /> @@ -361,7 +383,7 @@ export const Tweaks = (props: TweakProps) => { setPhysics({ ...physics, alphaDecay: value / 50 })} + onChange={(v) => setPhysicsCallback(v, 'alphaDecay', 50)} /> { value={physics.centeringStrength} max={2} step={0.01} - onChange={(v) => setPhysics({ ...physics, centeringStrength: v })} + onChange={(v) => setPhysicsCallback(v, 'centeringStrength', 1)} /> @@ -445,7 +467,7 @@ export const Tweaks = (props: TweakProps) => { }} /> - + { Links - + { Accent - + { @@ -744,24 +762,21 @@ export const Tweaks = (props: TweakProps) => { @@ -785,31 +800,28 @@ export const Tweaks = (props: TweakProps) => { Labels - + { {!visuals.labels ? 'Never' : visuals.labels < 2 - ? 'On Highlight' - : 'Always'} + ? 'On Highlight' + : 'Always'} {' '} @@ -869,16 +881,14 @@ export const Tweaks = (props: TweakProps) => { @@ -932,8 +942,8 @@ export const Tweaks = (props: TweakProps) => { @@ -1045,7 +1055,7 @@ export const Tweaks = (props: TweakProps) => { Expand Node - + } @@ -1077,7 +1087,7 @@ export const Tweaks = (props: TweakProps) => { Open in Emacs - + } @@ -1111,7 +1121,7 @@ export const Tweaks = (props: TweakProps) => { Follow Emacs by... - + } @@ -1136,37 +1146,35 @@ export const Tweaks = (props: TweakProps) => { - {/* - - Follow local graph - - - - } - colorScheme="" - color="black" + + + Local graph + + + + } + colorScheme="" + color="black" + > + {behavior.localSame === 'add' ? 'Add' : 'Replace'} + + + {' '} + + setBehavior({ ...behavior, localSame: 'replace' })} > - {behavior.localSame === 'add' ? 'Add' : 'New'} - - - {' '} - - setBehavior({ ...behavior, localSame: 'new' })} - > - Open that nodes graph - - setBehavior({ ...behavior, localSame: 'add' })} - > - Add node to local graph - - - - - */} + Open that nodes graph + + setBehavior({ ...behavior, localSame: 'add' })}> + Add node to local graph + + + + + + {label} {infoText && } @@ -1253,7 +1261,7 @@ export interface EnableSectionProps { export const EnableSection = (props: EnableSectionProps) => { const { value, onChange, label, infoText, children } = props return ( - + {label} @@ -1279,7 +1287,7 @@ export interface DropDownMenuProps { export const DropDownMenu = (props: DropDownMenuProps) => { const { textArray, onClickArray, displayValue } = props return ( - + }> {displayValue} @@ -1287,7 +1295,7 @@ export const DropDownMenu = (props: DropDownMenuProps) => { {' '} {textArray.map((option, i) => { - ; {option} + ; {option} })} @@ -1299,17 +1307,27 @@ export interface ColorMenuProps { label: string colorList: string[] value: string - visuals: typeof initialVisuals visValue: string setVisuals?: any } export const ColorMenu = (props: ColorMenuProps) => { - const { label, colorList, value, visuals, visValue, setVisuals } = props + const { label, colorList, value, visValue, setVisuals } = props + + const clickCallback = useCallback( + (color) => + setVisuals((curr: typeof initialVisuals) => { + return { + ...curr, + [value]: color, + } + }), + [], + ) return ( {label} - + }> {} @@ -1317,7 +1335,7 @@ export const ColorMenu = (props: ColorMenuProps) => { {' '} setVisuals({ ...visuals, [value]: '' })} + onClick={() => clickCallback('')} justifyContent="space-between" alignItems="center" display="flex" @@ -1327,12 +1345,7 @@ export const ColorMenu = (props: ColorMenuProps) => { {colorList.map((color: string) => ( - setVisuals({ - ...visuals, - [value]: color, - }) - } + onClick={() => clickCallback(color)} justifyContent="space-between" alignItems="center" display="flex" -- cgit v1.2.3