Skip to content

Commit 6b4cd71

Browse files
authored
feat: 增加检测是否重叠安全距离属性 (#2106)
* feat: 增加检测是否重叠安全距离属性 * chore: 修复ci
1 parent f42573a commit 6b4cd71

File tree

7 files changed

+70
-34
lines changed

7 files changed

+70
-34
lines changed

.github/workflows/mirror.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/f2/src/components/axis/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,9 @@ export interface AxisProps<
142142
* @default false
143143
*/
144144
labelAutoHide?: boolean;
145+
/**
146+
* 检测是否重叠安全边距
147+
* @default 2
148+
*/
149+
safetyDistance?: number | string;
145150
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ export default (View) => {
366366
}
367367

368368
hasOverlapAtSeq(ticks, step) {
369-
const safetyMargin = 2;
369+
const { px2hd } = this.context;
370+
const { safetyDistance = 2 } = this.props;
370371
const XDistance = this._getXTicksDistance([ticks[0], ticks[step]]);
371372

372373
let prevIdx = 0;
@@ -376,7 +377,7 @@ export default (View) => {
376377
const { align = 'center' } = { ...label, ...labelStyle };
377378

378379
let minDistance =
379-
(ticks[prevIdx].labelWidth + ticks[currIdx].labelWidth) / 2 + safetyMargin;
380+
(ticks[prevIdx].labelWidth + ticks[currIdx].labelWidth) / 2 + px2hd(safetyDistance);
380381
if (prevIdx === 0 && align === 'between') {
381382
minDistance += ticks[prevIdx].labelWidth / 2;
382383
}
9.96 KB
Loading
11.1 KB
Loading

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,63 @@ describe('Axis labelAutoRotate', () => {
336336
await delay(1000);
337337
expect(context).toMatchImageSnapshot();
338338
});
339+
340+
it('safetyDistance属性', async () => {
341+
const data = [
342+
{ category: '2025-01-04', value: 10 },
343+
{ category: '2025-02-04', value: 15 },
344+
{ category: '2025-03-04', value: 20 },
345+
{ category: '2025-04-04', value: 25 },
346+
{ category: '2025-05-04', value: 25 },
347+
{ category: '2025-06-04', value: 25 },
348+
];
349+
const context = createContext('safetyDistance属性');
350+
351+
const { props } = (
352+
<Canvas context={context} pixelRatio={1} width={350} height={250}>
353+
<Chart data={data}>
354+
<Axis
355+
field="category"
356+
style={{
357+
label: {
358+
fontSize: '19px',
359+
},
360+
}}
361+
labelAutoRotate={true}
362+
/>
363+
<Axis field="value" />
364+
<Interval x="category" y="value" color="#2FC25B" />
365+
</Chart>
366+
</Canvas>
367+
);
368+
369+
const canvas = new Canvas(props);
370+
await canvas.render();
371+
372+
await delay(1000);
373+
expect(context).toMatchImageSnapshot();
374+
375+
const { props: nextProps } = (
376+
<Canvas context={context} pixelRatio={1} width={350} height={250}>
377+
<Chart data={data}>
378+
<Axis
379+
field="category"
380+
style={{
381+
label: {
382+
fontSize: '19px',
383+
},
384+
}}
385+
labelAutoRotate={true}
386+
safetyDistance={3}
387+
/>
388+
<Axis field="value" />
389+
<Interval x="category" y="value" color="#2FC25B" />
390+
</Chart>
391+
</Canvas>
392+
);
393+
394+
await canvas.update(nextProps);
395+
await delay(1000);
396+
expect(context).toMatchImageSnapshot();
397+
});
339398
});

packages/f2/test/components/magnifier/magnifier.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ describe('Magnifier', () => {
268268
const canvas = new Canvas(props);
269269
await canvas.render();
270270

271-
await delay(500);
271+
await delay(1000);
272272
expect(context).toMatchImageSnapshot();
273273
});
274274

@@ -302,7 +302,7 @@ describe('Magnifier', () => {
302302
const canvas = new Canvas(props);
303303
await canvas.render();
304304

305-
await delay(500);
305+
await delay(1000);
306306
expect(context).toMatchImageSnapshot();
307307
});
308308
it('动态折线图', async () => {
@@ -508,7 +508,7 @@ describe('Magnifier', () => {
508508
);
509509
const canvas = new Canvas(props);
510510
await canvas.render();
511-
await delay(500);
511+
await delay(800);
512512
expect(context).toMatchImageSnapshot();
513513
});
514514
});

0 commit comments

Comments
 (0)