-
Notifications
You must be signed in to change notification settings - Fork 365
Normalize annotations elements to be based on common box model #706
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
Conversation
@kurkle for other annotations, where the changes could depend on these ones, of this PR, do you prefer other PRs (I was thinking 1 for point and polygon and 1 for line) or to apply the changes all in this ones? Of course, the second one is faster, no dependency. |
Probably best to do all at once, in this case. |
I'm gonna work on that this week! |
@kurkle offtopic. After new Karma version, when I run []\chartjs-plugin-annotation>npm run dev:ff
> [email protected] dev:ff
> karma start --auto-watch --no-single-run --browsers firefox
INFO [preprocessor.rollup]: Generating bundle for ./src\index.js
INFO [preprocessor.rollup]: Generating bundle for ./test\index.js
WARN [karma]: No captured browser, open http://localhost:9876/
INFO [karma-server]: Karma v6.3.17 server started at http://localhost:9876/
INFO [launcher]: Launching browsers firefox with concurrency unlimited
INFO [launcher]: Starting browser Firefox
INFO [preprocessor.rollup]: Generating bundle for ./test\index.js
INFO [filelist]: Changed file "[]/chartjs-plugin-annotation/test/index.js". <----- HERE
WARN [karma]: No captured browser, open http://localhost:9876/
INFO [Firefox 97.0 (Windows 10)]: Connected on socket IxXwYXD3S64JKcl2AAAB with id 52745204
Firefox 97.0 (Windows 10) WARN: 'Testing with chart.js v3.7.1' Do you have the same issue and behavior or it's something related to my env? |
Yes, its karma-rollup-preprocessor 7.0.8 that is causing it. Fix: |
Shall I commit the update of package-lock.json? |
Conflicts: src/helpers/helpers.chart.js src/helpers/helpers.core.js src/types/box.js src/types/ellipse.js src/types/label.js src/types/line.js src/types/polygon.js
@LeeLenaleee I have added a drawio file for each annotation type (new diagrams folder in doc) and exported them in PNG in img folder. Let me know if you think it could be improved from your point of view. |
@@ -95,9 +95,9 @@ export function getChartPoint(chart, options) { | |||
/** | |||
* @param {Chart} chart | |||
* @param {CoreAnnotationOptions} options | |||
* @returns {{x?:number, y?: number, x2?: number, y2?: number, width?: number, height?: number}} | |||
* @returns {{x:number, y: number, x2: number, y2: number, centerX: number, centerY: number, width: number, height: number}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the return value deserves its own type, maybe called AnnotationBoxModel
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have already AnnotationElement
even if it includes options
in its definition. in my opinion, we need to map the new model in more TS types.
@@ -30,8 +30,8 @@ export function inBoxRange(point, {x, y, width, height}, axis, borderWidth) { | |||
} | |||
|
|||
export function getElementCenterPoint(element, useFinalPosition) { | |||
const {x, y} = element.getProps(['x', 'y'], useFinalPosition); | |||
return {x, y}; | |||
const {centerX, centerY} = element.getProps(['centerX', 'centerY'], useFinalPosition); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better for backward compatibility, if we used x
and y
for the center point? (and x1,y1 for the top/left)
On the other hand centerX and centerY are explicit. Could also go further explicit and use top, left, bottom, right for the corner coordinates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better for backward compatibility, if we used
x
andy
for the center point? (and x1,y1 for the top/left)
make sense!
On the other hand centerX and centerY are explicit. Could also go further explicit and use top, left, bottom, right for the corner coordinates.
Could make sense but in this way we don't have any backward compatibility, for any annotation type. Do you want I do in this PR or with another one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kurkle be also aware that top, left, bottom and right can not map very well the line annotation because bottom could be greater than top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better for backward compatibility, if we used
x
andy
for the center point? (and x1,y1 for the top/left)make sense!
@kurkle sorry but I think I misunderstood your comment. In my poor option it couldn't be a good idea to use x,y
for center because it's not readable, I guess. The getCenterPoint
method returns {x: number, y: number}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean with "not readable"? The element properties can be read directly from the element. But if you mean its not obvious what x and y are, I agree.
I think its ok to go with centerX/Y, just wanted to bounce these thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean with "not readable"? The element properties can be read directly from the element. But if you mean its not obvious what x and y are, I agree.
I meant "user friendly" or obvious (as you wrote). I didn't the user can not access to them ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kurkle be also aware that top, left, bottom and right can not map very well the line annotation because bottom could be greater than top.
@kurkle I thought about line annotation. We could go to top, left, bottom and right model but we need to add some additional logic to know which corners of the box must be join to draw the line to the right direction.
Let me know what I think it's better.
@kurkle I have seen your approval. |
If you agree I would like to spend a couple of days, maybe next week, in a PR where top left bottom right model could be used. |
Sure go ahead and explore! |
@kurkle about |
Fix #532
This PR normalizes the annotations elements to the following box model: