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

Fast Text width & height #189

Closed
vilterp opened this Issue Mar 6, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@vilterp

vilterp commented Mar 6, 2015

Adding something like textWidth : Text -> Float and textHeight : Text -> Float to either Graphics.Collage or Text would be nice for laying out graphics which include text, but also forms. I suspect using the canvas's measureText method would be faster than the current way of getting text width & height, which is making the text into an element and using widthOf, which uses the DOM.

This would be a good addition to the recent change allowing direct rendering of text to canvas (#118).

I'm currently developing an app in which elements containing text are dragged and dropped. Constructing the Forms every frame from the data model involves getting the widths of each piece of text, and according to the Chrome profiler getting this width (the htmlHeight method) is taking up the most time of anything in my code on each frame.

@vilterp vilterp changed the title from Fast Text width & heigh to Fast Text width & height Mar 6, 2015

@vilterp

This comment has been minimized.

Show comment
Hide comment
@vilterp

vilterp Apr 9, 2015

Here's a test showing measureText being 15x faster when I ran it (120k ops/sec vs. 8k ops/sec): https://jsperf.com/text-measurement-element-vs-canvas

vilterp commented Apr 9, 2015

Here's a test showing measureText being 15x faster when I ran it (120k ops/sec vs. 8k ops/sec): https://jsperf.com/text-measurement-element-vs-canvas

@vilterp vilterp referenced this issue Apr 21, 2015

Merged

upgrade to 0.15 #35

@vilterp

This comment has been minimized.

Show comment
Hide comment
@vilterp

vilterp May 5, 2015

Implemented this as a native module in elm-diagrams; unfortunately canvas and DOM do not measure text width the same way, and canvas does not measure text height at all (see vilterp/elm-diagrams#36). So, not sure how to go about this.

vilterp commented May 5, 2015

Implemented this as a native module in elm-diagrams; unfortunately canvas and DOM do not measure text width the same way, and canvas does not measure text height at all (see vilterp/elm-diagrams#36). So, not sure how to go about this.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz May 11, 2016

Member

Sorry this did not get attention til now! The Graphics.* modules now live in evancz/elm-graphics so I am trying to get stuff migrated over there.

That said, I would like to keep that API stable for now. I expect to be focusing on <canvas> for professional users and "friendly graphics" for learning as separate use cases. Progress will be made when those start happening.

Member

evancz commented May 11, 2016

Sorry this did not get attention til now! The Graphics.* modules now live in evancz/elm-graphics so I am trying to get stuff migrated over there.

That said, I would like to keep that API stable for now. I expect to be focusing on <canvas> for professional users and "friendly graphics" for learning as separate use cases. Progress will be made when those start happening.

@evancz evancz closed this May 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment