Skip to content

Commit 3d90e6b

Browse files
authored
feat: 环比 statistic.htmlContent 回调参数补充 size,容器宽度设置 (#1250)
* feat: 环比 statistic.htmlContent 回调参数补充 size,容器宽度设置 * test: 加长等待,保证测试通过
1 parent 0e9ff68 commit 3d90e6b

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

__tests__/bugs/donut-statistic-spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ describe('Statistics scale format', () => {
3838
];
3939

4040
const donutPlot = new Donut(canvasDiv, {
41-
forceFit: true,
41+
forceFit: false,
42+
width: 400,
43+
height: 400,
4244
title: {
4345
visible: true,
4446
text: '环图',
@@ -59,9 +61,9 @@ describe('Statistics scale format', () => {
5961
colorField: 'type',
6062
animation: false,
6163
statistic: {
62-
htmlContent: (data) => {
64+
htmlContent: (data, size) => {
6365
const { name, value, color } = data;
64-
return `<div>
66+
return `<div class="statistic" style="width: ${size}px; text-align: center">
6567
<h3 class="ring-guide-name" style="color: ${color}">${name}</h3>
6668
<p class="ring-guide-value">${value}</p>
6769
</div>`;
@@ -72,5 +74,7 @@ describe('Statistics scale format', () => {
7274
// @ts-ignore
7375
expect(donutPlot.getLayers()[0].labelComponent.arcPoints[0].name).toBe('-27-');
7476
expect(canvasDiv.getElementsByClassName('ring-guide-value')[0].textContent).toBe('-100-');
77+
// @ts-ignore
78+
expect(canvasDiv.getElementsByClassName('statistic')[0].style.width).toBe('153.088px');
7579
});
7680
});

__tests__/bugs/issue-1137-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('#1137', () => {
4040
}, 1000);
4141

4242
it('test', async () => {
43-
await wait(1500);
43+
await wait(2000);
4444
const view = plot.getView();
4545
const label = plot.getLayer().getLabels()[0];
4646
const geometry = view.geometries[0];

src/plots/donut/component/ring-statistic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default class RingStatistic extends StatisticHtml {
6363
/** 中心文本显示 */
6464
let htmlString;
6565
if (this.options.htmlContent) {
66-
htmlString = this.options.htmlContent(displayData);
66+
htmlString = this.options.htmlContent(displayData, this.getStatisticSize());
6767
} else {
6868
htmlString = this.getStatisticTemplate(displayData);
6969
}
@@ -133,7 +133,7 @@ export default class RingStatistic extends StatisticHtml {
133133
const htmlContent = this.options.htmlContent;
134134
let htmlString: string;
135135
if (htmlContent) {
136-
htmlString = htmlContent(data);
136+
htmlString = htmlContent(data, this.getStatisticSize());
137137
} else {
138138
htmlString = this.getStatisticTemplate(data);
139139
}

0 commit comments

Comments
 (0)