UNPKG

@antv/g2plot

Version:

G2 Plot, a market of plots built with the Grammar of Graphics'

44 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var _ = tslib_1.__importStar(require("@antv/util")); var text_hide_1 = tslib_1.__importDefault(require("./text-hide")); function nodesResampling(shape, option, index, cfg) { var nodes = cfg.nodes.nodes; /** nodeLength为偶数,则奇数index的shape保留,反之则偶数index的shape保留 */ var oddKeep = nodes.length % 2 === 0 ? false : true; if (isKeep(option.keep, index, nodes)) { return; } { var isOdd = index % 2 === 0 ? true : false; if ((!oddKeep && isOdd) || (oddKeep && !isOdd)) { text_hide_1.default(shape); } } } exports.default = nodesResampling; function isKeep(keepCfg, index, nodes) { /** 允许设置start end 或任意index */ var conditions = []; _.each(keepCfg, function (cfg) { if (cfg === 'start') { conditions.push(index === 0); } else if (cfg === 'end') { conditions.push(index === nodes.length - 1); } else if (_.isNumber(cfg)) { conditions.push(index === cfg); } }); for (var _i = 0, conditions_1 = conditions; _i < conditions_1.length; _i++) { var condition = conditions_1[_i]; if (condition === true) { return true; } } return false; } exports.isKeep = isKeep; //# sourceMappingURL=nodes-resampling.js.map