-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Enable text-offset
with variable label placement
#8642
Conversation
5edb0b0
to
cfc3284
Compare
cc @mapbox/map-design-team @mapbox/studio |
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.
This will need an update to the style-spec and their docs as well before merge.
In addition to the docs change, this is also likely to break styles where both text-variable-anchor
has been specified without text-radial-offset
. In those cases the text-offset
is being ignored at present, but this change would consider it when computing the radial offset. This behavior change will need to be called out clearly.
The advantage of this approach is that it won't break the existing styles, as at the moment using of |
Done in the latest commit, please take a look |
I'd be in favour of remove the two-component radial offset if we implement this for text-offset. I'll take another closer look at the implementation after a studio/map design review but it looks good! |
I don't believe it's not allowed, instead having one means the other is ignored. In Studio, if you set text-offset, then set text-variable-anchor, the text-offset value is not removed from your stylesheet. To @asheemmamoowala's point, this does have the potential to break some maps and we would need to call it out. The impact may be somewhat contained as radial offset is a relatively new feature in Studio. The changes to the style spec look good to me. |
@ansis could you take a look at the implementation? |
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.
Thanks for fixing comment, from my side, lgtm
As for the final approval, would be great get ✔️ from @ansis @asheemmamoowala
One thing I want to make sure is that this change still works if users enter in negative values into One way to make this happen is to take the absolute value of the user input, and then manipulate the signs of the The documentation for
(Technically sometimes the value adjusted to 0, which arguably isn't captured in "the signs of values." I couldn't think of a concise, elegant way to explicitly capture that and I think it's probably alright to leave that out.) cc @mapbox/map-design-team |
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.
Just have a couple comments:
- Instead of ignoring negative values in
text-offset
, can absolute value be used ? - Can the size of the render test images be reduced?
"version": 8, | ||
"metadata": { | ||
"test": { | ||
"height": 256, |
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.
We try to keep the image sizes as small as possible. Would 64x64 work? Curious if you made it large for variable-anchor placements to be applicable.
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.
Thanks for noticing! 64x64 is too small, but 128x128 fits very well
@asheemmamoowala @chloekraw thanks for your comments! Applied in the latest commits. |
src/style-spec/reference/v8.json
Outdated
@@ -2214,7 +2214,7 @@ | |||
}, | |||
"text-offset": { | |||
"type": "array", | |||
"doc": "Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up.", | |||
"doc": "Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up. Note that in combination with `text-variable-anchor` absolute values are used and they indicate radial offsets along x- and y-axis accordingly.", |
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.
@pozdnyakov few nits with this documentation entry:
Note that in combination with
text-variable-anchor
absolute values are used and they indicate radial offsets along x- and y-axis accordingly."
- Can "radial offset" be accurately applied here if the offset methodology is rectangular?
- Remove "note that"
- Start sentence with "If used with
text-variable-anchor
," (seems more consistent with other docs entries) - It's a bit ambiguous what "they" refers to and what's taken as absolute values
My preferred entry:
If used with
text-variable-anchor
, input values will be taken as absolute values. Offsets along the x- and y-axis will be applied automatically based on the anchor position.
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.
Thanks for your proposal!
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 left notes in two spots where I think things could be a bit clearer but overall this looks great! thanks
src/data/bucket/symbol_attributes.js
Outdated
@@ -96,7 +96,7 @@ export const symbolInstance = createLayout([ | |||
{ type: 'Uint16', name: 'numIconVertices' }, | |||
{ type: 'Uint32', name: 'crossTileID' }, | |||
{ type: 'Float32', name: 'textBoxScale'}, | |||
{ type: 'Float32', name: 'radialTextOffset'} |
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.
Would renaming this to something else like variableTextOffset
make it clearer that it isn't just the radial offset property that gets stored here?
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.
Maybe textOffset
is even better, once assigned, it is not variable any more here 🤔
} | ||
|
||
return [x, y]; |
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.
Number.POSITIVE_INFINITY
is useful because it can be stored in the Float32Array. I think it's a bit unintuitive and could maybe be made clearer. Do you have any ideas how this could be done?
Maybe using an object here ( { isRadial: false, x: 1, y: 2 }
)?
And maybe moving the line radialTextOffset1 = Number.POSITIVE_INFINITY;
even closer to the line where symbol instance is created so that it is clear that it is being encoded?
I don't have super clear ideas on how this could be better but I know it wasn't clear what was happening without looking elsewhere.
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've introduced const INVALID_TEXT_OFFSET = Number.POSITIVE_INFINITY;
, hope it will improve readability
This PR allows using of `text-offset` together with `text-variable-anchor`, if `text-radial-offset` is not provided. Assuming we got `text-offset` [x, y] the offset is calculated based on the `text-variable-anchor` values as following: "left": [-x, 0] "right": [x, 0] "top": [0, -y] "bottom": [0, y] "top-left": [-x, -y] "top-right": [x, -y] "bottom-left": [-x, y] "bottom-right": [x, y] We allow only positive `text-offset` values for simplicity.
Co-Authored-By: Asheem Mamoowala <[email protected]>
Also, render tests image size was decreased.
62d00bf
to
36dbda2
Compare
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.
Looks great, thank you @pozdnyakov!
This PR allows using of
text-offset
together withtext-variable-anchor
, iftext-radial-offset
is not provided. Assumingtext-offset
values are [x, y] the offset is calculated based on thetext-variable-anchor
values as following:"left": [-x, 0]
"right": [x, 0]
"top": [0, -y]
"bottom": [0, y]
"top-left": [-x, -y]
"top-right": [x, -y]
"bottom-left": [-x, y]
"bottom-right": [x, y]
We allow only positive
text-offset
values for simplicity.This is an alternate approach to #8609
Fixes #8598