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

feat: avoid label collision #247

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

MAudelGisaia
Copy link
Contributor

Capture.video.du.03-02-2025.18.25.25.webm

@@ -70,6 +70,7 @@ export class HistogramParams {
public ticksDateFormat: string = null;
public xAxisPosition: Position = Position.bottom;
public descriptionPosition: Position = Position.bottom;
public overlapXTolerance = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

why 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could be more if needed, it apply a padding of 2 on left and right side, to detect the overlap before the label collide.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it should be an input ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could be a good idea !

Copy link
Member

Choose a reason for hiding this comment

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

Yes good Idea, we should add a new input for this overlap tolerance

}
}

if(!this._xlabelMeanWidth) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not recompute it each time ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this var helps me to know when i can put more label when the chart grow. So i cacl the mean size once, when all label are displayed.

Copy link
Contributor

Choose a reason for hiding this comment

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

The virtual labels always has the maximum number of labels right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

for (let i = 0; i < labels.size(); i++) {
const next = i + 1;
if(nodes[next]){
const c = this.getDimension(nodes[i]);
Copy link
Member

Choose a reason for hiding this comment

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

Do 'c' and 'n' stand for current and next ? if so, can you add a comment for those var names or rename the variable ?

const horizontalOffset = this.getHorizontalOffset(chartAxes);
let sumWidth = 0;
// create virtual nodes. Helps to get label's width.
const virtualLabels = this.chartDimensions.svg.append('g');
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 you can try to select the already existing labels.
Or you need to use one common method between the real label axis and the virtual one in order to avoid duplication

@@ -70,6 +70,7 @@ export class HistogramParams {
public ticksDateFormat: string = null;
public xAxisPosition: Position = Position.bottom;
public descriptionPosition: Position = Position.bottom;
public overlapXTolerance = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Yes good Idea, we should add a new input for this overlap tolerance

@MohamedHamouGisaia
Copy link
Member

LGTM !
I'll add one more request:
In HistogramParams.xLabels, we need to document the fact that now this number of labels is a prefered maximum number of labels displayed in x-axis and that if the chart's width doesn't allow to fit that number, the chart automatically manages hiding some labels for clarity

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

Successfully merging this pull request may close these issues.

Labels on x-axes should handle the histogram size and resize
3 participants