Skip to content

Commit 8db7db5

Browse files
Witxzyxuzhiyong03
andauthored
feature: 新增瀑布流、打招呼、挂载卡片列表组件,marklang支持懒加载数学公式、代码高亮插件,调整部分组件样式及已知bug (#3)
* feature: 新增瀑布流组件、招呼、挂载卡片列表组件,调整部分组件样式 * feature: marklang支持懒加载数学公式、代码高亮插件 --------- Co-authored-by: xuzhiyong03 <xuzhiyong03@baidu.com>
1 parent ca04218 commit 8db7db5

151 files changed

Lines changed: 11738 additions & 636 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/cosmic-dqa/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cosui/cosmic-dqa",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "",
55
"main": "./dist/mobile/index.js",
66
"exports": {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AgentCard
22

3-
- Agent卡片:用于展示AI助手的基本信息,包括头像、名称和描述信息
3+
- Agent卡片:用于展示agent的基本信息,包括头像、名称和描述信息
44
- 覆盖平台:PC/Mobile
55

6-
## 代码演示
6+
## 代码演示

packages/cosmic-dqa/src/chart/base-chart.ts

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {ECharts, EChartsOption, TooltipComponentOption} from 'echarts';
1919
import Loading from '@cosui/cosmic/loading';
2020
import {isAndroid} from '@cosui/cosmic/util';
2121
import {colors, customColors} from './constant';
22-
import {ChartProps, ChartData, Theme} from './interface';
22+
import {ChartProps, ChartData, Theme, Type, RegisterMapParams} from './interface';
2323
import {deepMerge} from './utils';
2424

2525
/**
@@ -41,6 +41,8 @@ export default class BaseChart extends Component<ChartProps & ChartData> {
4141
'cos-loading': Loading
4242
};
4343

44+
// 是否已设置事件监听,在图表渲染完后设置
45+
hasEventListener: boolean = false;
4446
// ECharts实例
4547
chartInstance: ECharts | null;
4648
// 根元素样式表
@@ -51,34 +53,45 @@ export default class BaseChart extends Component<ChartProps & ChartData> {
5153
initData() {
5254
return {
5355
option: {},
54-
_loading: true
56+
_loading: true,
57+
async: false
5558
};
5659
}
5760

5861
inited() {
5962
this.chartInstance = null;
6063
this.styleDeclaration = null;
6164
this.themeObserverCleanup = null;
65+
// 地图需要异步请求地图配置
66+
if (this.data.get('type') === Type.MAP) {
67+
this.data.set('async', true);
68+
}
6269
}
6370

6471
attached() {
6572
this.styleDeclaration = getComputedStyle(this.el!);
73+
// 异步无需自动更新配置,需要在外部手动调用 updateChart 方法更新配置
74+
if (!this.data.get('async')) {
75+
this.updateChart();
76+
}
77+
}
78+
registerMap(...args: RegisterMapParams): void {
6679
const chartContainer = this.ref('chartContainer') as unknown as HTMLDivElement;
67-
6880
import('echarts').then(echarts => {
69-
const mainChart = echarts.init(chartContainer);
70-
71-
this.initChart(mainChart);
81+
echarts.registerMap(...args);
82+
const chartInstance = echarts.init(chartContainer);
83+
this.chartInstance = chartInstance;
84+
this.addChartListener();
85+
this.updateChartOption();
7286
}).catch(error => {
7387
throw new Error(`ECharts initialization failed: ${error.message}`);
7488
}).finally(() => {
7589
this.data.set('_loading', false);
7690
});
7791
}
78-
7992
updated() {
80-
if (this.chartInstance && this.data.get('option')) {
81-
this.updateChart();
93+
if (this.chartInstance && this.data.get('option') && !this.data.get('async')) {
94+
this.updateChartOption();
8295
}
8396
}
8497

@@ -87,31 +100,44 @@ export default class BaseChart extends Component<ChartProps & ChartData> {
87100
this.themeObserverCleanup?.();
88101
window.removeEventListener('resize', this.handleResize);
89102
}
90-
91-
// 初始化图表
92-
initChart(chartInstance: ECharts) {
93-
this.chartInstance = chartInstance;
94-
this.handleResize = this.handleResize.bind(this);
95-
96-
// 监听窗口大小变化
97-
window.addEventListener('resize', this.handleResize);
98-
// 监听图表渲染完成事件
99-
this.chartInstance.on('finished', this.handleChartRendered.bind(this));
100-
// 监听主题模式变化
101-
this.themeObserverCleanup = this.onColorSchemeChange(() => {
102-
this.chartInstance?.setOption(this.getDarkModeStyle());
103+
addChartListener() {
104+
if (!this.chartInstance) {
105+
return;
106+
}
107+
if (!this.hasEventListener) {
108+
this.handleResize = this.handleResize.bind(this);
109+
// 监听窗口大小变化
110+
window.addEventListener('resize', this.handleResize);
111+
// 监听图表渲染完成事件
112+
this.chartInstance?.on('finished', this.handleChartRendered.bind(this));
113+
// 监听主题模式变化
114+
this.themeObserverCleanup = this.onColorSchemeChange(() => {
115+
this.chartInstance?.setOption(this.getDarkModeStyle());
116+
});
117+
this.hasEventListener = true;
118+
}
119+
}
120+
// 更新图表
121+
updateChart() {
122+
const chartContainer = this.ref('chartContainer') as unknown as HTMLDivElement;
123+
import('echarts').then(echarts => {
124+
const chartInstance = echarts.init(chartContainer);
125+
this.chartInstance = chartInstance;
126+
this.addChartListener();
127+
this.updateChartOption();
128+
}).catch(error => {
129+
throw new Error(`ECharts initialization failed: ${error.message}`);
130+
}).finally(() => {
131+
this.data.set('_loading', false);
103132
});
104-
this.updateChart();
105133
}
106134

107135
// 更新图表
108-
updateChart() {
136+
updateChartOption() {
109137
if (!this.chartInstance) {
110138
return;
111139
}
112-
113140
const option = this.mergeOption();
114-
115141
this.chartInstance.setOption(option, true);
116142
}
117143

packages/cosmic-dqa/src/chart/constant.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import {Type} from './interface';
2222
export const componentNameMap = {
2323
[Type.LINE]: 'cosd-line-chart',
2424
[Type.BAR]: 'cosd-bar-chart',
25-
[Type.PIE]: 'cosd-pie-chart'
25+
[Type.PIE]: 'cosd-pie-chart',
26+
[Type.MAP]: 'cosd-map-chart',
27+
[Type.RADAR]: 'cosd-radar-chart'
2628
};
2729

2830
/**

packages/cosmic-dqa/src/chart/doc/api.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
### Props
44
|名称|类型|初始值|是否必选|说明|覆盖平台|
55
|---|---|---|---|---|---|
6-
| type | 'line' \| 'pie' \| 'bar' | 'bar' || 图表类型,可选值:<br>• 'line':折线图<br>• 'pie':饼图<br>• 'bar':柱状图 | PC/Mobile |
6+
| type | 'line' \| 'pie' \| 'bar' \| 'map' \| 'radar' | 'bar' || 图表类型,可选值:<br>• 'line':折线图<br>• 'pie':饼图<br>• 'bar':柱状图<br>• 'map':地图<br>• 'radar':雷达图 | PC/Mobile |
77
| option | EChartsOption | {} || 图表的初始配置,配置参数同 [ECharts配置项](https://echarts.apache.org/zh/option.html#title) <br />**注意事项:** <br /> (1)不支持(除 tooltip.formatter,非 ssr 场景使用)函数类型的配置项,比如各种 formatter <br />(2)不支持跳转 <br />(3)不支持 使用 concat($prevData.key, key) 的追加式方式更新 option 数据 <br/> (4)不支持 series 里有不同类型的 type(比如 line bar 混合)| PC/Mobile |
8+
| async | Boolean | false || 与默认同步渲染互斥,开启后默认渲染会loading(此时不会触发图表rendered),须搭配updateChart(地图须改为调用registerMap)异步完成渲染(此时才会触发图表rendered) | PC/Mobile |
89

910
### Events
1011
|事件|参数|说明|覆盖平台|
1112
|---|---|---|---|
1213
|render-finished|/|图表渲染完成事件|PC/Mobile|
1314

1415
### Methods
15-
|方法名|类型|说明|
16-
|---|---|---|
17-
|getEchartsInstance|() => [ECharts](https://echarts.apache.org/zh/api.html#echartsInstance)|获取 echarts 实例,可调用 echarts 方法自定义事件|
16+
|方法名|参数|返回值|说明|
17+
|---|---|---|---|
18+
|getEchartsInstance| - |() => [ECharts](https://echarts.apache.org/zh/api.html#echartsInstance)|获取 echarts 实例,可调用 echarts 方法自定义事件|
19+
|updateChart| - | - | 异步更新图表(须同时设置async为true)|
20+
|registerMap|[Parameters<typeof echarts.registerMap>](https://echarts.apache.org/zh/api.html#echarts.registerMap) | - | 地图需要异步更新地图数据(须同时设置async为true)并完成渲染(不需要再调用updateChart,内部会自行更新) |

packages/cosmic-dqa/src/chart/doc/line-chart.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default class LineChartDemo extends Component {
77
<div style="height: 300px">
88
<cosd-chart
99
type="line"
10+
async
1011
s-ref="lineChart"
1112
option="{{lineOption}}"
1213
on-chart-rendered="handleChartRendered"
@@ -17,7 +18,12 @@ export default class LineChartDemo extends Component {
1718
static components = {
1819
'cosd-chart': Chart
1920
};
20-
21+
attached() {
22+
setTimeout(() => {
23+
const chartRef = this.ref('lineChart');
24+
chartRef.updateChart();
25+
}, 3000)
26+
}
2127
initData() {
2228
return {
2329
lineOption: {
@@ -43,10 +49,12 @@ export default class LineChartDemo extends Component {
4349
}
4450
4551
handleChartRendered() {
46-
console.log('Line Chart rendered');
4752
const chartRef = this.ref('lineChart');
4853
const echartInstance = chartRef?.getEchartsInstance();
49-
console.log(echartInstance);
54+
echartInstance.dispatchAction({
55+
type: 'highlight',
56+
dataIndex: 3
57+
});
5058
echartInstance.on('legendselectchanged', (params) => {
5159
console.log(params);
5260
});

0 commit comments

Comments
 (0)