@formant/ava
Version:
A framework for automated visual analytics.
73 lines (72 loc) • 3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
/* eslint-disable no-template-curly-in-string */
var ntv_1 = require("../../../ntv");
var base_1 = require("./base");
var helpers_1 = require("./helpers");
var variableMetaMap = {
measures: {
varType: 'metric_name',
},
'.dim': {
varType: 'dim_value',
},
};
var ExceptionNarrativeStrategy = /** @class */ (function (_super) {
tslib_1.__extends(ExceptionNarrativeStrategy, _super);
function ExceptionNarrativeStrategy() {
return _super !== null && _super.apply(this, arguments) || this;
}
ExceptionNarrativeStrategy.prototype.generateTextSpec = function (insightInfo, lang) {
var measures = insightInfo.measures, dimensions = insightInfo.dimensions, insightType = insightInfo.insightType, exceptions = insightInfo.exceptions;
var spec = (0, ntv_1.generateTextSpec)({
structures: ExceptionNarrativeStrategy.structures[lang],
structureTemps: ExceptionNarrativeStrategy.structureTemps[lang],
variable: {
measures: measures.map(function (m) { return m.fieldName; }).join((0, helpers_1.getDefaultSeparator)(lang)),
dimensions: dimensions.map(function (m) { return m.fieldName; }).join((0, helpers_1.getDefaultSeparator)(lang)),
insightType: (0, helpers_1.getInsightName)(insightType, lang),
exceptions: exceptions.map(function (dim) { return ({ dim: dim }); }),
},
});
return spec.sections[0].paragraphs;
};
ExceptionNarrativeStrategy.insightType = 'exception';
ExceptionNarrativeStrategy.structures = {
'zh-CN': [
{
template: '大部分 ${dimensions} 的维值在 ${measures} 上具有 ${insightType},除了&{exceptionList}。',
variableMetaMap: variableMetaMap,
},
],
'en-US': [
{
template: 'Most of the dimension values of ${dimensions} have ${insightType} on ${measures}, except for &{exceptionList}.',
variableMetaMap: variableMetaMap,
},
],
};
ExceptionNarrativeStrategy.structureTemps = {
'zh-CN': [
{
templateId: 'exceptionList',
template: '${.dim}',
useVariable: 'exceptions',
separator: (0, helpers_1.getDefaultSeparator)('zh-CN'),
variableMetaMap: variableMetaMap,
},
],
'en-US': [
{
templateId: 'exceptionList',
template: '${.dim}',
useVariable: 'exceptions',
separator: (0, helpers_1.getDefaultSeparator)('en-US'),
variableMetaMap: variableMetaMap,
},
],
};
return ExceptionNarrativeStrategy;
}(base_1.InsightNarrativeStrategy));
exports.default = ExceptionNarrativeStrategy;