Skip to content

Commit

Permalink
fix: 补充types的定义
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Jul 9, 2020
1 parent 55ba804 commit 7e25cec
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 54 deletions.
1 change: 1 addition & 0 deletions test/unit/graphic/canvas-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '../../../src/graphic/shape/circle';

const dom = document.createElement('canvas');
dom.id = 'canvas';
dom.style.width = '300px';
document.body.appendChild(dom);

describe('Canvas', function() {
Expand Down
8 changes: 8 additions & 0 deletions types/Plot.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Point } from './Point';

export interface Plot {
tl: Point;
tr: Point;
br: Point;
bl: Point;
}
24 changes: 24 additions & 0 deletions types/Util.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PartialDeep } from 'type-fest';
import { Point } from './Point';
import { Plot } from './Plot';

/**
* 常用工具库。
Expand Down Expand Up @@ -56,6 +57,10 @@ export const Util: {
* 判断是否为对象类型。
*/
isObject(value: any): value is object;
/**
* 判断2个对象是否相等
*/
isEqual(value: any, other: any): boolean;

/**
* 深拷贝。
Expand Down Expand Up @@ -91,6 +96,12 @@ export const Util: {
func: <K extends keyof T>(value: T[K], key: K) => void | false,
): void;

/**
* 数组查找
* @param arr
*/
find<T>(arr: T[], fn: (value: T, index: number) => boolean): T;

/**
* 获取当前设备的像素比。
*/
Expand All @@ -102,4 +113,17 @@ export const Util: {
* @todo 明确参数 canvas 和返回结果的类型
*/
getRelativePosition(point: Point, canvas: any): any;
/**
* 计算padding
* @param padding
*/
parsePadding(padding: number | number[]): number[];
};

export const Helper: {
getClip: (coord: any) => any;
/**
* 判断点是否在plot之内
*/
isPointInPlot: (point: Point, plot: Plot) => boolean;
}
154 changes: 100 additions & 54 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Util } from './Util';
import { Util, Helper } from './Util';
import {
CanvasCommonProps,
CanvasLineProps,
Expand Down Expand Up @@ -110,6 +110,7 @@ import { ChartParams, ChartInnerProps, ChartPlugins, Chart } from './Chart';
declare namespace F2 {
export {
Util,
Helper,
CanvasCommonProps,
CanvasLineProps,
CanvasTextProps,
Expand Down Expand Up @@ -202,59 +203,104 @@ declare namespace F2 {
ChartInnerProps,
ChartPlugins,
Chart,
};
}
}

export = F2;

// ==== src ====
declare module '@antv/f2/src/index-all.js' {
export = F2;
}

declare module '@antv/f2/src/index-simple.js' {
export = F2;
}

declare module '@antv/f2/src/index.js' {
export = F2;
}

// ==== lib ====
declare module '@antv/f2/lib/index-all.js' {
export = F2;
}

declare module '@antv/f2/lib/index-simple.js' {
export = F2;
}

declare module '@antv/f2/lib/index.js' {
export = F2;
}

// ==== build ====
declare module '@antv/f2/build/f2-all.js' {
export = F2;
}

declare module '@antv/f2/build/f2-simple.js' {
export = F2;
}

declare module '@antv/f2/build/f2.js' {
export = F2;
}

// ==== dist ====
declare module '@antv/f2/dist/f2-all.min.js' {
export = F2;
}

declare module '@antv/f2/dist/f2-simple.min.js' {
export = F2;
}
export {
Util,
Helper,
CanvasCommonProps,
CanvasLineProps,
CanvasTextProps,
CanvasPointProps,
CanvasBackgroundProps,
CanvasProps,
Point,
Data,
DataRecord,
DataField,
DataRecordScale,
DataFieldScale,
ScaleType,
ScaleCommonProps,
ScaleIdentityProps,
ScaleLinearProps,
ScaleCatProps,
ScaleTimeCatProps,
ScaleProps,
AnimateKind,
AnimateElement,
AnimateAnimationName,
AnimateAnimationFunc,
AnimateEasingName,
AnimateEasingFunc,
AnimateDelayFunc,
AnimateConfig,
AnimateElementParams,
AnimateChartParams,
Animate,
GeometryKind,
GeometryShapeKind,
GeometryAdjustKind,
GeometryAdjustParams,
GeometryParams,
Geometry,
CoordinateKind,
CoordinateRectParams,
CoordinatePolarParams,
CoordinateParams,
AxisPositionKind,
AxisLineParams,
AxisGridParams,
AxisTickLineParams,
AxisLabelParams,
AxisParams,
LegendMarkerSymbol,
LegendMarkerParams,
LegendMarkerFunc,
LegendMarker,
LegendItem,
LegendParams,
LegendControllerLegend,
LegendControllerLegends,
LegendController,
G,
PluginLifecycle,
Plugin,
TooltipItem,
Tooltip,
TooltipParams,
InteractionKind,
InteractionPieSelectParams,
InteractionIntervalSelectParams,
InteractionPanParams,
InteractionPinchParams,
InteractionSwipeParams,
InteractionParams,
GestureParams,
ScrollBarParams,
PieLabelText,
PieLabelParams,
GuideElementPositionLiteral,
GuideElementPositionFunc,
GuideElementPosition,
GuideLineParams,
GuideTextParams,
GuidePointParams,
GuideTagParams,
GuideRectParams,
GuideHtmlParams,
GuideArcParams,
GuideRegionFilterParams,
GuideResult,
Guide,
Shape,
Global,
IntervalLabelParams,
ChartParams,
ChartInnerProps,
ChartPlugins,
Chart,
};

declare module '@antv/f2/dist/f2.min.js' {
export = F2;
}
export default F2;

0 comments on commit 7e25cec

Please sign in to comment.