You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2020/07/30 08:03:15 UTC

[incubator-echarts] branch next updated: fix(axis): improve ticks calculation in time axis

This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch next
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git


The following commit(s) were added to refs/heads/next by this push:
     new d001989  fix(axis): improve ticks calculation in time axis
d001989 is described below

commit d0019896575606f259fd9c73e3fe1341efb6075b
Author: pissang <bm...@gmail.com>
AuthorDate: Thu Jul 30 16:02:38 2020 +0800

    fix(axis): improve ticks calculation in time axis
---
 src/scale/Time.ts | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/scale/Time.ts b/src/scale/Time.ts
index 6a92364..03b62b2 100644
--- a/src/scale/Time.ts
+++ b/src/scale/Time.ts
@@ -324,7 +324,7 @@ function getIntervalTicks(
     let iter = 0;
 
     for (let i = 0, hasTickInLevel = false; i < unitNames.length && iter++ < safeLimit; ++i) {
-        const date = new Date(extent[0]);
+        let date = new Date(extent[0]);
 
         if (unitNames[i] === 'week' || unitNames[i] === 'half-week') {
             date[setHoursMethodName](0);
@@ -341,7 +341,13 @@ function getIntervalTicks(
             }
 
             outer: while (iter++ < safeLimit) {
-                const dateInterval = approxInterval > ONE_DAY * 16 ? 15
+                const tmpDate = new Date(date);
+                tmpDate[setDateMethodName](1);
+                tmpDate[setMonthMethodName](tmpDate[getMonthMethodName]() + 1);
+                tmpDate[setDateMethodName](0);  // Set day to 0 to return the last day of last month.
+                const daysInMonth = tmpDate.getDate();
+
+                const dateInterval = approxInterval > ONE_DAY * 16 ? Math.floor(daysInMonth / 2) + 1  // In this case we only want one tick betwen two month.
                     : approxInterval > ONE_DAY * 8 ? 8
                         : approxInterval > ONE_DAY * 3.5 ? 4
                             : approxInterval > ONE_DAY * 1.5 ? 2 : 1;
@@ -349,11 +355,6 @@ function getIntervalTicks(
                 // const dates = approxInterval > ONE_DAY * 8 ? [15]
                 //     : (approxInterval > ONE_DAY * 3.5 ? [8, 16, 24] : [4, 8, 12, 16, 20, 24, 28]);
 
-                const tmpDate = new Date(date);
-                tmpDate[setMonthMethodName](tmpDate[getMonthMethodName]() + 2);
-                tmpDate[setDateMethodName](0);  // Set day to 0 to return the last day of last month.
-                const daysInMonth = tmpDate.getDate();
-
                 for (let d = dateInterval; d < daysInMonth; d += dateInterval) {
 
                     date[setDateMethodName](d);
@@ -372,8 +373,6 @@ function getIntervalTicks(
 
                 // Reset date to 0. The date may be 30, and days of next month may be 29. Which will excced
                 date[setDateMethodName](1);
-
-                // Move to next month. Add 2 because getMonth starts with 0, setMonth starts with 1.
                 date[setMonthMethodName](date[getMonthMethodName]() + 1);
             }
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org