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,103 +19,129 @@ ...@@ -19,103 +19,129 @@
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;
onlyPlan?: boolean; onlyPlan?: boolean;
}; };
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 initGraph = (flinkData: any) => {
register({ const initListen = (graph: Graph) => {
shape: 'data-processing-dag-node', graph.on('node:selected', ({ cell }) => {
width: 212, setOpen(true);
height: 48, setCurentSelect(cell);
component: onlyPlan ? DagPlanNode : DagDataNode, graph.positionCell(cell, 'center');
ports: portConfig });
});
graph.on('node:unselected', ({ cell }) => {
Edge.config(edgeConfig); setOpen(false);
Graph.registerConnector('curveConnector', regConnect, true); setCurentSelect(undefined);
Graph.registerEdge('data-processing-curve', Edge, true); graph.zoomToFit(zoomOptions);
graph.centerContent();
const graph: Graph = new Graph({ });
// @ts-ignore };
container: container.current,
...graphConfig const initGraph = (flinkData: any) => {
}); register({
shape: 'data-processing-dag-node',
// Adaptive layout width: 250,
const dagreLayout = new DagreLayout(layoutConfig); height: 140,
const model = dagreLayout.layout(flinkData); component: onlyPlan ? DagPlanNode : DagDataNode,
graph.fromJSON(model); ports: portConfig
});
// Automatically zoom to fit
const zoomOptions = { Edge.config(edgeConfig);
padding: { Graph.registerConnector('curveConnector', regConnect, true);
left: 50, Graph.registerEdge('data-processing-curve', Edge, true);
right: 50,
bottom: 100 const graph: Graph = new Graph({
}, // @ts-ignore
}; container: container.current,
graph.zoomToFit(zoomOptions); ...graphConfig
graph.centerContent(); });
graph.on('scale', ({ sx }) => setZoom(sx))
updateDag(job.vertices, graph); graph.use(
return graph; new Selection({
}; enabled: true,
multiple: false,
useEffect(() => { rubberband: false,
const flinkData = buildDag(job.plan); showNodeSelectionBox: true
// Clean up old data })
if (graph) {
graph.clearCells();
}
setGraph(initGraph(flinkData));
}, [currentJob]);
useEffect(() => {
graph?.zoomTo(zoom)
}, [zoom]);
useEffect(() => {
updateDag(job.vertices, graph);
if (currentJob != job.jid) {
setCurrentJob(job.jid);
}
}, [job]);
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
style={{
height: '100%',
width: '100%'
}}
ref={container}
/>
</span>
); );
// Adaptive layout
const model = new DagreLayout(layoutConfig).layout(flinkData);
graph.fromJSON(model);
// Automatically zoom to fit
graph.zoomToFit(zoomOptions);
graph.centerContent();
updateDag(job.vertices, graph);
initListen(graph);
return graph;
};
useEffect(() => {
const flinkData = buildDag(job.plan);
// Clean up old data
if (graph) {
graph.clearCells();
}
setGraph(initGraph(flinkData));
}, [curentJob]);
useEffect(() => {
updateDag(job.vertices, graph);
if (curentJob != job.jid) {
setCurentJob(job.jid);
}
}, [job]);
return (
<>
<div
style={{
height: '100%',
width: '100%'
}}
ref={container}
/>
<Drawer
title={curentSelect?.name}
open={open}
getContainer={false}
size={'large'}
mask={false}
>
<p>{curentSelect?.getData().description}</p>
</Drawer>
</>
);
}; };
export default FlinkDag; export default FlinkDag;
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