Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(console): make dag layout fitable #1326

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions console/src/components/DAG/DAG.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type TaskT = {
type: 'PPL' | 'CMP'
}

const CANVAS_DEFAULT_SIZE = 2000

export default function DAG({ nodes = [], edges = [] }: any) {
const ref = useRef<CanvasRef | null>(null)

Expand Down Expand Up @@ -122,6 +124,8 @@ export default function DAG({ nodes = [], edges = [] }: any) {
}
})

const [rect, setRect] = React.useState({ width: CANVAS_DEFAULT_SIZE, height: CANVAS_DEFAULT_SIZE })

return (
<div
className='flowContainer'
Expand All @@ -136,7 +140,7 @@ export default function DAG({ nodes = [], edges = [] }: any) {
<TransformWrapper wheel={{ disabled: true }} limitToBounds={false} maxScale={1.2} minScale={0.8}>
{({ zoomIn, zoomOut, resetTransform }) => (
<>
<div className='flow-tools'>
<div className='flow-tools' style={{ top: rect.height + 200 }}>
<button type='button' onClick={() => zoomIn()}>
+
</button>
Expand All @@ -151,11 +155,26 @@ export default function DAG({ nodes = [], edges = [] }: any) {
<Canvas
fit
ref={ref}
maxHeight={1000}
maxHeight={rect.height + 200}
maxWidth={rect.width}
zoomable={false}
nodes={$nodes}
edges={$edges}
direction='RIGHT'
defaultPosition={CanvasPosition.LEFT}
onLayoutChange={(layout) => {
if (
rect.width !== layout.width &&
rect.height !== layout.height &&
rect.width > 0 &&
rect.height > 0
) {
setRect({
width: layout.width ?? CANVAS_DEFAULT_SIZE,
height: layout.height ?? CANVAS_DEFAULT_SIZE,
})
}
}}
node={
<Node
className='node'
Expand Down