Skip to content

Commit

Permalink
fix: coordinate
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfu1 committed Jan 8, 2024
1 parent 3ef5c79 commit 9f3670c
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 57 deletions.
24 changes: 0 additions & 24 deletions packages/plots/src/core/adaptor/coordinate.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/plots/src/core/adaptor/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { mark } from './mark';
export { coordinate } from './coordinate';
export * from './coordinate-layout';
21 changes: 9 additions & 12 deletions packages/plots/src/core/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ export const TRANSFORM_OPTION_KEY = {
binField: 'encode.x',
srcField: 'encode.src',
linkColorField: 'encode.linkColor',
radius: 'coordinate.outerRadius',
innerRadius: 'coordinate.innerRadius',
startAngle: 'coordinate.startAngle',
endAngle: 'coordinate.endAngle',
focusX: 'coordinate.focusX',
focusY: 'coordinate.focusY',
distortionX: 'coordinate.distortionX',
distortionY: 'coordinate.distortionY',
visual: 'coordinate.visual',
/**
* @title 堆叠
* @example
Expand Down Expand Up @@ -231,18 +240,6 @@ export const CONFIG_SHAPE = [
},
];

export const COORDIANTE_OPTIONS = [
'radius',
'innerRadius',
'startAngle',
'endAngle',
'focusX',
'focusY',
'distortionX',
'distortionY',
'visual',
];

/**
* @description 一些特殊的配置项,需要自定义转换逻辑
*/
Expand Down
4 changes: 1 addition & 3 deletions packages/plots/src/core/plots/pie/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { flow, transformOptions, isArray, set } from '../../utils';
import { coordinate } from '../../adaptor';

import type { Adaptor } from '../../types';
import type { PieOptions } from './type';

Expand Down Expand Up @@ -46,5 +44,5 @@ export function adaptor(params: Params) {
}
return params;
};
return flow(emptyData, coordinate, transformOptions)(params);
return flow(emptyData, transformOptions)(params);
}
3 changes: 1 addition & 2 deletions packages/plots/src/core/plots/radar/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { flow, transformOptions, get, set } from '../../utils';
import { coordinate } from '../../adaptor';

import type { Adaptor } from '../../types';
import type { RadarOptions } from './type';
Expand All @@ -19,5 +18,5 @@ export function adaptor(params: Params) {
return params;
};

return flow(init, coordinate, transformOptions)(params);
return flow(init, transformOptions)(params);
}
8 changes: 2 additions & 6 deletions packages/plots/src/core/plots/radial-bar/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { flow, set, pick, transformOptions, isNumber, get } from '../../utils';
import { flow, set, transformOptions, isNumber, get } from '../../utils';
import { mark } from '../../adaptor';
import { COORDIANTE_OPTIONS } from '../../constants';
import type { Adaptor } from '../../types';
import type { RadialBarOptions } from './type';

Expand All @@ -17,17 +16,14 @@ export function adaptor(params: Params) {
*/
const coordinate = (params: Params) => {
const { options } = params;
const { startAngle, maxAngle, coordinate, radius, innerRadius } = options;
const { startAngle, maxAngle, coordinate } = options;
// 默认开始角度是-90度
const start = isNumber(startAngle) ? (startAngle / (2 * Math.PI)) * 360 : -90;
// 结束角度通过maxAngle来计算
const end = isNumber(maxAngle) ? ((Number(maxAngle) + start) / 180) * Math.PI : Math.PI;
set(params, ['options', 'coordinate'], {
...coordinate,
...pick(options.coordinate, COORDIANTE_OPTIONS),
endAngle: end,
outerRadius: radius,
innerRadius,
startAngle: startAngle ?? -Math.PI / 2,
});

Expand Down
3 changes: 1 addition & 2 deletions packages/plots/src/core/plots/rose/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { flow, transformOptions } from '../../utils';
import { coordinate } from '../../adaptor';

import type { Adaptor } from '../../types';
import type { RoseOptions } from './type';
Expand All @@ -11,5 +10,5 @@ type Params = Adaptor<RoseOptions>;
* @param options
*/
export function adaptor(params: Params) {
return flow(coordinate, transformOptions)(params);
return flow(transformOptions)(params);
}
3 changes: 1 addition & 2 deletions packages/plots/src/core/plots/sunburst/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { coordinate } from '../../adaptor';
import { flow, transformOptions } from '../../utils';

import type { Adaptor } from '../../types';
Expand All @@ -18,5 +17,5 @@ export function adaptor(params: Params) {
return params;
};

return flow(init, coordinate, transformOptions)(params);
return flow(init, transformOptions)(params);
}
7 changes: 2 additions & 5 deletions packages/plots/src/core/utils/delete-excess-keys.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { TRANSFORM_OPTION_KEY, VIEW_OPTIONS, CONFIG_SHAPE, COORDIANTE_OPTIONS, ANNOTATION_LIST } from '../constants';
import { TRANSFORM_OPTION_KEY, VIEW_OPTIONS, CONFIG_SHAPE, ANNOTATION_LIST } from '../constants';
import { Options } from '../types';

/**
* 统一删除已转换的配置项
*/
export const deleteExcessKeys = <O extends Options>(options: O): O => {
const { children = [] } = options;
const deleteKeys = Object.keys(TRANSFORM_OPTION_KEY).concat(
CONFIG_SHAPE.map((item) => item.key),
COORDIANTE_OPTIONS,
);
const deleteKeys = Object.keys(TRANSFORM_OPTION_KEY).concat(CONFIG_SHAPE.map((item) => item.key));
deleteKeys.forEach((key) => {
delete options[key];
});
Expand Down

0 comments on commit 9f3670c

Please sign in to comment.