Skip to content

Conversation

@ryan-di
Copy link
Member

@ryan-di ryan-di commented Mar 21, 2023

fix #5932

First, we will remove element stats from "stats for nerds" (which gets renamed to "general stats") and will be placed into its own panel/island. The rationale behind is that elements stats are more individual. Moreover, it's now interactive, meaning an element's shape and location can be edited from the element stats panel/island.

Apart from the previously available summary of the scene, we've added an additional section, Element properties. The idea behind this is to allow users to change some of the properties more easily and more accurately.


For now, there are at most six properties to be displayed:

  • x
  • y
  • w
  • h
  • angle
  • font size

For individual elements, the displayed properties are the ones that can be edited.

And for group / multiple elements,

  • when there are multiple values, displays "MIXED"
  • if, some value, is editable for at least one of the elements, editing is enabled

We've built a Figma like drag input to allow the user to control how the value is changed. The drag is activated when the pointer is over the "icon" part of the input as can be seen here:

image

Figma did a really great job with the numeric input, where the pointer gets wrapped, much like the game Snake.


Todos

  • profile perf
  • naming
  • collapsing the general stats
  • panel positioning
  • icons for angle and font-size

next PRs

  • input drag wrap behavior
  • support corner radius

@vercel
Copy link

vercel bot commented Mar 21, 2023

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

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

@dwelle
Copy link
Member

dwelle commented Mar 26, 2023

@ryan-di what about adding aspect ratio. It's useful when drawing device frames, and will be especially useful once we ship frames.

excal-stats-aspect-ratio

Code:

function greatestCommonDenominator(a: number, b: number): number {
  if (b === 0) {
    return a;
  }
  return greatestCommonDenominator(b, a % b);
}

function isMaxTwoDigit(a: number) {
  return a >= 1 && a <= 99;
}

function findRatioOrFraction(width: number, height: number) {
  // round because with excalidraw's imprecise bounding box, even in grid mode,
  // coupled with floating point rounding errors, we'd rarely get a perfect
  // aspect ratio
  width = Math.round(width);
  height = Math.round(height);
  const greatestCommonDivisor = greatestCommonDenominator(width, height);
  const simplifiedWidth = Math.round(width / greatestCommonDivisor);
  const simplifiedHeight = Math.round(height / greatestCommonDivisor);

  // we want to display in W:H format only if both W and H are <= 2 digits
  if (isMaxTwoDigit(simplifiedWidth) && isMaxTwoDigit(simplifiedHeight)) {
    return `${simplifiedWidth}:${simplifiedHeight}`;
  }
  return (width / height).toPrecision(3);
}
<tr>
  <td>Aspect ratio</td>
  <td>
    {findRatioOrFraction(
      selectedBoundingBox[2] - selectedBoundingBox[0],
      selectedBoundingBox[3] - selectedBoundingBox[1],
    )}
  </td>
</tr>

What's left to figure out is how editing works.

Might be problematic for multi-selection. We'd have to disable non-proportional aspect ratio change with multi-selection as we don't allow non-proportional resize in the editor. With proportional resize it could be as easy as doing a multi-selection resize manually. EDIT: that's actually a no-op. So unless we implement #5423, we need to disable editing aspect ratio for multi-selection.

@najibghadri
Copy link

Hi! :) Any news on this? Can this be picked up or is this not good anymore?

@dwelle
Copy link
Member

dwelle commented Apr 29, 2024

We initially hit some roadblocks that required more changes/refactor elsewhere. Should be more or less unblocked now, though we bumped down in priority. We may restart the effort soon.

@ryan-di if we align the width/height change behavior with the behavior from side-resizing, that should simplify things a lot. Were there any other issues you were facing?

@ryan-di
Copy link
Member Author

ryan-di commented Apr 29, 2024

@dwelle there was also a lack of geometric helpers iirc. Agree with you that we should be a in a much better position to pick this up without much resistance 👍

@najibghadri
Copy link

najibghadri commented Apr 30, 2024

Nice, thanks @ryan-di @dwelle . Actually for us Radius change would be the most important as that's the only property from the ones mentioned that can't be changed from UI. Huge plus if there's an option to change each 4 corners separately. I would say there's no need implement the drag pointer like in figma, a simple number text/number input would be enough for most users.
(#3600)

Right now we have to use a rectangle and two circles to do rouned rectangles. Very difficult to use bc you can't have a stroke, and can't change height/width dynamically.

Screenshot 2024-04-30 at 11 04 26

@ryan-di
Copy link
Member Author

ryan-di commented May 27, 2024

Todos:

  • drag to change a rotated element's width and height correctly
  • when changing an element's width or height using the input value, fix the origin
  • add support for custom font size
  • add support for min width
  • disable properties that are not editable for the selected element
  • record history properly
  • shift to change the step size
  • multiple elements resize

dwelle added 2 commits June 12, 2024 19:37
so we don't need to keep a migration from `boolean` to init the defaults
Copy link
Member

@dwelle dwelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@dwelle dwelle merged commit d2f67e6 into excalidraw:master Jun 12, 2024
@ejazkhan10
Copy link

When will this be available as part of npm package.
Currently, the latest stable version I am seeing is 0.17.6. It was updated 2 months ago.

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 element stats editable

4 participants