[WIP] update iOS SDK guides#8354
Conversation
There was a problem hiding this comment.
Setting style functions is a subtask of configuring the map content’s appearance. I think the table mapping function types to MGLStyleFunction subclasses and MGLInterpolationMode values should be moved down here, to help progress the reader from simpler concepts to more advanced concepts.
There was a problem hiding this comment.
I agree. Especially since the tables currently repeat for each property.
There was a problem hiding this comment.
Let’s split up this table into two: one for function types and the other for interpolation modes.
There was a problem hiding this comment.
This is also a terminological difference. It’s worth mentioning that a “function type” is an “interpolation mode” up in the first table.
There was a problem hiding this comment.
Function types (“zoom”, “property”, “zoom-and-property”) don’t appear in the style JSON, only in the style specification.
There was a problem hiding this comment.
We could make this guide platform-agnostic, either by replacing UIColor with some other type like NSNumber that also exists on macOS, or by relying on type inference in Swift and the MGLColor macro in Objective-C. Then we could move this guide to platform/darwin/docs/guides/.
There was a problem hiding this comment.
MGLColor is a fine internal workaround, but I don’t believe we’ve encouraged its use publicly(?). Telling developers to use MGLColor has a couple issues:
- It’s not necessary for the vast majority of our developers (who are iOS-only).
- MGLColor’s purpose and action is opaque — actually using it has no technical downside, but the cognitive burden of learning what it is isn’t negligible. I’d expect a significant portion of our users to just assume that it’s the required way to define colors and not understand why that’s not the case.
At this point, I think it’s more reasonable to expect macOS developers to know UIColor doesn’t exist on that platform, rather than asking iOS developers to use a macro they don’t need.
There was a problem hiding this comment.
Definitely onboard with consistently using type inference in Swift, though.
There was a problem hiding this comment.
Point taken about MGLColor being pedagogically problematic. In the Mapbox API Documentation examples in Objective-C, I took to using conditional compilation macros, which are better documented but even more poorly understood by less experienced developers.
What about bringing this guide under the same codegen mechanism that the “Information for Style Authors” guide uses?
- Move this guide to platform/darwin/docs/guides/Data-Driven Styling.md.ejs.
- Define a
cocoaPrefixvariable at the top. - Put a
<% cocoaPrefix %>variable anywhere we’re currently sayingUI. - Extend generate-style-code.js to also write out iOS- and macOS-specific versions of the guide.
- Run
make style-code.
With this approach, the style-related guides would be more consistent with each other even at the code level. Additionally, it’ll give us the ability to put some of these (rather substantial) code examples in unit tests and insert them into this document automatically, ensuring that the examples stay current. We already use that approach for examples embedded in API documentation.
There was a problem hiding this comment.
Since the DDS guide currently lives in platform/ios/docs/guides/, this link is broken in the macOS generated documentation. https://github.com/mapbox/mapbox-gl-native/pull/8354/files#r105503718 would be preferable, but if we can’t do that, then we should conditionalize this sentence on the platform. There are some examples above of only including a sentence on iOS or only on macOS.
There was a problem hiding this comment.
MGLColor is a fine internal workaround, but I don’t believe we’ve encouraged its use publicly(?). Telling developers to use MGLColor has a couple issues:
- It’s not necessary for the vast majority of our developers (who are iOS-only).
- MGLColor’s purpose and action is opaque — actually using it has no technical downside, but the cognitive burden of learning what it is isn’t negligible. I’d expect a significant portion of our users to just assume that it’s the required way to define colors and not understand why that’s not the case.
At this point, I think it’s more reasonable to expect macOS developers to know UIColor doesn’t exist on that platform, rather than asking iOS developers to use a macro they don’t need.
There was a problem hiding this comment.
Use smart quotes: Mapbox's → Mapbox’s
There was a problem hiding this comment.
to illustrateto style a map
There was a problem hiding this comment.
referred to what is now a
MGLCameraStyleFunction.
This seems like unnecessary repetition. Could we say something like: “In iOS SDK v3.4, this function was called MGLStyleFunction.”?
There was a problem hiding this comment.
Let’s convert -> to → (or some other arrow symbol).
There was a problem hiding this comment.
Or “to”, since this is prose.
There was a problem hiding this comment.
Definitely onboard with consistently using type inference in Swift, though.
There was a problem hiding this comment.
we create ranges where earthquakes with a magnitude of 0 to just less than 2.5 would be yellow,
There was a problem hiding this comment.
Unfortunately we can’t rely on GitHub to host these assets — be sure to commit and use the files required for this guide.
There was a problem hiding this comment.
Definitely! In the process of doing that. I copied this from a gist and am still working on optimizing the screenshots
There was a problem hiding this comment.
Remove the colon in this heading.
There was a problem hiding this comment.
Or “to”, since this is prose.
There was a problem hiding this comment.
Specifying swift here would get us syntax coloring.
There was a problem hiding this comment.
URL(string:) only returns nil if the string is a malformed URL. Since the URL is formed from a string literal, we know it’s well-formed, so we can ! unwrap the optional without indenting everything below.
There was a problem hiding this comment.
But if we were to indent, we should use four spaces for each level of indentation.
There was a problem hiding this comment.
This reminds me: we should find a good place to mention the ability to use #8025, even if it isn’t important enough to show in a code example.
There was a problem hiding this comment.
Oh, good point. I will see if I can adjust the example to show that. Alternatively, we can use it in an upcoming example. Or both.
There was a problem hiding this comment.
Per #8025 (comment), let’s take this opportunity to point out that not every interpolation mode is available for every attribute. The developer should consult the documentation for an individual layout or paint attribute to see which function types and interpolation modes it supports.
3a5e79a to
f9f084a
Compare
There was a problem hiding this comment.
Don't forget to update the jazzy.yml files so the new guide shows up in the generated documentation side bar for iOS and macOS.
Also, there are changes to the For Style Author.md.ejs template here that have not yet been picked up by make style-code and committed as part of this PR. I looks like we plan to create a template for the DDS guide (per #8354 (comment)) so running make style-code will happen in due time.
👍
There was a problem hiding this comment.
Someday, it might be useful to include some designed images that combine a screenshot like this with a conceptual illustration of why these dots are special -- this could be something like an app screenshot on the left with a written function that maps a number to a color in the middle and an image of relevant tabular data on the right (just an idea).
Of course, nothing like this is required now but we might want to be on the lookout for images that end up in other parts of our docs or website and copy them back here.
There was a problem hiding this comment.
I noticed that 4 #s cause Stops to become STOPS in the generated documentation and that looks strange. Also, super nit, but we should probably format the headers consistently (add a space between the # and the first character of the text)
There was a problem hiding this comment.
In the generated documentation, the four #s capitalization issue combined with the formatting caused by the back ticks makes this looke like MGLINTERPOLATIONMODE with a really thin font weight.
There was a problem hiding this comment.
Instead of calling out that "exponential and interval interpolation modes" can be used on a camera function, this might be a good place to add another table that shows which functions support which modes. That is:
camera: exponential & interval
source: all of them
composite: exponential, interval, categorial (but not identity)
3608a12 to
1de8180
Compare
| @@ -0,0 +1 @@ | |||
| wat | |||
There was a problem hiding this comment.
oops that's from debugging! 😳
1de8180 to
987fb62
Compare
987fb62 to
0cbe2f7
Compare
There was a problem hiding this comment.
A couple of these variables appear to be unused. You can safely remove them.
There was a problem hiding this comment.
Looks like this item is complete.
There was a problem hiding this comment.
It isn't necessary to specify NSColor/UIColor here, because Swift can infer the type from the type of circleColor.
There was a problem hiding this comment.
Move this entry up to keep the table alphabetized by the first column.
There was a problem hiding this comment.
This table doesn't need its own subheading, but a complete sentence introducing the concept of an interpolation mode is would help to make this document flow better.
There was a problem hiding this comment.
Of these variables, it looks like only os is in use.
There was a problem hiding this comment.
This reads sort of like a release note. Let's cast this sentence in the present tense and talk about how the API includes style functions rather than introducing them.
Additionally, we have a tendency to use MGLStyleValue as an umbrella for both constants and functions. So even if we talk about the various style function subclasses, I think we should discuss the MGLStyleValue factory method that produces each kind of style function.
There was a problem hiding this comment.
Are these to-does done?
|
General note: these guides would benefit greatly from linking up the method/class names to their jazzy pages. ... which is something we should look into contributing upstream to jazzy. |
There was a problem hiding this comment.
You can also remove the initial tab indentation, as it’s indenting the entire block by one.
There was a problem hiding this comment.
keys stops dictionary
Is this a dictionary of stops for multiple keys? Pluralization is a little awkward, but if the meaning is correct then it’s probably OK.
There was a problem hiding this comment.
Remove the spaces before the colons and realign these lines.
There was a problem hiding this comment.
Promote this to a bigger header, as in the bottom of the Runtime Styling guide.
|
Are these code snippets testable? We’re dynamically inserting tested snippets into header documentation, but I’m not sure we’ve done that yet for guides. /cc @ericrwolfe |
8c4a636 to
e6a1dfb
Compare
|
Re: testability I'd originally shied away from adding code snippets to the runtime styling guide out of concern for maintainability. But now that we have testable code examples we could certainly take a similar approach for the markdown guides. We might be able to rework the original script from this PR #7337 to scan through the guides directory and replace placeholder tokens in the markdown files. Note that the current examples script in cc @1ec5 |
We also took that approach for the examples in the headers because jazzy documentation links to specific lines in the headers based on the source code it consumes – we didn’t want the line numbers to go out of sync because of inserted code. But that problem doesn’t affect the Markdown guides. |
|
I opened a ticket so we can discuss how to make code snippets testable. #8461 |


For Style Authorsguide to include DDS related terminology- [ ] Update Runtime Styling guide as necessaryThe data-driven styling guide currently includes more code than the other previous guides, and may be more tutorial. It is intended to illustrate the differences between the different interpolation modes and how to use them, but it can be trimmed down.
Intended to partially address #8192 and the last two items on #7924.