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

Enable text-offset with variable label placement #8642

Merged
merged 8 commits into from
Aug 30, 2019

Conversation

pozdnyakov
Copy link
Contributor

@pozdnyakov pozdnyakov commented Aug 15, 2019

This PR allows using of text-offset together with text-variable-anchor, if text-radial-offset is not provided. Assuming text-offset values are [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]

download

We allow only positive text-offset values for simplicity.

This is an alternate approach to #8609

Fixes #8598

@asheemmamoowala
Copy link
Contributor

cc @mapbox/map-design-team @mapbox/studio

Copy link
Contributor

@asheemmamoowala asheemmamoowala left a 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.

@pozdnyakov
Copy link
Contributor Author

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.

The advantage of this approach is that it won't break the existing styles, as at the moment using of text-offset together with text-variable-anchor is not allowed by the style specification 😄

@pozdnyakov
Copy link
Contributor Author

This will need an update to the style-spec and their docs as well before merge.

Done in the latest commit, please take a look

@ansis
Copy link
Contributor

ansis commented Aug 20, 2019

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!

@dereklieu
Copy link
Contributor

at the moment using of text-offset together with text-variable-anchor is not allowed by the style specification

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.

@asheemmamoowala asheemmamoowala added this to the release-ristretto milestone Aug 22, 2019
@asheemmamoowala
Copy link
Contributor

@ansis: I'll take another closer look at the implementation after a studio/map design review but it looks good!

@dereklieu : The changes to the style spec look good to me.

@ansis could you take a look at the implementation?

Copy link
Contributor

@alexshalamov alexshalamov left a 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

@chloekraw
Copy link
Contributor

We allow only positive text-offset values for simplicity.

One thing I want to make sure is that this change still works if users enter in negative values into text-offset for backwards compatibility and user-friendliness reasons. Imagine you have text-offset set based on the documentation and then you decide to add text-variable-anchor to your style. You might assume it will just work.

One way to make this happen is to take the absolute value of the user input, and then manipulate the signs of the x,y values based on the anchor position, according to the logic from #8642 (comment). Are we doing this in the current implementation?

The documentation for text-offset could then read something like:

Layout property. Optional array of numbers. Units in ems. Defaults to [0,0]. Requires text-field. Disabled by text-radial-offset. Disabled by text-variable-anchor.

Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up.

If used with text-variable-anchor, the signs of values are automatically adjusted based on the current anchor position.

(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

Copy link
Contributor

@asheemmamoowala asheemmamoowala left a 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?

src/style-spec/reference/v8.json Outdated Show resolved Hide resolved
src/symbol/symbol_layout.js Show resolved Hide resolved
"version": 8,
"metadata": {
"test": {
"height": 256,
Copy link
Contributor

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.

Copy link
Contributor Author

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

@pozdnyakov
Copy link
Contributor Author

@asheemmamoowala @chloekraw thanks for your comments! Applied in the latest commits.

@ansis ansis requested review from tristen and removed request for tristen August 28, 2019 15:03
@@ -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.",
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your proposal!

Copy link
Contributor

@ansis ansis left a 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

@@ -96,7 +96,7 @@ export const symbolInstance = createLayout([
{ type: 'Uint16', name: 'numIconVertices' },
{ type: 'Uint32', name: 'crossTileID' },
{ type: 'Float32', name: 'textBoxScale'},
{ type: 'Float32', name: 'radialTextOffset'}
Copy link
Contributor

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?

Copy link
Contributor Author

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];
Copy link
Contributor

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.

Copy link
Contributor Author

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

pozdnyakov and others added 4 commits August 29, 2019 18:27
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 <asheem.mamoowala@mapbox.com>
@pozdnyakov pozdnyakov force-pushed the mikhail_text_offset_variable_anchor branch from 62d00bf to 36dbda2 Compare August 29, 2019 15:57
Copy link
Contributor

@chloekraw chloekraw left a 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!

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.

text-radial-offset does not account for icon size or bounding boxes
6 participants