diff --git a/core/core-frontend/src/models/chart/chart.d.ts b/core/core-frontend/src/models/chart/chart.d.ts index 18c3b14035..85f6e0538b 100644 --- a/core/core-frontend/src/models/chart/chart.d.ts +++ b/core/core-frontend/src/models/chart/chart.d.ts @@ -78,7 +78,7 @@ declare interface Chart { fontFamily?: string dashboardHidden?: boolean inMobile?: boolean - [key: any]: any + [key: string]: any } declare type CustomAttr = DeepPartial | JSONString> declare type CustomStyle = DeepPartial | JSONString> diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bar.ts index 9bd0b78126..48a53615f4 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/bar.ts @@ -218,7 +218,7 @@ export class Bar extends G2ChartView { } return valueFormatter(value, labelCfg.formatterCfg) } - } + } as any if (!l.fullDisplay) { newLabel.transform = [{ type: 'overlapHide' }] } diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/barUtil.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/barUtil.ts index d9e6213794..bcf0b5c4de 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/barUtil.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/barUtil.ts @@ -5,9 +5,39 @@ import { handleSetZeroSingleDimension, parseJson } from '@/views/chart/components/js/util' -import { Chart as G2Chart, G2Spec } from '@antv/g2' +import { Chart as G2Chart } from '@antv/g2' + +/** + * 运行时形态与 G2Spec 完全一致 ,G2 以普通对象消费 + */ +export interface ChildSpec { + axis?: Record + encode?: Record + scale?: Record + style?: Record + transform?: Array> + labels?: any[] + tooltip?: any + interaction?: Record + data?: any + [key: string]: any +} + +export interface ViewSpec { + type?: string + children?: ChildSpec[] + data?: any + scale?: Record + theme?: Record + coordinate?: Record + title?: any + legend?: Record + tooltip?: any + interaction?: Record + annotations?: any[] + [key: string]: any +} -export type ViewSpec = { children?: G2Spec[]; [key: string]: any } & G2Spec export type Transform = { type: string [key: string]: any @@ -66,7 +96,8 @@ export function createTooltipWrapper(chart: Chart) { document.body.appendChild(g2TooltipWrapper) } // 如果开启轮播则不使用自定义tooltip容器 - return chart.customAttr?.tooltip?.carousel?.enable ? undefined : g2TooltipWrapper + const customAttr = parseJson(chart.customAttr) + return customAttr?.tooltip?.carousel?.enable ? undefined : g2TooltipWrapper } export function tooltipCss(tooltipAttr: DeepPartial) { @@ -102,7 +133,8 @@ export function tooltipMaxHeight(chart: Chart) { const defaultHeight = 80 const chartRect = chartContainer?.getBoundingClientRect() let doubleHeight = chartRect.height * 2 - 20 - if (chart.customAttr?.tooltip?.carousel?.enable) { + const customAttr = parseJson(chart.customAttr) + if (customAttr?.tooltip?.carousel?.enable) { doubleHeight = chartRect.height / 1.2 - 20 } const maxHeight = chartContainer ? Math.max(doubleHeight, defaultHeight) : defaultHeight @@ -111,7 +143,8 @@ export function tooltipMaxHeight(chart: Chart) { export function listenerTooltipShow(newChart: G2Chart, chart: Chart) { newChart.on('tooltip:show', event => { - const isCarousel = chart.customAttr?.tooltip?.carousel?.enable + const customAttr = parseJson(chart.customAttr) + const isCarousel = customAttr?.tooltip?.carousel?.enable const tooltipWrapper = isCarousel ? document.getElementById(chart.container) : document.getElementById(tooltipWrapperId(chart.container)) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/group-bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/group-bar.ts index 88de9a5c52..69e633278f 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/group-bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/group-bar.ts @@ -86,7 +86,7 @@ export class GroupBar extends StackBar { fontSize: labelAttr.fontSize, ...position, formatter: (value, _data) => valueFormatter(value, labelAttr.labelFormatter) - } + } as any if (!labelAttr.fullDisplay) { label.transform = [{ type: 'overlapHide' }] } diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/horizontal-bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/horizontal-bar.ts index c56dfdd028..d0a61434ff 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/horizontal-bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/horizontal-bar.ts @@ -79,8 +79,8 @@ export class HorizontalBar extends Bar { }), ...(basicStyle.radiusColumnBar !== 'topRoundAngle' && basicStyle.radiusColumnBar !== 'roundAngle' && { radius: 0 }) - } - let columnWidthRatio + } as any + let columnWidthRatio: number | undefined const _v = basicStyle.columnWidthRatio ?? DEFAULT_BASIC_STYLE.columnWidthRatio if (_v >= 1 && _v <= 100) { columnWidthRatio = _v / 100.0 @@ -92,7 +92,7 @@ export class HorizontalBar extends Bar { if (columnWidthRatio) { style = { ...style, - columnWidthRatio + columnWidthRatio: columnWidthRatio } } if ( diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/progress-bar.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/progress-bar.ts index 04d9cd6487..2c23a61aa0 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/progress-bar.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/progress-bar.ts @@ -11,7 +11,7 @@ import { } from '@/views/chart/components/js/panel/charts/g2/bar/barUtil' import { cloneDeep, defaultTo } from 'lodash-es' import { G2DrawOptions } from '@/views/chart/components/js/panel/types/impl/g2' -import { Chart, Chart as G2Column } from '@antv/g2' +import { Chart as G2Column } from '@antv/g2' import { useI18n } from '@/hooks/web/useI18n' import { handleChartDashboardHidden, diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/waterfall.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/waterfall.ts index 14e8e91764..1637bea064 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/waterfall.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/g2/bar/waterfall.ts @@ -1,4 +1,4 @@ -import { Chart as G2Column, IntervalMark } from '@antv/g2' +import { Chart as G2Column } from '@antv/g2' import { G2DrawOptions } from '@/views/chart/components/js/panel/types/impl/g2' import { useI18n } from '@/hooks/web/useI18n' import { flow, hexColorToRGBA, parseJson } from '@/views/chart/components/js/util' @@ -234,7 +234,7 @@ export class Waterfall extends Bar { return d.difference > 0 ? colors[0] : colors[1] } } - } as IntervalMark, + }, ...children.slice(1) ] }