Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: label 为 null 时,图形更小 #1443

Merged
merged 1 commit into from
Apr 15, 2022
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
9 changes: 7 additions & 2 deletions packages/f2/src/components/axis/withAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,20 @@ export default (View) => {
getMaxBBox(ticks, style: Style): BBox {
const { context } = this;
const { measureText } = context;
const { labelOffset } = style;
const { label, labelOffset } = style;

let width = 0;
let height = 0;
ticks.forEach((tick: Tick) => {
if (!label) return;
const { labelStyle, text } = tick;
const bbox = measureText(text, { ...style.label, ...labelStyle });
const bbox = measureText(text, { ...label, ...labelStyle });
width = Math.max(width, bbox.width);
height = Math.max(height, bbox.height);
});
if (!width && !height) {
return { width, height };
}

const bbox = {
width: width + labelOffset,
Expand Down Expand Up @@ -219,6 +223,7 @@ export default (View) => {
if (dimType === 'y') {
return null;
}
console.log(bbox);
// 4 个方向都需要留空
return ['top', 'right', 'bottom', 'left'].map(
(position: 'top' | 'right' | 'bottom' | 'left') => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 27 additions & 6 deletions packages/f2/test/components/line/radar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,9 @@ describe('雷达图', () => {
const context = createContext('Tooltip 默认展示');
const { props } = (
<Canvas context={context} pixelRatio={1}>
<Chart
data={data1}
coord="polar"
>
<Chart data={data1} coord="polar">
<Axis field="time" grid="line" />
<Axis field="value" grid="line" style={{label: {text: ''}}} />
<Axis field="value" grid="line" style={{ label: null }} />
<Line x="time" y="value" color="name" />
<Tooltip alwaysShow={true} defaultItem={data1[0]} snap />
</Chart>
Expand All @@ -178,6 +175,30 @@ describe('雷达图', () => {

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

it('雷达图-label 为 null', async () => {
const context = createContext();
const { props } = (
<Canvas context={context} pixelRatio={1}>
<Chart data={data} coord="polar">
<Axis
field="item"
style={{
label: null,
}}
/>
<Axis field="score" />
<Line x="item" y="score" color="user" />
</Chart>
</Canvas>
);

const canvas = new Canvas(props);
canvas.render();

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