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.

95 lines (92 loc) 3.69 kB
import { createEntityPhraseFactory } from '../createEntityPhraseFactory.js'; import { isNumber } from '../../utils/isType.js'; import { getPrefixCls } from '../../utils/getPrefixCls.js'; import 'clarinet'; import { createInlineDocument } from '../utils/createInlineDocument.js'; import 'tslib'; // import { ArrowDown, ArrowUp } from '../../assets/icons'; var MARGIN_RIGHT = 1; var defaultDeltaValueDescriptor = { classNames: function (value, _a) { var assessment = _a.assessment; return [getPrefixCls("value-".concat(assessment))]; }, getText: getAssessmentText, render: function (value, _a) { var assessment = _a.assessment; return createInlineDocument(getComparePrefix(assessment, ['-', '+']), value, 'prefix'); }, style: function (value, _a, themeSeedToken) { var assessment = _a.assessment; return ({ color: getCompareColor(assessment, themeSeedToken), }); }, tooltip: { title: function (value, metadata) { return (isNumber(metadata.origin) ? "".concat(metadata.origin) : null); }, }, }; var createDeltaValue = createEntityPhraseFactory('delta_value', defaultDeltaValueDescriptor); var defaultRatioValueDescriptor = { classNames: function (value, _a) { var assessment = _a.assessment; return [getPrefixCls("value-".concat(assessment))]; }, getText: getAssessmentText, render: function (value, _a) { var assessment = _a.assessment; var prefix = getComparePrefix(assessment, [createArrow('up'), createArrow('down')]); return createInlineDocument(prefix, value, 'prefix'); }, style: function (value, _a, themeSeedToken) { var assessment = _a.assessment; return ({ color: getCompareColor(assessment, themeSeedToken), }); }, tooltip: { title: function (value, metadata) { return (isNumber(metadata.origin) ? "".concat(metadata.origin) : null); }, }, }; var createRatioValue = createEntityPhraseFactory('ratio_value', defaultRatioValueDescriptor); function getCompareColor(assessment, themeSeedToken) { var color; if (assessment === 'positive') color = themeSeedToken.colorPositive; if (assessment === 'negative') color = themeSeedToken.colorNegative; return color; } function getComparePrefix(assessment, _a) { var neg = _a[0], pos = _a[1]; var prefix = null; if (assessment === 'negative') prefix = neg; if (assessment === 'positive') prefix = pos; return prefix; } function getAssessmentText(value, metadata) { return "".concat((metadata === null || metadata === void 0 ? void 0 : metadata.assessment) === 'negative' ? '-' : '').concat(value); } function createArrow(direction) { var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); svg.setAttribute('width', '8px'); svg.setAttribute('height', '9px'); svg.setAttribute('viewBox', '0 0 8 9'); svg.style.marginRight = "".concat(MARGIN_RIGHT, "px"); svg.setAttribute('version', '1.1'); var g = document.createElementNS('http://www.w3.org/2000/svg', 'g'); g.setAttribute('transform', 'translate(-2.000000, -2.000000)'); var polygon = document.createElementNS('http://www.w3.org/2000/svg', 'polygon'); polygon.setAttribute('fill', 'currentColor'); var points = direction === 'down' ? '6 2 9.5 11 2.5 11' // arrow down : '6 11 9.5 2 2.5 2'; // arrow up polygon.setAttribute('points', points); g.appendChild(polygon); svg.appendChild(g); return svg; } export { createDeltaValue, createRatioValue }; //# sourceMappingURL=createCompare.js.map