Skip to content

Commit

Permalink
fix: size 判断移入geometry里面 (#2237)
Browse files Browse the repository at this point in the history
Co-authored-by: liufu.lf <liufu.lf@antfin.com>
  • Loading branch information
lxfu1 and liufu.lf authored Jan 19, 2021
1 parent 903a393 commit a9f3713
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
29 changes: 29 additions & 0 deletions __tests__/unit/plots/scatter/size-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,33 @@ describe('scatter', () => {

scatter.destroy();
});

it('size: default', () => {
const scatter = new Scatter(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data,
xField: 'weight',
yField: 'height',
sizeField: 'weight',
});

scatter.render();

const geometry = scatter.chart.geometries[0];
const elements = geometry.elements;
const sizeArr = [];
elements.forEach((ele) => {
sizeArr.push(ele.getModel().size);
});
sizeArr.sort((a, b) => a - b);

// @ts-ignore
expect(elements.length).toBe(507);
expect(sizeArr[0] > 0).toBeTruthy();
expect(sizeArr[0]).not.toEqual(sizeArr[sizeArr.length - 1]);

scatter.destroy();
});
});
9 changes: 7 additions & 2 deletions src/plots/scatter/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isBoolean } from '@antv/util';
import { isBoolean, isArray } from '@antv/util';
import { Params } from '../../core/adaptor';
import { flow, deepAssign } from '../../utils';
import { point } from '../../adaptor/geometries';
Expand Down Expand Up @@ -29,10 +29,15 @@ export function transformOptions(options: ScatterOptions): ScatterOptions {
*/
function geometry(params: Params<ScatterOptions>): Params<ScatterOptions> {
const { chart, options } = params;
const { data, type, color, shape, size, pointStyle, shapeField, colorField, xField, yField, sizeField } = options;
const { data, type, color, shape, pointStyle, shapeField, colorField, xField, yField, sizeField } = options;
let { size } = options;

let { tooltip } = options;

if (sizeField && !isArray(size)) {
size = [2, 8];
}

if (tooltip && !tooltip.fields) {
tooltip = {
...tooltip,
Expand Down

0 comments on commit a9f3713

Please sign in to comment.