Skip to content

Commit 5c42f7c

Browse files
committed
feat: 添加3D文档聚类散点图功能
- 引入echarts-gl依赖以支持3D图表渲染 - 新增ClusterScatter数据结构定义 - 实现2D/3D视图切换功能 - 添加WebGL兼容性检测机制 - 重构聚类页面UI布局和交互逻辑 - 更新路由配置以支持.html扩展名访问
1 parent 7d00643 commit 5c42f7c

13 files changed

Lines changed: 798 additions & 139 deletions

File tree

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@element-plus/icons-vue": "2.3.2",
1818
"algoliasearch": "4.26.0",
1919
"echarts": "6.0.0",
20+
"echarts-gl": "^2.1.0",
2021
"element-plus": "2.13.2",
2122
"js-yaml": "4.1.1",
2223
"jsmind": "0.9.1",

src/api/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import UrlConst from '@/const/UrlConst'
1111
import CommitInfo from '@/dto/CommitInfo'
1212
import Category from '@/dto/Category'
1313
import ClusterNode from '@/dto/ClusterNode'
14+
import ClusterScatter from '@/dto/ClusterScatterPoint'
1415
import DocQuality from '@/dto/doc/DocQuality'
1516
import KnowledgeRichnessNode from '@/dto/KnowledgeRichnessNode'
1617
// import DocService from '@/service/DocService'
@@ -83,6 +84,11 @@ class Api implements Cacheable{
8384
return http(UrlUtils.concatUrl(baseUrl(), UrlConst.docClusterJson)).then(r => r.json())
8485
}
8586

87+
@cache
88+
public async getDocClusterScatter(): Promise<ClusterScatter> {
89+
return http(UrlUtils.concatUrl(baseUrl(), UrlConst.docClusterScatterJson)).then(r => r.json())
90+
}
91+
8692
@cache
8793
public async getKnowledgeRichness(): Promise<KnowledgeRichnessNode[]> {
8894
return http(UrlUtils.concatUrl(baseUrl(), UrlConst.knowledgeRichnessJson)).then(r => r.json())

src/build/DocService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Cacheable from "@/decorator/Cacheable";
1414
import ArrayUtils from "../util/ArrayUtils";
1515
import CommitInfo from "@/dto/CommitInfo";
1616
import ClusterNode from "@/dto/ClusterNode";
17+
import ClusterScatter from "@/dto/ClusterScatterPoint";
1718
import DocQuality from "../dto/doc/DocQuality";
1819
import Cache from "../decorator/Cache";
1920
import generateDocCluster from '../scripts/generateDocCluster'
@@ -191,6 +192,11 @@ class DocService extends BaseService implements Cacheable {
191192
return generateDocCluster.main(true)
192193
}
193194

195+
@cache
196+
public async getDocClusterScatter(): Promise<ClusterScatter> {
197+
return generateDocCluster.generateClusterScatter()
198+
}
199+
194200
public async getDocTagPrediction() {
195201
return (await generateDocCluster.generateDocTagPrediction())
196202
}

src/components/header/Header.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export default defineComponent({
102102
navList: [
103103
{ name: '首页', path: '/home.html', match: '/home' },
104104
{ name: '标签', path: '/tag.html', match: '/tag' },
105-
{ name: '聚类', path: '/cluster', match: '/cluster' },
105+
{ name: '聚类', path: '/cluster.html', match: '/cluster' },
106106
],
107107
};
108108
},

src/const/UrlConst.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default {
1212
tagMappingJson: '/tagMapping.json',
1313
wordcloudJson: '/wordcloud.json',
1414
docClusterJson: '/docCluster.json',
15+
docClusterScatterJson: '/docClusterScatter.json',
1516
docTagPrediction: '/docTagPrediction.json',
1617
docQualityJson: '/docQuality.json',
1718
textSimilarJson: '/textSimilar.json',

src/dto/ClusterScatterPoint.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// 散点聚类图的单个文档点
2+
export interface ClusterScatterPoint {
3+
id: string // docUrl2Id 后的文档 id, 供跳转
4+
name: string // 原始文件路径(前端 displayName 截取文件名)
5+
x: number // 2D MDS 投影坐标
6+
y: number
7+
x3: number // 3D MDS 投影坐标
8+
y3: number
9+
z3: number
10+
cluster: number // K-means 簇标签
11+
tags: string[] // frontmatter tags, 供 tooltip
12+
size: number // 点径编码(正文长度归一)
13+
}
14+
15+
// 簇元信息, 供图例
16+
export interface ClusterMeta {
17+
id: number
18+
label: string // 簇主 tag(自动命名), 无则 "簇 N"
19+
size: number // 成员数
20+
}
21+
22+
export interface ClusterScatter {
23+
points: ClusterScatterPoint[]
24+
clusters: ClusterMeta[]
25+
}
26+
27+
export default ClusterScatter

src/global.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@ declare module '@vue/runtime-core' {
33
interface ComponentCustomProperties {
44
$isMobile: () => boolean
55
}
6+
}
7+
8+
// echarts-gl 未随包提供类型声明, 这里给出最小模块声明(install 形态, 供 echarts.use)
9+
declare module 'echarts-gl/charts' {
10+
export const Scatter3DChart: any
11+
}
12+
declare module 'echarts-gl/components' {
13+
export const Grid3DComponent: any
614
}

0 commit comments

Comments
 (0)