@antv/g2plot
Version:
G2 Plot, a market of plots built with the Grammar of Graphics'
53 lines • 2.47 kB
JavaScript
import { __extends } from "tslib";
import * as _ from '@antv/util';
import LabelParser from '../../../../components/label/parser';
import { getPrecisionFormatter, getSuffixFormatter, combineFormatter, getNoopFormatter, } from '../../../../util/formatter';
var FunnelLabelParser = /** @class */ (function (_super) {
__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 = combineFormatter(getNoopFormatter(), getPrecisionFormatter(labelProps.precision), 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;
}(LabelParser));
export default FunnelLabelParser;
//# sourceMappingURL=funnel-label-parser.js.map