UNPKG

@antv/f2

Version:

Charts for mobile visualization.

120 lines (119 loc) 3.8 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _tslib = require("tslib"); var _fEngine = require("@antv/f-engine"); var _util = require("@antv/util"); var _geometry = _interopRequireDefault(require("../geometry")); // 默认配色 var COLORS = ['#E62C3B', '#0E9976', '#999999' // 平盘 ]; var _default = exports.default = function _default(View) { return /** @class */function (_super) { (0, _tslib.__extends)(Candlestick, _super); function Candlestick() { return _super !== null && _super.apply(this, arguments) || this; } Candlestick.prototype.getDefaultCfg = function () { return { geomType: 'candlestick' }; }; Candlestick.prototype.getSize = function () { var _a = this, attrs = _a.attrs, props = _a.props; var _b = props.sizeRatio, sizeRatio = _b === void 0 ? 0.5 : _b; var x = attrs.x; var scale = x.scale; var values = scale.values; return 1 / values.length * sizeRatio; }; Candlestick.prototype._getColor = function (colors, child, prevChild) { var normalized = child.normalized; // 处理颜色 var y = normalized.y; var open = y[0], close = y[1]; if (close > open) { return colors[0]; } if (close < open) { return colors[1]; } // 相等的情况下,再和昨日的收盘价比较 if (!prevChild) { // 第一个固定为涨 return colors[0]; } var prevNormalized = prevChild.normalized; // 处理颜色 var prevY = prevNormalized.y; var prevClose = prevY[1]; if (close > prevClose) { return colors[0]; } if (close < prevClose) { return colors[1]; } return colors[2]; }; Candlestick.prototype.mapping = function () { var records = _super.prototype.mapping.call(this); var props = this.props; var coord = props.coord; var y0 = this.getY0Value(); var defaultSize = this.getSize(); var colorAttr = this.getAttr('color'); var colors = colorAttr ? colorAttr.range : COLORS; for (var i = 0, len = records.length; i < len; i++) { var record = records[i]; var children = record.children; for (var j = 0, len_1 = children.length; j < len_1; j++) { var child = children[j]; var normalized = child.normalized, mappedSize = child.size; // 没有指定size,则根据数据来计算默认size if ((0, _util.isNil)(mappedSize)) { var x = normalized.x, y = normalized.y, _a = normalized.size, size = _a === void 0 ? defaultSize : _a; (0, _util.mix)(child, coord.convertRect({ x: x, y: y, y0: y0, size: size })); } else { var x = child.x, y = child.y; var rect = { x: x, y: y, y0: y0, size: mappedSize }; (0, _util.mix)(child, coord.transformToRect(rect)); } // 处理颜色 child.color = this._getColor(colors, child, children[j - 1]); (0, _util.mix)(child.shape, this.getSelectionStyle(child)); } } return records; }; Candlestick.prototype.render = function () { var props = this.props; var records = this.mapping(); return (0, _fEngine.jsx)(View, (0, _tslib.__assign)({}, props, { records: records })); }; return Candlestick; }(_geometry.default); };