Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: split gridSize from enabled state & support custom gridStep #8364

Merged
merged 4 commits into from
Aug 14, 2024

Conversation

dwelle
Copy link
Member

@dwelle dwelle commented Aug 11, 2024

fix #8244

Adding support to customize grid step (the bold lines). We could allow customizing grid cell size (currently 20px), but it feels less useful and I don't think it was ever even requested, so for simplicity's sake, we're not allowing it that now.


  • support for customizing gridStep from the stats menu (tracked as appState.gridStep, previously hardcoded). Clamped to <1, 100>, integer.
  • shows gridStep input in Stats only when grid mode enabled
  • divorced gridSize from enabled state, which is now tracked separately as appState.gridModeEnabled
  • fixed grid rendering to work with arbitrary integer gridSize & gridStep
  • props.gridModeEnabled is now independent from appState and doesn't override it (previously it was overriding gridSize)
  • grid lines rendering more crisp when 100% zoom
  • grid step lines not rendered when gridStep=1
  • grip lines not rendered when too small (on small zoom)
  • Stats <DragInput> now also takes sensitivity to allow to reduce pointer px sensitivity
  • gridSize, gridStep, and zoom.value now properly normalized on restore
  • added utils: round(value, precision)

excal-gridStep

Sorry, something went wrong.

Copy link

vercel bot commented Aug 11, 2024

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

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

Copy link

github-actions bot commented Aug 11, 2024

Coverage Report

