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

[Bug] boxplot.encode does not get respected when used with category axis and series.data #20319

Closed
jonoshearman opened this issue Sep 4, 2024 · 2 comments
Labels
bug en This issue is in English topic: boxplot

Comments

@jonoshearman
Copy link
Contributor

Version

5.5.1

Link to Minimal Reproduction

https://echarts.apache.org/examples/en/editor.html?c=line-simple&version=5.5.1&code=PYBwLglsB2AEC8sDeAoWsDmAnCATAXLANpKwBGwYYwAtoQOQBsjApPbAL4A0ys1IDACwAGNjwpVaQ0e27J-DZmw4BdLmj7BgAG0gDkG9GBwYMAUywMAhgA8IAZ3obuG7WfPQCxJKvXobAIJ29oREhgbokXwAniBmDJA0ZvR-UZg4uACSnmY2hMKpUdBWSQwAKpkAsgCiAQAamQDKKeEuUahpMXEMAG5W2gCuyYWR2HjZuLmEAIwj6MWlsPQAagEAMgCqtQ3NI22RHWlgsfFLAMZWYO7AWNEtnWNZOXmwAExzsAun9ADCAWXVADiAHkAEoATXqTXukQ4GjUGmiQQcoXChyijwmU1gBVaI3RowyWJeszxaPC6Exz0I71a8NSuEuVnsZjAoUO9mAAywZ1OYU66CI0wKbxFAGYRSIeABWEX0GDJBEC4hisU8MUADnVAE4eFLYNLpTx6AAzLlYehKgVEfWCI0GkXS96wZjGsAACywZkVFNgKmcVpZODMIWI5M6XwSECStgcMKix26SwoNhA2ko8ciZCsWAA6ngPQwJZn0GZoGdgJNCKQXiLoqFZm91XqZSpOB9GWArKjlUKncIxf3hMPhzxhTxXuLJY7hFbOn3J8xXhqR6PYKr1Vr17rYPrDXO0gvhNqAOxixir6d6-2ymXO5j-zqP2H432RpZ9QZmWOOD6J74pmmGYfNmeYFu6RbCCWsCBMExIzB8SJwdSsCkp0ZYVlWvC1jw9bEI2zpqrurbtr6nbdmGva3qhIqTuqV4OgeURCmuG7rluYo7nu0pMZEfYMXaMqOvejDPlEYmke0b4lN8FxXBgNzRD-sADPYEDQBgsBBhAIYAHTkbAAAUZBYMAADWZYAJTQf-DCAemYDQaB-a4IWSzFh8sEOPBTa-kh3kobS6HlpWpw1oQ9p4UQIoEc2u5tvsUTkT21rjqK9F6jOxoKpaHyCmxmo6plMr2qa5q5b6gq2jewk8K6Swel6PpPmSUkRjJDBydctzKap6maeRLJgEZADuNxmf11l_icdnAKmDlOTmLlufQHm-l59g-UFaT-ZtgUfBhoXVjBEW4aEMUTnFggJR2TJDfBuJRHC6D-hwADcQA

Steps to Reproduce

as in the example, data values are set in series.data and series.encode contains rules for x/y axis where x is a category axis.

Current Behavior

the boxplot series will be created using the first 5 available dimensions ignoring the encode rules.
The axis will show integer numbers instead of the category values.

image

Expected Behavior

encoding rules should be respected and the category values be used instead of the category index:
image

Environment

- OS:
- Browser:
- Framework:

Any additional comments?

If a dataset is used with the identical values then the encode rules are respected and it works ( see example, bottom chart has 2 boxplot series)

ie:

{
...
  dataset: [
    {
      source: [
        [10, 20, 30, 40, 50, 'one'],
        [33, 38, 39, 40, 55, 'four'],
        [40, 45, 50, 52, 66, 'three']
      ]
    }
  ],
  series: [
    {
      name: 'Using series.data (broken)',
      type: 'boxplot',
      encode: { x: 5, y: [0, 1, 2, 3, 4] }, // <-- this is not being respected
      data: [
        [10, 20, 30, 40, 50, 'one'],
        [33, 38, 39, 40, 55, 'four'],
        [40, 45, 50, 52, 66, 'three']
      ]
    },
    {
      name: 'Using dataset (working)',
      type: 'boxplot',
      encode: { x: 5, y: [0, 1, 2, 3, 4] }, // <-- this works fine
      datasetIndex: 0
    }
  ]
...
}
@echarts-bot echarts-bot bot added en This issue is in English pending We are not sure about whether this is a bug/new feature. labels Sep 4, 2024
@jonoshearman
Copy link
Contributor Author

I investigated this a bit, and it seems the issue is in WhiskerBoxCommonMixin when getInitialData() is run.

there is a check for category axis and ordinalMeta is set to the 'base' dimension, and inserted as the 0th value dimension in series data. This is always set for category-axis which I think is breaking the encode settings.

I'm happy to submit a PR for this - what is the recommended way to check for encode rules on a series option?

@jonoshearman
Copy link
Contributor Author

jonoshearman commented Sep 4, 2024

my proposal would be this:

        const encodeRules = this.getEncode();

        if (xAxisType === 'category') {
            option.layout = 'horizontal';
            ordinalMeta = xAxisModel.getOrdinalMeta();
            addOrdinal = !encodeRules?.data?.has('x');  //instead of addOrdinal = true
        }
        else if (yAxisType === 'category') {
            option.layout = 'vertical';
            ordinalMeta = yAxisModel.getOrdinalMeta();
            addOrdinal = !encodeRules?.data?.has('y'); //instead of addOrdinal = true
        }
        else {
            option.layout = option.layout || 'horizontal';
        }

inside the getInitialData() function.
It feels a little crude, but I tested it and it works in some simple examples.
Let me know if this would be sufficient and I'll submit a PR

@Ovilia Ovilia closed this as completed in 41ff0b0 Sep 25, 2024
@plainheart plainheart added topic: boxplot and removed pending We are not sure about whether this is a bug/new feature. labels Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug en This issue is in English topic: boxplot
Projects
None yet
Development

No branches or pull requests

2 participants