UNPKG

@antv/t8

Version:

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

39 lines (36 loc) 1.54 kB
import { createEntityPhraseFactory } from '../createEntityPhraseFactory.js'; import 'preact/jsx-runtime'; import 'tslib'; import 'preact/hooks'; import '../../charts/line/useLineCompute.js'; import { Proportion } from '../../charts/proportion/index.js'; import { render, h } from 'preact'; import { createInlineDocument } from '../utils/createInlineDocument.js'; import { isNumber } from '../../utils/isType.js'; import 'clarinet'; var defaultProportionDescriptor = { render: function (value, _a) { var origin = _a.origin; var chartElement = document.createElement('span'); render(h(Proportion, { data: getProportionNumber(value, origin) }), chartElement); 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