UNPKG

@antv/f2

Version:

Charts for mobile visualization.

88 lines (87 loc) 2.82 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.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_1 = normalized.y, _a = normalized.size, size = _a === void 0 ? defaultSize : _a; mix(child, coord.convertRect({ x: x, y: y_1, y0: y0, size: size })); } else { var x = child.x, y_2 = child.y; var rect = { x: x, y: y_2, y0: y0, size: mappedSize }; mix(child, coord.transformToRect(rect)); } // 处理颜色 var y = normalized.y; var open_1 = y[0], close_1 = y[1]; child.color = close_1 > open_1 ? colors[0] : close_1 < open_1 ? colors[1] : colors[2]; 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); });