Skip to content

Conversation

@mtolmacs
Copy link
Collaborator

@mtolmacs mtolmacs commented Aug 8, 2024

Motivation: In order to efficiently debug vector math, geometric calculations and similar situations we need a way to visualize concepts, like lines, points, boxes and such.

The feature should only work in DEV mode, should not be included in production builds as much as possible and the rendering should only be in the excalidraw-app package, avoiding pollution of the main excalidraw package.

Feature can be activated in the main menu (hamburger menu) via the "Visual debug" menu item. The setting is preserved until deactivated.

Available debug commands (imported from packages/excalidraw/visualdebug.ts:

  • An always present X shape at the global [0, 0] coordinate
  • debugDrawPoint(): Draws a single global point as an X
  • debugDrawLine(): Draws one or multiple line segments (global coords)
  • debugDrawBounds(): Draw Bounds
  • debgDrawBbox(): Draw BBox

All debug functions allow receiving an optional options object, which let's you set the color and permanence of the debug object. Points get a "fuzzy" option, which adds a small random bias to the point in order to distinguish multiple points drawn over each other.

@vercel
Copy link

vercel bot commented Aug 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
excalidraw ✅ Ready (Inspect) Visit Preview Aug 27, 2024 5:36pm
excalidraw-package-example ✅ Ready (Inspect) Visit Preview Aug 27, 2024 5:36pm
excalidraw-package-example-with-nextjs ✅ Ready (Inspect) Visit Preview Aug 27, 2024 5:36pm
1 Skipped Deployment
Name Status Preview Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Aug 27, 2024 5:36pm

@mtolmacs mtolmacs self-assigned this Aug 8, 2024
@github-actions
Copy link

github-actions bot commented Aug 8, 2024

Coverage Report

Status Category Percentage Covered / Total
🔴 Lines 66.71% (🎯 70%) 58623 / 87871
🔴 Statements 66.71% (🎯 70%) 58623 / 87871
🟢 Functions 68.07% (🎯 68%) 1742 / 2559
🟢 Branches 80.88% (🎯 70%) 7310 / 9038
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
excalidraw-app/App.tsx 56.44% 58.33% 17.94% 56.44% 159-163, 169-178, 218-253, 255-277, 280-311, 314-319, 322-323, 351, 379-381, 399-400, 402-416, 420-423, 427-438, 441-453, 467-489, 497-552, 556-557, 560-569, 592-602, 622-646, 652-653, 661-698, 701-711, 724-737, 746-752, 769-775, 798-818, 839, 866-872, 883-885, 888-892, 901-912, 916-918, 936-940, 956-962, 981-982, 999-1004, 1013-1018, 1038-1043, 1052-1057, 1060-1065, 1075-1083, 1088-1091, 1098-1106, 1111-1115
excalidraw-app/app_constants.ts 100% 100% 100% 100%
excalidraw-app/components/AppFooter.tsx 96.55% 33.33% 100% 96.55% 21
excalidraw-app/components/AppMainMenu.tsx 89.41% 33.33% 0% 89.41% 60-68
excalidraw-app/components/DebugCanvas.tsx 20.81% 40% 20% 20.81% 19-31, 34-43, 46-57, 60-108, 111-119, 122-130, 134-135, 146-147, 149-150, 159-256, 265-290
packages/excalidraw/visualdebug.ts 0% 0% 0% 0% 1-157
packages/excalidraw/element/typeChecks.ts 86.12% 86% 84.84% 86.12% 172-177, 236-238, 279, 287-289, 294-296, 298-302, 305-320, 330, 334-339, 343-346
Generated in workflow #3177

@imanzaker
Copy link

i get the menus in the footer but they do nothing. can you send a short video of its process and application?

@mtolmacs
Copy link
Collaborator Author

It is only available in DEV mode and only in the excalidraw-app.

The app menu now contain a new menu item called Visual Debug. It toggles the functionality at your discretion. You will see if it's activated when you see a gray X on the scene coordinates 0,0.

In order to take advantage of it's capabilities, you have to use a debug function from packages/excalidraw/visualdebug.ts. There are options to have frame-by-frame clearing and persistent paint, depending on your use-case.
visualdebug

A very useful improvement I was able to add are "pages", where you can turn the page from your code and start debug drawing on a new page in permanent painting mode, then when you get back to the app, you can see it frame-by-frame.
visualdebug2

clarencechaan pushed a commit to clarencechaan/excalidraw that referenced this pull request Oct 3, 2024
Add visual debugger to the Excalidraw app (only).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants