Shapes go brrr

This commit is contained in:
1ilit 2023-09-19 15:46:43 +03:00
parent db580f892d
commit 990016b036
2 changed files with 46 additions and 3 deletions

View File

@ -1,10 +1,9 @@
import './App.css';
import Diagram from './diagram';
function App() {
return (
<h1 className="text-3xl font-bold underline">
Hello world!
</h1>
<Diagram/>
);
}

44
src/diagram/index.jsx Normal file
View File

@ -0,0 +1,44 @@
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: {
color: "#F1F92A",
},
model: graph,
height: window.height,
width: window.width,
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);
}, []);
return (
<>
<div id="canvas" className="h-screen w-screen" ref={canvas} />
</>
);
}
export default Diagram;