Status Category Percentage Covered / Total
🔴 Lines 66.59% (🎯 70%) 58273 / 87497
🔴 Statements 66.59% (🎯 70%) 58273 / 87497
🟢 Functions 68.28% (🎯 68%) 1733 / 2538
🟢 Branches 80.98% (🎯 70%) 7290 / 9002
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
packages/excalidraw/appState.ts 98.26% 90% 71.42% 98.26% 18, 266-267, 274-275
packages/excalidraw/constants.ts 99.53% 50% 100% 99.53% 10-11
packages/excalidraw/math.ts 77.76% 87.87% 83.33% 77.76% 79, 81-84, 95-155, 195-220, 238-243, 247-277, 286-290, 323-324, 381-382, 399-400, 463-464, 512-514, 572, 577-580, 685, 699-706
packages/excalidraw/types.ts 100% 100% 100% 100%
packages/excalidraw/actions/actionCanvas.tsx 70.85% 65.95% 61.11% 70.85% 49-53, 55-61, 114, 154-155, 195-196, 211-226, 235-236, 244, 290-316, 383-392, 397-399, 408-418, 422-424, 434-441, 444-446, 452-455, 481-507, 519-546
packages/excalidraw/actions/actionDuplicateSelection.tsx 86.68% 84.84% 85.71% 86.68% 45-59, 166, 181-190, 192-204
packages/excalidraw/actions/actionToggleGridMode.tsx 100% 100% 100% 100%
packages/excalidraw/actions/actionToggleObjectsSnapMode.tsx 70.96% 80% 60% 70.96% 16-24
packages/excalidraw/components/App.tsx 70.35% 77.36% 69.74% 70.35% 484-485, 595-604, 703-704, 722-723, 744-804, 807-813, 822, 828-831, 834-910, 913-932, 935-940, 948-958, 960-961, 966-967, 971-973, 987, 994-1256, 1316-1317, 1349-1351, 1358-1403, 1429, 1439, 1446-1449, 1458-1462, 1494-1495, 1579-1589, 1594-1609, 1613-1660, 1737-1742, 1771-1776, 1779-1809, 1817-1842, 1845-1854, 1857-1969, 1972-1980, 1989-2002, 2005-2031, 2034-2105, 2108-2149, 2152-2157, 2194-2195, 2217-2218, 2249-2250, 2254-2255, 2275-2283, 2288-2301, 2307-2308, 2312, 2317-2325, 2327-2335, 2347, 2389-2390, 2412-2413, 2420, 2493-2495, 2498-2503, 2508-2509, 2549-2557, 2562-2571, 2609-2610, 2697-2698, 2702, 2705-2706, 2714-2717, 2726-2739, 2745-2748, 2751, 2753-2754, 2761-2762, 2768-2769, 2772-2773, 2781-2782, 2785-2786, 2797-2805, 2810-2811, 2862-2863, 2877-2883, 2889-2897, 2901-2909, 2913-2914, 2917-2950, 2953-2965, 2976-2977, 2988-2989, 3006-3010, 3014-3017, 3024-3026, 3044-3051, 3054, 3056-3061, 3065-3067, 3113-3114, 3121-3123, 3125-3148, 3174, 3180, 3236-3237, 3254-3256, 3278-3279, 3285-3288, 3294-3375, 3429, 3433, 3468-3469, 3528, 3538-3556, 3559-3565, 3568-3569, 3575-3591, 3696-3697, 3720-3734, 3739-3758, 3810-3811, 3891-3896, 3927, 4053-4054, 4056-4063, 4097-4101, 4103-4104, 4106-4109, 4134-4135, 4153-4155, 4157-4159, 4161, 4242-4245, 4267-4275, 4279-4281, 4291-4292, 4294-4314, 4321-4344, 4347-4353, 4370-4373, 4379-4382, 4392-4399, 4494-4498, 4502, 4507-4508, 4513-4517, 4550-4551, 4554-4555, 4567-4571, 4576-4577, 4583-4593, 4598-4625, 4630-4641, 4738-4739, 4823, 4848, 4874-4876, 4943-4944, 4962-4963, 5138-5139, 5142-5143, 5151-5152, 5202-5206, 5260-5267, 5273-5339, 5383, 5440, 5467, 5474-5475, 5488-5491, 5522, 5570-5573, 5576-5582, 5584-5587, 5604-5613, 5616-5617, 5737-5738, 5741, 5743-5748, 5754-5756, 5758, 5767, 5789-5794, 5796-5799, 5803-5804, 5814-5914, 5918-5919, 5934-5935, 5971-5977, 6004-6005, 6036, 6038-6065, 6072-6073, 6095-6096, 6115, 6117-6160, 6165-6166, 6168-6169, 6185-6186, 6192-6193, 6197-6200, 6203-6204, 6218-6245, 6253-6254, 6258-6261, 6263-6267, 6285-6289, 6336-6341, 6343-6345, 6361, 6363-6376, 6401-6404, 6448, 6465-6466, 6468-6491, 6506-6507, 6621-6649, 6755-6756, 6776-6777, 6871, 6877-6878, 6901-6920, 6935, 7064, 7086-7124, 7128-7178, 7193, 7202, 7236-7242, 7268-7270, 7437-7440, 7462-7492, 7505, 7507-7515, 7529, 7531-7539, 7546-7549, 7557-7562, 7589-7590, 7595-7597, 7600-7601, 7626-7627, 7658-7659, 7742-7743, 7790-7803, 7880-7883, 7909-7910, 7966, 7981-7987, 7994-8008, 8032-8038, 8070, 8112, 8118, 8133-8140, 8143-8150, 8206, 8284-8285, 8306-8308, 8311, 8325-8349, 8453-8466, 8487-8511, 8520-8559, 8572-8573, 8582-8589, 8607-8614, 8668-8694, 8696-8697, 8771-8772, 8779, 8781-8817, 8846, 8905, 8939-8941, 8966-8971, 8973-8974, 8979-8981, 8984-9004, 9018-9019, 9025-9034, 9039, 9043-9047, 9056-9060, 9063-9068, 9072-9079, 9109, 9111-9115, 9117-9127, 9143-9145, 9156-9164, 9168-9212, 9215-9286, 9294, 9312-9319, 9321-9337, 9352-9374, 9393-9395, 9441-9442, 9558-9562, 9564-9580, 9582-9586, 9598-9599, 9609-9625, 9644-9663, 9665-9666, 9693-9694, 9698-9699, 9709, 9711-9714, 9716-9717, 9757, 9796-9797, 9807, 9849, 9862-9870, 9891-9892, 9924-9927, 10020-10027, 10053-10054, 10097-10151, 10199-10200, 10209-10212, 10217-10218, 10239-10241, 10243-10247, 10285
packages/excalidraw/components/LayerUI.tsx 84.96% 87.93% 46.42% 84.96% 328, 349-352, 365-366, 381-386, 431-476, 479-483, 486-502, 509-517, 564-567
packages/excalidraw/components/Stats/CanvasGrid.tsx 26.86% 100% 0% 26.86% 17-65
packages/excalidraw/components/Stats/DragInput.tsx 64.83% 87.5% 55.55% 64.83% 108-110, 179-274, 276-279, 288-298, 312
packages/excalidraw/components/Stats/index.tsx 92.87% 88.88% 60% 92.87% 178-185, 203-213, 233-241
packages/excalidraw/components/Stats/utils.ts 84.47% 78.78% 100% 84.47% 135-136, 141-151, 181-200, 207-210, 226-227, 266-276
packages/excalidraw/components/canvases/StaticCanvas.tsx 98.55% 94.44% 100% 98.55% 36-37
packages/excalidraw/data/restore.ts 88.36% 83.92% 78.57% 88.36% 97-100, 116, 173, 223-225, 255-259, 300-303, 407, 437-447, 492-493, 502-510, 513-527, 534-543, 552-561, 579-584
packages/excalidraw/element/dragElements.ts 75.49% 68.57% 100% 75.49% 40, 42-43, 50-51, 66-71, 183-207, 213-217, 222-242
packages/excalidraw/element/linearElementEditor.ts 76.19% 81.19% 86.48% 76.19% 106-107, 148, 152-209, 225-226, 231-232, 236-237, 239-240, 243-256, 259-261, 272-273, 275-297, 322-325, 396-397, 422, 442, 460-468, 556-557, 681-682, 695, 721-722, 728-729, 746-789, 887-888, 892-893, 900-905, 911-913, 915-962, 1113-1114, 1117-1188, 1203-1210, 1231-1246, 1333-1334, 1337-1338, 1379-1380, 1444, 1451, 1488-1521, 1637-1669
packages/excalidraw/renderer/staticScene.ts 70.31% 79.36% 100% 70.31% 74-75, 93-94, 127-128, 144-189, 202-203, 245-251, 253-256, 328-329, 336-396, 412-413
packages/excalidraw/scene/index.ts 100% 100% 100% 100%
packages/excalidraw/scene/normalize.ts 100% 100% 100% 100%
packages/excalidraw/scene/zoom.ts 100% 100% 100% 100%
Generated in workflow #3072

