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

Clarify easing function requirements and clean up references to Anima… #4266

Merged
merged 2 commits into from
Feb 20, 2017

Conversation

stevage
Copy link
Contributor

@stevage stevage commented Feb 13, 2017

…tionOptions.

Fixes #4182.

@@ -411,7 +413,8 @@ class Camera extends Evented {
* details not specified in `options`.
*
* @memberof Map#
* @param {CameraOptions|AnimationOptions} options Options describing the destination and animation of the transition.
* @param {Object} options Options describing the destination and animation of the transition.
* Accepts [CameraOptions](#CameraOptions) and [AnimationOptions](#AnimationOptions).
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we stick with {CameraOptions|AnimationOptions} as the type for this parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seemed slightly misleading, because the object doesn't have to be either a CameraOptions or an AnimationOptions, but can share attributes from both.

Copy link
Contributor

Choose a reason for hiding this comment

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

In Flow, our type definition standard, the | operator (the "union" operator) indicates that an object may "share attributes from both: https://flowtype.org/docs/union-intersection-types.html#_

Copy link
Contributor

Choose a reason for hiding this comment

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

You can think of it more like the bitwise | than the logical ||

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. Should have known you'd be following a standard :)

(I actually found that Flow doc page a bit ambiguous, but the page on disjoint unions makes clear that unions are non-disjoint by default)

js/ui/camera.js Outdated
@@ -29,7 +29,8 @@ const Evented = require('../util/evented');
*
* @typedef {Object} AnimationOptions
* @property {number} duration The animation's duration, measured in milliseconds.
* @property {Function} easing The animation's easing function.
* @property {Function} easing A function taking a time in the range 0..1 and returning a number where 0 is
* the initial state and 1 is the final state.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure / haven't checked, but it's likely that the function is expected to be nondecreasing. 🤔 I wonder if there's a non-math-class way of saying that, heh.

Copy link
Contributor

Choose a reason for hiding this comment

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

What makes you think that the function is expected to be nondecreasing? (I'm ok with using math class language!)

Copy link
Contributor

Choose a reason for hiding this comment

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

Eh, I think it was just an overly-cautious red flag instinct -- it's an assumption I could imagine making if I were implementing animations w/ a custom easing function -- but now that I look at camera.js, I don't see any obvious cases where we assume it.

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 didn't test, but does the return value have to be within 0..1? Easing functions in systems like D3 generally don't.

@@ -302,7 +303,8 @@ class Camera extends Evented {
* @param {Object} [options]
* @param {boolean} [options.linear=false] If `true`, the map transitions using
* {@link Map#easeTo}. If `false`, the map transitions using {@link Map#flyTo}. See
* {@link Map#flyTo} for information about the options specific to that animated transition.
* those functions and @{link AnimationOptions} for information about options available.
* @param {Function} [options.easing] An easing function for the animated transition. See [AnimationOptions](#AnimationOptions).
* @param {Function} [options.easing] An easing function for the animated transition.
Copy link
Contributor

Choose a reason for hiding this comment

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

options.easing is duplicated here. In fact, for consistency, would it make sense to remove options.easing (and options.offset) in favor of setting the type of [options] to {AnimationOptions}? I realize that, at present, this means more clicks for readers of the docs, but my preference would be to solve that problem somehow in the documentation generation step.

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @lucaswoj @mollymerp - I remember a brief discussion about this, but I can't find the comment/thread.

Copy link
Contributor

Choose a reason for hiding this comment

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

in favor of setting the type of [options] to {AnimationOptions}?

Good idea. If we go this route, we may also want to:

  • rename/alias options.linear to options.animate
  • add options.duration (this will just be passed to Map#flyTo)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, messed up my git. I'll wait till you decide. (If you can add commits, feel free.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest we keep this PR simple and make the switch to AnimationOptions in a follow up. Would you mind ticketing this?

Copy link
Contributor

Choose a reason for hiding this comment

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

✅ Ticketed at #4286

@anandthakker
Copy link
Contributor

Thanks for this, @stevage!

js/ui/camera.js Outdated
@@ -29,7 +29,8 @@ const Evented = require('../util/evented');
*
* @typedef {Object} AnimationOptions
* @property {number} duration The animation's duration, measured in milliseconds.
* @property {Function} easing The animation's easing function.
* @property {Function} easing A function taking a time in the range 0..1 and returning a number where 0 is
* the initial state and 1 is the final state.
Copy link
Contributor

Choose a reason for hiding this comment

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

What makes you think that the function is expected to be nondecreasing? (I'm ok with using math class language!)

@@ -302,7 +303,8 @@ class Camera extends Evented {
* @param {Object} [options]
* @param {boolean} [options.linear=false] If `true`, the map transitions using
* {@link Map#easeTo}. If `false`, the map transitions using {@link Map#flyTo}. See
* {@link Map#flyTo} for information about the options specific to that animated transition.
* those functions and @{link AnimationOptions} for information about options available.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm 👎 on this edit. The @see tag already suggests the user may see those methods for more info. We don't need to state this explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. To me it wasn't obvious that you can pass additional options and they will be respected by easeTo or flyTo respectively.

@@ -302,7 +303,8 @@ class Camera extends Evented {
* @param {Object} [options]
* @param {boolean} [options.linear=false] If `true`, the map transitions using
* {@link Map#easeTo}. If `false`, the map transitions using {@link Map#flyTo}. See
* {@link Map#flyTo} for information about the options specific to that animated transition.
* those functions and @{link AnimationOptions} for information about options available.
* @param {Function} [options.easing] An easing function for the animated transition. See [AnimationOptions](#AnimationOptions).
* @param {Function} [options.easing] An easing function for the animated transition.
Copy link
Contributor

Choose a reason for hiding this comment

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

in favor of setting the type of [options] to {AnimationOptions}?

Good idea. If we go this route, we may also want to:

  • rename/alias options.linear to options.animate
  • add options.duration (this will just be passed to Map#flyTo)

@lucaswoj lucaswoj merged commit 1e513a4 into mapbox:mb-pages Feb 20, 2017
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.

3 participants