Skip to content

Commit 319789b

Browse files
authored
fix(#2236): liquid distance calculate error (#2238)
* fix(#2236): liquid distance calucate error * docs(liquid): fix typo disatance * fix: ci * chore: optimize the test case
1 parent bcd2143 commit 319789b

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

__tests__/bugs/issue-2080-spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ describe('donut plot', () => {
5353

5454
let annotations = getAnnotations(donutPlot.chart);
5555
expect(annotations.length).toBeGreaterThan(0);
56-
let htmlAnnotations = document.querySelectorAll('.g2-html-annotation');
56+
let htmlAnnotations = donutPlot.container.querySelectorAll('.g2-html-annotation');
5757
expect((htmlAnnotations[0] as HTMLElement).innerText).toBe('总计' /** 中心文本指标卡,默认title */);
5858

5959
donutPlot.update({ statistic: { title: { formatter: () => 'test' }, content: false } });
6060

6161
annotations = getAnnotations(donutPlot.chart);
6262
expect(annotations.length).toBe(1);
63-
htmlAnnotations = document.querySelectorAll('.g2-html-annotation');
63+
htmlAnnotations = donutPlot.container.querySelectorAll('.g2-html-annotation');
6464
expect((htmlAnnotations[0] as HTMLElement).innerText).toBe('test' /** 中心文本指标卡,默认title */);
6565

6666
donutPlot.destroy();

__tests__/bugs/issue-2236-spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Liquid } from '../../src';
2+
import { createDiv } from '../utils/dom';
3+
4+
describe('#2236', () => {
5+
it('liquid distance', () => {
6+
const liquid = new Liquid(createDiv(), {
7+
autoFit: false,
8+
width: 300,
9+
height: 300,
10+
percent: 0.25,
11+
outline: {
12+
border: 4,
13+
distance: 1,
14+
},
15+
wave: {
16+
length: 128,
17+
},
18+
});
19+
20+
liquid.render();
21+
22+
// @ts-ignore
23+
expect(liquid.chart.middleGroup.getChildren()[0].getChildren()[1].get('clipShape').attr('r')).toBe(132);
24+
// clipShape r + distance + border / 2
25+
// @ts-ignore
26+
expect(liquid.chart.middleGroup.getChildren()[0].getChildren()[0].attr('r')).toBe(132 + 1 + 4 / 2);
27+
28+
liquid.destroy();
29+
});
30+
});

__tests__/unit/plots/liquid/index-spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('liquid', () => {
4848
expect(liquid.chart.middleGroup.findAllByName('waterwave-path')[0].get('animations')[0].toAttrs.matrix[6]).toBe(
4949
192
5050
);
51-
expect(liquid.chart.middleGroup.findAllByName('waves')[0].get('clipShape').attr('r')).toBe(135);
51+
expect(liquid.chart.middleGroup.findAllByName('waves')[0].get('clipShape').attr('r')).toBe(134);
5252

5353
liquid.update({
5454
outline: {
@@ -70,7 +70,7 @@ describe('liquid', () => {
7070
expect(liquid.chart.middleGroup.findAllByName('waterwave-path')[0].get('animations')[0].toAttrs.matrix[6]).toBe(
7171
128
7272
);
73-
expect(liquid.chart.middleGroup.findAllByName('waves')[0].get('clipShape').attr('r')).toBe(127);
73+
expect(liquid.chart.middleGroup.findAllByName('waves')[0].get('clipShape').attr('r')).toBe(125);
7474

7575
liquid.destroy();
7676
});

docs/api/plots/liquid.en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The ouline configure for liquid plot, includes:
4242
| Attr | Type | Desc |
4343
| ------------ | -------------- | ----------------------------------------------------- |
4444
| border | number | border width of ouline, default 2px |
45-
| disatance | number | disatance between ouline and wave, default 0px |
45+
| distance | number | distance between ouline and wave, default 0px |
4646

4747
#### wave
4848

docs/api/plots/liquid.zh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ order: 12
4242
| 属性名 | 类型 | 介绍 |
4343
| ------------ | -------------- | -------------------------------------------- |
4444
| border | number | 外框容器的 border 宽度,默认为 2 像素 |
45-
| disatance | number | 外框容器和内部波形的间距,默认为 0 像素 |
45+
| distance | number | 外框容器和内部波形的间距,默认为 0 像素 |
4646

4747
#### wave
4848

src/plots/liquid/shapes/liquid.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ registerShape('interval', 'liquid-fill-gauge', {
309309
attrs: {
310310
x: center.x,
311311
y: center.y,
312-
r: radius - distance,
312+
r: radius - distance - border / 2, // border 的大小会占用宽度
313313
},
314314
});
315315

0 commit comments

Comments
 (0)