You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by "Srajan-Sanjay-Saxena (via GitHub)" <gi...@apache.org> on 2025/11/10 19:50:39 UTC

[PR] fix(time-axis): resolve TypeError when using customValues with format… [echarts]

Srajan-Sanjay-Saxena opened a new pull request, #21352:
URL: https://github.com/apache/echarts/pull/21352

   fix(time-axis): resolve TypeError when using customValues with formatter on time axis
   
   ## Brief Information
   
   This pull request is in the type of:
   
   - [x] bug fixing
   - [ ] new feature
   - [ ] others
   
   ### What does this PR do?
   
   Fixes TypeError "Cannot read properties of undefined (reading 'level')" when using customValues with formatter function on time axis.
   
   ### Fixed issues
   
   - Resolves GitHub issue with customValues + formatter combination causing runtime errors
   
   ## Details
   
   ### Before: What was the problem?
   
   When using `customValues` with a `formatter` function on a time axis, ECharts threw a TypeError: "Cannot read properties of undefined (reading 'level')". This occurred because:
   
   - customValues creates basic ScaleTick objects without time property
   - TimeScale formatter code assumed tick.time always exists
   - Code accessed tick.time.level and tick.time.upperTimeUnit without null checks
   
   ### After: How does it behave after the fixing?
   
   The time axis now properly handles customValues with formatter functions without throwing errors. The fix:
   
   1. src/util/time.ts:346 - Added null check: `level: tick.time ? tick.time.level : 0`
   2. src/scale/Time.ts:208-212 - Wrapped tick.time access in conditional: `if (tick.time) { ... }`
   
   Testing:
   - Created test/customFormat.html with enhanced styling and custom labels
   - Verified fixes work with npm run prepare && npm run build
   - Confirmed both fixes present in distribution files
   
   Impact:
   - Maintains backward compatibility for existing time axis functionality
   - Enables proper custom tick positioning with formatted labels on time axes
   
   ## Document Info
   
   - [x] 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
   
   ## Misc
   
   ### Security Checking
   
   - [x] This PR uses security-sensitive Web APIs.
   
   ### ZRender Changes
   
   - [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).
   
   ### Related test cases or examples to use the new APIs
   
   test/customFormat.html demonstrates the fix with customValues + formatter combination
   
   ### Merging options
   
   - [x] Please squash the commits into a single one when merging.
   
   ### Other information
   
   Files Modified:
   - src/util/time.ts (leveledFormat function)
   - src/scale/Time.ts (getTicks method)
   - test/customFormat.html (enhanced styling demo)
   - dist/* (rebuilt distribution files)
   
   I am attaching a video for the solution i have added
   https://github.com/user-attachments/assets/29d9d047-edab-414d-9512-6dae1cf455ff
   
   


-- 
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] fix(time-axis): resolve TypeError when using customValues with format… [echarts]

Posted by "Srajan-Sanjay-Saxena (via GitHub)" <gi...@apache.org>.
Srajan-Sanjay-Saxena commented on code in PR #21352:
URL: https://github.com/apache/echarts/pull/21352#discussion_r2519138577


##########
dist/extension/bmap.js:
##########


Review Comment:
   done in commit 3010cb8795ae6c022810c6876d47dc0b4b98fb44



-- 
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] fix(time-axis): resolve TypeError when using customValues with format… [echarts]

Posted by "Srajan-Sanjay-Saxena (via GitHub)" <gi...@apache.org>.
Srajan-Sanjay-Saxena commented on code in PR #21352:
URL: https://github.com/apache/echarts/pull/21352#discussion_r2519351446


##########
src/scale/Time.ts:
##########
@@ -206,8 +206,10 @@ class TimeScale extends IntervalScale<TimeScaleSetting> {
         let upperUnitIndex = primaryTimeUnits.length - 1;
         let maxLevel = 0;
         each(ticks, tick => {
-            upperUnitIndex = Math.min(upperUnitIndex, indexOf(primaryTimeUnits, tick.time.upperTimeUnit));
-            maxLevel = Math.max(maxLevel, tick.time.level);
+            if (tick.time) {

Review Comment:
   i mean yeah if you are not bothered right now about type level security and just want fast growth of the app then you can keep it disabled ... but you know it will always cause these kind of issues where possible nullability results into crashing of some renderings . I guess for the next bump to a higher version we should enable that .



-- 
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] fix(axis-time): fix chart can't work when using `customValues` with `formatter` in axis label [echarts]

Posted by "plainheart (via GitHub)" <gi...@apache.org>.
plainheart merged PR #21352:
URL: https://github.com/apache/echarts/pull/21352


-- 
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] fix(time-axis): resolve TypeError when using customValues with format… [echarts]

Posted by "Srajan-Sanjay-Saxena (via GitHub)" <gi...@apache.org>.
Srajan-Sanjay-Saxena commented on code in PR #21352:
URL: https://github.com/apache/echarts/pull/21352#discussion_r2519365832


##########
test/customFormat.html:
##########
@@ -0,0 +1,90 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>ECharts Custom Format Test</title>
+    <script src="../dist/echarts.min.js?v=3"></script>
+</head>
+<body>
+    <div id="chart" style="width: 800px; height: 400px;"></div>
+
+    <script>
+        const weeklyData = [

Review Comment:
   done in e9b24dbcefef1ff4c6969c6b5295b4336a891936



-- 
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] fix(time-axis): resolve TypeError when using customValues with format… [echarts]

Posted by "plainheart (via GitHub)" <gi...@apache.org>.
plainheart commented on code in PR #21352:
URL: https://github.com/apache/echarts/pull/21352#discussion_r2519283334


##########
test/customFormat.html:
##########
@@ -0,0 +1,90 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>ECharts Custom Format Test</title>
+    <script src="../dist/echarts.min.js?v=3"></script>
+</head>
+<body>
+    <div id="chart" style="width: 800px; height: 400px;"></div>
+
+    <script>
+        const weeklyData = [

Review Comment:
   I suggest adding this test case to the present `test/axis-customTicks.html`.



##########
src/scale/Time.ts:
##########
@@ -206,8 +206,10 @@ class TimeScale extends IntervalScale<TimeScaleSetting> {
         let upperUnitIndex = primaryTimeUnits.length - 1;
         let maxLevel = 0;
         each(ticks, tick => {
-            upperUnitIndex = Math.min(upperUnitIndex, indexOf(primaryTimeUnits, tick.time.upperTimeUnit));
-            maxLevel = Math.max(maxLevel, tick.time.level);
+            if (tick.time) {

Review Comment:
   I noticed that TypeScript suppresses this TypeError as per the current tsconfig.json, where the `strictNullChecks` option is disabled. But if we enable it, there are many errors to be fixed. For simplicity, I agree with your current fix by adding the safeguard.
   
   @100pah How do you think about this?



-- 
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] fix(time-axis): resolve TypeError when using customValues with format… [echarts]

Posted by "Srajan-Sanjay-Saxena (via GitHub)" <gi...@apache.org>.
Srajan-Sanjay-Saxena commented on code in PR #21352:
URL: https://github.com/apache/echarts/pull/21352#discussion_r2519351446


##########
src/scale/Time.ts:
##########
@@ -206,8 +206,10 @@ class TimeScale extends IntervalScale<TimeScaleSetting> {
         let upperUnitIndex = primaryTimeUnits.length - 1;
         let maxLevel = 0;
         each(ticks, tick => {
-            upperUnitIndex = Math.min(upperUnitIndex, indexOf(primaryTimeUnits, tick.time.upperTimeUnit));
-            maxLevel = Math.max(maxLevel, tick.time.level);
+            if (tick.time) {

Review Comment:
   i mean yeah if you are not bothered right now about type level security and just want fast growth of the app then you can keep it disabled ... but you know it will always cause these kind of issues where possible nullability results into crashing of some renderings . I guess for the next bump to a higher version we should enable that .



-- 
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] fix(time-axis): resolve TypeError when using customValues with format… [echarts]

Posted by "plainheart (via GitHub)" <gi...@apache.org>.
plainheart commented on code in PR #21352:
URL: https://github.com/apache/echarts/pull/21352#discussion_r2519078329


##########
dist/extension/bmap.js:
##########


Review Comment:
   Please DO NOT commit the files in [dist](https://github.com/apache/echarts/tree/master/dist), [i18n](https://github.com/apache/echarts/tree/master/i18n), and [ssr/client/dist](https://github.com/apache/echarts/tree/master/ssr/client/dist) folders in a non-release pull request. These folders are for release use only.



-- 
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] fix(axis-time): fix chart can't work when using `customValues` with `formatter` in axis label [echarts]

Posted by "echarts-bot[bot] (via GitHub)" <gi...@apache.org>.
echarts-bot[bot] commented on PR #21352:
URL: https://github.com/apache/echarts/pull/21352#issuecomment-3533050349

   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


Re: [PR] fix(time-axis): resolve TypeError when using customValues with format… [echarts]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #21352:
URL: https://github.com/apache/echarts/pull/21352#issuecomment-3523302764

   The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-21352@3010cb8
   <!-- ECHARTS_PR_PREVIEW -->


-- 
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] fix(time-axis): resolve TypeError when using customValues with format… [echarts]

Posted by "echarts-bot[bot] (via GitHub)" <gi...@apache.org>.
echarts-bot[bot] commented on PR #21352:
URL: https://github.com/apache/echarts/pull/21352#issuecomment-3513650336

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


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