You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by "Justin-ZS (via GitHub)" <gi...@apache.org> on 2025/03/19 09:57:49 UTC
[PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Justin-ZS opened a new pull request, #20838:
URL: https://github.com/apache/echarts/pull/20838
<!-- Please fill in the following information to help us review your PR more efficiently. -->
## Brief Information
This pull request is in the type of:
- [ ] bug fixing
- [x] new feature
- [ ] others
### What does this PR do?
<!-- USE ONE SENTENCE TO DESCRIBE WHAT THIS PR DOES. -->
Add `dataMin` and `dataMax` properties for value axes to extend the axis range while preserving nice scale algorithm.
### Fixed issues
<!--
- #xxxx: ...
-->
- #20770
## Details
### Before: What was the problem?
<!-- DESCRIBE THE BUG OR REQUIREMENT HERE. -->
Currently, ECharts provides two ways to set axis range:
1. Let ECharts auto-calculate nice values by default
1. Use `min`/`max` to set fixed values, but this disables the nice scale algorithm
There was no way to ensure a specific data point would be included in the axis range while still benefiting from the nice scale algorithm.
<!-- ADD SCREENSHOT HERE IF APPLICABLE. -->
### After: How does it behave after the fixing?
<!-- THE RESULT AFTER FIXING AND A SIMPLE EXPLANATION ABOUT HOW IT IS FIXED. -->
With the new `dataMin`/`dataMax` properties, users can:
- Specify values that should be included in the axis range
- Only affect the range if the specified value extends beyond the actual data range
- Still benefit from ECharts' nice scale algorithm for rounding values
These properties are only effective for value axes (`value`, `log`) and have no effect on category axes.
<!-- ADD SCREENSHOT HERE IF APPLICABLE. -->
## Document Info
One of the following should be checked.
- [ ] This PR doesn't relate to document changes
- [x] The document should be updated later
- [ ] The document changes have been made in apache/echarts-doc#xxx
## Misc
### ZRender Changes
- [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).
### Related test cases or examples to use the new APIs
Test cases have been included in `test/axis-data-min-max.html` to verify different scenarios including:
- Basic usage with standard value axes
- Scenarios with negative values
- Usage with log axes
- Verification that they don't affect category axes
## Others
### Merging options
- [ ] Please squash the commits into a single one when merging.
### Other information
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "Justin-ZS (via GitHub)" <gi...@apache.org>.
Justin-ZS commented on PR #20838:
URL: https://github.com/apache/echarts/pull/20838#issuecomment-2812414765
> This seems a little unexpected to me. Have you tried with the callback of [axis.min](https://echarts.apache.org/en/option.html#yAxis.min)?
>
> ```js
> yAxis: {
> max: value => Math.max(value, 1000)
> }
> ```
>
> or simply
>
> ```js
> yAxis: {
> max: 'dataMax'
> }
> ```
Neither approach works in this case.
As described in apache/echarts#20770, we need a simple way to the axis max to a nice round value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "Justin-ZS (via GitHub)" <gi...@apache.org>.
Justin-ZS commented on PR #20838:
URL: https://github.com/apache/echarts/pull/20838#issuecomment-2804121177
> I’ve experienced this problem as a user so interested to see how this PR progresses, I will say the naming here is a bit confusing, especially since ECharts already supports a different concept as: `min: 'dataMin'` and `max: ‘dataMax’`
I intentionally use the terms `dataMin/dataMax`:
1. From a usage perspective, `dataMin/dataMax` should not be used simultaneously with `min/max`.
2. If a user does combine them, `dataMin/dataMax` will affect the result of `min: 'dataMin'` and `max: ‘dataMax’`.
For example: if the original data range is `[100, 300]`, setting `{ dataMax: 500, max: 'dataMax' }` will fix the axis maximum to 500.
Using the same terms here makes the it more intuitive.
3. I'm open to change the name if the maintainers have any recommendations
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "Justin-ZS (via GitHub)" <gi...@apache.org>.
Justin-ZS commented on PR #20838:
URL: https://github.com/apache/echarts/pull/20838#issuecomment-2823772007
> @Justin-ZS Can you further explain in which case should I set max value to be some rounded value larger than my given value, instead of not setting `max` at all?
When comparing multiple similar charts. (like sales data from different stores, one chart for one store)
When not setting the `max`, the axis max of chart 1 is `4000`, and the axis max of chart 2 is `3000`.
Setting "max" to all charts directly will make them ugly, as the max value could be `3744.55`
With this new feature, all axis max will be `4000`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "echarts-bot[bot] (via GitHub)" <gi...@apache.org>.
echarts-bot[bot] commented on PR #20838:
URL: https://github.com/apache/echarts/pull/20838#issuecomment-2735994627
Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout [the coding standard](https://echarts.apache.org/en/coding-standard.html) and Wiki about [How to make a pull request](https://github.com/apache/echarts/wiki/How-to-make-a-pull-request).
Document changes are required in this PR. Please also make a PR to [apache/echarts-doc](https://github.com/apache/echarts-doc) for document changes and update the issue id in the PR description. When the doc PR is merged, the maintainers will remove the `PR: awaiting doc` label.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "Justin-ZS (via GitHub)" <gi...@apache.org>.
Justin-ZS commented on PR #20838:
URL: https://github.com/apache/echarts/pull/20838#issuecomment-2975815826
> It should be helpful to provide a feature to _nice_ the min/max value of the axis. Thanks for the help! However, I don't think this should be the default behavior, and this also has a compatibility problem.
>
> For the current implementation, when `dataMax` is larger than the actual data max, a niced value that is no smaller than the `dataMax` is used; while when `dataMax` is smaller than the actual data max, it's not used at all. This behavior seems really confusing to me.
>
> I would suggest using `max: 'niceDataMax'` instead of providing a new option, and the data max is calculated to be a nice number automatically without providing a value. Does this satisfy your requirement?
Regarding compatibility, there should be no issues。
The behavior remains unchanged when `dataMin/dataMax` are not set.
To solve the use case, we need both:
1. User-defined max value
2. Enable nice rounding or not
With `max: 'niceDataMax'` alone, we can't achieve both because:
- It only enable the nice rounding
- But can't let users specify a reference max value
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "sjcobb (via GitHub)" <gi...@apache.org>.
sjcobb commented on PR #20838:
URL: https://github.com/apache/echarts/pull/20838#issuecomment-2798288007
I’ve experienced this problem as a user so interested to see how this PR progresses, I will say the naming here is a bit confusing, especially since ECharts already supports a different concept as: `min: 'dataMin'` and `max: ‘dataMax’`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "Justin-ZS (via GitHub)" <gi...@apache.org>.
Justin-ZS commented on PR #20838:
URL: https://github.com/apache/echarts/pull/20838#issuecomment-3344635876
@Ovilia @100pah
PR has been updated accordingly.
Could you help to review again? Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "100pah (via GitHub)" <gi...@apache.org>.
100pah commented on PR #20838:
URL: https://github.com/apache/echarts/pull/20838#issuecomment-3342547774
@Ovilia @Justin-ZS
At first glance, I originally thought the newly introduced `dataMin`/`dataMax` were not intuitive and didn't align well with the existing props `min`/`max`. But after thinking though this logic, I now find the design and naming appropriate.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "Ovilia (via GitHub)" <gi...@apache.org>.
Ovilia merged PR #20838:
URL: https://github.com/apache/echarts/pull/20838
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "Ovilia (via GitHub)" <gi...@apache.org>.
Ovilia commented on PR #20838:
URL: https://github.com/apache/echarts/pull/20838#issuecomment-2823351396
@Justin-ZS Can you further explain in which case should I set max value to be some rounded value larger than my given value, instead of not setting `max` at all?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "Justin-ZS (via GitHub)" <gi...@apache.org>.
Justin-ZS commented on PR #20838:
URL: https://github.com/apache/echarts/pull/20838#issuecomment-2768863902
@Ovilia @100pah Could you help to review the PR? Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "100pah (via GitHub)" <gi...@apache.org>.
100pah commented on code in PR #20838:
URL: https://github.com/apache/echarts/pull/20838#discussion_r2384917982
##########
src/coord/scaleRawExtentInfo.ts:
##########
@@ -98,6 +103,19 @@ export class ScaleRawExtentInfo {
const isOrdinal = this._isOrdinal = scale.type === 'ordinal';
this._needCrossZero = scale.type === 'interval' && model.getNeedCrossZero && model.getNeedCrossZero();
+ if (scale.type === 'interval' || scale.type === 'log') {
+ // Process custom dataMin/dataMax
+ this._dataMinRaw = (model as AxisBaseModel<NumericAxisBaseOptionCommon>).get('dataMin', true);
Review Comment:
`_dataMinRaw` and `_dataMaxRaw` is never used outside this function and do not need to persist. Therefore, it should be a local variable rather that a class member.
##########
src/coord/scaleRawExtentInfo.ts:
##########
@@ -98,6 +103,19 @@ export class ScaleRawExtentInfo {
const isOrdinal = this._isOrdinal = scale.type === 'ordinal';
this._needCrossZero = scale.type === 'interval' && model.getNeedCrossZero && model.getNeedCrossZero();
+ if (scale.type === 'interval' || scale.type === 'log') {
Review Comment:
I think `scale.type === 'time'` can be added to this condition.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
Re: [PR] feat(axis): support dataMin/dataMax to calc a nice axis range [echarts]
Posted by "echarts-bot[bot] (via GitHub)" <gi...@apache.org>.
echarts-bot[bot] commented on PR #20838:
URL: https://github.com/apache/echarts/pull/20838#issuecomment-3471071859
Congratulations! Your PR has been merged. Thanks for your contribution! 👍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org