Skip to content

Commit ae36c74

Browse files
authored
feat: add chart bar/pie/donut (#66)
* refactor(designs): optimize plain text support line number * refactor(designs): add chart bar/line/pie structures * refactor(site): adjust site gallery dataset and templates * refactor(dev): adjust dev page * refactor(designs): optimize designs * refactor(site): update ai playground prompt * refactor(utils): move hash to global * refactor: fix cr issues * refactor(runtime): change infographic default options * refactor(site): update ai template list
1 parent e8e09c8 commit ae36c74

File tree

24 files changed

+1431
-850
lines changed

24 files changed

+1431
-850
lines changed

__tests__/unit/resource/utils/ref.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { beforeEach, describe, expect, it, vi } from 'vitest';
22
import { parseDataURI } from '../../../../src/resource/utils/data-uri';
3-
import { getSimpleHash } from '../../../../src/resource/utils/hash';
43
import {
54
getResourceHref,
65
getResourceId,
76
} from '../../../../src/resource/utils/ref';
7+
import { getSimpleHash } from '../../../../src/utils';
88

99
// Mock dependencies
1010
vi.mock('../../../../src/resource/utils/data-uri', () => ({
1111
parseDataURI: vi.fn(),
1212
}));
1313

14-
vi.mock('../../../../src/resource/utils/hash', () => ({
14+
vi.mock('../../../../src/utils', () => ({
1515
getSimpleHash: vi.fn(),
1616
}));
1717

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { describe, expect, it } from 'vitest';
2+
import type { InfographicOptions } from '../../../src/options/types';
3+
import { mergeOptions } from '../../../src/runtime/utils';
4+
5+
describe('runtime/utils', () => {
6+
describe('mergeOptions', () => {
7+
it('prefers source overrides while keeping unrelated base fields', () => {
8+
const base: Partial<InfographicOptions> = {
9+
width: 400,
10+
height: 200,
11+
padding: 12,
12+
};
13+
const overrides: Partial<InfographicOptions> = {
14+
width: 800,
15+
theme: 'dark',
16+
};
17+
18+
const merged = mergeOptions(base, overrides);
19+
20+
expect(merged.width).toBe(800);
21+
expect(merged.height).toBe(200);
22+
expect(merged.padding).toBe(12);
23+
expect(merged.theme).toBe('dark');
24+
});
25+
26+
it('combines nested design, themeConfig, and svg objects', () => {
27+
const base: Partial<InfographicOptions> = {
28+
design: {
29+
structure: { type: 'base-structure' },
30+
title: 'base-title',
31+
},
32+
themeConfig: {
33+
palette: 'light',
34+
},
35+
svg: {
36+
attributes: {
37+
viewBox: '0 0 200 200',
38+
},
39+
},
40+
};
41+
const overrides: Partial<InfographicOptions> = {
42+
design: {
43+
title: 'override-title',
44+
items: ['override-item'],
45+
},
46+
themeConfig: {
47+
palette: 'dark',
48+
},
49+
svg: {
50+
style: {
51+
display: 'block',
52+
},
53+
},
54+
};
55+
56+
const merged = mergeOptions(base, overrides);
57+
58+
expect(merged.design?.structure).toEqual(base.design?.structure);
59+
expect(merged.design?.title).toBe('override-title');
60+
expect(merged.design?.items).toEqual(['override-item']);
61+
62+
expect(merged.themeConfig?.palette).toBe('dark');
63+
64+
expect(merged.svg?.attributes).toEqual(base.svg?.attributes);
65+
expect(merged.svg?.style).toEqual(overrides.svg?.style);
66+
});
67+
});
68+
});

__tests__/unit/resource/utils/hash.test.ts renamed to __tests__/unit/utils/hash.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { getSimpleHash } from '../../../../src/resource/utils/hash';
2+
import { getSimpleHash } from '../../../src/utils';
33

44
describe('hash', () => {
55
describe('getSimpleHash', () => {

dev/src/Composite.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export const Composite = () => {
198198

199199
const value: InfographicOptions = {
200200
padding: 20,
201+
editable: true,
201202
design: {
202203
title: 'default',
203204
structure: structureObj,

dev/src/Preview.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ export const Preview = () => {
327327
options={{
328328
template,
329329
data: parsedData,
330-
padding: 20,
331330
theme,
332331
themeConfig,
333332
editable: true,

site/src/components/AIPlayground/Prompt.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const SYSTEM_PROMPT = `
3030
interface InfographicOptions {
3131
data: Data; // 数据
3232
template?: string; // 模板名称
33+
padding?: number; // 信息图内边距,默认 0
3334
theme?: string; // 主题名称,如果要深色模式,传入 'dark', 否则不传
3435
themeConfig?: {
3536
palette?: string[]; // 色板,支持 rgb/rgba/hex 颜色格式
@@ -83,10 +84,17 @@ interface ItemDatum {
8384
- hierarchy-tree-curved-line-rounded-rect-node
8485
- hierarchy-tree-tech-style-badge-card
8586
- chart-column-simple
87+
- chart-bar-plain-text
88+
- chart-line-plain-text
89+
- chart-pie-plain-text
90+
- chart-pie-compact-card
91+
- chart-pie-donut-plain-text
92+
- chart-pie-donut-pill-badge
8693
8794
## 注意事项
8895
- 必须严格按照 \`\`\`json 代码块的格式返回信息图配置
8996
- JSON 必须是有效的格式,可以被解析
9097
- 根据用户需求或者用户文本的语义,选择最合适的类型
9198
- 数据要完整、准确
99+
- 内边距 Padding 建议设置为 20
92100
`;

site/src/components/Gallery/datasets.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,25 @@ export const DATASET = {
151151
label: '2021年',
152152
value: 120,
153153
desc: '转型初期,稳步试水',
154+
icon: 'icon:lucide/sprout',
154155
},
155156
{
156157
label: '2022年',
157158
value: 150,
158159
desc: '平台优化,效率显著提升',
160+
icon: 'icon:lucide/zap',
159161
},
160162
{
161163
label: '2023年',
162164
value: 190,
163165
desc: '深化数智融合,全面增长',
166+
icon: 'icon:lucide/brain-circuit',
164167
},
165168
{
166169
label: '2024年',
167170
value: 240,
168171
desc: '拓展生态协同,冲击新高',
172+
icon: 'icon:lucide/trophy',
169173
},
170174
],
171175
},

0 commit comments

Comments
 (0)