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 的 ts 类型定义 #1659

Merged
merged 1 commit into from
Nov 24, 2022
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
1 change: 0 additions & 1 deletion packages/f2/src/attr/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Scale, ScaleConfig } from '../deps/f2-scale/src';
import { mix, isFunction, isNil, isArray, valuesOfKey } from '@antv/util';

class Base {
// eslint-disable-next-line
data: any;
field: string;
scale: Scale;
Expand Down
24 changes: 22 additions & 2 deletions packages/f2/src/components/gauge/gaugeView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import { jsx } from '../../index';
import { jsx } from '@antv/f-engine';

export default (props) => {
export interface Point {
x: number;
y: number;
}

export interface Tick {
tickValue: number;
start: Point;
end: Point;
}

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

export default (props: GaugeViewProps) => {
const { center, startAngle, endAngle, r, percent, ticks } = props;
const { x, y } = center;
const diff = endAngle - startAngle;
Expand Down
13 changes: 7 additions & 6 deletions packages/f2/src/components/gauge/withGauge.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { jsx, Component, ComponentType, ClassComponent } from '@antv/f-engine';
import { jsx, Component, ComponentType } from '@antv/f-engine';
import { Point, Tick } from './gaugeView';

const getPoint = (cener, angle, r) => {
const getPoint = (cener: Point, angle: number, r: number): Point => {
const x = cener.x + Math.cos(angle) * r;
const y = cener.y + Math.sin(angle) * r;
return { x, y };
Expand All @@ -10,12 +11,12 @@ const getTicks = (
start: number,
end: number,
tickCount: number,
center,
center: Point,
r: number,
tickOffset: number,
tickLength: number
) => {
const ticks = [];
const ticks = [] as Tick[];
const diff = end - start;
for (let i = 0; i <= tickCount; i++) {
const tickValue = start + (diff * i) / tickCount;
Expand All @@ -38,11 +39,11 @@ export interface GuageProps {
tickLength?: number | string;
r?: number | string;
r0?: number | string;
center?: { x: number; y: number };
center?: Point;
percent?: number;
}

export default (View: ComponentType): ClassComponent<GuageProps> => {
export default (View: ComponentType) => {
return class Guage extends Component<GuageProps> {
render() {
const { props, context } = this;
Expand Down
2 changes: 1 addition & 1 deletion packages/f2/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export { default as Tooltip, withTooltip, TooltipView, TooltipProps } from './to
export { default as Treemap, withTreemap, TreemapView } from './treemap';
export { default as Sunburst, withSunburst, SunburstView } from './sunburst';
export { default as PieLabel, withPieLabel, PieLabelView } from './pieLabel';
export { default as Gauge, withGauge, GaugeView } from './gauge';
export { default as Gauge, GuageProps, withGauge, GaugeView } from './gauge';
export { default as Zoom } from './zoom';
export { default as ScrollBar, withScrollBar, ScrollBarView } from './scrollBar';
5 changes: 4 additions & 1 deletion packages/f2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "../../tsconfig.json"
"extends": "../../tsconfig.json",
"compilerOptions": {
"preserveSymlinks": true
}
}
11 changes: 0 additions & 11 deletions packages/f2/typing.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
import '../../typings';

// import { JSX as JSXNamespace } from './src/jsx/jsx-namespace';

// // 全局
// declare global {
// namespace JSX {
// export type Element = JSXNamespace.Element;
// export type ElementClass = JSXNamespace.ElementClass;
// export type IntrinsicElements = JSXNamespace.IntrinsicElements;
// }
// }
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"useDefineForClassFields": false,
"resolveJsonModule": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"allowJs": true
"experimentalDecorators": true
},
"exclude": [
"scripts",
Expand Down