Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gauge 支持 view 的 props ts 类型扩展 #1728

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions packages/f2/src/components/gauge/gaugeView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { jsx } from '@antv/f-engine';
import { GaugeProps } from './withGauge';

export interface Point {
x: number;
Expand All @@ -11,16 +12,9 @@ export interface Tick {
end: Point;
}

export interface GaugeViewProps {
center: Point;
startAngle: number;
endAngle: number;
r: number | string;
percent: number;
ticks: Tick[];
}
export { GaugeProps };

export default (props: GaugeViewProps) => {
export default (props: GaugeProps) => {
const { center, startAngle, endAngle, r, percent, ticks } = props;
const { x, y } = center;
const diff = endAngle - startAngle;
Expand Down
8 changes: 4 additions & 4 deletions packages/f2/src/components/gauge/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import withGauge, { GuageProps } from './withGauge';
import GaugeView from './gaugeView';
import withGauge from './withGauge';
import GaugeView, { GaugeProps } from './gaugeView';

export { GuageProps, withGauge, GaugeView };
export default withGauge(GaugeView);
export { GaugeProps, withGauge, GaugeView };
export default withGauge<GaugeProps>(GaugeView);
11 changes: 7 additions & 4 deletions packages/f2/src/components/gauge/withGauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const getTicks = (
return ticks;
};

export interface GuageProps {
export interface GaugeProps {
startAngle?: number;
endAngle?: number;
tickCount?: number;
Expand All @@ -40,11 +40,12 @@ export interface GuageProps {
r?: number | string;
r0?: number | string;
center?: Point;
percent?: number;
ticks?: Tick[];
percent: number;
}

export default (View: ComponentType) => {
return class Guage<IProps extends GuageProps = GuageProps> extends Component<IProps> {
const withGauge = <IProps extends GaugeProps = GaugeProps>(View: ComponentType<IProps>) => {
return class Gauge<P extends IProps = IProps> extends Component<P> {
render() {
const { props, context } = this;
const { startAngle, endAngle, tickCount, center, r, tickOffset, tickLength } = props;
Expand All @@ -62,3 +63,5 @@ export default (View: ComponentType) => {
}
};
};

export default withGauge;
2 changes: 1 addition & 1 deletion packages/f2/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export { default as Tooltip, TooltipProps, withTooltip, TooltipView } from './to
export { default as Treemap, TreemapProps, withTreemap, TreemapView } from './treemap';
export { default as Sunburst, SunburstProps, withSunburst, SunburstView } from './sunburst';
export { default as PieLabel, PieLabelProps, withPieLabel, PieLabelView } from './pieLabel';
export { default as Gauge, GuageProps, withGauge, GaugeView } from './gauge';
export { default as Gauge, GaugeProps, withGauge, GaugeView } from './gauge';
export { default as Zoom, ZoomProps } from './zoom';
export { default as ScrollBar, ScrollBarProps, withScrollBar, ScrollBarView } from './scrollBar';