Add showCardinality setting
This commit is contained in:
parent
187b70cbdf
commit
3ec1f91903
@ -1077,10 +1077,17 @@ export default function ControlPanel({
|
|||||||
function: resetView,
|
function: resetView,
|
||||||
shortcut: "Ctrl+R",
|
shortcut: "Ctrl+R",
|
||||||
},
|
},
|
||||||
Grid: {
|
"Show grid": {
|
||||||
function: viewGrid,
|
function: viewGrid,
|
||||||
shortcut: "Ctrl+Shift+G",
|
shortcut: "Ctrl+Shift+G",
|
||||||
},
|
},
|
||||||
|
"Show cardinality": {
|
||||||
|
function: () =>
|
||||||
|
setSettings((prev) => ({
|
||||||
|
...prev,
|
||||||
|
showCardinality: !prev.showCardinality,
|
||||||
|
})),
|
||||||
|
},
|
||||||
Theme: {
|
Theme: {
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import { useRef, useState } from "react";
|
import { useContext, useRef, useState } from "react";
|
||||||
import { calcPath } from "../utils";
|
import { calcPath } from "../utils";
|
||||||
import { Cardinality } from "../data/data";
|
import { Cardinality } from "../data/data";
|
||||||
|
import { SettingsContext } from "../pages/Editor";
|
||||||
|
|
||||||
export default function Relationship(props) {
|
export default function Relationship(props) {
|
||||||
const [hovered, setHovered] = useState(false);
|
const [hovered, setHovered] = useState(false);
|
||||||
|
const { settings } = useContext(SettingsContext);
|
||||||
const pathRef = useRef();
|
const pathRef = useRef();
|
||||||
|
|
||||||
let cardinalityStart = "1";
|
let cardinalityStart = "1";
|
||||||
@ -31,18 +33,20 @@ export default function Relationship(props) {
|
|||||||
let cardinalityStartY = 0;
|
let cardinalityStartY = 0;
|
||||||
let cardinalityEndY = 0;
|
let cardinalityEndY = 0;
|
||||||
|
|
||||||
|
const length = 32;
|
||||||
|
|
||||||
if (pathRef.current) {
|
if (pathRef.current) {
|
||||||
const pathLength = pathRef.current.getTotalLength();
|
const pathLength = pathRef.current.getTotalLength();
|
||||||
const point1 = pathRef.current.getPointAtLength(32);
|
const point1 = pathRef.current.getPointAtLength(length);
|
||||||
cardinalityStartX = point1.x;
|
cardinalityStartX = point1.x;
|
||||||
cardinalityStartY = point1.y;
|
cardinalityStartY = point1.y;
|
||||||
const point2 = pathRef.current.getPointAtLength(pathLength - 32);
|
const point2 = pathRef.current.getPointAtLength(pathLength - length);
|
||||||
cardinalityEndX = point2.x;
|
cardinalityEndX = point2.x;
|
||||||
cardinalityEndY = point2.y;
|
cardinalityEndY = point2.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<g>
|
<g className="select-none">
|
||||||
<defs>
|
<defs>
|
||||||
<filter id="shadow" x="-20%" y="-20%" width="140%" height="140%">
|
<filter id="shadow" x="-20%" y="-20%" width="140%" height="140%">
|
||||||
<feDropShadow
|
<feDropShadow
|
||||||
@ -72,7 +76,7 @@ export default function Relationship(props) {
|
|||||||
onMouseEnter={() => setHovered(true)}
|
onMouseEnter={() => setHovered(true)}
|
||||||
onMouseLeave={() => setHovered(false)}
|
onMouseLeave={() => setHovered(false)}
|
||||||
/>
|
/>
|
||||||
{pathRef.current && (
|
{pathRef.current && settings.showCardinality && (
|
||||||
<>
|
<>
|
||||||
<circle
|
<circle
|
||||||
cx={cardinalityStartX}
|
cx={cardinalityStartX}
|
||||||
@ -90,10 +94,6 @@ export default function Relationship(props) {
|
|||||||
>
|
>
|
||||||
{cardinalityStart}
|
{cardinalityStart}
|
||||||
</text>
|
</text>
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{pathRef.current && (
|
|
||||||
<>
|
|
||||||
<circle
|
<circle
|
||||||
cx={cardinalityEndX}
|
cx={cardinalityEndX}
|
||||||
cy={cardinalityEndY}
|
cy={cardinalityEndY}
|
||||||
|
@ -63,6 +63,7 @@ export default function Editor() {
|
|||||||
mode: "light",
|
mode: "light",
|
||||||
autosave: true,
|
autosave: true,
|
||||||
panning: true,
|
panning: true,
|
||||||
|
showCardinality: true,
|
||||||
});
|
});
|
||||||
const [tasks, setTasks] = useState([]);
|
const [tasks, setTasks] = useState([]);
|
||||||
const [messages, setMessages] = useState([]);
|
const [messages, setMessages] = useState([]);
|
||||||
|
Loading…
Reference in New Issue
Block a user