-
-
Notifications
You must be signed in to change notification settings - Fork 370
textlabel recipe #4879
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
textlabel recipe #4879
Conversation
Benchmark ResultsSHA: 6036fe0f7dfb2e629864b05eb6ba71892ac73210 Warning These results are subject to substantial noise because GitHub's CI runs on shared machines that are not ideally suited for benchmarking. |
|
The most common shape will be rounded rect, which you can't stretch without getting skewed corners. So meshscatter won't work unless we have a screen space aware rounded rect shader on top of a rectangle or something. |
|
Ugh that's true. So the low tech solution is poly then, probably with a struct RoundedRect{N, T} <: GeometryPrimitive{N, T}
origin::Point{N, T}
widths::Vec{N, T}
cornerradius::T
endin GeometryBasics so actually have something to pass. I've been thinking about extending scatter with some "complex" shapes before, i.e. with sdfs defined in shaders like with Rect and Circle. We could pass up to 4 parameters through uv_offset_width without adding more uniforms (does that even matter much?). RoundedRect just needs a corner radius as far as I can tell, so it would fit the bill. I assume this would end up being higher quality and better performance, so maybe it's worth spending time on for this? Iirc I originally thought about either for 2D arrows or tooltips. 2D arrows should be doable with 2 parameters - head length and tail width. Having this would again remove a lines(egments) plot, fix overlap issues for semi-transparent arrows and probably simplify the whole scaling business. Tooltips are more complicated with the little triangle, but I think we still only need a side, a position fraction and triangle size. For CairoMakie this could effectively just lower to BezierPaths. All the data for the shape generation needs to be there anyway. This could also be generalized drastically by adding a render pipeline step that accumulates sdfs instead of immediately turning them into colors. We would probably want #4689 for this though, and compatibility with CairoMakie is questionable... |
src/basic_recipes/text_background.jl
Outdated
| # FXAA generates artifacts if: | ||
| # mesh has fxaa = true and text/lines has false | ||
| # and the luma/brightness difference between text_color/strokecolor and background_color is low enough | ||
|
|
||
| # The defaults use fxaa = false to remove artifacting and use an opaque | ||
| # stroke to hide the pixelated border. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm so annoyed by this...
With how fxaa works atm I'm pretty sure there is no way to avoid these issues:
parent = Scene(backgroundcolor = :blue, size = (120, 310))
# No fxaa involved for reference
scene = Scene(parent, viewport = Rect2f(10, 250, 100, 50), backgroundcolor = :lightgray, clear = true)
text!(scene, "Test 1", fontsize = 30, align = (:center, :center))
scene
verts = Makie.roundedrectvertices(Rect2f(-0.9,-0.9,1.8,1.8), 0.5, 10)
m = Makie.poly_convert(verts)
# default fxaa settings create a fuzzy font (and lines, scatter)
scene = Scene(parent, viewport = Rect2f(10, 190, 100, 50))
mesh!(scene, m, color = :lightgray, shading = NoShading, fxaa = true)
text!(scene, "Test 2", fontsize = 30, align = (:center, :center), fxaa = false)
# no fxaa fixes fuzziness but remove aliasing on mesh
scene = Scene(parent, viewport = Rect2f(10, 130, 100, 50))
mesh!(scene, m, color = :lightgray, shading = NoShading, fxaa = false)
text!(scene, "Test 3", fontsize = 30, align = (:center, :center), fxaa = false)
# fxaa = true reduces text (scatter, lines) quality
scene = Scene(parent, viewport = Rect2f(10, 70, 100, 50))
mesh!(scene, m, color = :lightgray, shading = NoShading, fxaa = true)
text!(scene, "Test 4", fontsize = 30, align = (:center, :center), fxaa = true)
# hiding aliased border doesn't work with transparency
scene = Scene(parent, viewport = Rect2f(10, 10, 100, 50))
mesh!(scene, m, color = (:lightgray, 0.5), shading = NoShading, fxaa = false)
lines!(scene, [verts..., verts[1]], color = (:lightgray, 0.5), fxaa = false, linewidth = 4)
text!(scene, "Test 5", fontsize = 30, align = (:center, :center), fxaa = false)
parentThis could be fixed by using scatter or by reworking the render pipeline. Iirc I tried adjusting the pipeline in #4689 and had some test failures with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attributes
-
I'd say one primitive should own color/strokecolor/etc...Maybe easiest tofollow CSS:
- strokecolor is for the stroke around it
- color means text_color
- background_color (already correct)
- background_linestyle -> linestyle (border_style?)
- pad -> padding
- etc... I could also just do a renaming in the end
-
We should expand e.g. padding=2 -> (2, 2, 2, 2)
-
Should we follow text and have it
textlabel(positions; text=strings)?
Styling
Would be nice if this can look nice by default. Personally, I'd go for white bgcolor, rounded edges and some padding by default. But can also leave this up for a final review
Features
This has to work for 3d axes with draw_on_top, since that's the main use case I see for this and one reason why it's hard for a user to implement something like this.
Bugs
begin
f, ax, pl = scatter(rand(Point3f, 10), axis=(; type=Axis3))
pos = Point3f(0.5)
textlabel!(ax, pos, "MatrixSpace", pad=(10, 10, 10, 10), draw_on_top=false, cornerradius=2)
f
end
Yea that's probably easier than going back and forth.
Done
Done by pre-transforming.
Because clip planes are also inherited if
Right now it would be
I'm not a fan of that. I think generally a recipe adds more context to what passthrough attributes mean which is good to add to their names. E.g. |
…preted as origin, size
|
This is failing the Tooltip test due to text stroke and glow being included in bbox calculations. That's fine. It's also failing two WGLMakie tests due to timeouts, which I don't understand. Maybe related to these errors?
|
| points_transformed = apply_transform(transform_func, points) | ||
| function poly_convert(polygon::AbstractVector{<:VecTypes{N, T}}, transform_func=identity) where {N, T} | ||
| points2d = convert(Vector{Point2{float_type(T)}}, polygon) | ||
| points_transformed = apply_transform(transform_func, points2d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to limit the info going in to transform_func to 2D?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Iirc earcut_triangulate errored with 3D points
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we force 2D after transformation then, not before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason this is in the pr is to fix overlap in W/GLMakie. I'm effectively setting z values so that things are ordered as:
poly points 1
text 1
poly points 2
text 2
...
where all the poly points are in the same poly plot. If the z values are dropped in poly!() the elements will no longer be interleaved and you'll have the issue Julius showed #4879 (comment) on every backend again.
The change I made basically just allows z values in points to be used for z ordering. That's what I need for this pr. The other option would be to copy and paste edited parts of poly. I can do that too if that's the preferred solution.
SimonDanisch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready to merge, whenever all the problems from the last review are addressed.
|
This would be ready to merge if WGLMakie wouldn't fail to render two tests. I have no idea why those are timing out, but they do so in local CI runs for me too. They however don't if I run the code manually and display them in vscode or in firefox. Note that missing refimages do not show up as failing CI. Check refimages/ci run |
89c2f6b to
ec878c2
Compare
|
The docs page for this hasn't actually been included in the |




Description
Prototype for #4874
This adds
textlabel!()which draws some text input and renders an automatically resizedshapebehind it.TODO:
Questions:
Should this work with per-plot (and per-glyphcollection?) backgroundsType of change
Delete options that do not apply:
Checklist