MCPcopy Index your code
hub / github.com/apache/echarts / calcNiceForTimeScale

Function calcNiceForTimeScale

src/scale/Time.ts:740–785  ·  view source on GitHub ↗
(scale: TimeScale, opt)

Source from the content-addressed store, hash-verified

738}
739
740export 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
787Scale.registerClass(TimeScale);
788

Callers

nothing calls this directly

Calls 6

ensureValidSplitNumberFunction · 0.90
bisectFunction · 0.85
setTimeIntervalMethod · 0.80
getExtentMethod · 0.65
setExtentMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…