Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/f2/src/components/axis/withAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type BBox = {
width: number;
};

const SHOW_MIDDLE_LABEL_THRESHOLD = 10;

export { AxisProps };

export default (View) => {
Expand Down Expand Up @@ -442,9 +444,12 @@ export default (View) => {
tick.visible = false;
});

// 没找到最佳步长,则保留第一个和最后一个数据
// 没找到最佳步长,则保留第一个和最后一个数据,如果总range较大,保留中间的label
if (finalSeq > maxSeq) {
ticks[0].visible = true;
if(range > SHOW_MIDDLE_LABEL_THRESHOLD && !this.hasOverlapAtSeq(ticks, maxSeq)) {
ticks[maxSeq].visible = true;
}
ticks[range].visible = true
return;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
166 changes: 166 additions & 0 deletions packages/f2/test/components/axis/labelAuto.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,170 @@ describe('Axis labelAutoRotate', () => {
await delay(1000);
expect(context).toMatchImageSnapshot();
});

it('不均匀隐藏', async () => {
const context = createContext('不均匀隐藏');

const { props } = (
<Canvas context={context} pixelRatio={1} width={350} height={250}>
<Chart
data={[
{
x: '2023-01',
y: 83.22,
},
{
x: '2023-02',
y: 78.28,
},
{
x: '2023-03',
y: 77.5,
},
{
x: '2023-04',
y: 83.38,
},
{
x: '2023-05',
y: 87.87,
},
{
x: '2023-06',
y: 90.78,
},
{
x: '2023-07',
y: 93.05,
},
{
x: '2023-08',
y: 93.22,
},
{
x: '2023-09',
y: 93.4,
},
{
x: '2023-10',
y: 87.94,
},
{
x: '2023-11',
y: 82.36,
},
{
x: '2023-12',
y: 68.32,
},
{
x: '2024-01',
y: 39.55,
},
{
x: '2024-02',
y: 20.78,
},
{
x: '2024-03',
y: 11.39,
},
{
x: '2024-04',
y: 4.12,
},
{
x: '2024-05',
y: -0.97,
},
{
x: '2024-06',
y: 0.04,
},
{
x: '2024-07',
y: 4.61,
},
{
x: '2024-08',
y: 6.04,
},
{
x: '2024-09',
y: 5.34,
},
{
x: '2024-10',
y: 10.14,
},
{
x: '2024-11',
y: 10.38,
},
{
x: '2024-12',
y: 8.09,
},
{
x: '2025-01',
y: 1.76,
},
{
x: '2025-02',
y: -9.14,
},
{
x: '2025-03',
y: -21.03,
},
{
x: '2025-04',
y: -37.68,
},
{
x: '2025-05',
y: -43.5,
},
{
x: '2025-06',
y: -44.38,
},
{
x: '2025-07',
y: -42.99,
},
{
x: '2025-08',
y: -39.59,
},
]}
scale={{
time: {
range: [0, 1],
},
}}
style={{
padding: [0, 0, 0, 0],
}}
>
<Axis
field="x"
labelAutoHide={true}
style={{
label: {
align: 'center',
},
}}
/>
<Axis field="y" />
<Line x="x" y="y" />
</Chart>
</Canvas>
);
const canvas = new Canvas(props);
await canvas.render();

await delay(1000);
expect(context).toMatchImageSnapshot();
});
});
Loading