-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
191 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Gear } from '@gravity-ui/icons'; | ||
import { Button, Flex, Icon, Popup, RadioButton, RadioButtonOption, Text } from "@gravity-ui/uikit"; | ||
import React, { useRef, useState } from "react"; | ||
import { useFn } from "../../utils/hooks/useFn"; | ||
import { Graph } from '../../graph'; | ||
|
||
const ConnectionVariants: RadioButtonOption[] = [ | ||
{ value: 'bezier', content: 'Bezier' }, | ||
{ value: 'line', content: 'Line' }, | ||
]; | ||
|
||
const ConnectionArrowsVariants: RadioButtonOption[] = [ | ||
{ value: 'bezier', content: 'Show' }, | ||
{ value: 'line', content: 'Hide' }, | ||
]; | ||
|
||
function useRerender() { | ||
const [tick, setTick] = useState(Date.now()); | ||
return useFn(() => { | ||
setTick(Date.now()); | ||
}) | ||
} | ||
|
||
export function GraphSettings({graph}: {graph: Graph}) { | ||
|
||
const rerender = useRerender(); | ||
const settingBtnRef = useRef(); | ||
const [settingsOpened, setSettingsOpened] = useState(false); | ||
return <> | ||
<Button ref={settingBtnRef} onClick={() => setSettingsOpened((prevOpen) => !prevOpen)}> | ||
<Icon data={Gear} /> | ||
</Button> | ||
<Popup anchorRef={settingBtnRef} open={settingsOpened} onClose={() => setSettingsOpened(false)} placement={["right-end"]}> | ||
<Flex direction="column" className="settings-popup" gap={3}> | ||
<Text variant="subheader-2">Graph settings</Text> | ||
<Flex direction="column" gap={2}> | ||
<Text variant="subheader-1">Connection type</Text> | ||
<RadioButton | ||
size="l" | ||
onUpdate={(value) => { | ||
graph.updateSettings({ | ||
useBezierConnections: value === ConnectionVariants[0].value | ||
}); | ||
rerender(); | ||
}} | ||
value={ConnectionVariants[graph.rootStore.settings.getConfigFlag('useBezierConnections') ? 0 : 1].value} | ||
options={ConnectionVariants} | ||
/> | ||
</Flex> | ||
<Flex direction="column" gap={2}> | ||
<Text variant="subheader-2">Show arrows</Text> | ||
<RadioButton | ||
size="l" | ||
onUpdate={(value) => { | ||
graph.updateSettings({ | ||
showConnectionArrows: value === ConnectionArrowsVariants[0].value | ||
}); | ||
rerender(); | ||
}} | ||
value={ConnectionArrowsVariants[graph.rootStore.settings.getConfigFlag('showConnectionArrows') ? 0 : 1].value} | ||
options={ConnectionArrowsVariants} | ||
/> | ||
</Flex> | ||
</Flex> | ||
</Popup> | ||
</> | ||
} |