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

Support configurable update #4362

Merged
merged 6 commits into from Jun 11, 2017
Merged

Support configurable update #4362

merged 6 commits into from Jun 11, 2017

Conversation

ricardocosta
Copy link
Contributor

See discussion in the issue for context and possible approaches.

When invoking update() inside an event handler, such as onHover, options.hover.animationDuration was not being respected. Given that some use cases may require additional animation properties for the manual update call, this commit changes that method signature to accept a configuration object.

This object provides backwards compatibility with duration and lazy properties, and also introduces the easing property so that the event animation is different from the global one.

Issue #4300

See discussion in the issue for context and possible approaches.

When invoking update() inside an event handler, such as onHover,
`options.hover.animationDuration` was not being respected. Given that
some use cases may require additional animation properties for the
manual update call, this commit changes that method signature to accept
a configuration object.

This object provides backwards compatibility with duration and lazy
properties, and also introduces the easing property so that the event
animation is different from the global one.

Issue #4300
@ricardocosta
Copy link
Contributor Author

@simonbrunel, @etimberg Can you take a look at this approach? 🙏

Also, codeclimate doesn't seem to like the snippet for keeping backwards compatibility. Any suggestions?

var me = this;

if (!config || typeof config !== 'object') {
Copy link
Member

Choose a reason for hiding this comment

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

We should have a test, if possible, that verifies that backwards compatibility isn't broken.

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 can try that. Is there any other place other than core.controller.tests.js? Because that isn't testing _bufferedRender, nor render at the moment.

Add tests that guarantee that when update is called manually with
arguments, it properly builds the _bufferedRequest or calls render with
the proper arguments.
It includes test cases for when update is called with legacy arguments
(duration and lazy) instead of the config object.

Issue #4300
.update() documentation was previously updated but .render() was left
out. Since the backwards compatible change was also made to render(),
this commit adds documentation for it.

Issue #4300
Copy link
Member

@simonbrunel simonbrunel left a comment

Choose a reason for hiding this comment

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

Looks good, just a few notes about the docs and unit tests.

})
```

> **Note:** `.update(duration, lazy)` is still supported in backwards compatibility mode.
Copy link
Member

Choose a reason for hiding this comment

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

I would not write about it: it still works but people should not know about it.

```

> **Note:** `.render(duration, lazy)` is still supported in backwards compatibility mode.
Copy link
Member

Choose a reason for hiding this comment

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

Same here :)

});
});

describe('when using backwards compatibility', function() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we move that "compatibility" suite in global.deprecations.tests.js as:

describe('Deprecations', function() {
    describe('Version 2.7.0', function() {
        describe('Chart.Controller.update(duration, lazy)', function() {
            // ...
        });
        describe('Chart.Controller.render(duration, lazy)', function() {
            // ...
        });
    });

	describe('Version 2.6.0', function() {
    // ...

});

describe('when using backwards compatibility', function() {
describe('when _bufferedRender is true', function() {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to differentiate when _bufferedRender is true or false (which is internal, so should not be tested). Both methods (update and render) could be tested by checking that Chart.animationService.addAnimation() is called with the correct arguments?

Instead of relying on internal properties such as _bufferedRender and
_bufferedRequest, the tests are now rewritten to focus on the parameters
provided when calling Chart.animationService#addAnimation.

The mention to the old signature of render and update was also removed
from the docs.

Issue #4300
@ricardocosta
Copy link
Contributor Author

@simonbrunel Can you take another look?

var addAnimationSpy;

beforeEach(function() {
chart = acquireChart({
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to avoid global variables and use this instead:

this.chart = ...
this.addAnimationSpy = ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those are declared inside the describe. But I can change them to use this if that's the usual pattern in the project.

beforeEach(function() {
chart = acquireChart({
type: 'doughnut',
data: {
Copy link
Member

Choose a reason for hiding this comment

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

do we need data for this unit tests?

}]
},
options: {
cutoutPercentage: 85,
Copy link
Member

Choose a reason for hiding this comment

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

Is this option relevant? we should avoid setting data/options that are not useful for the test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both data and cutoutPercentage were set just to have a "consistent" chart instance, so to speak. Since the type is doughnut it made sense to be explicit about the cutout percentage. Will remove them if you think they can cause confusion. 👍

- Use `this`
- Do not use properties/data that are not needed for the spec.
this.addAnimationSpy = spyOn(Chart.animationService, 'addAnimation');
});

it('adds an animation with the provided options', function() {
Copy link
Member

Choose a reason for hiding this comment

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

it('should add... to be consistent with all tests :)

Copy link
Member

@simonbrunel simonbrunel left a comment

Choose a reason for hiding this comment

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

Looks good, thanks :)

@ricardocosta
Copy link
Contributor Author

Fixed. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants