Skip to content

Commit

Permalink
feat(radial-bar): add radial bar label adaptor
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed Feb 19, 2021
1 parent f45d02b commit 9ed9afb
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
32 changes: 32 additions & 0 deletions __tests__/unit/plots/radial-bar/label-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { RadialBar } from '../../../../src';
import { createDiv } from '../../../utils/dom';
import { antvStar } from '../../../data/antv-star';

const xField = 'name';
const yField = 'star';

describe('radial-bar label', () => {
it('bar label', () => {
const bar = new RadialBar(createDiv(), {
width: 400,
height: 300,
data: antvStar,
xField,
yField,
barStyle: {
fill: 'red',
fillOpacity: 0.6,
cursor: 'pointer',
},
label: {},
});
bar.render();

// @ts-ignore
expect(bar.chart.geometries[0].labelOption.cfg.type).toBe('polar');

bar.update({ label: false });
expect(bar.chart.geometries[0].labelOption).toBe(false);
bar.destroy();
});
});
44 changes: 42 additions & 2 deletions src/plots/radial-bar/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { interaction, animation, theme, scale, tooltip, legend, annotation } from '../../adaptor/common';
import { Params } from '../../core/adaptor';
import { flow, deepAssign } from '../../utils';
import { flow, deepAssign, findGeometry, transformLabel } from '../../utils';
import { interval, point } from '../../adaptor/geometries';
import { RadialBarOptions } from './types';
import { getScaleMax } from './utils';
Expand Down Expand Up @@ -88,11 +88,51 @@ export function axis(params: Params<RadialBarOptions>): Params<RadialBarOptions>
return params;
}

/**
* 数据标签
* @param params
*/
function label(params: Params<RadialBarOptions>): Params<RadialBarOptions> {
const { chart, options } = params;
const { label, yField } = options;

const intervalGeometry = findGeometry(chart, 'interval');

// label 为 false, 空 则不显示 label
if (!label) {
intervalGeometry.label(false);
} else {
const { callback, ...cfg } = label;
intervalGeometry.label({
fields: [yField],
callback,
cfg: {
...transformLabel(cfg),
type: 'polar',
},
});
}

return params;
}

/**
* 图适配器
* @param chart
* @param options
*/
export function adaptor(params: Params<RadialBarOptions>) {
return flow(geometry, meta, axis, coordinate, interaction, animation, theme, tooltip, legend, annotation())(params);
return flow(
geometry,
meta,
axis,
coordinate,
interaction,
animation,
theme,
tooltip,
legend,
annotation(),
label
)(params);
}

0 comments on commit 9ed9afb

Please sign in to comment.