Skip to content

Add beforeDraw and afterDraw hooks to the annotations#744

Merged
stockiNail merged 28 commits into
chartjs:masterfrom
pepstock-org:elementsHooks
Jan 27, 2023
Merged

Add beforeDraw and afterDraw hooks to the annotations#744
stockiNail merged 28 commits into
chartjs:masterfrom
pepstock-org:elementsHooks

Conversation

@stockiNail

@stockiNail stockiNail commented May 21, 2022

Copy link
Copy Markdown
Collaborator

This PR is adding before/after draw hooks in order to allow the user to apply whatever needed customization on out-of the-box annotations. Fix #146.

The hooks will be invoked once for every annotation for each drawing cycle.

plugins: {
  annotation: {
    annotations: {
      line: {
        type: 'line',
        ....
        beforeDraw(context) {
          console.log('beforeDraw');
        },
        afterDraw(context) {
          console.log('afterDraw');
        },
      },
    }
  }
}
Hook Arguments Return type Default Description
beforeDraw context void annotation.beforeDraw invoked before the element drawing
afterDraw context void annotation.afterDraw invoked after the element drawing

Common hooks for all annotations can be set in the annotation plugin options:

plugins: {
  annotation: {
    beforeDraw(context) {
      console.log('Common beforeDraw');
    },
    afterDraw(context) {
      console.log('Common afterDraw');
    },
    annotations: {
      line: {
        type: 'line',
        ....
      },
    }
  }
}

TODO

  • test cases
  • types
  • documentation
  • samples

@stockiNail stockiNail added this to the 2.0.0 milestone May 21, 2022
@stockiNail
stockiNail marked this pull request as ready for review May 23, 2022 11:12
@stockiNail
stockiNail requested review from LeeLenaleee and kurkle May 23, 2022 11:12
@stockiNail stockiNail modified the milestones: 2.0.0, 2.1.0 Jun 3, 2022
@stockiNail
stockiNail marked this pull request as draft July 21, 2022 15:47
@stockiNail
stockiNail marked this pull request as ready for review August 5, 2022 10:38

@kurkle kurkle 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.

I still don't like the counters
How about making it simpler, just draw before/after the main element is drawn?
We could add afterDrawChildren later, if it's really needed.

@stockiNail

Copy link
Copy Markdown
Collaborator Author

I still don't like the counters
How about making it simpler, just draw before/after the main element is drawn?
We could add afterDrawChildren later, if it's really needed.

I think its reasonable
But Let me take time to review the PR
My memory is not so persistent and I dont remember so well what I wrote

@stockiNail

stockiNail commented Sep 28, 2022

Copy link
Copy Markdown
Collaborator Author

How about making it simpler, just draw before/after the main element is drawn?

done! review applied!

No counters anymore!

@stockiNail
stockiNail requested a review from kurkle October 27, 2022 11:21
@stockiNail stockiNail modified the milestones: 2.1.0, 2.2.0 Nov 17, 2022

@kurkle kurkle 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.

Sorry for the huge delay on these. LGTM

@stockiNail
stockiNail merged commit 44722bf into chartjs:master Jan 27, 2023
@stockiNail
stockiNail deleted the elementsHooks branch January 27, 2023 10:04
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.

padding issue with drawing an average line

2 participants