UNPKG

@antv/f2

Version:

Charts for mobile visualization.

113 lines 3.48 kB
import { __assign, __extends } from "tslib"; import { jsx } from '@antv/f-engine'; import { isNil, mix } from '@antv/util'; import Geometry from '../geometry'; // 默认配色 var COLORS = ['#E62C3B', '#0E9976', '#999999' // 平盘 ]; export default (function (View) { return /** @class */function (_super) { __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 (isNil(mappedSize)) { var x = normalized.x, y = normalized.y, _a = normalized.size, size = _a === void 0 ? defaultSize : _a; 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 }; mix(child, coord.transformToRect(rect)); } // 处理颜色 child.color = this._getColor(colors, child, children[j - 1]); mix(child.shape, this.getSelectionStyle(child)); } } return records; }; Candlestick.prototype.render = function () { var props = this.props; var records = this.mapping(); return jsx(View, __assign({}, props, { records: records })); }; return Candlestick; }(Geometry); });