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AAC,SAAS,EAAE,GAAG,UAAU,CAAC,WAAW,GAAG,CAAC,CAAC;gBAC3E,0BAA0B,CAAC,SAAS,aAClC,KAAK,EAAE,UAAG,cAAc,OAAI,EAC5B,SAAS,EAAE,0BAAmB,OAAO,QAAK,IAEvC,WAAW,CAAC,KAAK,CAAC,EACrB,CAAC;gBAEH,IAAM,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;gBACpC,IAAI,MAAM,CAAC,UAAU,EAAE;oBACrB,OAAO,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;iBAChE;gBAED,IAAI,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC;gBAC1B,IAAI,MAAM,CAAC,SAAS,EAAE;oBACpB,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;iBAC9C;gBAED,sDAAsD;gBACtD,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAG,IAAI,CAAE,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;YACpE,CAAC,IACE,IAAI,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,WAAW,EACnF,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { IGroup, View } from '@antv/g2';\nimport { each, get, isFunction, isNumber, isString } from '@antv/util';\nimport { Datum, ShapeStyle, Statistic, StatisticText } from '../types';\nimport { kebabCase } from './kebab-case';\nimport { pick } from './pick';\n\n/**\n * @desc 生成 html-statistic 的 style 字符串 (兼容 canvas 的 shapeStyle 到 css样式上)\n *\n * @param width\n * @param style\n */\nexport function adapteStyle(style?: StatisticText['style']): object {\n const styleObject = {\n overflow: 'hidden',\n 'white-space': 'nowrap',\n 'text-overflow': 'ellipsis',\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n };\n\n const shapeStyleKeys = [\n 'stroke',\n 'lineWidth',\n 'shadowColor',\n 'strokeOpacity',\n 'shadowBlur',\n 'shadowOffsetX',\n 'shadowOffsetY',\n 'fill',\n ];\n\n // 兼容 shapeStyle 设置 · start\n if (get(style, 'fill')) {\n styleObject['color'] = style['fill'];\n }\n const {\n shadowColor,\n shadowBlur = 0,\n shadowOffsetX = 0,\n shadowOffsetY = 0,\n } = pick(style, shapeStyleKeys) as ShapeStyle;\n styleObject['text-shadow'] = `${[shadowColor, `${shadowOffsetX}px`, `${shadowOffsetY}px`, `${shadowBlur}px`].join(\n ' '\n )}`;\n\n const { stroke, lineWidth = 0 } = pick(style, shapeStyleKeys) as ShapeStyle;\n styleObject['-webkit-text-stroke'] = `${[`${lineWidth}px`, stroke].join(' ')}`;\n // 兼容 shapeStyle 设置 · end\n\n each(style, (v, k) => {\n // 兼容 shapeStyle 的 fontSize 没有单位\n if (['fontSize'].includes(k) && isNumber(v)) {\n styleObject[kebabCase(k)] = `${v}px`;\n } else if (k && !shapeStyleKeys.includes(k)) {\n styleObject[kebabCase(k)] = `${v}`;\n }\n });\n\n return styleObject;\n}\n\n/**\n * @desc 设置 html-statistic 容器的默认样式\n *\n * - 默认事件穿透\n */\nexport function setStatisticContainerStyle(container: HTMLElement, style: Partial) {\n container.style['pointer-events'] = 'none';\n each(style, (v, k) => {\n if (k && v) {\n container.style[k] = v;\n }\n });\n}\n\n/**\n * 渲染环图 html-annotation(默认 position 居中 [50%, 50%])\n * @param chart\n * @param options\n * @param meta 字段元信息\n * @param {optional} datum 当前的元数据\n */\nexport const renderStatistic = (chart: View, options: { statistic: Statistic; plotType: string }, datum?: Datum) => {\n const { statistic, plotType } = options;\n const { title: titleOpt, content: contentOpt } = statistic;\n\n [titleOpt, contentOpt].forEach((option, idx) => {\n if (!option) {\n return;\n }\n let transform = '';\n if (idx === 0) {\n transform = contentOpt ? 'translate(-50%, -100%)' : 'translate(-50%, -50%)';\n } else {\n transform = titleOpt ? 'translate(-50%, 0)' : 'translate(-50%, -50%)';\n }\n const style = isFunction(option.style) ? option.style(datum) : option.style;\n\n chart.annotation().html({\n position: ['50%', '50%'],\n html: (container, view) => {\n const coordinate = view.getCoordinate();\n let containerW = 0;\n if (plotType === 'pie' || plotType === 'ring-progress') {\n containerW = coordinate.getRadius() * coordinate.innerRadius * 2;\n } else if (plotType === 'liquid') {\n const liquidShape = get(view.geometries, [0, 'elements', 0, 'shape']);\n if (liquidShape) {\n // 获取到水波图边框大小\n const path = (liquidShape as IGroup).find((t) => t.get('name') === 'wrap');\n const { width } = path.getCanvasBBox();\n containerW = width;\n }\n } else if (!containerW) {\n // 保底方案\n containerW = coordinate.getWidth();\n }\n setStatisticContainerStyle(container, {\n width: `${containerW}px`,\n transform,\n // user's style setting has high priority\n ...adapteStyle(style),\n });\n\n const filteredData = view.getData();\n if (option.customHtml) {\n return option.customHtml(container, view, datum, filteredData);\n }\n\n let text = option.content;\n if (option.formatter) {\n text = option.formatter(datum, filteredData);\n }\n // todo G2 层修复可以返回空字符串 & G2 层修复允许返回非字符串的内容,比如数值 number\n return text ? (isString(text) ? text : `${text}`) : '
';\n },\n // @ts-ignore\n key: `${idx === 0 ? 'top' : 'bottom'}-statistic`,\n ...pick(option, ['offsetX', 'offsetY', 'rotate', 'style', 'formatter']) /** 透传配置 */,\n });\n });\n};\n\n/**\n * 渲染 html-annotation for gauge (等不规则 plot), 默认 position 居中居底 [50%, 100%])\n * @param chart\n * @param options\n * @param meta 字段元信息\n * @param {optional} datum 当前的元数据\n */\nexport const renderGaugeStatistic = (chart: View, options: { statistic: Statistic }, datum?: Datum) => {\n const { statistic } = options;\n const { title: titleOpt, content: contentOpt } = statistic;\n\n [titleOpt, contentOpt].forEach((option) => {\n if (!option) {\n return;\n }\n const style = isFunction(option.style) ? option.style(datum) : option.style;\n chart.annotation().html({\n position: ['50%', '100%'],\n html: (container, view) => {\n const coordinate = view.getCoordinate();\n // 弧形的坐标\n const polarCoord = view.views[0].getCoordinate();\n const polarCenter = polarCoord.getCenter();\n const polarRadius = polarCoord.getRadius();\n const polarMaxY = Math.max(Math.sin(polarCoord.startAngle), Math.sin(polarCoord.endAngle)) * polarRadius;\n const offsetY = polarCenter.y + polarMaxY - coordinate.y.start - parseFloat(get(style, 'fontSize', 0));\n\n const containerWidth = coordinate.getRadius() * coordinate.innerRadius * 2;\n setStatisticContainerStyle(container, {\n width: `${containerWidth}px`,\n transform: `translate(-50%, ${offsetY}px)`,\n // user's style setting has high priority\n ...adapteStyle(style),\n });\n\n const filteredData = view.getData();\n if (option.customHtml) {\n return option.customHtml(container, view, datum, filteredData);\n }\n\n let text = option.content;\n if (option.formatter) {\n text = option.formatter(datum, filteredData);\n }\n\n // todo G2 层修复可以返回空字符串 & G2 层修复允许返回非字符串的内容,比如数值 number\n return text ? (isString(text) ? text : `${text}`) : '
';\n },\n ...pick(option, ['offsetX', 'offsetY', 'rotate', 'style', 'formatter']) /** 透传配置 */,\n });\n });\n};\n"]}