Skip to content

Rewrote the annotation update handler, bugfixes#45

Merged
compwright merged 2 commits into
chartjs:masterfrom
compwright:feature-annotation-events
Dec 3, 2016
Merged

Rewrote the annotation update handler, bugfixes#45
compwright merged 2 commits into
chartjs:masterfrom
compwright:feature-annotation-events

Conversation

@compwright

@compwright compwright commented Dec 3, 2016

Copy link
Copy Markdown
Collaborator
  • Fixes a bug where calling chartInstance.update() broke the referential integrity of the annotations, preventing further updates
  • Fixes a bug where the hovering element flag was getting reset when calling chartInstance.update() from inside the onMouseover handler
  • Annotations now use an unambiguous unique ID rather than an array index to map configs to element instances
  • Properly hooked in the scale adjuster using the afterDataLimits scale option
  • Refactored the plugin object to its own file
  • Refactored helpers.js to use a consistent module format
  • Pointed the main property in package.json back to the src directory to deal with Webpack warnings
  • Tighter plugin code and var names

@compwright compwright added the bug label Dec 3, 2016
@compwright compwright force-pushed the feature-annotation-events branch from 0a3524a to fbb5c84 Compare December 3, 2016 03:05
@compwright compwright changed the title Feature annotation events Rewrote the annotation update handler, bugfixes Dec 3, 2016
@compwright compwright force-pushed the feature-annotation-events branch from fbb5c84 to b5cf142 Compare December 3, 2016 03:45

@etimberg etimberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few minor comments. I haven't had a chance to run this yet. I will try and do that tomorrow

Comment thread src/annotation.js
var element;
if (typeof annotation._id === 'undefined' && !!annotationTypes[annotation.type]) {
annotation._id = helpers.objectId();
var cls = annotationTypes[annotation.type];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not sure if a linter would complain about the first character not being a capital

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

jshint doesn't complain. I'd rather have it lowercase, because convention is that newable classes are capital. cls is a variable class reference, not the class definition itself. I think this subtle difference makes the code more readily understandable.

Comment thread src/annotation.js Outdated
ns.config.annotations.forEach(function(annotation) {
var element;
if (typeof annotation._id === 'undefined' && !!annotationTypes[annotation.type]) {
annotation._id = helpers.objectId();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do you think it would be worth it to make this property public so that users could define their own IDs for annotations?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That's an interesting idea. I wouldn't want to be required to define it, and while I can't think of any reason why I'd want to set a specific ID, it's better to err on the side of flexibility. It would be a simple change here.

Comment thread src/index.js Outdated
// Configure plugin namespace
Chart.Annotation = Chart.Annotation || {};

Chart.Annotation.dblClickSpeed = 350; // ms

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

did we document this property in the readme?

Comment thread src/index.js Outdated

var helpers = require('./helpers.js')(Chart);

Chart.Annotation.ScaleAdjuster = function(scale) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the intent of putting this at Chart.Annotation.ScaleAdjuster to allow it to be replaced easily by a consumer of this lib?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not replaced necessarily (although that would be possible), but used or reused in other places. Originally did it this way because I thought that I would have to have users manually add it to their scales options objects, but then I found a way to add it automatically at the right time, so this doesn't need to be public anymore.

@etimberg etimberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. I tested out the behaviour and didn't notice any problems.

I think the package.json needs to be updated to specify Chart.js v2.4.0 as a dependency. The distanceBetweenPoints helper was introduced then.

* Fixes a bug where calling `chartInstance.update()` broke the referential integrity of the annotations, preventing further updates
* Fixes a bug where the `hovering` element flag was getting reset when calling `chartInstance.update()` from inside the `onMouseover` handler
* Annotations now use an unambiguous unique ID rather than an array index to map configs to element instances
* Properly hooked in the scale adjuster using the `afterDataLimits` scale option
* Refactored the plugin object to its own file
* Refactored helpers.js to use a consistent module format
* Pointed the `main` property in `package.json` back to the `src` directory to deal with Webpack warnings
* Tighter plugin code and var names
@compwright compwright force-pushed the feature-annotation-events branch from b5cf142 to 4bb9f92 Compare December 3, 2016 15:03
@compwright compwright merged commit d57020c into chartjs:master Dec 3, 2016
compwright added a commit to compwright/chartjs-plugin-annotation that referenced this pull request Dec 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants