Blame view

天文台pc/tianwentai-ui/node_modules/recharts/lib/cartesian/getEquidistantTicks.js 1.95 KB
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.getEquidistantTicks = getEquidistantTicks;
  var _TickUtils = require("../util/TickUtils");
  var _getEveryNthWithCondition = require("../util/getEveryNthWithCondition");
  function getEquidistantTicks(sign, boundaries, getTickSize, ticks, minTickGap) {
    var result = (ticks || []).slice();
    var initialStart = boundaries.start,
      end = boundaries.end;
    var index = 0;
    // Premature optimisation idea 1: Estimate a lower bound, and start from there.
    // For now, start from every tick
    var stepsize = 1;
    var start = initialStart;
    var _loop = function _loop() {
        // Given stepsize, evaluate whether every stepsize-th tick can be shown.
        // If it can not, then increase the stepsize by 1, and try again.
  
        var entry = ticks === null || ticks === void 0 ? void 0 : ticks[index];
  
        // Break condition - If we have evaluate all the ticks, then we are done.
        if (entry === undefined) {
          return {
            v: (0, _getEveryNthWithCondition.getEveryNthWithCondition)(ticks, stepsize)
          };
        }
  
        // Check if the element collides with the next element
        var i = index;
        var size;
        var getSize = function getSize() {
          if (size === undefined) {
            size = getTickSize(entry, i);
          }
          return size;
        };
        var tickCoord = entry.coordinate;
        // We will always show the first tick.
        var isShow = index === 0 || (0, _TickUtils.isVisible)(sign, tickCoord, getSize, start, end);
        if (!isShow) {
          // Start all over with a larger stepsize
          index = 0;
          start = initialStart;
          stepsize += 1;
        }
        if (isShow) {
          // If it can be shown, update the start
          start = tickCoord + sign * (getSize() / 2 + minTickGap);
          index += stepsize;
        }
      },
      _ret;
    while (stepsize <= result.length) {
      _ret = _loop();
      if (_ret) return _ret.v;
    }
    return [];
  }