Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

[core] Enable property functions for text-{field,transform} - #7944

Merged
jfirebaugh merged 18 commits into
masterfrom
dds-text-field-transform
Feb 17, 2017
Merged

jfirebaugh merged 18 commits into
masterfrom
dds-text-field-transform

Conversation

@anandthakker

Copy link
Copy Markdown
Contributor

So, I got to what I thought should at least compile here so that I could try it / iterate, but ran into this semi-mysterious compiler error:

▸ Compiling parser.cpp

❌  /Users/anand/c/mapbox/mapbox-gl-native/include/mbgl/style/conversion/function.hpp:333:20: no matching constructor for initialization of 'CompositeFunction<std::__1::basic_string<char> >'

            return CompositeFunction<T>(*propertyString, convertedStops, *defaultValue);
                   ^                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



❌  /Users/anand/c/mapbox/mapbox-gl-native/include/mbgl/style/conversion/function.hpp:333:20: no matching constructor for initialization of 'CompositeFunction<mbgl::style::TextTransformType>'

            return CompositeFunction<T>(*propertyString, convertedStops, *defaultValue);
      ^

Telling that this has something to do with style functions, and the types here are string and TextTransformType -- precisely the ones I'm expecting to get via layout.evaluate<TextField>(zoom, *feature) and layout.evaluate<TextTransform>(zoom, *feature) in symbol_layout. (This seems to work fine for IconOffset and IconRotate.)

I'll keep messing w/ it, just flagging here in case it's something I'm unlikely to find on my own.

cc @jfirebaugh

@mention-bot

Copy link
Copy Markdown

@anandthakker, thanks for your PR! By analyzing this pull request, we identified @jfirebaugh, @1ec5 and @boundsj to be potential reviewers.

@anandthakker

anandthakker commented Feb 4, 2017 •

Copy link
Copy Markdown
Contributor Author

Ah, hmm: the generated MGLSymbolStyleLayerTests.mm attempts to construct CompositeFunction<std::string> and CompositeFunction<mbgl::style::TextTransformType>, which are specifically what the two errors are complaining about. Seems promising.

@anandthakker

Copy link
Copy Markdown
Contributor Author

Okay, maybe not: I didn't trust the "Comiling parser.cpp" in the make output, but building in Xcode where I can trace the error, it does indeed originate there.

@anandthakker

Copy link
Copy Markdown
Contributor Author

Alright, new hypothesis: the new data driven properties I'm adding here, text-field and text-transform, appear to the the first non-interpolatable properties to be implemented. I think perhaps that the problem is:

  • We enforce at compile-time that if T is not interpolatable, then CompositeFunction<T>::Stops must be a map from float to IntervalStops or CategoricalStops (not ExponentialStops).
  • However, here in conversion/function.hpp, we construct it with ExponentialStops. (I think this couldn't actually happen at runtime?)

@anandthakker

anandthakker commented Feb 5, 2017 •

Copy link
Copy Markdown
Contributor Author

Took a crack at solving the issue w/ converting non-interpolatable in 941c7a8, using std::enable_if to differentiate results based on the predicate Interpolatable<T>.

@jfirebaugh is there a cleaner or more idiomatic way to do this?

Value to use for a text label. Feature properties are specified using tokens
like {field_name}.
like {field_name}. (Token replacement is only supported for literal text-field
values--not for data-driven property functions.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you add this note manually after running make style-code? If so, it’ll be wiped away the next time someone runs make style-code. Make sure to put any documentation overrides in platform/darwin/scripts/style-spec-overrides-v8.json.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nope! The note comes directly from the description of this property in v8.json

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I was confused because this page doesn’t include the new wording.

Value to use for a text label. Feature properties are specified using tokens
like {field_name}.
like {field_name}. (Token replacement is only supported for literal text-field
values--not for data-driven property functions.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Surround “text-field” in backticks. This allows generate-style-code.js to replace it with text (the overridden name of this property).

Value to use for a text label. Feature properties are specified using tokens
like {field_name}.
like {field_name}. (Token replacement is only supported for literal text-field
values--not for data-driven property functions.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is a “data-driven property function”? An MGLSourceStyleFunction?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hm, yeah good point, I should have been more precise with the language here. I'll ticket this in -gl-js, along with the backtick thing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An override in style-spec-overrides-v8.json is probably inevitable, because the style specification doesn’t yet refer to “source functions”: mapbox/mapbox-gl-js#4154.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, okay. I suppose, in that case, that the least confusion-causing thing to do might be to just drop the parenthetical in the style-spec-overrides-v8.json, since there's no established vocabulary for these function types yet?

@1ec5 what do you think?

@1ec5 1ec5 Feb 6, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It’s a good point to document. There’s no harm in using one term in the style specification and overriding it here to refer to the specific class (MGLSourceStyleFunction); that’s what style-spec-overrides-v8.json was designed for.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah okay, I misunderstood: there is a publicly documented way to refer to it. It'll need to refer to both MGLSourceStyleFunction and MGLCompositeStyleFunction.

@1ec5 1ec5 added Core The cross-platform C++ core, aka mbgl runtime styling labels Feb 5, 2017
@1ec5 1ec5 added this to the ios-v3.5.0 milestone Feb 5, 2017
anandthakker added a commit to mapbox/mapbox-gl-js that referenced this pull request Feb 6, 2017
@jfirebaugh

Copy link
Copy Markdown
Contributor

CameraFunction and SourceFunction avoid attempting to construct ExponentialStops for a non-interpolatable type via StopsConverter, which is templated on the possible variant types (e.g. from here). The implementation of StopsConverter loops through the possible stop types statically using parameter pack expansion, testing each in turn. (This code is far from obvious -- sorry I neglected to comment it.)

We should follow a similar approach for CompositeFunction. And likewise default to IntervalStops if the type is non-interpolatable.

@anandthakker
anandthakker force-pushed the dds-text-field-transform branch from 7f984e1 to 70c994e Compare February 7, 2017 21:28
anandthakker added a commit to mapbox/mapbox-gl-js that referenced this pull request Feb 8, 2017
anandthakker added a commit to mapbox/mapbox-gl-js that referenced this pull request Feb 8, 2017
@anandthakker
anandthakker force-pushed the dds-text-field-transform branch from 70c994e to e1e975d Compare February 8, 2017 16:57
@anandthakker

Copy link
Copy Markdown
Contributor Author

@boundsj @1ec5 I'm seeing a compiler error in MGLStyleValue_Private.h that I think is analogous to the one discussed above (here and here): namely, there's a branch of code that is only reachable at runtime if the underlying type for the MGLCompositeStyleFunction is interpolatable, but it fails at compile-time because we are trying to construct a composite function with a string output type.

Could you point me in the right direction for the ideal way to resolve this?

@boundsj

boundsj commented Feb 8, 2017

Copy link
Copy Markdown
Contributor

@anandthakker these conditionals in MGLStyleLayer.mm.ejs generate an implementation that is compatible with the static type checking by calling either the toPropertyValue or toInterpolatablePropertyValue methods in MGLStyleValue_Private.h depending on whether the property is interpolatable or not.

Following that convention, the existing toDataDrivenPropertyValue in MGLStyleValue_Private.h could be renamed toInterpolatableDataDrivenPropertyValue and a toDataDrivenPropertyValue conversion method could be added (for the non-interpolatable case) that does not attempt to create invalid functions like the one noted above. MGLStyleLayer.mm.ejs would then need to be updated with another conditional to call that method for these new non-interpolatable data driven property values.

Note that we don't have this problem with the getter implementation (going from the C++ objects back to Objective-C) since we use the PropertyValueEvaluator in MGLStyleValue_Private.h with stops visitors that works with all the possible variant types. Since the setters (Objective-C to C++) can't take advantage of generics in this way, I'm not sure if there is a better option than what I described above (adding a new specific method and calling it based on the property capabilities).

cc @1ec5 @jfirebaugh

@1ec5

1ec5 commented Feb 8, 2017 •

Copy link
Copy Markdown
Contributor

Following that convention, the existing toDataDrivenPropertyValue in MGLStyleValue_Private.h could be renamed toInterpolatableDataDrivenPropertyValue and a toDataDrivenPropertyValue conversion method could be added (for the non-interpolatable case) that does not attempt to create invalid functions like the one noted above.

To avoid code duplication, we could split off the MGLCompositeStyleFunction case from toDataDrivenPropertyValue() into two toCompositeDataDrivenPropertyValue() methods, one of them a stub that’s conditioned (via std::enable_if) on whether MBGLType is TextTransformType etc. toDataDrivenPropertyValue() would call toCompositeDataDrivenPropertyValue() like normal.

anandthakker added a commit to mapbox/mapbox-gl-js that referenced this pull request Feb 9, 2017
@anandthakker
anandthakker force-pushed the dds-text-field-transform branch from e1e975d to b647388 Compare February 9, 2017 23:26
@anandthakker

Copy link
Copy Markdown
Contributor Author

Followup on #7944 (comment): As I started digging into resolving the compilation issues in the MGLCompositeStyleFunction => mbgl::style::CompositeFunction conversion today, it felt like I was solving the same problems that are being solved by mbgl::style::conversion::*.

I'm now thinking that we should accomplish the MGL => mbgl conversion — at least for property values — by having the darwin platform bindings implement the Value conversions required to leverage the existing mbgl::style::conversion system. This will hopefully mean less code/logic duplication and better maintainability.

@1ec5 notes:

The only catch I can think of is that you can't overload a method based on ObjC class types and expect it to respect inheritance.

I'll dig into this tomorrow AM -- hopefully the ObjC overloading thing is not a dealbreaker

anandthakker added a commit to mapbox/mapbox-gl-js that referenced this pull request Feb 14, 2017
@anandthakker
anandthakker force-pushed the dds-text-field-transform branch from b647388 to 53b9147 Compare February 14, 2017 17:03
anandthakker added a commit to mapbox/mapbox-gl-js that referenced this pull request Feb 15, 2017
anandthakker added a commit to mapbox/mapbox-gl-js that referenced this pull request Feb 15, 2017
anandthakker added a commit to mapbox/mapbox-gl-js that referenced this pull request Feb 15, 2017
Anand Thakker added 7 commits February 16, 2017 13:25
Tweak the generated inline docs for text-field -- note that this was
done by manually changing modifying an older version of v8.json and
running `make darwin-style-code`; this is because the current version of
mapbox-gl-js includes changes that enable property functions for symbol
properties that are not yet implemented here, so that generating style
code from the version of the submodule referenced here will NOT work.
 - Do not test ExponentialStops for non-interpolatable types
 - Remove erroneous assertions for `piecewise-constant` function types
@anandthakker
anandthakker force-pushed the dds-text-field-transform branch from 76c3051 to fe1c70e Compare February 16, 2017 22:03
@anandthakker

Copy link
Copy Markdown
Contributor Author

Couple pieces of unfinished business addressed since @jfirebaugh 's 🍏 :

  1. The conversion system refactor failed to account for Enums properly. Handled that here: 462cd0d (with a small fixup for colors in 3b83f01)
  2. The MGLStyleLayerTests template needed a couple of fixes. Easiest to read those changes here

@boundsj or @1ec5 could I get 👀 from one of you on these changes?

@1ec5

1ec5 commented Feb 16, 2017

Copy link
Copy Markdown
Contributor

Can you add tests to exercise enums, colors, and other types, which should’ve failed in #8026?


functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeInterval compositeStops:@{@18: constantStyleValue} attributeName:@"" options:nil];
XCTAssertThrowsSpecificNamed(layer.fillAntialiased = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it");
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"" options:nil];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing indentation.

NSObject* toRawStyleSpecValue(NSObject *rawMGLValue, MBGLEnum &mbglValue) {
if ([rawMGLValue isKindOfClass:[NSValue class]]) {
const auto rawNSValue = (NSValue *)rawMGLValue;
if (strcmp([rawNSValue objCType], @encode(CGVector)) == 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By the way, I see special handling for CGVector values, but not NSEdgeInsets/UIEdgeInsets values. Do we need it too? Here’s the full correspondence between JSON and Foundation types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a good catch. I've ticketed it out here as part of the completionist quest to propagate this approach to all of the MGL=>mbgl style property value conversions (or, at least the runtime-styling ones...)

@anandthakker

anandthakker commented Feb 16, 2017 •

Copy link
Copy Markdown
Contributor Author

Can you add tests to exercise enums, colors, and other types, which should’ve failed in #8026?

  • Colors are covered in MGLStyleValueTests::testFunctionsWithDataDrivenProperties()
  • Enums and strings are covered in MGLSymbolLayerTests::testProperties() (text-transform and text-field, respectively)
  • Numbers and strings are covered covered in MGLCircleLayerTests::testProperties() (circle-radius)

I think what's missing here are the array-based types -- which, you're right, include NSEdgeInset/UIEdgeInsetValues that we still need special-case handling for.

Currently, there is no unit test specific to MGLStyleValueTransformer -- instead, the code therein gets exercised via the style layer tests. One option is to create some unit tests specific to MGLStyleValueTransformer. Another is to wait for DDS support to be implemented for style properties with these array-based types, which will result in their conversions being exercised in the style layer tests. My gut feeling is that MGLStyleValueTransformer is not an especially meaningful abstraction, and thus encoding unit tests against it would create more maintenance burden than testing value.

@anandthakker

Copy link
Copy Markdown
Contributor Author

@1ec5 fixed the indentation issue and responded above on the two other issues you raised -- I think they're both covered by #8088 and not urgent to resolve before that... what do you think?

@anandthakker

Copy link
Copy Markdown
Contributor Author

@mapbox/android after fixing a small typo, the android bitrise build passed, but could I get quick 👀 on this before it goes in? The android-related changes are conveniently in three consecutive files in the diff, starting here: https://github.com/mapbox/mapbox-gl-native/pull/7944/files#diff-ffc041b38fb81bccaa2c261dbc6b938e

@jfirebaugh
jfirebaugh merged commit 062b183 into master Feb 17, 2017
@jfirebaugh
jfirebaugh deleted the dds-text-field-transform branch February 17, 2017 21:16
ivovandongen added a commit that referenced this pull request Feb 20, 2017
ivovandongen added a commit that referenced this pull request Feb 20, 2017
ivovandongen added a commit that referenced this pull request Feb 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Core The cross-platform C++ core, aka mbgl runtime styling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants