Skip to content

Commit 8688e41

Browse files
XinyueDuduxinyue.dxy
andauthored
feat: feat error style (#160)
Co-authored-by: duxinyue.dxy <[email protected]>
1 parent 32a356f commit 8688e41

File tree

3 files changed

+321
-5
lines changed

3 files changed

+321
-5
lines changed

src/ChartCodeRender/demos/errorRender.tsx

Lines changed: 309 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChartType, Column, FlowDiagram, GPTVisLite, withChartCode } from '@antv/gpt-vis';
1+
import { ChartType, Column, FlowDiagram, GPTVisLite, MindMap, withChartCode } from '@antv/gpt-vis';
22
import type { FC } from 'react';
33
import React from 'react';
44
import type { ErrorRender } from '../type';
@@ -39,6 +39,309 @@ const example2Markdown = `
3939
`;
4040

4141
// 示例 - 图表渲染错误
42+
const example5Markdown = `
43+
#### 图表渲染错误抛错
44+
\`\`\`vis-chart
45+
{
46+
"type": "mind-map",
47+
"data": {
48+
"name": "Transformer 模型",
49+
"children": [
50+
{
51+
"name": "概述",
52+
"children": [
53+
{
54+
"name": "定义与背景",
55+
"children": [
56+
{
57+
"name": "2017年 Vaswani 等人提出"
58+
},
59+
{
60+
"name": "自然语言处理任务"
61+
}
62+
]
63+
},
64+
{
65+
"name": "主要特点",
66+
"children": [
67+
{
68+
"name": "无需循环结构"
69+
},
70+
{
71+
"name": "依赖自注意力机制"
72+
},
73+
{
74+
"name": "可并行处理"
75+
}
76+
]
77+
},
78+
{
79+
"name": "应用领域",
80+
"children": [
81+
{
82+
"name": "机器翻译"
83+
},
84+
{
85+
"name": "文本摘要"
86+
},
87+
{
88+
"name": "问答系统"
89+
},
90+
{
91+
"name": "语音处理"
92+
}
93+
]
94+
}
95+
]
96+
},
97+
{
98+
"name": "核心组件",
99+
"children": [
100+
{
101+
"name": "自注意力机制",
102+
"children": [
103+
{
104+
"name": "机制原理",
105+
"children": [
106+
{
107+
"name": "每个词关注其他词"
108+
},
109+
{
110+
"name": "计算注意力权重"
111+
}
112+
]
113+
},
114+
{
115+
"name": "优点",
116+
"children": [
117+
{
118+
"name": "捕捉长距离依赖"
119+
},
120+
{
121+
"name": "可并行计算"
122+
}
123+
]
124+
}
125+
]
126+
},
127+
{
128+
"name": "多头自注意力",
129+
"children": [
130+
{
131+
"name": "多个注意力头并行计算"
132+
},
133+
{
134+
"name": "拼接与线性变换"
135+
}
136+
]
137+
},
138+
{
139+
"name": "位置编码",
140+
"children": [
141+
{
142+
"name": "作用",
143+
"children": [
144+
{
145+
"name": "提供序列顺序信息"
146+
}
147+
]
148+
},
149+
{
150+
"name": "实现方式",
151+
"children": [
152+
{
153+
"name": "正弦/余弦函数"
154+
},
155+
{
156+
"name": "可学习的嵌入"
157+
}
158+
]
159+
}
160+
]
161+
},
162+
{
163+
"name": "前馈网络",
164+
"children": [
165+
{
166+
"name": "两层全连接网络"
167+
},
168+
{
169+
"name": "每个位置独立处理"
170+
}
171+
]
172+
},
173+
{
174+
"name": "残差连接与层归一化",
175+
"children": [
176+
{
177+
"name": "缓解梯度消失"
178+
},
179+
{
180+
"name": "加速训练"
181+
}
182+
]
183+
}
184+
]
185+
},
186+
{
187+
"name": "架构",
188+
"children": [
189+
{
190+
"name": "编码器",
191+
"children": [
192+
{
193+
"name": "多层结构"
194+
},
195+
{
196+
"name": "每层组成",
197+
"children": [
198+
{
199+
"name": "自注意力"
200+
},
201+
{
202+
"name": "前馈网络"
203+
}
204+
]
205+
}
206+
]
207+
},
208+
{
209+
"name": "解码器",
210+
"children": [
211+
{
212+
"name": "多层结构"
213+
},
214+
{
215+
"name": "每层组成",
216+
"children": [
217+
{
218+
"name": "自注意力"
219+
},
220+
{
221+
"name": "编码器-解码器注意力"
222+
},
223+
{
224+
"name": "前馈网络"
225+
}
226+
]
227+
}
228+
]
229+
},
230+
{
231+
"name": "输入输出嵌入",
232+
"children": [
233+
{
234+
"name": "词向量转换"
235+
},
236+
{
237+
"name": "与位置编码结合"
238+
}
239+
]
240+
}
241+
]
242+
},
243+
{
244+
"name": "计算复杂度与优化",
245+
"children": [
246+
{
247+
"name": "自注意力复杂度",
248+
"children": [
249+
{
250+
"name": "O(N²)"
251+
}
252+
]
253+
},
254+
{
255+
"name": "改进方案",
256+
"children": [
257+
{
258+
"name": "Set Transformer - 诱导点降低复杂度"
259+
},
260+
{
261+
"name": "Reformer - 局部注意力和哈希"
262+
},
263+
{
264+
"name": "Linformer - 降低注意力矩阵维度"
265+
},
266+
{
267+
"name": "Longformer - 长序列局部/全局注意力"
268+
},
269+
{
270+
"name": "Charformer - 字符级高效表示"
271+
}
272+
]
273+
}
274+
]
275+
},
276+
{
277+
"name": "应用与扩展",
278+
"children": [
279+
{
280+
"name": "自然语言处理",
281+
"children": [
282+
{
283+
"name": "BERT、GPT 等"
284+
}
285+
]
286+
},
287+
{
288+
"name": "计算机视觉",
289+
"children": [
290+
{
291+
"name": "Vision Transformer (ViT)"
292+
}
293+
]
294+
},
295+
{
296+
"name": "语音处理",
297+
"children": [
298+
{
299+
"name": "Transformer 语音识别"
300+
}
301+
]
302+
},
303+
{
304+
"name": "强化学习",
305+
"children": [
306+
{
307+
"name": "状态关系建模"
308+
}
309+
]
310+
}
311+
]
312+
},
313+
{
314+
"name": "总结",
315+
"children": [
316+
{
317+
"name": "优势",
318+
"children": [
319+
{
320+
"name": "高效并行"
321+
},
322+
{
323+
"name": "长距离依赖捕捉"
324+
}
325+
]
326+
},
327+
{
328+
"name": "挑战",
329+
"children": [
330+
{
331+
"name": "大型模型计算开销"
332+
},
333+
{
334+
"name": "需要大量训练数据"
335+
}
336+
]
337+
}
338+
]
339+
}
340+
]
341+
}
342+
}
343+
`;
344+
42345
const example3Markdown = `
43346
#### 默认图表渲染错误
44347
\`\`\`vis-chart
@@ -280,7 +583,7 @@ const CustomErrorCode2 = withChartCode({
280583

281584
// 默认图表渲染错误
282585
const DefaultChartError = withChartCode({
283-
components: { [ChartType.FlowDiagram]: FlowDiagram },
586+
components: { [ChartType.FlowDiagram]: FlowDiagram, [ChartType.MindMap]: MindMap },
284587
});
285588

286589
const CustomChartError = withChartCode({
@@ -321,6 +624,10 @@ export default () => {
321624
<GPTVisLite components={{ code: DefaultChartError }}>{example3Markdown}</GPTVisLite>
322625
</div>
323626

627+
<div>
628+
<GPTVisLite components={{ code: DefaultChartError }}>{example5Markdown}</GPTVisLite>
629+
</div>
630+
324631
<div>
325632
<GPTVisLite components={{ code: CustomChartError }}>{example4Markdown}</GPTVisLite>
326633
</div>

src/ChartCodeRender/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ group:
3131

3232
## 自定义错误渲染
3333

34-
通过 `errorRender` 属性可以自定义错误渲染,让用户能够获取到完整的错误信息进行个性化的错误处理。
34+
通过 `errorRender` `componentErrorRender` 属性可以自定义错误渲染,让用户能够获取到完整的错误信息进行个性化的错误处理。
3535

3636
<code src="./demos/errorRender"></code>
3737

src/ChartCodeRender/styles.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import styled, { createGlobalStyle } from 'styled-components';
22

33
export const StyledGPTVis = styled.div`
44
min-width: 300px;
5-
height: 300px;
65
max-width: 100%;
76
overflow: hidden;
87
position: relative;
@@ -60,7 +59,16 @@ export const CopyButton = styled.button`
6059

6160
export const ChartWrapper = styled.div`
6261
width: 100%;
63-
height: 100%;
62+
63+
h5 {
64+
font-size: 12px;
65+
font-weight: 400;
66+
color: #666;
67+
height: 150px;
68+
display: flex;
69+
align-items: center;
70+
justify-content: center;
71+
}
6472
6573
& > * {
6674
max-width: 100%;
@@ -103,6 +111,7 @@ export const TabContent = styled.div`
103111
`;
104112

105113
export const ErrorMessage = styled.div`
114+
padding: 16px;
106115
height: 150px;
107116
font-size: 12px;
108117
color: #666;

0 commit comments

Comments
 (0)