Skip to content

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

Merged
merged 19 commits into from
Apr 7, 2022
Merged

Normalize annotations elements to be based on common box model #706

merged 19 commits into from
Apr 7, 2022

Conversation

stockiNail
Copy link
Collaborator

@stockiNail stockiNail commented Mar 1, 2022

Fix #532

This PR normalizes the annotations elements to the following box model:

145609678-792aac72-2cf0-4bb7-9b05-464a605e8d80

@stockiNail
Copy link
Collaborator Author

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

@kurkle
Copy link
Member

kurkle commented Mar 4, 2022

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

@stockiNail
Copy link
Collaborator Author

Probably best to do all at once, in this case.

I'm gonna work on that this week!

@stockiNail
Copy link
Collaborator Author

@kurkle offtopic. After new Karma version, when I run npm run dev (also dev:ff), the index.js file of tests is changed with a source code completely different (auto generated).

[]\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?

@kurkle
Copy link
Member

kurkle commented Mar 9, 2022

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: npm i [email protected] --save-dev

Ref: jlmakes/karma-rollup-preprocessor#75

@stockiNail stockiNail changed the title Normalize box, ellipse and label annotations to be based on common box model Normalize annotations elements to be based on common box model Mar 9, 2022
@stockiNail
Copy link
Collaborator Author

Yes, its karma-rollup-preprocessor 7.0.8 that is causing it. Fix: npm i [email protected] --save-dev

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
@stockiNail stockiNail marked this pull request as ready for review April 6, 2022 11:43
@stockiNail stockiNail requested review from kurkle and LeeLenaleee April 6, 2022 11:48
@stockiNail
Copy link
Collaborator Author

@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}}
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 the return value deserves its own type, maybe called AnnotationBoxModel?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, makes sense

Copy link
Collaborator Author

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);
Copy link
Member

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.

Copy link
Collaborator Author

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)

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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)

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}.

Copy link
Member

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.

Copy link
Collaborator Author

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 ;)

Copy link
Collaborator Author

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.

@stockiNail
Copy link
Collaborator Author

stockiNail commented Apr 6, 2022

@kurkle I have seen your approval.
Does it mean you dont want to evaluate your proposed model? Or just postponed to another PR?

@stockiNail
Copy link
Collaborator Author

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.
Personally I think could make sense more than x x2 y y2, that I dont love it. As said the line annotation could need more time and thoughts.

@kurkle
Copy link
Member

kurkle commented Apr 7, 2022

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. Personally I think could make sense more than x x2 y y2, that I dont love it. As said the line annotation could need more time and thoughts.

Sure go ahead and explore!

@stockiNail stockiNail merged commit 43002ff into chartjs:master Apr 7, 2022
@stockiNail
Copy link
Collaborator Author

@kurkle about AnnotationBoxModel and JSDoc, I thought yesterday and I'll submit a PR to add JSDOC to all exported functions and public methods. Doing that, I'll review also the types to add to JSDOC. I was thinking to add JSDOC to the types (currently there are some jsdoc but not to all, therefore we bothadd to or remove form all) but I hand over the decision to you, if make sense.

@stockiNail stockiNail deleted the normalizeBox branch April 7, 2022 07:37
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.

Normalize all annotation to be based on box model (x, y, width, height)
3 participants