Skip to content

Add fallbacks for manual manipulation of slider/frames #1233

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

Merged
merged 2 commits into from
Dec 9, 2016

Conversation

rreusser
Copy link
Contributor

@rreusser rreusser commented Dec 7, 2016

cc @bpostlethwaite @etpinard

This PR fixes two cases:

  1. When slider options are added, it needs to refetch the slider steps from the d3 data. The mouse events are in a closure, so it was previously using outdated data in callbacks.
  2. When slider options are removed, it checks whether the active index is invalid. If it is, it just moves the slider to the first position.

This PR does not fix:

  • It does not search for a matching option after the update has occurred. Like if you remove the thid option, it will not fix the active index from 5 -> 4. That can be added, but I did not yet address that case in the interest of stopping blocking @bpostlethwaite ASAP.

This PR also sneaks in Plot.recomputeFrameHash(gd) which does what it says. I should add tests for that; it's just a small bonus to prevent @bpostlethwaite from needing to do it manually.

@rreusser rreusser added status: reviewable bug something broken labels Dec 7, 2016
@etpinard etpinard added this to the v1.21.0 milestone Dec 7, 2016
// the join data that creates this slider. So if this slider still exists,
// the group should be valid, *to the best of my knowledge.* If not,
// we'd have to look it up by d3 data join index/key.
var opts = gSlider.data()[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the same behavior happen for updatemenus ?

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 think so. Need to investigate make a parallel PR for that. This is one is just of particular concern because of @bpostlethwaite's current project with the slider transform thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. No need to address updatemenus in this PR.

Can you open an issue for that and for your This PR does not fix: point above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See: #1234 #1235

// steps have changed since this was initialized. The sliderGroup,
// however, has not changed since that *is* the slider, so it must
// be present to receive mouse events.
function getSliderOpts() {
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for the comment 📚

/*
* Recompute the lookup table that maps frame name -> frame object. addFrames/
* deleteFrames already manages this data one at a time, so the only time this
* is necessary is if you poke around manually in `gd._transitionData_frames`
Copy link
Contributor

Choose a reason for hiding this comment

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

typo ⏰ gd._transitionData_frames -> gd._transitionData._frames

@@ -209,6 +210,59 @@ describe('sliders initialization', function() {
});
});

describe('ugly internal manipulation of steps', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

great test case name!

// The selected option no longer exists, so confirm it's
// been fixed during the process of updating/drawing it:
expect(gd._fullLayout.sliders[0].active).toEqual(0);
}).catch(fail).then(done);
Copy link
Contributor

Choose a reason for hiding this comment

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

very nice test case.

@etpinard
Copy link
Contributor

etpinard commented Dec 7, 2016

@bpostlethwaite wanna try this branch out in the workspace?

@bpostlethwaite
Copy link
Member

Yep will do

@bpostlethwaite
Copy link
Member

Successfully used this in WS2 👍 from me

@etpinard
Copy link
Contributor

etpinard commented Dec 9, 2016

@rreusser 💃

@bpostlethwaite I'll release 1.21.0 on Monday.

@rreusser rreusser merged commit 294e007 into master Dec 9, 2016
@rreusser rreusser deleted the fix-slider-manipulation branch December 9, 2016 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants