Skip to content

Commit

Permalink
fix: 修复 ts 类型 (#1634)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Nov 3, 2022
1 parent 7cb005e commit 7e7097a
Show file tree
Hide file tree
Showing 31 changed files with 99 additions and 349 deletions.
86 changes: 0 additions & 86 deletions packages/f2/src/base/equal.ts

This file was deleted.

12 changes: 4 additions & 8 deletions packages/f2/src/chart/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JSX } from '../index';
import { ScaleConfig } from '@antv/f2-scale';
import { each, findIndex, isArray } from '@antv/util';
import equal from '../base/equal';
import { isEqual } from '@antv/f-engine';
import { Layout, Component } from '../index';
import Coord from '../coord';
import { Children } from '../index';
Expand Down Expand Up @@ -37,10 +37,6 @@ export interface ChartChildProps {
// [field: string]: Scale;
// };

interface IChart {
props: Props;
}

export interface PositionLayout {
position: 'top' | 'right' | 'bottom' | 'left';
width: number;
Expand All @@ -53,7 +49,7 @@ export interface ComponentPosition {
}

// 统计图表
class Chart extends Component implements IChart {
class Chart extends Component {
data: any;

private layout: Layout;
Expand Down Expand Up @@ -109,7 +105,7 @@ class Chart extends Component implements IChart {
const { style: lastStyle, data: lastData, scale: lastScale } = lastProps;

// 布局
if (!equal(nextStyle, lastStyle)) {
if (!isEqual(nextStyle, lastStyle)) {
const style = this.getStyle(nextProps);
this.layout = layoutController.create(style);
coordController.updateLayout(this.layout);
Expand All @@ -120,7 +116,7 @@ class Chart extends Component implements IChart {
}

// scale
if (!equal(nextScale, lastScale)) {
if (!isEqual(nextScale, lastScale)) {
scaleController.update(nextScale);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/f2/src/components/axis/rect/bottom.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jsx } from '../../../index';
import { RectProps } from '../types';
import { TextAttrs } from '../../../types';
import { TextStyleProps } from '@antv/f-engine';

export default (props: RectProps<'bottom'>, context) => {
const { ticks, coord, style, animation } = props;
Expand Down Expand Up @@ -65,7 +65,7 @@ export default (props: RectProps<'bottom'>, context) => {
const { points, text, tickValue, labelStyle } = tick;
const start = points[0];
const { align = 'center' } = labelStyle || label || {};
const textAttrs: TextAttrs = {
const textAttrs: TextStyleProps = {
x: start.x,
y: start.y + labelOffset,
textBaseline: 'top',
Expand Down
16 changes: 8 additions & 8 deletions packages/f2/src/components/axis/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { LineAttrs, TextAttrs } from '../../types';
import { LineStyleProps, TextStyleProps } from '@antv/f-engine';
import Coord from '../../coord';
import { ChartChildProps } from '../../chart';

interface TickLine extends LineAttrs {
interface TickLine extends LineStyleProps {
length?: number; // tick line 的长度
}

interface Text extends TextAttrs {
interface Text extends TextStyleProps {
align?: 'left' | 'right' | 'start' | 'center' | 'end' | 'between';
}

Expand All @@ -18,19 +18,19 @@ type LabelCallback<Type = void> = (
index: number,
total: number
) => StyleText<Type>;
type GridCallBack = (text: Tick['text'], index: number, total: number) => LineAttrs;
type GridCallBack = (text: Tick['text'], index: number, total: number) => LineStyleProps;

export interface Style<Type = void> {
grid?: LineAttrs;
grid?: LineStyleProps;
tickLine?: TickLine;
line?: LineAttrs;
line?: LineStyleProps;
labelOffset?: number;
label?: StyleText<Type>;
}

export interface StyleProps<Type = void> extends Omit<Style, 'label' | 'grid' | 'labelOffset'> {
label?: StyleText<Type> | LabelCallback<Type>;
grid?: LineAttrs | GridCallBack;
grid?: LineStyleProps | GridCallBack;
labelOffset?: number | string;
}

Expand All @@ -45,7 +45,7 @@ export interface Tick {
text: string;
tickValue: string | number;
labelStyle?: Text;
gridStyle?: LineAttrs;
gridStyle?: LineStyleProps;
gridPoints?: Point[];
}

Expand Down
16 changes: 8 additions & 8 deletions packages/f2/src/components/axis/withAxis.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deepMix, isFunction, mix, each, clone, isString, isNumber } from '@antv/util';
import { jsx } from '../../index';
import equal from '../../base/equal';
import { isEqual } from '@antv/f-engine';
import { PositionLayout } from '../../chart/index';
import { Component } from '@antv/f-engine';
import { Style, Tick, AxisProps } from './types';
Expand All @@ -12,7 +12,7 @@ type BBox = {

export default (View) => {
return class Axis extends Component<AxisProps, {}> {
style: Style = {};
axisStyle: Style = {};

constructor(props: AxisProps) {
super(props);
Expand All @@ -28,7 +28,7 @@ export default (View) => {

const nextScaleOption = this.getScaleOption(nextProps);
const lastScaleOption = this.getScaleOption(lastProps);
if (!equal(nextScaleOption, lastScaleOption)) {
if (!isEqual(nextScaleOption, lastScaleOption)) {
chart.setScale(field, nextScaleOption);
}
}
Expand Down Expand Up @@ -165,9 +165,9 @@ export default (View) => {
const styleValue = isFunction(style[key]) ? undefined : style[key];

if (isString(value) || isNumber(value)) {
this.style[key] = px2hd(styleValue) || value;
this.axisStyle[key] = px2hd(styleValue) || value;
} else {
this.style[key] = px2hd(deepMix(clone(value), styleValue));
this.axisStyle[key] = px2hd(deepMix(clone(value), styleValue));
}
});

Expand Down Expand Up @@ -214,7 +214,7 @@ export default (View) => {
}

const ticks = this.getTicks();
const bbox = this.getMaxBBox(ticks, this.style);
const bbox = this.getMaxBBox(ticks, this.axisStyle);

const { isPolar } = coord;
const dimType = this._getDimType();
Expand Down Expand Up @@ -254,7 +254,7 @@ export default (View) => {
}

render() {
const { props, style } = this;
const { props, axisStyle } = this;
const { visible, coord } = props;
if (visible === false) {
return null;
Expand All @@ -267,7 +267,7 @@ export default (View) => {
return (
<View
{...props}
style={style}
style={axisStyle}
ticks={this.convertTicks(ticks)}
coord={coord}
position={position}
Expand Down
9 changes: 4 additions & 5 deletions packages/f2/src/components/geometry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { Adjust, getAdjust } from '@antv/f2-adjust';
import { toTimeStamp } from '../../util/index';
import { GeomType, GeometryProps, GeometryAdjust } from './interface';
import AttrController from '../../controller/attr';
import equal from '../../base/equal';
import { Scale } from '@antv/f2-scale';
import { Types } from '@antv/f-engine';
import { AnimationProps, isEqual } from '@antv/f-engine';

// 保留原始数据的字段
const FIELD_ORIGIN = 'origin';
Expand Down Expand Up @@ -41,7 +40,7 @@ class Geometry<
attrController: AttrController;

// 动画配置
animation: Types.AnimationCycle;
animation: AnimationProps;

getDefaultCfg() {
return {};
Expand Down Expand Up @@ -72,7 +71,7 @@ class Geometry<

attrController.attrsRange = this._getThemeAttrsRange();
const nextAttrOptions = attrController.getAttrOptions(nextProps, justifyContentCenter);
if (!equal(nextAttrOptions, lastAttrOptions)) {
if (!isEqual(nextAttrOptions, lastAttrOptions)) {
attrController.update(nextAttrOptions);
this.records = null;
}
Expand All @@ -88,7 +87,7 @@ class Geometry<
}

// zoomRange发生变化,records也需要重新计算
if (!equal(nextZoomRange, lastZoomRange)) {
if (!isEqual(nextZoomRange, lastZoomRange)) {
this.records = null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/f2/src/components/geometry/interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Chart from '../../chart';
import Coord from '../../coord';
import { Types } from '@antv/f-engine';
import { AnimationProps } from '@antv/f-engine';
import { SelectionProps } from './selection';

export interface AttrRange {
Expand Down Expand Up @@ -40,6 +40,6 @@ export interface GeometryProps extends SelectionProps {
coord?: Coord;
startOnZero?: boolean;
style?: Style;
animation?: Types.AnimationCycle;
animation?: AnimationProps;
[k: string]: any; // TODO
}
12 changes: 5 additions & 7 deletions packages/f2/src/components/geometry/selection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { isFunction } from '@antv/util';
import { Component } from '@antv/f-engine';
import { ShapeAttrs, Point } from '../../types';
import equal from '../../base/equal';
import { Component, isEqual as equal, ShapeStyleProps } from '@antv/f-engine';

function isEqual(origin1, origin2, fields: string[]) {
if (origin1 === origin2) {
Expand All @@ -16,15 +14,15 @@ function isEqual(origin1, origin2, fields: string[]) {
return true;
}

type StyleType = (record: any) => ShapeAttrs;
type StyleType = (record: any) => ShapeStyleProps;

export interface SelectionProps {
selection?: {
triggerOn?: 'click' | 'press' | string;
type?: 'single' | 'multiple';
defaultSelected?: any[];
selectedStyle?: ShapeAttrs | StyleType;
unSelectedStyle?: ShapeAttrs | StyleType;
selectedStyle?: ShapeStyleProps | StyleType;
unSelectedStyle?: ShapeStyleProps | StyleType;
cancelable?: boolean;
};
[k: string]: any;
Expand Down Expand Up @@ -131,7 +129,7 @@ class Selection<
}
}

getSnapRecords(_point: Point) {
getSnapRecords(_point) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/f2/src/components/guide/views/Arc.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { jsx } from '../../../index';
import { deepMix } from '@antv/util';
import { Style } from '../../../types';
import { ArcStyleProps } from '@antv/f-engine';

type ArcGuideProps = {
points?: { x: number; y: number }[] | null;
style?: Style;
style?: ArcStyleProps;
theme?: any;
};

Expand Down
6 changes: 3 additions & 3 deletions packages/f2/src/components/guide/views/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { jsx } from '../../../index';
import { Style } from '../../../types';
import { ImageStyleProps } from '@antv/f-engine';
import { deepMix } from '@antv/util';

type ImageGuideProps = {
src: string;
points?: { x: number; y: number }[] | null;
attrs?: any;
style?: Style;
attrs?: ImageStyleProps;
style?: ImageStyleProps;
offsetX?: number;
offsetY?: number;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/f2/src/components/guide/views/Line.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { jsx } from '../../../index';
import { isArray, deepMix } from '@antv/util';
import { Style } from '../../../types';
import { LineStyleProps } from '@antv/f-engine';

type LineGuideProps = {
points?: { x: number; y: number }[] | null;
style?: Style;
style?: LineStyleProps;
offsetX?: number | number[];
offsetY?: number | number[];
theme?: any;
Expand Down
Loading

0 comments on commit 7e7097a

Please sign in to comment.