drawDB/src/components/diagram/index.jsx

41 lines
783 B
React
Raw Normal View History

2023-09-19 20:46:43 +08:00
import React, { useEffect, useRef } from "react";
import { dia, shapes } from "jointjs";
function Diagram() {
const canvas = useRef(null);
useEffect(() => {
const graph = new dia.Graph();
new dia.Paper({
el: document.getElementById("canvas"),
background: {
2023-09-19 20:46:48 +08:00
color: "#aec3b0",
2023-09-19 20:46:43 +08:00
},
model: graph,
2023-09-19 20:46:46 +08:00
height: "100%",
2023-09-19 20:46:44 +08:00
width: "100%",
2023-09-19 20:46:43 +08:00
gridSize: 1,
interactive: true,
});
const rect = new shapes.standard.Rectangle();
rect.position(100, 100);
rect.resize(100, 40);
rect.attr({
body: {
fill: "#7039FF",
},
label: {
text: "hi",
fill: "white",
},
});
rect.addTo(graph);
}, []);
2023-09-19 20:46:48 +08:00
return <div id="canvas" ref={canvas} />;
2023-09-19 20:46:43 +08:00
}
export default Diagram;