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(second-geometry): 辅助几何图形 point 支持独立设置 state style #2429

Merged
merged 2 commits into from
Mar 17, 2021
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
2 changes: 1 addition & 1 deletion __tests__/bugs/issue-2220-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('pie tooltip', () => {

await delay(80);
pie.chart.showTooltip(point);
await delay(100);
await delay(300);
// @ts-ignore
let items = tooltipController.getTooltipItems(point);
expect(items[0].name).toBe('xxx');
Expand Down
1 change: 1 addition & 0 deletions docs/common/point-style.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
| shape | \_string \| Function\_ | The shape of the data point, support callback way, example: `shape: (x, y, series) => string` |
| size | _number \| Function_ | The size of the data point, support callback way, example: `size: (x, y, series) => number` |
| style | _object \| Function_ | Data point style, support callback way, example: `style: (x, y, series) => object` |
| state | _object_ | State styles of point, setting style of specify state。Refer to [_state_](#state)` |
1 change: 1 addition & 0 deletions docs/common/point-style.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
| shape | _string \| Function_ | 数据点形状,也可以支持回调的方式设置,回调参数为 `shape: (x, y, series) => string` |
| size | _number \| Function_ | 数据点大小,也可以支持回调的方式设置,回调参数为 `size: (x, y, series) => number` |
| style | _object \| Function_ | 数据点样式,也可以支持回调的方式设置,回调参数为 `style: (x, y, series) => object` |
| state | _object_ | 数据点状态样式,设置对应状态的样式。详细参考 [_state_](#state)` |
58 changes: 0 additions & 58 deletions examples/dual-axes/column-line/demo/slider-culumn-line.ts

This file was deleted.

8 changes: 5 additions & 3 deletions src/plots/area/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Geometry } from '@antv/g2';
import { each } from '@antv/util';
import { tooltip, slider, interaction, animation, theme, annotation, limitInPlot, state } from '../../adaptor/common';
import { tooltip, slider, interaction, animation, theme, annotation, limitInPlot } from '../../adaptor/common';
import { findGeometry } from '../../utils';
import { Params } from '../../core/adaptor';
import { area, point, line } from '../../adaptor/geometries';
Expand Down Expand Up @@ -30,6 +30,8 @@ function geometry(params: Params<AreaOptions>): Params<AreaOptions> {
tooltip,
seriesField,
} = options;
const pointState = pointMapping?.state;

const chartData = getDataWhetherPecentage(data, yField, xField, yField, isPercent);
chart.data(chartData);
// 百分比堆积图,默认会给一个 % 格式化逻辑, 用户可自定义
Expand Down Expand Up @@ -61,11 +63,12 @@ function geometry(params: Params<AreaOptions>): Params<AreaOptions> {
},
});
const second = deepAssign({}, primary, { options: { tooltip: false } });
const pointParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });

// area geometry 处理
area(primary);
line(second);
point(second);
point(pointParams);

return params;
}
Expand Down Expand Up @@ -131,7 +134,6 @@ export function adaptor(params: Params<AreaOptions>) {
meta,
adjust,
theme,
state,
axis,
legend,
tooltip,
Expand Down
2 changes: 1 addition & 1 deletion src/plots/area/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export interface AreaOptions extends Options {
/** 面积中折线的样式 */
readonly line?: LineGeometryOptions['line'];
/** 面积图数据点图形样式 */
readonly point?: PointGeometryOptions['point'];
readonly point?: PointGeometryOptions['point'] & Pick<PointGeometryOptions, 'state'>;
}
3 changes: 2 additions & 1 deletion src/plots/line/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { LineOptions } from './types';
function geometry(params: Params<LineOptions>): Params<LineOptions> {
const { chart, options } = params;
const { data, color, lineStyle, lineShape, point: pointMapping, seriesField } = options;
const pointState = pointMapping?.state;

chart.data(data);

Expand All @@ -38,7 +39,7 @@ function geometry(params: Params<LineOptions>): Params<LineOptions> {
label: undefined,
},
});
const second = deepAssign({}, primary, { options: { tooltip: false } });
const second = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });

line(primary);
point(second);
Expand Down
4 changes: 2 additions & 2 deletions src/plots/line/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export interface LineOptions extends Options {
readonly lineStyle?: StyleAttr;
/** 折线 shape 配置 */
readonly lineShape?: Required<LineGeometryOptions>['line']['shape'];
/** 折线数据点图形样式 */
readonly point?: PointGeometryOptions['point'];
/** 折线数据点:1、图形映射属性 2、状态样式 */
readonly point?: PointGeometryOptions['point'] & Pick<PointGeometryOptions, 'state'>;
}
5 changes: 4 additions & 1 deletion src/plots/radar/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function geometry(params: Params<RadarOptions>): Params<RadarOptions> {
const { chart, options } = params;
const { data, lineStyle, color, point: pointOptions, area: areaOptions } = options;

const pointState = pointOptions?.state;

chart.data(data);

// 雷达图 主 geometry
Expand Down Expand Up @@ -43,9 +45,10 @@ function geometry(params: Params<RadarOptions>): Params<RadarOptions> {
tooltip: false,
},
});
const pointParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });

line(primary);
point(second);
point(pointParams);
area(second);

return params;
Expand Down
2 changes: 1 addition & 1 deletion src/plots/radar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface RadarOptions extends Options {
/** 折线图形样式 */
readonly lineStyle?: ShapeStyle | ((x: any, y: any, series?: any) => ShapeStyle);
/** 数据点图形样式 */
readonly point?: PointGeometryOptions['point'];
readonly point?: PointGeometryOptions['point'] & Pick<PointGeometryOptions, 'state'>;
/** area 图形样式, 均提供回调的方式, 不开放 field 映射配置 */
readonly area?: AreaGeometryOptions['area'];
/** 角度轴配置 */
Expand Down
4 changes: 3 additions & 1 deletion src/plots/tiny-area/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { TinyAreaOptions } from './types';
function geometry(params: Params<TinyAreaOptions>): Params<TinyAreaOptions> {
const { chart, options } = params;
const { data, color, areaStyle, point: pointOptions, line: lineOptions } = options;
const pointState = pointOptions?.state;

const seriesData = getTinyData(data);

Expand All @@ -29,11 +30,12 @@ function geometry(params: Params<TinyAreaOptions>): Params<TinyAreaOptions> {
},
});
const second = deepAssign({}, primary, { options: { tooltip: false } });
const pointParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });

// area geometry 处理
area(primary);
line(second);
point(second);
point(pointParams);

chart.axis(false);
chart.legend(false);
Expand Down
3 changes: 2 additions & 1 deletion src/plots/tiny-area/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Options, StyleAttr } from '../../types';
import { MappingOptions } from '../../adaptor/geometries/base';
import { PointGeometryOptions } from '../../adaptor/geometries/point';

/** mini 图类型定义需要 omit 很多的 G2 Options 配置 */
export interface TinyAreaOptions extends Omit<Options, 'data' | 'legend' | 'label'> {
Expand All @@ -12,5 +13,5 @@ export interface TinyAreaOptions extends Omit<Options, 'data' | 'legend' | 'labe
/** 面积折线图形样式 */
readonly line?: MappingOptions;
/** 面积点图形样式 */
readonly point?: MappingOptions;
readonly point?: MappingOptions & Pick<PointGeometryOptions, 'state'>;
}
6 changes: 4 additions & 2 deletions src/plots/tiny-line/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function geometry(params: Params<TinyLineOptions>): Params<TinyLineOptions> {
const { chart, options } = params;
const { data, color, lineStyle, point: pointMapping } = options;

const pointState = pointMapping?.state;

const seriesData = getTinyData(data);

chart.data(seriesData);
Expand All @@ -33,10 +35,10 @@ function geometry(params: Params<TinyLineOptions>): Params<TinyLineOptions> {
point: pointMapping,
},
});
const second = deepAssign({}, primary, { options: { tooltip: false } });
const pointParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });

line(primary);
point(second);
point(pointParams);

chart.axis(false);
chart.legend(false);
Expand Down
3 changes: 2 additions & 1 deletion src/plots/tiny-line/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Options, StyleAttr } from '../../types';
import { MappingOptions } from '../../adaptor/geometries/base';
import { PointGeometryOptions } from '../../adaptor/geometries/point';

/** mini 图类型定义需要 omit 很多的 G2 Options 配置 */
export interface TinyLineOptions extends Omit<Options, 'data' | 'legend' | 'label'> {
Expand All @@ -12,5 +13,5 @@ export interface TinyLineOptions extends Omit<Options, 'data' | 'legend' | 'labe
/** 折线图形样式 */
readonly lineStyle?: StyleAttr;
/** 折线点图形样式 */
readonly point?: MappingOptions;
readonly point?: MappingOptions & Pick<PointGeometryOptions, 'state'>;
}