Skip to content

Commit 2619cf0

Browse files
aliceflaviawang步悠
andauthored
fix: 针对没有找到最佳步长的情况,首尾展示轴文本 (#2117)
Co-authored-by: 步悠 <[email protected]>
1 parent ae964f7 commit 2619cf0

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

packages/f2/src/components/axis/withAxis.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,20 @@ export default (View) => {
434434
}
435435
}
436436

437-
if (finalSeq > maxSeq || finalSeq === 1) {
437+
if (finalSeq === 1) {
438438
return;
439439
}
440440

441441
ticks.forEach((tick) => {
442442
tick.visible = false;
443443
});
444444

445+
// 没找到最佳步长,则保留第一个和最后一个数据
446+
if (finalSeq > maxSeq) {
447+
ticks[0].visible = true;
448+
ticks[range].visible = true
449+
return;
450+
}
445451
for (let i = 0; i <= range; i += finalSeq) {
446452
ticks[i].visible = true;
447453
}
9.08 KB
Loading

packages/f2/test/components/axis/labelAuto.test.tsx

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,89 @@ describe('Axis labelAutoRotate', () => {
143143
expect(context).toMatchImageSnapshot();
144144
});
145145

146+
it('启用标签自动隐藏(labelAutoHide=true):无法获取最佳步长,设置首尾', async () => {
147+
const context = createContext('启用标签自动隐藏');
148+
const testChartData = [
149+
{
150+
"category": "2023-01",
151+
"value": 83.22
152+
},
153+
{
154+
"category": "2023-02",
155+
"value": 78.28
156+
},
157+
{
158+
"category": "2023-03",
159+
"value": 77.5
160+
},
161+
{
162+
"category": "2023-04",
163+
"value": 83.38
164+
},
165+
{
166+
"category": "2023-05",
167+
"value": 87.87
168+
},
169+
{
170+
"category": "2023-06",
171+
"value": 90.78
172+
},
173+
{
174+
"category": "2023-07",
175+
"value": 93.05
176+
},
177+
{
178+
"category": "2023-08",
179+
"value": 93.22
180+
},
181+
{
182+
"category": "2023-09",
183+
"value": 93.4
184+
},
185+
{
186+
"category": "2023-10",
187+
"value": 87.94
188+
},
189+
{
190+
"category": "2023-11",
191+
"value": 82.36
192+
},
193+
{
194+
"category": "2023-12",
195+
"value": 68.32
196+
},
197+
]
198+
199+
const { props } = (
200+
<Canvas context={context} pixelRatio={1} width={350} height={250}>
201+
<Chart
202+
data={testChartData}
203+
style={{
204+
padding: [0, 0, 0, 0],
205+
}}
206+
>
207+
<Axis
208+
field="category"
209+
labelAutoHide={true}
210+
style={{
211+
label: {
212+
align: 'center',
213+
},
214+
}}
215+
/>
216+
<Axis field="value" />
217+
<Interval x="category" y="value" />
218+
</Chart>
219+
</Canvas>
220+
);
221+
222+
const canvas = new Canvas(props);
223+
await canvas.render();
224+
225+
await delay(1000);
226+
expect(context).toMatchImageSnapshot();
227+
});
228+
146229
it('labelAutoHide测试', async () => {
147230
const largeData = Array.from({ length: 100 }, (_, i) => ({
148231
category: `Cat${i + 1}`,

0 commit comments

Comments
 (0)