Skip to content

Commit bb0a6ab

Browse files
committed
feat: improve long text display in table chart
1 parent 92d2190 commit bb0a6ab

File tree

1 file changed

+28
-0
lines changed
  • frontend/src/views/chat/component/charts

1 file changed

+28
-0
lines changed

frontend/src/views/chat/component/charts/Table.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type S2MountContainer,
99
type SortMethod,
1010
type Node,
11+
type CellTextWordWrapStyle,
1112
} from '@antv/s2'
1213
import { debounce, filter } from 'lodash-es'
1314
import { i18n } from '@/i18n'
@@ -70,6 +71,15 @@ export class Table extends BaseChart {
7071
data: this.data,
7172
}
7273

74+
const cellTextWordWrapStyle: CellTextWordWrapStyle = {
75+
// 最大行数,文本超出后将被截断
76+
maxLines: 3,
77+
// 文本是否换行
78+
wordWrap: true,
79+
// 可选项见:https://g.antv.antgroup.com/api/basic/text#textoverflow
80+
textOverflow: 'ellipsis',
81+
}
82+
7383
const s2Options: S2Options = {
7484
width: 600,
7585
height: 360,
@@ -146,6 +156,24 @@ export class Table extends BaseChart {
146156
},
147157
},
148158
},
159+
// 如果有省略号, 复制到的是完整文本
160+
interaction: {
161+
copy: {
162+
enable: true,
163+
withFormat: true,
164+
withHeader: true,
165+
},
166+
brushSelection: {
167+
dataCell: true,
168+
rowCell: true,
169+
colCell: true,
170+
},
171+
},
172+
style: {
173+
colCell: cellTextWordWrapStyle,
174+
// 如果是数值不建议换行, 容易产生歧义
175+
dataCell: cellTextWordWrapStyle,
176+
},
149177
placeholder: {
150178
cell: '-',
151179
empty: {

0 commit comments

Comments
 (0)