@antv/g2plot
Version:
G2 Plot, a market of plots built with the Grammar of Graphics'
55 lines • 2.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var _ = tslib_1.__importStar(require("@antv/util"));
var parser_1 = tslib_1.__importDefault(require("../../../../components/label/parser"));
var formatter_1 = require("../../../../util/formatter");
var FunnelLabelParser = /** @class */ (function (_super) {
tslib_1.__extends(FunnelLabelParser, _super);
function FunnelLabelParser() {
return _super !== null && _super.apply(this, arguments) || this;
}
FunnelLabelParser.prototype.parseFormatter = function (config) {
var _this = this;
var values = [];
for (var _i = 1; _i < arguments.length; _i++) {
values[_i - 1] = arguments[_i];
}
var labelProps = this.originConfig;
var preformatter = formatter_1.combineFormatter(formatter_1.getNoopFormatter(), formatter_1.getPrecisionFormatter(labelProps.precision), formatter_1.getSuffixFormatter(labelProps.suffix));
var plotProps = this.plot.options;
config.formatter = function (xValue, item, idx) {
var proc = function (yValue, yValueTop) {
var yValueFormatted = preformatter(yValue, item, idx);
if (_.isFunction(labelProps.formatter)) {
return labelProps.formatter(xValue, item, idx, yValue, yValueTop);
}
else {
return xValue + " " + yValueFormatted;
}
};
if (plotProps.compareField) {
var yValues_1 = _.get(item, "_origin.__compare__.yValues");
var yValuesTop_1 = _.get(_this.plot.getData(), "0.__compare__.yValues");
if (plotProps.transpose) {
_.set(config, 'textStyle.lineHeight', _.get(config, 'textStyle.fontSize', 12));
}
return [0, 1]
.map(function (i) {
var yValue = yValues_1[i];
var yValueTop = yValuesTop_1[i];
return proc(yValue, yValueTop);
})
.join(plotProps.transpose ? '\n\n' : ' ');
}
else {
var yValue = _.get(item, "_origin." + plotProps.yField);
var yValueTop = _.get(_this.plot.getData(), "0." + plotProps.yField);
return proc(yValue, yValueTop);
}
};
};
return FunnelLabelParser;
}(parser_1.default));
exports.default = FunnelLabelParser;
//# sourceMappingURL=funnel-label-parser.js.map