fix(图表): 消除部分图表 TS2339 警告

This commit is contained in:
jianneng-fit2cloud
2026-04-21 15:56:26 +08:00
parent 1f67ea09bb
commit 5ed9b73754
7 changed files with 47 additions and 14 deletions

View File

@@ -78,7 +78,7 @@ declare interface Chart {
fontFamily?: string
dashboardHidden?: boolean
inMobile?: boolean
[key: any]: any
[key: string]: any
}
declare type CustomAttr = DeepPartial<ChartAttr> | JSONString<DeepPartial<ChartAttr>>
declare type CustomStyle = DeepPartial<ChartStyle> | JSONString<DeepPartial<ChartStyle>>

View File

@@ -218,7 +218,7 @@ export class Bar extends G2ChartView<ViewSpec, G2Column> {
}
return valueFormatter(value, labelCfg.formatterCfg)
}
}
} as any
if (!l.fullDisplay) {
newLabel.transform = [{ type: 'overlapHide' }]
}

View File

@@ -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<string, any>
encode?: Record<string, any>
scale?: Record<string, any>
style?: Record<string, any>
transform?: Array<Record<string, any>>
labels?: any[]
tooltip?: any
interaction?: Record<string, any>
data?: any
[key: string]: any
}
export interface ViewSpec {
type?: string
children?: ChildSpec[]
data?: any
scale?: Record<string, any>
theme?: Record<string, any>
coordinate?: Record<string, any>
title?: any
legend?: Record<string, any>
tooltip?: any
interaction?: Record<string, any>
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<ChartTooltipAttr>) {
@@ -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))

View File

@@ -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' }]
}

View File

@@ -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 (

View File

@@ -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,

View File

@@ -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)
]
}