mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-03 02:54:06 +01:00
fix: optimize tick interval calculation using dayjs for improved accuracy
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
@@ -614,16 +614,7 @@ export const draw = function (text, id, version, diagObj) {
|
|||||||
*/
|
*/
|
||||||
function getEstimatedTickCount(minTime, maxTime, every, interval) {
|
function getEstimatedTickCount(minTime, maxTime, every, interval) {
|
||||||
const timeDiffMs = maxTime - minTime;
|
const timeDiffMs = maxTime - minTime;
|
||||||
const msPerUnit = {
|
const intervalMs = dayjs.duration({ [interval ?? 'day']: every }).asMilliseconds();
|
||||||
millisecond: 1,
|
|
||||||
second: 1000,
|
|
||||||
minute: 60 * 1000,
|
|
||||||
hour: 60 * 60 * 1000,
|
|
||||||
day: 24 * 60 * 60 * 1000,
|
|
||||||
week: 7 * 24 * 60 * 60 * 1000,
|
|
||||||
month: 30 * 24 * 60 * 60 * 1000, // Approximate
|
|
||||||
};
|
|
||||||
const intervalMs = (msPerUnit[interval] || msPerUnit.day) * every;
|
|
||||||
return Math.ceil(timeDiffMs / intervalMs);
|
return Math.ceil(timeDiffMs / intervalMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user