(scale: TimeScale, opt)
| 738 | } |
| 739 | |
| 740 | export const calcNiceForTimeScale: ScaleCalcNiceMethod = function (scale: TimeScale, opt) { |
| 741 | const extent = scale.getExtent(); |
| 742 | // If extent start and end are same, expand them |
| 743 | if (extent[0] === extent[1]) { |
| 744 | // Expand extent |
| 745 | extent[0] -= ONE_DAY; |
| 746 | extent[1] += ONE_DAY; |
| 747 | } |
| 748 | // If there are no data and extent are [Infinity, -Infinity] |
| 749 | if (extent[1] === -Infinity && extent[0] === Infinity) { |
| 750 | const d = new Date(); |
| 751 | extent[1] = +new Date(d.getFullYear(), d.getMonth(), d.getDate()); |
| 752 | extent[0] = extent[1] - ONE_DAY; |
| 753 | } |
| 754 | scale.setExtent(extent[0], extent[1]); |
| 755 | |
| 756 | const splitNumber = ensureValidSplitNumber(opt.splitNumber, 10); |
| 757 | let approxInterval = getScaleLinearSpanEffective(scale) / splitNumber; |
| 758 | |
| 759 | const minInterval = opt.minInterval; |
| 760 | const maxInterval = opt.maxInterval; |
| 761 | if (minInterval != null && approxInterval < minInterval) { |
| 762 | approxInterval = minInterval; |
| 763 | } |
| 764 | if (maxInterval != null && approxInterval > maxInterval) { |
| 765 | approxInterval = maxInterval; |
| 766 | } |
| 767 | |
| 768 | const scaleIntervalsLen = scaleIntervals.length; |
| 769 | const idx = Math.min( |
| 770 | bisect(scaleIntervals, approxInterval, 0, scaleIntervalsLen), |
| 771 | scaleIntervalsLen - 1 |
| 772 | ); |
| 773 | |
| 774 | // Interval that can be used to calculate ticks |
| 775 | const interval = scaleIntervals[idx][1]; |
| 776 | // Min level used when picking ticks from top down. |
| 777 | // We check one more level to avoid the ticks are to sparse in some case. |
| 778 | const minLevelUnit = scaleIntervals[Math.max(idx - 1, 0)][0]; |
| 779 | |
| 780 | scale.setTimeInterval({ |
| 781 | approxInterval, |
| 782 | interval, |
| 783 | minLevelUnit |
| 784 | }); |
| 785 | }; |
| 786 | |
| 787 | Scale.registerClass(TimeScale); |
| 788 |
nothing calls this directly
no test coverage detected
searching dependent graphs…