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/box plot labels #17579

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

konrad-amtenbrink
Copy link

@konrad-amtenbrink konrad-amtenbrink commented Aug 26, 2022

Brief Information

Box plot labels for all displayed values.

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

This PR implements labels for all visible/plotted values of the box plot (this also includes the whiskers).

Details

The box plot now utilises the basics of the label option (i.e. show, offset and formatter) to display labels for the values of each box of the box plot.

As the multiple labels are not supported for single series items - the setBoxLabels method was added to the BoxView. In order to custom calculate the positions and add the labels to the plot.

Document Info

One of the following should be checked.

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Example

Screenshot 2022-09-07 at 14 45 27

@echarts-bot
Copy link

echarts-bot bot commented Aug 26, 2022

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

@konrad-amtenbrink
Copy link
Author

I am happy to move the setBoxLabel logic to a different file or even abstract it further - I was just not sure where it would be best suitable.

@Ovilia
Copy link
Contributor

Ovilia commented Sep 2, 2022

Can you provide an image to illustrate what this PR is about?

@konrad-amtenbrink
Copy link
Author

@Ovilia Sure - I added it to the description.

Copy link
Contributor

@Ovilia Ovilia left a comment

Choose a reason for hiding this comment

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

Cool feature! Should we provide an option to let developers decide the alignment of each label?

Please also fix the lint errors and add test cases using npm run mktest boxplot-labels.

@konrad-amtenbrink
Copy link
Author

konrad-amtenbrink commented Sep 7, 2022

@Ovilia What do you mean by alignment of the labels?
Also fixed the linting and added the test.

@Ovilia
Copy link
Contributor

Ovilia commented Sep 8, 2022

There are five labels (numbers) for each boxplot item, three of which is on the left side and two right. But some developers may have different requirement like only displaying the middle value or display all values on the left. How can that be done?

@konrad-amtenbrink
Copy link
Author

@Ovilia I would vote to not add an option to display for example all labels on one side because they most likely will overlap and I do not see a use case for that (if there is someone with that specific use case - we can always open up a follow-up) - I can however add an option to specify which labels should be displayed

@konrad-amtenbrink
Copy link
Author

@Ovilia the user now has the option to set label.show to either all, iqr, median or whiskers to change what labels are displayed.

@konrad-amtenbrink
Copy link
Author

Hey @Ovilia are there any updates on this - do you need further changes from my side? Thank you very much :)

el.z2 = 100;

const itemModel = data.getItemModel<BoxplotDataItemOption>(dataIndex);
const emphasisModel = itemModel.getModel('emphasis');

if (seriesModel.option.label.show) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't access the attributes using seriesModel.option. Please use const labelModel = seriesModel.get('label'); const show = labelModel.get('show'); instead.

Please also change seriesModel.option in other places.

if (seriesModel.option.label.show) {
const formattedLabels =
((seriesModel as BoxplotSeriesModel).getRawValue(dataIndex) as number[])
.splice(1).map((value: number) => seriesModel.option.label.formatter(value).toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

You should probably not create a Text element and do all the stuffs by yourself. Instead, setLabelStyle should be called. See how this is done with line series. But in boxplot's case, there are multiple labels so you need to figure out how this should be done, but generally speaking, setLabelStyle should be called most likely.

Copy link
Author

Choose a reason for hiding this comment

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

I would not add it to setLabelStyle as it is super specific code which only applies to the bar chart, so it doesn't really make sense in my opinion to add it a general util method. However, I agree that it should live in the labelStyle util. So I would vote to move it there and refactor it so it does not create a Text element manually. What do you think?

Choose a reason for hiding this comment

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

@Ovilia any news on this? Is the proposed solution good enough?

@DanielBogenrieder
Copy link

Hey,
sorry to raise this again, but this would help us a lot. Are there any news on this?

},
label: {
show: true,
formatter: function (param) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If formatter is not provided here, there will be an error. You should not assert it to be defined.

if (labelModel.show) {
const formattedLabels =
((seriesModel as BoxplotSeriesModel).getRawValue(dataIndex) as number[])
.splice(1).map((value: number) => labelModel.formatter(value).toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not the correct way to format labels. If formatter is not defined, this should go wrong. You should probably do like sunburst.

Copy link
Author

Choose a reason for hiding this comment

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

@Ovilia I am not sure if I understood correctly - getFormattedLabel is defined to return a string but somehow returns an object when being called with dataIndex.

I think I am missing something here, could you clarify how you would implement the formatting of the labels?

Thanks

z2: 1000
});
const defaultOffset = 5;
const defaultXOffset = (ind % 2) === 0 ? (-(label.getBoundingRect().width + defaultOffset)) : defaultOffset;
Copy link
Contributor

Choose a reason for hiding this comment

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

As I said before, we should provide a way to let developers decide where to display the label to the left or right. The label.align can be changed into 'left' | 'right' | 'center' | { iqr: 'left' | 'right' | 'center' , ... }.

Copy link
Author

Choose a reason for hiding this comment

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

@Ovilia Sorry, maybe I am missing something here as well but there is no single label. We have five labels, right? I still don't get how someone could choose the align for the five in a way that makes sense - e.g. all labels on one side - even though they might overlap?

@Ovilia
Copy link
Contributor

Ovilia commented Dec 16, 2022

@DanielBogenrieder Sorry for late reply. I think this PR still need modification before merging.

@DanielBogenrieder
Copy link

Hey @Ovilia,
we still have some open questions to your comments. If you could clarify we could finish up the PR and get this merged?

Greetings and thanks,
Daniel

@konrad-amtenbrink
Copy link
Author

Hey @Ovilia,
I left some questions on your comments because I am not sure if I understand them correctly - are there any updates on this?

Greetings and thanks,
Konrad

@konrad-amtenbrink
Copy link
Author

Hey @Ovilia,
are there any updates on this PR?

Thanks,
Konrad

@DanielBogenrieder
Copy link

Any news on this? Anything we can do to get it merged?

@hazyram
Copy link

hazyram commented Sep 9, 2024

Is there an option to configure display labels in the current official version. At present, it seems that there is no mention in the official documents. How can I achieve displaying the median at the top?

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.

4 participants