@ryan-di
Copy link
Member

ryan-di commented Aug 13, 2024

When shift dragging, i.e. changing the grid steps by a step size of 5, I find it to be a bit too "sensitive" still. In the context of grids, changing gridStep by 5 changes the side length of the "grid box" by 100 and the area of the "grid box" actually changes exponentially.

We could either reduce the step size or take both sensitivity and step size into account so that sensitivity gets reduced when shift dragged. But this is really minor and probably not worth fussing over atm.

# Conflicts:
#	packages/excalidraw/actions/actionCanvas.tsx
@dwelle
Copy link
Member Author

dwelle commented Aug 13, 2024

When shift dragging, i.e. changing the grid steps by a step size of 5, I find it to be a bit too "sensitive" still. In the context of grids, changing gridStep by 5 changes the side length of the "grid box" by 100 and the area of the "grid box" actually changes exponentially.

We could either reduce the step size or take both sensitivity and step size into account so that sensitivity gets reduced when shift dragged. But this is really minor and probably not worth fussing over atm.

Yeah, though it would require props.sensitivity to be a function that gets passed whether it's a step-based interaction, which IMO not worth it as you say, since even the dragging itself on this property is not going to be that common use case.

@dwelle dwelle merged commit 3cfcc7b into master Aug 14, 2024
10 checks passed
@dwelle dwelle deleted the dwelle/gridStep branch August 14, 2024 12:59
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.

Make 10 divisions in each grid instead of 5
2 participants