From 524b506a882140ce4221099db625ed5c458e01f9 Mon Sep 17 00:00:00 2001 From: Junyu Jiang Date: Wed, 6 Mar 2024 14:53:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=20withGuide=20ts=20?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=20(#1934)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: update dumi-theme-antv (#1890) * feat: 优化 withGuide ts 类型 * fix: 修复 ts 类型错误 * Revert "chore: update dumi-theme-antv (#1890)" This reverts commit 450be5a12cae22d3a2514426b09391c30437b07c. --------- Co-authored-by: Frank William <65594180+ai-qing-hai@users.noreply.github.com> Co-authored-by: 不狸 --- packages/f2/src/components/guide/views/Arc.tsx | 7 ++++--- packages/f2/src/components/guide/views/Image.tsx | 13 +++++++------ packages/f2/src/components/guide/views/Line.tsx | 11 ++++++----- packages/f2/src/components/guide/views/Lottie.tsx | 15 ++++++++------- packages/f2/src/components/guide/views/Point.tsx | 11 ++++++----- packages/f2/src/components/guide/views/Rect.tsx | 7 ++++--- packages/f2/src/components/guide/views/Tag.tsx | 11 ++++++----- packages/f2/src/components/guide/views/Text.tsx | 11 ++++++----- packages/f2/src/components/guide/withGuide.tsx | 10 +++++----- 9 files changed, 52 insertions(+), 44 deletions(-) diff --git a/packages/f2/src/components/guide/views/Arc.tsx b/packages/f2/src/components/guide/views/Arc.tsx index 7c04b989d..82ee058c2 100644 --- a/packages/f2/src/components/guide/views/Arc.tsx +++ b/packages/f2/src/components/guide/views/Arc.tsx @@ -1,11 +1,12 @@ import { jsx, ArcStyleProps } from '@antv/f-engine'; import { deepMix } from '@antv/util'; +import { GuideProps } from '../withGuide'; -type ArcGuideProps = { +export interface ArcGuideProps extends GuideProps { points?: { x: number; y: number }[] | null; - style?: ArcStyleProps; + style?: Partial | ((record?) => Partial); theme?: any; -}; +} export default (props: ArcGuideProps) => { const { theme = {} } = props; diff --git a/packages/f2/src/components/guide/views/Image.tsx b/packages/f2/src/components/guide/views/Image.tsx index f59a69094..e88cd0328 100644 --- a/packages/f2/src/components/guide/views/Image.tsx +++ b/packages/f2/src/components/guide/views/Image.tsx @@ -1,16 +1,17 @@ import { jsx, ImageStyleProps } from '@antv/f-engine'; import { deepMix } from '@antv/util'; +import { GuideProps } from '../withGuide'; -type ImageGuideProps = { +export interface ImageGuideProps extends GuideProps { src: string; points?: { x: number; y: number }[] | null; attrs?: ImageStyleProps; - style?: ImageStyleProps; - offsetX?: number; - offsetY?: number; -}; + style?: Partial | ((record?) => Partial); + offsetX?: number | string; + offsetY?: number | string; +} -const defaultProps: ImageGuideProps = { +const defaultProps: Omit = { offsetX: 0, offsetY: 0, points: [], diff --git a/packages/f2/src/components/guide/views/Line.tsx b/packages/f2/src/components/guide/views/Line.tsx index a33bdbe4b..95ba5ae00 100644 --- a/packages/f2/src/components/guide/views/Line.tsx +++ b/packages/f2/src/components/guide/views/Line.tsx @@ -1,13 +1,14 @@ import { jsx, LineStyleProps } from '@antv/f-engine'; +import { GuideProps } from '../withGuide'; import { isArray, deepMix } from '@antv/util'; -type LineGuideProps = { +export interface LineGuideProps extends GuideProps { points?: { x: number; y: number }[] | null; - style?: LineStyleProps; - offsetX?: number | number[]; - offsetY?: number | number[]; + style?: Partial | ((record?) => Partial); + offsetX?: number | string | (number | string)[]; + offsetY?: number | string | (number | string)[]; theme?: any; -}; +} export default (props: LineGuideProps, context) => { const { theme = {} } = props; diff --git a/packages/f2/src/components/guide/views/Lottie.tsx b/packages/f2/src/components/guide/views/Lottie.tsx index d51d372a5..ec1ab2d5d 100644 --- a/packages/f2/src/components/guide/views/Lottie.tsx +++ b/packages/f2/src/components/guide/views/Lottie.tsx @@ -1,20 +1,21 @@ import { jsx, AnimationProps } from '@antv/f-engine'; import { deepMix } from '@antv/util'; import Lottie from '@antv/f-lottie'; +import { GuideProps } from '../withGuide'; -type LottieGuideProps = { +export interface LottieGuideProps extends GuideProps { points?: { x: number; y: number }[] | null; data?: string; - offsetX?: number | number[]; - offsetY?: number | number[]; - animation: AnimationProps; - options: { + offsetX?: number | string | (string | number)[]; + offsetY?: number | string | (string | number)[]; + animation: AnimationProps | ((points?, chart?) => AnimationProps); + options?: { loop: boolean | number; autoplay: boolean; }; -}; +} -const defaultProps: LottieGuideProps = { +const defaultProps: Omit = { offsetX: 0, offsetY: 0, points: [], diff --git a/packages/f2/src/components/guide/views/Point.tsx b/packages/f2/src/components/guide/views/Point.tsx index b1e6d9a06..51e4be8d1 100644 --- a/packages/f2/src/components/guide/views/Point.tsx +++ b/packages/f2/src/components/guide/views/Point.tsx @@ -1,13 +1,14 @@ import { jsx, CircleStyleProps } from '@antv/f-engine'; import { deepMix } from '@antv/util'; +import { GuideProps } from '../withGuide'; -type PointGuideProps = { - style?: CircleStyleProps; - offsetX?: number; - offsetY?: number; +export interface PointGuideProps extends GuideProps { + style?: Partial | ((record?) => Partial); + offsetX?: number | string; + offsetY?: number | string; points?: { x: number; y: number }[] | null; theme?: any; -}; +} export default (props: PointGuideProps, context) => { const { theme } = props; diff --git a/packages/f2/src/components/guide/views/Rect.tsx b/packages/f2/src/components/guide/views/Rect.tsx index b93afe889..494746347 100644 --- a/packages/f2/src/components/guide/views/Rect.tsx +++ b/packages/f2/src/components/guide/views/Rect.tsx @@ -1,11 +1,12 @@ import { jsx, RectStyleProps } from '@antv/f-engine'; import { deepMix } from '@antv/util'; +import { GuideProps } from '../withGuide'; -type RectGuideProps = { +export interface RectGuideProps extends GuideProps { points?: { x: number; y: number }[] | null; - style?: RectStyleProps; + style?: Partial | ((record?) => Partial); theme?: any; -}; +} export default (props: RectGuideProps) => { const { theme = {} } = props; diff --git a/packages/f2/src/components/guide/views/Tag.tsx b/packages/f2/src/components/guide/views/Tag.tsx index 732b4d665..b1b6125f2 100644 --- a/packages/f2/src/components/guide/views/Tag.tsx +++ b/packages/f2/src/components/guide/views/Tag.tsx @@ -1,11 +1,12 @@ import { jsx, Component, computeLayout } from '@antv/f-engine'; +import { GuideProps } from '../withGuide'; -interface TagGuideProps { +export interface TagGuideProps extends GuideProps { points?: { x: number; y: number }[] | null; canvasWidth?: number; canvasHeight?: number; - offsetX?: number; - offsetY?: number; + offsetX?: number | string; + offsetY?: number | string; autoAdjust?: boolean; /** * 箭头的方向 @@ -29,7 +30,7 @@ interface TagGuideProps { textStyle?: any; } -const defaultProps: TagGuideProps = { +const defaultProps: Omit = { offsetX: 0, offsetY: 0, points: [], @@ -75,7 +76,7 @@ const Label = ({ content, background, textStyle }) => { ); }; -export default class Tag extends Component { +export default class Tag extends Component { render() { const { props, context } = this; const { px2hd } = context; diff --git a/packages/f2/src/components/guide/views/Text.tsx b/packages/f2/src/components/guide/views/Text.tsx index f9e4faf59..0599582e0 100644 --- a/packages/f2/src/components/guide/views/Text.tsx +++ b/packages/f2/src/components/guide/views/Text.tsx @@ -1,14 +1,15 @@ import { jsx, TextStyleProps } from '@antv/f-engine'; +import { GuideProps } from '../withGuide'; import { deepMix } from '@antv/util'; -type TextGuideProps = { +export interface TextGuideProps extends GuideProps { points?: { x: number; y: number }[] | null; content: string | number; - style?: TextStyleProps; - offsetX?: number; - offsetY?: number; + style?: Partial | ((record?) => Partial); + offsetX?: number | string; + offsetY?: number | string; theme?: any; -}; +} export default (props: TextGuideProps, context) => { const { theme = {} } = props; diff --git a/packages/f2/src/components/guide/withGuide.tsx b/packages/f2/src/components/guide/withGuide.tsx index 7b33d6cd7..7907a660a 100644 --- a/packages/f2/src/components/guide/withGuide.tsx +++ b/packages/f2/src/components/guide/withGuide.tsx @@ -10,10 +10,10 @@ export interface GuideProps { [key: string]: any; } -export default (View: ComponentType) => { - return class Guide extends Component< - IProps & ChartChildProps - > { +export default function( + View: ComponentType +): ComponentType { + return class Guide extends Component { chart: Chart; constructor(props: IProps & ChartChildProps) { @@ -101,4 +101,4 @@ export default (View: ComponentType) => { ); } }; -}; +}