Skip to content

Commit

Permalink
fix: bullet的target支持回调函数处理 (#2397)
Browse files Browse the repository at this point in the history
* fix: bullet的target支持回调函数处理

* Update issue-2229-spec.ts

Co-authored-by: hustcc <i@hust.cc>
  • Loading branch information
arcsin1 and hustcc committed Mar 9, 2021
1 parent e87ea30 commit 02d9942
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
67 changes: 67 additions & 0 deletions __tests__/bugs/issue-2229-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Bullet } from '../../src/plots/bullet';
import { createDiv } from '../utils/dom';

const data = [
{
title: '重庆',
ranges: [30, 90, 120],
measures: [65],
target: 80,
},
{
title: '杭州',
ranges: [30, 90, 120],
measures: [50],
target: 100,
},
{
title: '广州',
ranges: [30, 90, 120],
measures: [40],
target: 85,
},
{
title: '深圳',
ranges: [30, 90, 120],
measures: [50],
target: 100,
},
];

describe('#2229', () => {
it('measureSize*rangeSize*targetSize', () => {
const bullet = new Bullet(createDiv('measureSize*rangeSize bullet'), {
width: 400,
height: 400,
data,
measureField: 'measures',
rangeField: 'ranges',
targetField: 'target',
xField: 'title',
size: {
range: () => {
return 20;
},
measure: () => {
return 15;
},
target: () => {
return 20;
},
},
});

bullet.render();
const chart = bullet.chart;
const rangeGeometry = chart.geometries[0];
expect(rangeGeometry.elements[0].getModel().size).toEqual(20);

const measureGeometry = chart.geometries[1];
expect(measureGeometry.elements[0].getModel().size).toEqual(15);

const targetGeometry = chart.geometries[2];
expect(targetGeometry.elements[0].getModel().size).toEqual(20 / 2);

bullet.destroy();
});
});
7 changes: 5 additions & 2 deletions src/plots/bullet/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { get } from '@antv/util';
import { get, isFunction } from '@antv/util';
import { Params } from '../../core/adaptor';
import { interaction, animation, theme, tooltip, scale } from '../../adaptor/common';
import { flow, transformLabel, deepAssign } from '../../utils';
import { Datum } from '../../types';
import { interval, point } from '../../adaptor/geometries';
import { BulletOptions } from './types';
import { transformData } from './utils';
Expand Down Expand Up @@ -63,7 +64,9 @@ function geometry(params: Params<BulletOptions>): Params<BulletOptions> {
point: {
color: get(color, 'target'),
style: get(bulletStyle, 'target'),
size: get(size, 'target') / 2,
size: isFunction(get(size, 'target'))
? (data: Datum) => get(size, 'target')(data) / 2
: get(size, 'target') / 2,
shape: layout === 'horizontal' ? 'line' : 'hyphen',
},
},
Expand Down

0 comments on commit 02d9942

Please sign in to comment.