Skip to content

Commit

Permalink
Quality of life updates for new lineage graph display.
Browse files Browse the repository at this point in the history
  • Loading branch information
phix committed Feb 19, 2024
1 parent 32ae5cb commit 7adaeb3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
6 changes: 3 additions & 3 deletions web/libs/graph/src/components/ZoomPanSvg/ZoomPanSvg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface ZoomPanControls {
centerOnExtent(extent: Extent): void
scaleZoom(kDelta?: number): void
resetZoom(): void
centerOnPositionedNode(nodeId: string): void
centerOnPositionedNode(nodeId: string, k?: number): void
}

interface Props extends BoxProps {
Expand Down Expand Up @@ -232,12 +232,12 @@ export const ZoomPanSvg = ({
animateToZoomState(zoomIdentity)
}

const centerOnPositionedNode = (nodeId: string) => {
const centerOnPositionedNode = (nodeId: string, k = currentZoomState.k) => {
const node = positionedNodes.find((node) => node.id === nodeId)
if (!node) return

const extent = getNodeExtent(node)
centerOnExtent(extent)
centerOnExtent(extent, k)
}

const fitContent = () => {
Expand Down
16 changes: 14 additions & 2 deletions web/src/routes/column-level/ZoomControls.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CropFree, ZoomIn, ZoomOut } from '@mui/icons-material'
import { CenterFocusStrong, CropFree, ZoomIn, ZoomOut } from '@mui/icons-material'
import { Tooltip } from '@mui/material'
import { theme } from '../../helpers/theme'
import Box from '@mui/material/Box'
Expand All @@ -8,9 +8,14 @@ import React from 'react'
interface ZoomControlsProps {
handleScaleZoom: (inOrOut: 'in' | 'out') => void
handleResetZoom: () => void
handleCenterOnNode?: () => void
}

export const ZoomControls = ({ handleScaleZoom, handleResetZoom }: ZoomControlsProps) => {
export const ZoomControls = ({
handleScaleZoom,
handleResetZoom,
handleCenterOnNode,
}: ZoomControlsProps) => {
return (
<Box
display={'flex'}
Expand Down Expand Up @@ -38,6 +43,13 @@ export const ZoomControls = ({ handleScaleZoom, handleResetZoom }: ZoomControlsP
<CropFree />
</IconButton>
</Tooltip>
{handleCenterOnNode && (
<Tooltip title={'Center on selected node'} placement={'left'}>
<IconButton size={'small'} onClick={handleCenterOnNode}>
<CenterFocusStrong />
</IconButton>
</Tooltip>
)}
</Box>
)
}
7 changes: 6 additions & 1 deletion web/src/routes/table-level/ActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ export const ActionBar = ({
control={
<Switch
size={'small'}
defaultChecked
value={isFull}
defaultChecked={searchParams.get('isFull') === 'true'}
onChange={(_, checked) => {
setIsFull(checked)
searchParams.set('isFull', checked.toString())
setSearchParams(searchParams)
}}
/>
}
Expand All @@ -123,8 +125,11 @@ export const ActionBar = ({
<Switch
size={'small'}
value={isCompact}
defaultChecked={searchParams.get('isCompact') === 'true'}
onChange={(_, checked) => {
setIsCompact(checked)
searchParams.set('isCompact', checked.toString())
setSearchParams(searchParams)
}}
/>
}
Expand Down
19 changes: 15 additions & 4 deletions web/src/routes/table-level/TableLevel.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Redux from 'redux'
import { ActionBar } from './ActionBar'
import { Box } from '@mui/system'
import { DEFAULT_MAX_SCALE, Graph, ZoomPanControls } from '../../../libs/graph'
import { Drawer } from '@mui/material'
import { Graph, ZoomPanControls } from '../../../libs/graph'
import { IState } from '../../store/reducers'
import { JobOrDataset } from '../../components/lineage/types'
import { LineageGraph } from '../../types/api'
Expand Down Expand Up @@ -41,8 +41,8 @@ const ColumnLevel: React.FC<ColumnLevelProps> = ({

const [depth, setDepth] = useState(Number(searchParams.get('depth')) || 2)

const [isCompact, setIsCompact] = useState(false)
const [isFull, setIsFull] = useState(true)
const [isCompact, setIsCompact] = useState(searchParams.get('isCompact') === 'true')
const [isFull, setIsFull] = useState(searchParams.get('isFull') === 'true')

const graphControls = useRef<ZoomPanControls>()

Expand All @@ -64,6 +64,13 @@ const ColumnLevel: React.FC<ColumnLevelProps> = ({
graphControls.current?.fitContent()
}

const handleCenterOnNode = () => {
graphControls.current?.centerOnPositionedNode(
`${nodeType}:${namespace}:${name}`,
DEFAULT_MAX_SCALE
)
}

const setGraphControls = useCallbackRef((zoomControls) => {
graphControls.current = zoomControls
})
Expand Down Expand Up @@ -103,7 +110,11 @@ const ColumnLevel: React.FC<ColumnLevelProps> = ({
<TableLevelDrawer />
</Box>
</Drawer>
<ZoomControls handleScaleZoom={handleScaleZoom} handleResetZoom={handleResetZoom} />
<ZoomControls
handleCenterOnNode={handleCenterOnNode}
handleScaleZoom={handleScaleZoom}
handleResetZoom={handleResetZoom}
/>
<ParentSize>
{(parent) => (
<Graph<JobOrDataset, TableLevelNodeData>
Expand Down

0 comments on commit 7adaeb3

Please sign in to comment.