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

Reimplemented paragraph fit w/ binary search #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

derekmiranda
Copy link
Collaborator

  • faster than previous implementation as difference between min and
    max font size increases
  • based on research from other text fitting procedures

Test results:

  • Fitting "This is just a fit paragraph" or "This is a fit-clamp paragraph" within a 100x100 container

minFontSize = 6, fontSize = 50:
old implementation rerenders w/ new font size 29 times
new implementation rerenders: 14

minFontSize = 1, fontSize = 100:
old implementation rerenders: 79
new implementation rerenders: 16

However, w/ minFontSize = 1, fontSize = 10:
old implementation rerenders: 0
new implementation rerenders: 1

- faster than previous implementation as difference between min and
max font size increases
Copy link
Contributor

@andrewdowis andrewdowis left a comment

Choose a reason for hiding this comment

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

I don't see a benefit to having fontSizeCheckFn() defined as an inline function (var optimalFontSize = ... on line 679). Making it a private function ensures it's already in memory and that any time there's an auto size, the function doesn't have to be defined again. Although, I guess I do understand basically purging the function when done. Still, declaring it and passing it around rather than calling a static function within the class doesn't make as much sense to me.

@derekmiranda
Copy link
Collaborator Author

derekmiranda commented Oct 29, 2018 via email

Copy link
Contributor

@kennyarehart kennyarehart left a comment

Choose a reason for hiding this comment

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

I agree with Andrew that the fontSizeCheckFn() should be abstracted. Also, resizeTimes on 681 is not defined within the module. I assume this is just for testing but don't forget to remove that when finalizing. I would do a few more tests with different width/height/font/minFont etc. I'm sure it will yield the same but just to be sure.

- fontSizeCheckFn no longer passed into getOptimalFontSize
- extra explanatory comments
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.

3 participants