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 a81258d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
10 changes: 3 additions & 7 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 { GuageProps as GuageBaseProps } from './withGauge';

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

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

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);
8 changes: 5 additions & 3 deletions packages/f2/src/components/gauge/withGauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ export interface GuageProps {
r?: number | string;
r0?: number | string;
center?: Point;
percent?: number;
ticks?: Tick[];
}

export default (View: ComponentType) => {
return class Guage<IProps extends GuageProps = GuageProps> extends Component<IProps> {
const withGauge = <IProps extends GuageProps = GuageProps>(View: ComponentType<IProps>) => {
return class Guage<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 +62,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 a81258d

Please sign in to comment.