-
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
5 changed files
with
215 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,60 @@ | ||
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 { Graph } from '../../graph'; | ||
import { useRerender } from './hooks'; | ||
|
||
const ConnectionVariants: RadioButtonOption[] = [ | ||
{ value: 'bezier', content: 'Bezier' }, | ||
{ value: 'line', content: 'Line' }, | ||
]; | ||
|
||
const ConnectionArrowsVariants: RadioButtonOption[] = [ | ||
{ value: 'bezier', content: 'Show' }, | ||
{ value: 'line', content: 'Hide' }, | ||
]; | ||
|
||
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> | ||
</> | ||
} |
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,39 @@ | ||
import React from "react"; | ||
import { Flex, Tooltip, Button, Icon } from "@gravity-ui/uikit"; | ||
import { MagnifierPlus, MagnifierMinus, SquareDashed, Gear } from '@gravity-ui/icons'; | ||
import { Graph } from "../../graph"; | ||
import { useRerender } from './hooks'; | ||
|
||
export function Toolbox({className, graph}: {className: string, graph: Graph}) { | ||
const rerender = useRerender(); | ||
return <Flex grow={1} justifyContent="center" className={className} direction="column"> | ||
<Tooltip content="Zoom +" placement="right"> | ||
<Button | ||
onClick={() => { | ||
graph.zoom({ scale: graph.cameraService.getCameraScale() + 0.08 }); | ||
rerender(); | ||
}} | ||
disabled={graph.cameraService.getCameraScale() >= 1} | ||
> | ||
<Icon data={MagnifierPlus} /> | ||
</Button> | ||
</Tooltip> | ||
<Tooltip content="Fit to viewport" placement="right"> | ||
<Button onClick={() => { | ||
graph.zoomTo('center'); | ||
rerender(); | ||
}}> | ||
<Icon data={SquareDashed} /> | ||
</Button> | ||
</Tooltip> | ||
<Tooltip content="Zoom -" placement="right"> | ||
<Button onClick={() => { | ||
graph.zoom({ scale: graph.cameraService.getCameraScale() - 0.08 }); | ||
rerender(); | ||
}} | ||
disabled={graph.cameraService.getCameraScale() <= 0.01}> | ||
<Icon data={MagnifierMinus} /> | ||
</Button> | ||
</Tooltip> | ||
</Flex> | ||
} |
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,9 @@ | ||
import { useState } from "react"; | ||
import { useFn } from "../../utils/hooks/useFn"; | ||
|
||
export function useRerender() { | ||
const [tick, setTick] = useState(Date.now()); | ||
return useFn(() => { | ||
setTick(Date.now()); | ||
}) | ||
} |