mirror of https://github.com/veypi/OneAuth.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
3.1 KiB
HTML
135 lines
3.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Data Structure Topology with D3.js</title>
|
|
<style>
|
|
.node {
|
|
fill: #f9f9f9;
|
|
stroke: #ccc;
|
|
stroke-width: 2px;
|
|
}
|
|
|
|
.field {
|
|
font-size: 14px;
|
|
font-family: Arial, sans-serif;
|
|
}
|
|
|
|
.edge {
|
|
fill: none;
|
|
stroke: #333;
|
|
stroke-width: 2px;
|
|
}
|
|
|
|
.label {
|
|
font-size: 12px;
|
|
font-family: Arial, sans-serif;
|
|
fill: #555;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="graph"></div>
|
|
<script src="https://d3js.org/d3.v7.min.js"></script>
|
|
<script>
|
|
const data = {
|
|
nodes: [
|
|
{id: "Node A", fields: ["Field1: int", "Field2: string"]},
|
|
{id: "Node B", fields: ["Field1: float", "Field2: bool"]},
|
|
{id: "Node C", fields: ["Field1: date", "Field2: char"]}
|
|
],
|
|
links: [
|
|
{source: "Node A", target: "Node B", type: "One-to-One"},
|
|
{source: "Node A", target: "Node C", type: "One-to-Many"},
|
|
{source: "Node B", target: "Node C", type: "Many-to-Many"}
|
|
]
|
|
};
|
|
|
|
const width = 800;
|
|
const height = 600;
|
|
|
|
const svg = d3.select("#graph")
|
|
.append("svg")
|
|
.attr("width", width)
|
|
.attr("height", height);
|
|
|
|
const simulation = d3.forceSimulation(data.nodes)
|
|
.force("link", d3.forceLink(data.links).id(d => d.id))
|
|
.force("charge", d3.forceManyBody().strength(-400))
|
|
.force("center", d3.forceCenter(width / 2, height / 2));
|
|
|
|
const linkElements = svg.selectAll(".edge")
|
|
.data(data.links)
|
|
.enter()
|
|
.append("line")
|
|
.attr("class", "edge");
|
|
|
|
const nodeElements = svg.selectAll(".node")
|
|
.data(data.nodes)
|
|
.enter()
|
|
.append("g")
|
|
.attr("class", "node")
|
|
.call(d3.drag()
|
|
.on("start", dragstarted)
|
|
.on("drag", dragged)
|
|
.on("end", dragended));
|
|
|
|
nodeElements.append("rect")
|
|
.attr("x", -75)
|
|
.attr("y", -50)
|
|
.attr("width", 150)
|
|
.attr("height", 100)
|
|
.attr("rx", 10)
|
|
.attr("ry", 10);
|
|
|
|
nodeElements.append("text")
|
|
.attr("dx", 0)
|
|
.attr("dy", -20)
|
|
.text(d => d.id)
|
|
.attr("text-anchor", "middle")
|
|
.attr("class", "field");
|
|
|
|
nodeElements.selectAll(".field-text")
|
|
.data(d => d.fields)
|
|
.enter()
|
|
.append("text")
|
|
.attr("dx", 0)
|
|
.attr("dy", (d, i) => i * 20 + 5)
|
|
.text(d => d)
|
|
.attr("text-anchor", "middle")
|
|
.attr("class", "field");
|
|
|
|
simulation.on("tick", () => {
|
|
linkElements
|
|
.attr("x1", d => d.source.x)
|
|
.attr("y1", d => d.source.y)
|
|
.attr("x2", d => d.target.x)
|
|
.attr("y2", d => d.target.y);
|
|
|
|
nodeElements.attr("transform", d => `translate(${d.x},${d.y})`);
|
|
});
|
|
|
|
function dragstarted(event, d) {
|
|
if (!event.active) simulation.alphaTarget(0.3).restart();
|
|
d.fx = d.x;
|
|
d.fy = d.y;
|
|
}
|
|
|
|
function dragged(event, d) {
|
|
d.fx = event.x;
|
|
d.fy = event.y;
|
|
}
|
|
|
|
function dragended(event, d) {
|
|
if (!event.active) simulation.alphaTarget(0);
|
|
d.fx = null;
|
|
d.fy = null;
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|