UNPKG

@antv/t8

Version:

T8 is a text visualization solution for unstructured data within the AntV technology stack, and it is a declarative T8 markdown syntax that can be used to describe the content of data interpretation reports.

35 lines (32 loc) 1.5 kB
import { createEntityPhraseFactory } from '../createEntityPhraseFactory.js'; import { isNumber } from '../../utils/isType.js'; import '../../charts/utils/selection.js'; import 'tslib'; import { renderProportionChart } from '../../charts/proportion/index.js'; import { createInlineDocument } from '../utils/createInlineDocument.js'; var defaultProportionDescriptor = { render: function (value, _a, paragraphType, themeSeedToken) { var origin = _a.origin; var chartElement = document.createElement('span'); renderProportionChart(chartElement, { data: getProportionNumber(value, origin) }, paragraphType, themeSeedToken); return createInlineDocument(chartElement, value, 'suffix'); }, tooltip: { title: function (value, metadata) { return (isNumber(metadata.origin) ? "".concat(metadata.origin) : null); }, }, }; var createProportion = createEntityPhraseFactory('proportion', defaultProportionDescriptor); /** text & entity */ var isNaN = function (v) { return Number.isNaN(v); }; function getProportionNumber(text, value) { if (value && !isNaN(value)) return value; if (text === null || text === void 0 ? void 0 : text.endsWith('%')) { var percentageValue = text === null || text === void 0 ? void 0 : text.replace(/%$/, ''); if (!isNaN(Number(percentageValue))) return Number(percentageValue) / 100; } return NaN; } export { createProportion }; //# sourceMappingURL=createProportion.js.map