Skip to content

Commit

Permalink
docs: add FAQ about title rendering issues when manually setting padd…
Browse files Browse the repository at this point in the history
…ing (#6554)

* docs: add FAQ about title rendering issues when manually setting padding

* docs: beautify FAQ document format
  • Loading branch information
BQXBQX authored Dec 13, 2024
1 parent 05d5bcd commit a4effad
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
51 changes: 51 additions & 0 deletions site/docs/manual/FAQ/index.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: 'Frequently Asked Questions (FAQ)'
order: 4
---

## Title Not Rendering After Manually Setting Padding

### Problem Description

When using AntV G2 to render charts, manually setting the `padding` can cause the chart title to not render properly or disappear entirely.

Related issue: [Title is not displayed after setting](https://github.com/antvis/G2/issues/6549)

### Cause Analysis

G2 dynamically calculates the space required for all components by default, but once a fixed `padding` value is specified, this automatic adjustment logic is skipped, which may lead to incomplete rendering of the components.

### Solutions

There are two ways to resolve this issue:

#### 1. Use the Default Layout (Recommended)

Allow G2 to automatically calculate the optimal spacing to ensure that all components are rendered correctly:

```javascript
chart
.interval()
.encode('x', 'category')
.encode('y', 'value')
.encode('color', 'type');
```

#### 2. Set Padding Correctly

If you must manually set the `padding`, make sure to reserve enough space for dynamically generated components:

```javascript
chart
.padding(50)
.interval()
.encode('x', 'category')
.encode('y', 'value')
.encode('color', 'type');
```

### Notes

- When manually setting `padding`, it is recommended to debug and find the appropriate values.
- Consider the space requirements for titles, legends, and other components.
- If a specific layout is not required, it's better to use G2's automatic layout system.
51 changes: 51 additions & 0 deletions site/docs/manual/FAQ/index.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: '常见问题 FAQ'
order: 4
---

## 手动设置 Padding 后标题无法渲染

### 问题描述

在使用 AntV G2 绘制图表时,手动设置 `padding` 可能会导致图表标题无法正常显示或完全消失。

相关问题:[设置完 title 不显示](https://github.com/antvis/G2/issues/6549)

### 原因分析

G2 默认会动态计算所有组件所需的间距,但一旦指定了固定的 `padding` 值,这个自动调整的逻辑就会被跳过,可能导致组件显示不完整。

### 解决方案

有两种方式可以解决这个问题:

#### 1. 使用默认布局(推荐)

让 G2 自动计算最佳间距,确保所有组件正常显示:

```javascript
chart
.interval()
.encode('x', 'category')
.encode('y', 'value')
.encode('color', 'type');
```

#### 2. 正确设置 Padding

如果确实需要手动设置 `padding`,请确保为动态生成的组件预留足够空间:

```javascript
chart
.padding(50)
.interval()
.encode('x', 'category')
.encode('y', 'value')
.encode('color', 'type');
```

### 注意事项

- 手动设置 `padding` 时,建议通过调试确定合适的数值
- 需要考虑标题、图例等组件的空间需求
- 在不需要特定布局时,优先使用 G2 的自动布局功能

0 comments on commit a4effad

Please sign in to comment.