Skip to content

Commit

Permalink
feat: 补充 line 类型定义
Browse files Browse the repository at this point in the history
  • Loading branch information
edokeh committed Nov 10, 2021
1 parent bda979c commit 4ce06bb
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 37 deletions.
27 changes: 26 additions & 1 deletion packages/f2/src/components/axis/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Coord from '../../coord';
import Chart from '../../chart';

interface Line {
lineWidth?: number;
Expand Down Expand Up @@ -55,7 +56,7 @@ export interface Style<Type = void> {
tickLine?: TickLine;
line?: Line;
labelOffset?: number;
label?: StyleText<Type>;
label: StyleText<Type>;
}

interface Point {
Expand Down Expand Up @@ -106,3 +107,27 @@ export interface PolarAxisProps {
animation?: any;
}

export interface AxisProps {
/**
* 映射的字段名称
*/
field: string;
position?: 'right' | 'left' | 'top' | 'bottom';
/**
* 是否显示该坐标轴
*/
visible?: boolean;
/**
* 坐标轴样式定制
*/
style?: Style;
/**
* note: 作为 `<Chart />` 子元素时将自动注入
*/
chart?: Chart;
/**
* note: 作为 `<Chart />` 子元素时将自动注入
*/
coord?: Coord;
[key: string]: any; // TODO
}
29 changes: 1 addition & 28 deletions packages/f2/src/components/axis/withAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,7 @@ import { deepMix } from '@antv/util';
import { jsx } from '../../jsx';
import equal from '../../base/equal';
import Component from '../../base/component';
import Chart from '../../chart';
import Coord from '../../coord';
import { Style } from './types';

export interface AxisProps {
/**
* 映射的字段名称
*/
field: string;
position?: 'right' | 'left' | 'top' | 'bottom';
/**
* 是否显示该坐标轴
*/
visible?: boolean;
/**
* 坐标轴样式定制
*/
style?: Style;
/**
* note: 作为 `<Chart />` 子元素时将自动注入
*/
chart?: Chart;
/**
* note: 作为 `<Chart />` 子元素时将自动注入
*/
coord?: Coord;
[key: string]: any; // TODO
}
import { Style, AxisProps } from './types';

export default (View) => {
return class Axis extends Component<AxisProps> {
Expand Down
4 changes: 2 additions & 2 deletions packages/f2/src/components/geometry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Chart from '../../chart';
import * as Adjust from '../../adjust';
import { Linear, Category } from '../../attr';
import { toTimeStamp } from '../../util/index';
import { GeomType } from './interface';
import { GeomType, GeometryProps } from './interface';
import AttrController from '../../controller/attr';
import equal from '../../base/equal';

Expand All @@ -30,7 +30,7 @@ const ATTRS = ['x', 'y', 'color', 'size', 'shape'];
// 分组处理的属性
const GROUP_ATTRS = ['color', 'size', 'shape'];

class Geometry extends Component {
class Geometry<T extends GeometryProps = GeometryProps> extends Component<T> {
isGeometry = true;
geomType: GeomType;

Expand Down
20 changes: 20 additions & 0 deletions packages/f2/src/components/geometry/interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import Chart from '../../chart';
import Coord from '../../coord';

export interface AttrRange {
shape?: any[];
color?: any[];
size?: any[];
}

export type GeomType = 'line' | 'point' | 'area' | 'polygon' | 'schema' | 'interval';

interface Style {
field: string;
smooth?: boolean;
stroke?: string | ((t) => string);
lineWidth?: number | ((t) => number);
}

export interface GeometryProps {
data: any;
adjust: any;
chart: Chart;
coord: Coord;
startOnZero: boolean;
style: Style;
[k: string]: any; // TODO
}
3 changes: 2 additions & 1 deletion packages/f2/src/components/line/lineView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isArray } from '@antv/util';
import { jsx } from '../../jsx';
import { LineViewProps } from './types'

function concatPoints(children) {
let result = [];
Expand Down Expand Up @@ -68,7 +69,7 @@ function AnimationEndView(props) {
);
}

export default (props: any) => {
export default (props: LineViewProps) => {
const { records, coord, animation, endView: EndView } = props;
const { left, top, width, height } = coord;

Expand Down
23 changes: 23 additions & 0 deletions packages/f2/src/components/line/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { GeometryProps } from '../geometry/interface';
import Coord from '../../coord';

interface Record {
key: string;
children: Record[];
[k: string]: any;
}

export interface LineViewProps {
records: Record[];
coord: Coord;
animation?: any;
endView?: (origin: any) => JSX.Element;
}

export interface LineProps extends GeometryProps {
coord: Coord;
connectNulls: boolean;
data: any;
adjust: any;
endView?: (origin: any) => JSX.Element;
}
7 changes: 4 additions & 3 deletions packages/f2/src/components/line/withLine.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { jsx } from '../../jsx';
import { isArray } from '@antv/util';
import Geometry from '../geometry';
import { LineProps } from './types';

export default View => {
return class Line extends Geometry {
return class Line extends Geometry<LineProps> {
getDefaultCfg() {
return {
geomType: 'line',
Expand Down Expand Up @@ -116,9 +117,9 @@ export default View => {

render() {
const { props } = this;
const { style, coord } = props;
const { coord } = props;
const records = this.mapping();
return <View {...props} coord={coord} records={records} style={style} />;
return <View {...props} coord={coord} records={records} />;
}
};
};
2 changes: 1 addition & 1 deletion packages/f2/src/components/pieLabel/withPieLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default View => {
label1,
label2,
lineHeight,
skipOverlapLabels,
// skipOverlapLabels,
} = this.props;
const { coord } = chart;
const { center, radius } = coord;
Expand Down
2 changes: 1 addition & 1 deletion packages/f2/src/components/tooltip/withTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default (View) => {
this.show(points[0]);
});

canvas.on(triggerOff, (ev) => {
canvas.on(triggerOff, (_ev) => {
if (!alwaysShow) {
this.hide();
}
Expand Down

0 comments on commit 4ce06bb

Please sign in to comment.