Unverified Commit 67bd6278 authored by gaoyan's avatar gaoyan Committed by GitHub

[Feature][Web]add dag select drawer (#2351)

* add dag select drawer * add dag select drawer
parent 20272b32
...@@ -166,3 +166,12 @@ export const layoutConfig: DagreLayoutOptions = { ...@@ -166,3 +166,12 @@ export const layoutConfig: DagreLayoutOptions = {
nodesep: 40, nodesep: 40,
controlPoints: true controlPoints: true
}; };
export const zoomOptions = {
padding: {
left: 50,
right: 50,
top: 50,
bottom: 50
}
};
...@@ -19,16 +19,22 @@ ...@@ -19,16 +19,22 @@
import DagDataNode from '@/components/FlinkDag/component/DagDataNode'; import DagDataNode from '@/components/FlinkDag/component/DagDataNode';
import DagPlanNode from '@/components/FlinkDag/component/DagPlanNode'; import DagPlanNode from '@/components/FlinkDag/component/DagPlanNode';
import {edgeConfig, graphConfig, layoutConfig, portConfig} from '@/components/FlinkDag/config'; import {
import {buildDag, regConnect, updateDag} from '@/components/FlinkDag/functions'; edgeConfig,
import {Jobs} from '@/types/DevOps/data'; graphConfig,
import {DagreLayout} from '@antv/layout'; layoutConfig,
import {Edge, Graph} from '@antv/x6'; portConfig,
import {register} from '@antv/x6-react-shape'; zoomOptions
import {useEffect, useRef, useState} from 'react'; } from '@/components/FlinkDag/config';
import { buildDag, regConnect, updateDag } from '@/components/FlinkDag/functions';
import { Jobs } from '@/types/DevOps/data';
import { DagreLayout } from '@antv/layout';
import { Edge, Graph } from '@antv/x6';
import { Selection } from '@antv/x6-plugin-selection';
import { register } from '@antv/x6-react-shape';
import { Drawer } from 'antd';
import { useEffect, useRef, useState } from 'react';
import './index.css'; import './index.css';
import {Slider} from "antd";
import {z} from "@umijs/utils/compiled/zod";
export type DagProps = { export type DagProps = {
job: Jobs.Job; job: Jobs.Job;
...@@ -38,17 +44,33 @@ export type DagProps = { ...@@ -38,17 +44,33 @@ export type DagProps = {
const FlinkDag = (props: DagProps) => { const FlinkDag = (props: DagProps) => {
const container = useRef(null); const container = useRef(null);
const {job, onlyPlan = false} = props; const { job, onlyPlan = false } = props;
const [graph, setGraph] = useState<Graph>(); const [graph, setGraph] = useState<Graph>();
const [zoom, setZoom] = useState<number>(1); const [curentJob, setCurentJob] = useState<string>();
const [currentJob, setCurrentJob] = useState<string>(); const [curentSelect, setCurentSelect] = useState<any>();
const [open, setOpen] = useState(false);
const initListen = (graph: Graph) => {
graph.on('node:selected', ({ cell }) => {
setOpen(true);
setCurentSelect(cell);
graph.positionCell(cell, 'center');
});
graph.on('node:unselected', ({ cell }) => {
setOpen(false);
setCurentSelect(undefined);
graph.zoomToFit(zoomOptions);
graph.centerContent();
});
};
const initGraph = (flinkData: any) => { const initGraph = (flinkData: any) => {
register({ register({
shape: 'data-processing-dag-node', shape: 'data-processing-dag-node',
width: 212, width: 250,
height: 48, height: 140,
component: onlyPlan ? DagPlanNode : DagDataNode, component: onlyPlan ? DagPlanNode : DagDataNode,
ports: portConfig ports: portConfig
}); });
...@@ -63,23 +85,24 @@ const FlinkDag = (props: DagProps) => { ...@@ -63,23 +85,24 @@ const FlinkDag = (props: DagProps) => {
...graphConfig ...graphConfig
}); });
graph.use(
new Selection({
enabled: true,
multiple: false,
rubberband: false,
showNodeSelectionBox: true
})
);
// Adaptive layout // Adaptive layout
const dagreLayout = new DagreLayout(layoutConfig); const model = new DagreLayout(layoutConfig).layout(flinkData);
const model = dagreLayout.layout(flinkData);
graph.fromJSON(model); graph.fromJSON(model);
// Automatically zoom to fit // Automatically zoom to fit
const zoomOptions = {
padding: {
left: 50,
right: 50,
bottom: 100
},
};
graph.zoomToFit(zoomOptions); graph.zoomToFit(zoomOptions);
graph.centerContent(); graph.centerContent();
graph.on('scale', ({ sx }) => setZoom(sx))
updateDag(job.vertices, graph); updateDag(job.vertices, graph);
initListen(graph);
return graph; return graph;
}; };
...@@ -90,23 +113,17 @@ const FlinkDag = (props: DagProps) => { ...@@ -90,23 +113,17 @@ const FlinkDag = (props: DagProps) => {
graph.clearCells(); graph.clearCells();
} }
setGraph(initGraph(flinkData)); setGraph(initGraph(flinkData));
}, [currentJob]); }, [curentJob]);
useEffect(() => {
graph?.zoomTo(zoom)
}, [zoom]);
useEffect(() => { useEffect(() => {
updateDag(job.vertices, graph); updateDag(job.vertices, graph);
if (currentJob != job.jid) { if (curentJob != job.jid) {
setCurrentJob(job.jid); setCurentJob(job.jid);
} }
}, [job]); }, [job]);
return ( return (
<span> <>
<div style={{height: 200, position: "absolute", top: "50%", right: 12, marginTop: -100,zIndex:999999999}}>
<Slider vertical value={zoom} min={0.5} max={1.5} tooltip={{open:false}} step={0.01} onChange={setZoom}/>
</div>
<div <div
style={{ style={{
height: '100%', height: '100%',
...@@ -114,7 +131,16 @@ const FlinkDag = (props: DagProps) => { ...@@ -114,7 +131,16 @@ const FlinkDag = (props: DagProps) => {
}} }}
ref={container} ref={container}
/> />
</span> <Drawer
title={curentSelect?.name}
open={open}
getContainer={false}
size={'large'}
mask={false}
>
<p>{curentSelect?.getData().description}</p>
</Drawer>
</>
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment