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

update style generation code for new style spec enum values docs #6508

Merged
merged 16 commits into from
Sep 30, 2016

Conversation

incanus
Copy link
Contributor

@incanus incanus commented Sep 29, 2016

Downstream work for mapbox/mapbox-gl-style-spec#510.

  • core
  • Darwin
  • Android

/cc @1ec5 @frederoni @ivovandongen

@incanus incanus added iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS Android Mapbox Maps SDK for Android documentation release blocker Blocks the next final release runtime styling labels Sep 29, 2016
@incanus incanus added this to the ios-v3.4.0 milestone Sep 29, 2016
@incanus incanus self-assigned this Sep 29, 2016
@mention-bot
Copy link

@incanus, thanks for your PR! By analyzing this pull request, we identified @jfirebaugh, @mikemorris and @yhahn to be potential reviewers.

@incanus
Copy link
Contributor Author

incanus commented Sep 29, 2016

Only thing I'm not crazy about with e9be66b is failure to fully get NS_ENUM values, e.g.:

typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerIconRotationAlignment) {
    /**
     When `symbolPlacement` is set to `point`, aligns icons east-west. When `symbolPlacement` is set to `line`, aligns icon x-axes with the line.
     */
    MGLSymbolStyleLayerIconRotationAlignmentMap,
    /**
     Produces icons whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbolPlacement`.
     */
    MGLSymbolStyleLayerIconRotationAlignmentViewport,
    /**
     When `symbolPlacement` is set to `point`, this is equivalent to `viewport`. When `symbolPlacement` is set to `line`, this is equivalent to `map`.
     */
    MGLSymbolStyleLayerIconRotationAlignmentAuto,
};

Note the point, line, viewport, etc.

Do we get this nitpicky?

@incanus incanus added ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold ✓ ready for review and removed ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold labels Sep 29, 2016
@1ec5
Copy link
Contributor

1ec5 commented Sep 29, 2016

Do we get this nitpicky?

Yes. The existing logic is robust enough to handle values of the property currently being described (first-person values), but not enough to handle values of another property being referenced (third-person values).

@1ec5
Copy link
Contributor

1ec5 commented Sep 29, 2016

We can maybe detect constructions such as “x is set to y” and find candidate values accordingly.

Getting this right will ensure that jazzy can autolink the referenced symbols. I think autolinking is important for enabling users to effectively navigate our documentation, which is spread out among many headers or many webpages.

@@ -31,7 +31,8 @@ namespace conversion {
//<%- property.name %>
inline std::string toString(mbgl::style::<%- propertyNativeType(property) %> value) {
switch (value) {
<% for (const value of property.values) { -%>
<% for (const value in property.values) { -%>
//<%- property.values[value].doc %>
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a left-over comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@incanus
Copy link
Contributor Author

incanus commented Sep 29, 2016

@ivovandongen Curious about your feedback again now after 0c8cc78 and c58f90a.

@incanus
Copy link
Contributor Author

incanus commented Sep 29, 2016

Working on some final Darwin-side propertyDoc() enhancements still. I may try something similar on the Android side after, but considering we didn't even have enum values documented at all in Java until c58f90a, this may not be high priority.

@@ -6,13 +6,31 @@

NS_ASSUME_NONNULL_BEGIN

/**
Controls the translation reference point.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the enums are on a different page than the properties that use them, perhaps this documentation could mention those properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I follow @1ec5.

Copy link
Contributor

Choose a reason for hiding this comment

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

For example:

Used by the MGLCircleStyleLayer.circleTranslateAnchor property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tail work per #6508 (comment).

typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerIconRotationAlignment) {
/**
When `symbolPlacement` is set to `point`, aligns icons east-west. When `symbolPlacement` is set to `line`, aligns icon x-axes with the line.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hopefully we can rely on this “x is set to y” phrase and expand y to the right enum value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done pending improvements in #6508 (comment).

@@ -178,7 +310,7 @@ typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerTextTranslateAnchor) {

The default value of this property is an `NSValue` object containing `NSEdgeInsetsZero` or `UIEdgeInsetsZero`. Set this property to `nil` to reset it to the default value.

This property is only applied to the style if `iconImage` is non-`nil`, and `iconTextFit` is non-`nil`, and `textField` is non-`nil`. Otherwise, it is ignored.
This property is only applied to the style if `iconImage` is non-`nil`, and `textField` is non-`nil`, and `iconTextFit` is set to an `NSValue` object containing `MGLSymbolStyleLayerIconTextFitBoth`, `MGLSymbolStyleLayerIconTextFitWidth`, or `MGLSymbolStyleLayerIconTextFitHeight`. Otherwise, it is ignored.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 This takes care of #6448 (comment).

@@ -143,7 +143,7 @@ public FillLayer withProperties(@NonNull Property<?>... properties) {
return (PropertyValue<String>) new PropertyValue(nativeGetFillColor());
}
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Some funky indentation going on 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.

Think I got this in caeee4f.

@incanus
Copy link
Contributor Author

incanus commented Sep 29, 2016

Got the last mile of Darwin docs in e08bc5a. Formatting rules documented in generate-style-code.js itself.

@incanus
Copy link
Contributor Author

incanus commented Sep 29, 2016

@ivovandongen To build on #6508 (comment), 1325127 brings over some of the logic from Darwin where we properly format symbol names in the PropertyFactory docs.

Before:

screen shot 2016-09-29 at 4 21 02 pm

After:

screen shot 2016-09-29 at 4 21 20 pm

Note how we go from referring to fill-color (GL style spec) to fillColor (Android property name).

Previously, unlike on Darwin, we didn't refer to symbols as they actually appear in the Android API, which can be confusing and lose people.

A few more questions about how much further we should go on this:

  • Is there a way in JavaDoc that we can cross-link these symbols for better discoverability rather than just surround them in backticks? If so, should we do this?

  • As of changes like mapbox/mapbox-gl-style-spec@742bc7a, we move certain documentation from the enum property names to the values. However, on Android, since this is through PropertyFactory and uses primitives like string, float, etc., we don't actually document the existence of enum values (again, unlike on Darwin; see for example for each of butt, round, and square here). I think that we should, but I'm not sure where this sort of thing would go. We should be documenting for users the range of possibilities to use in the runtime styling API.

    Compare iOS:

    /**
    Label placement relative to its geometry.
    */
    typedef NS_ENUM(NSUInteger, MGLSymbolStyleLayerSymbolPlacement) {
        /**
         The label is placed at the point where the geometry is located.
         */
        MGLSymbolStyleLayerSymbolPlacementPoint,
        /**
         The label is placed along the line of the geometry. Can only be used on `LineString` and `Polygon` geometries.
         */
        MGLSymbolStyleLayerSymbolPlacementLine,
    };

    To Android:

    /**
    * Label placement relative to its geometry.
    *
    * @param function a wrapper function for String
    * @return property wrapper around a String function
    */
    public static Property<Function<String>> symbolPlacement(Function<String> function) {
        return new LayoutProperty<>("symbol-placement", function);
    }

Note how we lost context like the fact that SYMBOL_PLACEMENT_LINE can only be used on LineString and Polygon geometries, or even that SYMBOL_PLACEMENT_POINT and SYMBOL_PLACEMENT_LINE are the options here.

/cc @tobrun @zugaldia

global.propertyDoc = function (propertyName, property, layerType) {
// Match references to other property names & values.
// Requires the format 'When `foo` is set to `bar`,'.
let doc = property.doc.replace(/When `(.+?)` is set to `(.+?)`,/g, function (m, peerPropertyName, propertyValue, offset, str) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is "When" needed? If so, can it be case-insensitive using the i flag? Is the comma needed? I think we should try to avoid coupling too tightly to how things are worded right now, because the style spec repo doesn't have any documentation that would inform a contributor that they need to worry about these details.

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 tried without the When and comma, but ran into issues that crossed sentence boundaries. I can try to refine it further.

Copy link
Contributor

@1ec5 1ec5 Sep 30, 2016

Choose a reason for hiding this comment

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

If the +? is matching too greedily for some reason, you can replace . with:

[^`]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Specifically I tried things like .[^\.]+? in the regex to avoid sentence-spanning over periods. Will take another crack.

Copy link
Contributor

Choose a reason for hiding this comment

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

> "When `foo` is set to `bar`, `baz` is set to `boo`.".match(/`(.+?)` is set to `(.+?)`/g)
[ "`foo` is set to `bar`", "`baz` is set to `boo`" ]
> "When `foo` is set to `bar`, `baz` becomes `boo`. When `moo` is set to `goo`, `oog` becomes `oop`.".match(/`(.+?)` is set to `(.+?)`/g)
[ "`foo` is set to `bar`", "`baz` becomes `boo`. When `moo` is set to `goo`" ]
> "When `foo` is set to `bar`, `baz` becomes `boo`. When `moo` is set to `goo`, `oog` becomes `oop`.".match(/`([^`]+?)` is set to `([^`]+?)`/g)
[ "`foo` is set to `bar`", "`moo` is set to `goo`" ]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tail work per #6508 (comment).

@1ec5
Copy link
Contributor

1ec5 commented Sep 30, 2016

Is there a way in JavaDoc that we can cross-link these symbols for better discoverability rather than just surround them in backticks? If so, should we do this?

{@SNAKES_ON_A_LAYER}

We should be documenting for users the range of possibilities to use in the runtime styling API.

How about a <dl> in the existing comments for the property factory methods?

//visibility
/**
* Layer visibility
*/
public static final String VISIBLE = "visible";
Copy link
Contributor

Choose a reason for hiding this comment

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

@incanus If you document in this way, it is only applied to the first constant VISIBLE. The // I used don't show up at all in javadoc. I use those more as you'd use #pragma mark, to organize the source, not to document. If you apply javadoc, you need to do it on all constants I'm afraid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/**
* `line-cap`: The display of line endings.
*/
//A cap with a squared-off end which is drawn to the exact endpoint of the line.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here. I would invert this, start the header with // and the individual comments with /** */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ivovandongen
Copy link
Contributor

Is there a way in JavaDoc that we can cross-link these symbols for better discoverability rather than just surround them in backticks? If so, should we do this?

http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html#CHDDIECH

@incanus
Copy link
Contributor Author

incanus commented Sep 30, 2016

Still pushing on Android finishing work here per discussion with @ivovandongen and more learnin' in the JavaDocs department.

@incanus
Copy link
Contributor Author

incanus commented Sep 30, 2016

The JavaDoc stuff gets tricky since we don't know the argument quantity or types, which only lets us do something like {@link symbolPlacement} and not the {@link symbolPlacement(string)} that is required for actual linking. Per http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html we could just use <code>symbolPlacement</code> instead. Doing some experiments.

@incanus
Copy link
Contributor Author

incanus commented Sep 30, 2016

I'm going to flag some things above in response to comments as tail work. The main goal here is to get use of enum docs on the books and improve over current master. Then we can incrementally make these all better across all platforms.

@incanus
Copy link
Contributor Author

incanus commented Sep 30, 2016

We should be documenting for users the range of possibilities to use in the runtime styling API.

How about a <dl> in the existing comments for the property factory methods?

Tail work per #6508 (comment).

incanus added a commit to mapbox/mapbox-gl-style-spec that referenced this pull request Sep 30, 2016
Adds `doc` property to all enum `values`, moving them from JSON arrays to objects. 

Downstream mobile SDK work in mapbox/mapbox-gl-native#6508.
Downstream Studio work in mapbox/studio#7765. 

Fixes a typo in `icon-text-fit`. 

Also updates validation, docs generation, and tests.
@incanus
Copy link
Contributor Author

incanus commented Sep 30, 2016

Tail work tickets: #6540, #6541, #6542.

@1ec5 Mind reviewing again and getting this ready to 🚢?

@1ec5
Copy link
Contributor

1ec5 commented Sep 30, 2016

The Qt build failed; looks like a spurious core test failure:

[ RUN      ] Timer.StartOverrides
../../../test/util/timer.test.cpp:165: Failure
Expected: (totalTime) <= (expectedTotalTime * 1.2), actual: 8-byte object <B4-05 00-00 00-00 00-00> vs 8-byte object <00-00 00-00 00-80 76-40>
[  FAILED  ] Timer.StartOverrides (1469 ms)

@incanus
Copy link
Contributor Author

incanus commented Sep 30, 2016

Restarted tests and all now pass. Working on merge now.

@incanus incanus merged commit ee4715a into master Sep 30, 2016
@incanus incanus deleted the style-spec-enum-docs branch September 30, 2016 22:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android documentation iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS release blocker Blocks the next final release runtime styling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants