From 3010cb8795ae6c022810c6876d47dc0b4b98fb44 Mon Sep 17 00:00:00 2001 From: Srajan-Sanjay-Saxena Date: Wed, 12 Nov 2025 22:39:05 +0530 Subject: [PATCH 1/2] fix(time-axis): resolve TypeError when using customValues with formatter on time axis Root Cause: - customValues creates basic ScaleTick objects without time property - TimeScale formatter code assumed tick.time always exists - Accessing tick.time.level and tick.time.upperTimeUnit without null checks Solution Applied: 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 correctly with customValues + formatter combination Impact: - Resolves GitHub issue with customValues + formatter combination - Maintains backward compatibility for existing time axis functionality - Enables proper custom tick positioning with formatted labels on time axes --- src/scale/Time.ts | 6 ++- src/util/time.ts | 2 +- test/customFormat.html | 90 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 test/customFormat.html diff --git a/src/scale/Time.ts b/src/scale/Time.ts index 07f589867e..a3a7de479c 100644 --- a/src/scale/Time.ts +++ b/src/scale/Time.ts @@ -206,8 +206,10 @@ class TimeScale extends IntervalScale { 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) { + upperUnitIndex = Math.min(upperUnitIndex, indexOf(primaryTimeUnits, tick.time.upperTimeUnit)); + maxLevel = Math.max(maxLevel, tick.time.level); + } }); if (scaleBreakHelper) { diff --git a/src/util/time.ts b/src/util/time.ts index 5157c63f41..6c6ed6bfe8 100644 --- a/src/util/time.ts +++ b/src/util/time.ts @@ -343,7 +343,7 @@ export function leveledFormat( else if (zrUtil.isFunction(formatter)) { const extra: TimeAxisLabelFormatterExtraParams = { time: tick.time, - level: tick.time.level, + level: tick.time ? tick.time.level : 0, }; const scaleBreakHelper = getScaleBreakHelper(); if (scaleBreakHelper) { diff --git a/test/customFormat.html b/test/customFormat.html new file mode 100644 index 0000000000..49940d8e72 --- /dev/null +++ b/test/customFormat.html @@ -0,0 +1,90 @@ + + + + ECharts Custom Format Test + + + +
+ + + + \ No newline at end of file From e9b24dbcefef1ff4c6969c6b5295b4336a891936 Mon Sep 17 00:00:00 2001 From: Srajan-Sanjay-Saxena Date: Wed, 12 Nov 2025 23:56:52 +0530 Subject: [PATCH 2/2] test: add customValues with formatter test case to axis-customTicks.html - Moved test case from standalone customFormat.html to existing axis-customTicks.html - Added test demonstrating time axis with customValues + formatter combination - Verifies the fix for TypeError when accessing tick.time.level --- test/axis-customTicks.html | 55 +++++++++++++++++++++++ test/customFormat.html | 90 -------------------------------------- 2 files changed, 55 insertions(+), 90 deletions(-) delete mode 100644 test/customFormat.html diff --git a/test/axis-customTicks.html b/test/axis-customTicks.html index 7f79f099d8..9aa8ec04e3 100644 --- a/test/axis-customTicks.html +++ b/test/axis-customTicks.html @@ -40,6 +40,7 @@
+
+ + diff --git a/test/customFormat.html b/test/customFormat.html deleted file mode 100644 index 49940d8e72..0000000000 --- a/test/customFormat.html +++ /dev/null @@ -1,90 +0,0 @@ - - - - ECharts Custom Format Test - - - -
- - - - \ No newline at end of file