diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-10-17 01:28:40 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2021-10-17 01:28:40 +0200 |
commit | 6ed792c982991b679d1c50060f4ca25b2eb1b9ca (patch) | |
tree | c1f4e920c0cfa2e9a2dfa1605d242e25cd28bfdd /components | |
parent | ca2fa3dc8d405d0ec451f16b9fcc72cde6bbf470 (diff) | |
parent | d1f02171bd4727fb0c09657d6fe0f21f5cde9617 (diff) |
Merge pull request #120 from org-roam/feat/community-detection
Feat/community detection
Diffstat (limited to 'components')
-rw-r--r-- | components/Tweaks/GraphColorSelect.tsx | 64 | ||||
-rw-r--r-- | components/Tweaks/ThemeSelect.tsx | 8 | ||||
-rw-r--r-- | components/Tweaks/VisualsPanel.tsx | 16 | ||||
-rw-r--r-- | components/Tweaks/index.tsx | 12 | ||||
-rw-r--r-- | components/config.ts | 3 |
5 files changed, 100 insertions, 3 deletions
diff --git a/components/Tweaks/GraphColorSelect.tsx b/components/Tweaks/GraphColorSelect.tsx new file mode 100644 index 0000000..60fd8cf --- /dev/null +++ b/components/Tweaks/GraphColorSelect.tsx @@ -0,0 +1,64 @@ +import React, { useContext } from 'react' +import { + Box, + Button, + Flex, + Menu, + MenuButton, + MenuItem, + MenuList, + Portal, + Text, +} from '@chakra-ui/react' +import { ChevronDownIcon } from '@chakra-ui/icons' +import { initialColoring } from '../config' + +export interface GraphColorSelectProps { + coloring: typeof initialColoring + setColoring: any +} + +export const GraphColorSelect = (props: GraphColorSelectProps) => { + type Theme = { [key: string]: string } + const { coloring, setColoring } = props + return ( + <Flex alignItems="center" justifyContent="space-between" pl={7} pr={2}> + <Text>Graph coloring</Text> + <Menu isLazy placement="right"> + <MenuButton + as={Button} + size="sm" + colorScheme="" + color="black" + rightIcon={<ChevronDownIcon />} + > + {coloring.method === 'degree' ? 'Links' : 'Communities'} + </MenuButton> + <Portal> + <MenuList minW={10} zIndex="popover" bgColor="gray.200"> + <MenuItem + onClick={() => + setColoring((curr: typeof initialColoring) => ({ ...curr, method: 'degree' })) + } + justifyContent="space-between" + alignItems="center" + display="flex" + > + Number of links + </MenuItem> + <MenuItem + onClick={() => + setColoring((curr: typeof initialColoring) => ({ ...curr, method: 'community' })) + } + justifyContent="space-between" + alignItems="center" + display="flex" + > + Communities + </MenuItem> + </MenuList> + </Portal> + </Menu> + </Flex> + ) +} diff --git a/components/Tweaks/ThemeSelect.tsx b/components/Tweaks/ThemeSelect.tsx index 6a6b5d8..d5a7f54 100644 --- a/components/Tweaks/ThemeSelect.tsx +++ b/components/Tweaks/ThemeSelect.tsx @@ -22,7 +22,13 @@ export const ThemeSelect = () => { <Flex alignItems="center" justifyContent="space-between" pl={7} pr={2}> <Text>Theme</Text> <Menu isLazy placement="bottom" closeOnSelect={false}> - <MenuButton as={Button} colorScheme="" color="black" rightIcon={<ChevronDownIcon />}> + <MenuButton + as={Button} + size="sm" + colorScheme="" + color="black" + rightIcon={<ChevronDownIcon />} + > {emacsTheme[0]} </MenuButton> <MenuList minW={10} zIndex="popover" bgColor="gray.200"> diff --git a/components/Tweaks/VisualsPanel.tsx b/components/Tweaks/VisualsPanel.tsx index 23ba41f..f364c4f 100644 --- a/components/Tweaks/VisualsPanel.tsx +++ b/components/Tweaks/VisualsPanel.tsx @@ -18,12 +18,13 @@ import { import React, { useCallback } from 'react' import { HighlightingPanel } from './HighlightingPanel' import { ColorsPanel } from './ColorsPanel' -import { initialVisuals } from '../config' +import { initialColoring, initialVisuals } from '../config' import { NodesNLinksPanel } from './NodesNLinksPanel' import { LabelsPanel } from './LabelsPanel' import { CitationsPanel } from './CitationsPanel' import { ColorMenu } from './ColorMenu' import { ThemeSelect } from './ThemeSelect' +import { GraphColorSelect } from './GraphColorSelect' export interface VisualsPanelProps { visuals: typeof initialVisuals @@ -31,14 +32,25 @@ export interface VisualsPanelProps { highlightColor: string setHighlightColor: any threeDim: boolean + coloring: typeof initialColoring + setColoring: any } export const VisualsPanel = (props: VisualsPanelProps) => { - const { visuals, setVisuals, highlightColor, setHighlightColor, threeDim } = props + const { + coloring, + setColoring, + visuals, + setVisuals, + highlightColor, + setHighlightColor, + threeDim, + } = props const setVisualsCallback = useCallback((val) => setVisuals(val), []) return ( <VStack justifyContent="flex-start" align="stretch"> <ThemeSelect /> + <GraphColorSelect {...{ coloring, setColoring }} /> <Accordion allowToggle defaultIndex={[0]} paddingLeft={3}> <AccordionItem> <AccordionButton> diff --git a/components/Tweaks/index.tsx b/components/Tweaks/index.tsx index cff0e78..a07559a 100644 --- a/components/Tweaks/index.tsx +++ b/components/Tweaks/index.tsx @@ -23,6 +23,7 @@ import { initialLocal, TagColors, colorList, + initialColoring, } from '../config' import FilterPanel from './FilterPanel' @@ -49,6 +50,8 @@ export interface TweakProps { tags: string[] tagColors: TagColors setTagColors: any + coloring: typeof initialColoring + setColoring: any local: typeof initialLocal setLocal: any } @@ -70,6 +73,8 @@ export const Tweaks = (props: TweakProps) => { tags, tagColors, setTagColors, + coloring, + setColoring, local, setLocal, } = props @@ -129,6 +134,9 @@ export const Tweaks = (props: TweakProps) => { setMouse(initialMouse) setPhysics(initialPhysics) setBehavior(initialBehavior) + setColoring(initialColoring) + setHighlightColor('purple.500') + setLocal(initialLocal) }} variant="subtle" size="sm" @@ -200,6 +208,10 @@ export const Tweaks = (props: TweakProps) => { highlightColor={highlightColor} setHighlightColor={setHighlightColor} threeDim={threeDim} + {...{ + coloring, + setColoring, + }} /> </AccordionPanel> </AccordionItem> diff --git a/components/config.ts b/components/config.ts index 32a4c21..d61e416 100644 --- a/components/config.ts +++ b/components/config.ts @@ -45,6 +45,9 @@ export const initialFilter = { date: [], noter: true, } +export const initialColoring = { + method: 'degree', +} export const initialVisuals = { particles: false, |