feat: add debug coordinate overlay

Makes debugging issues in conversion from screen space
to diagram space easier.

Only adding english translations as I do not speak the
other languages.
This commit is contained in:
Felix Zedén Yverås 2024-06-27 18:03:44 +02:00
parent 354ea47529
commit 32c82168fe
4 changed files with 184 additions and 91 deletions

View File

@ -433,6 +433,7 @@ export default function Canvas() {
const theme = localStorage.getItem("theme"); const theme = localStorage.getItem("theme");
return ( return (
<>
<div className="flex-grow h-full touch-none" id="canvas"> <div className="flex-grow h-full touch-none" id="canvas">
<div ref={canvas} className="w-full h-full"> <div ref={canvas} className="w-full h-full">
<svg <svg
@ -442,7 +443,8 @@ export default function Canvas() {
className="w-full h-full" className="w-full h-full"
style={{ style={{
cursor: cursor, cursor: cursor,
backgroundColor: theme === "dark" ? "rgba(22, 22, 26, 1)" : "white", backgroundColor:
theme === "dark" ? "rgba(22, 22, 26, 1)" : "white",
}} }}
> >
{settings.showGrid && ( {settings.showGrid && (
@ -527,6 +529,77 @@ export default function Canvas() {
</g> </g>
</svg> </svg>
</div> </div>
{settings.showDebugCoordinates && (
<div className="fixed flex flex-col flex-wrap gap-6 bg-[rgba(var(--semi-grey-1),var(--tw-bg-opacity))]/40 border border-color bottom-4 right-4 p-4 rounded-xl backdrop-blur-sm pointer-events-none select-none">
<table className="table-auto grow">
<thead>
<tr>
<th className="text-left" colSpan={3}>
{t("transform")}
</th>
</tr>
<tr className="italic [&_th]:font-normal [&_th]:text-right">
<th>pan x</th>
<th>pan y</th>
<th>scale</th>
</tr>
</thead>
<tbody className="[&_td]:text-right [&_td]:min-w-[8ch]">
<tr>
<td>{transform.pan.x.toFixed(2)}</td>
<td>{transform.pan.y.toFixed(2)}</td>
<td>{transform.zoom.toFixed(4)}</td>
</tr>
</tbody>
</table>
<table className="table-auto grow [&_th]:text-left [&_th:not(:first-of-type)]:text-right [&_td:not(:first-of-type)]:text-right [&_td]:min-w-[8ch]">
<thead>
<tr>
<th colSpan={4}>{t("viewbox")}</th>
</tr>
<tr className="italic [&_th]:font-normal">
<th>left</th>
<th>top</th>
<th>width</th>
<th>height</th>
</tr>
</thead>
<tbody>
<tr>
<td>TODO</td>
<td>TODO</td>
<td>TODO</td>
<td>TODO</td>
</tr>
</tbody>
</table>
<table className="table-auto grow [&_th]:text-left [&_th:not(:first-of-type)]:text-right [&_td:not(:first-of-type)]:text-right [&_td]:min-w-[8ch]">
<thead>
<tr>
<th colSpan={3}>{t("cursor_coordinates")}</th>
</tr>
<tr className="italic [&_th]:font-normal">
<th>{t("coordinate_space")}</th>
<th>x</th>
<th>y</th>
</tr>
</thead>
<tbody>
<tr>
<td>{t("coordinate_space_screen")}</td>
<td>TODO</td>
<td>TODO</td>
</tr>
<tr>
<td>{t("coordinate_space_diagram")}</td>
<td>TODO</td>
<td>TODO</td>
</tr>
</tbody>
</table>
</div> </div>
)}
</div>
</>
); );
} }

View File

@ -1158,6 +1158,18 @@ export default function ControlPanel({
showCardinality: !prev.showCardinality, showCardinality: !prev.showCardinality,
})), })),
}, },
show_debug_coordinates: {
state: settings.showDebugCoordinates ? (
<i className="bi bi-toggle-on" />
) : (
<i className="bi bi-toggle-off" />
),
function: () =>
setSettings((prev) => ({
...prev,
showDebugCoordinates: !prev.showDebugCoordinates,
})),
},
theme: { theme: {
children: [ children: [
{ {

View File

@ -13,6 +13,7 @@ export default function SettingsContextProvider({ children }) {
panning: true, panning: true,
showCardinality: true, showCardinality: true,
tableWidth: tableWidth, tableWidth: tableWidth,
showCursorCoordinates: false,
}); });
return ( return (

View File

@ -59,6 +59,13 @@ const en = {
show_timeline: "Show timeline", show_timeline: "Show timeline",
autosave: "Autosave", autosave: "Autosave",
panning: "Panning", panning: "Panning",
show_debug_coordinates: "Show debug coordinates",
transform: "Transform",
viewbox: "View Box",
cursor_coordinates: "Cursor Coordinates",
coordinate_space: "Space",
coordinate_space_screen: "Screen",
coordinate_space_diagram: "Diagram",
table_width: "Table width", table_width: "Table width",
language: "Language", language: "Language",
flush_storage: "Flush storage", flush_storage: "Flush storage",