Skip to content

Commit

Permalink
feat: gauge 支持 view 的 props ts 类型扩展
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Feb 15, 2023
1 parent 38d378f commit 5dcb48f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
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';

0 comments on commit 5dcb48f

Please sign in to comment.