UNPKG

989 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7// cat平均算法,保头保尾
8var _default = exports.default = function _default(cfg) {
9 var values = cfg.values,
10 tickCount = cfg.tickCount;
11 if (!tickCount) {
12 return values;
13 }
14 if (values.length <= 1) {
15 return values;
16 }
17 // 获取间隔步长, 最小是1
18 var step = Math.floor(values.length / (tickCount - 1)) || 1;
19 var ticks = [];
20 // 按间隔数取对应节点
21 for (var index = 0; index < values.length; index = index + step) {
22 ticks.push(values[index]);
23 }
24 var last = values[values.length - 1];
25 // 如果最后一个tick不等于原数据的最后一个
26 if (ticks[ticks.length - 1] !== last) {
27 if (ticks.length >= tickCount) {
28 // 如果当前的tick个数满足要求
29 ticks[ticks.length - 1] = last;
30 } else {
31 // 不满足tickCount则直接加入最后一个
32 ticks.push(last);
33 }
34 }
35 return ticks;
36};
\No newline at end of file