-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathGraphGallery.zh.qmd
More file actions
1008 lines (872 loc) · 24.9 KB
/
Copy pathGraphGallery.zh.qmd
File metadata and controls
1008 lines (872 loc) · 24.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: Graph Gallery
---
👋 **Bizard** 是一个为生物医学研究量身定制的高级可视化代码综合存储库。目前包含约 750 张图表,涵盖超过 65 种图表类型。以下是所有图表的图库。
表格中的每一行对应一个图表。您可以点击图表进行放大预览。点击图表的蓝色标题,可以跳转到对应的图文教程页面。表格的搜索框提供了图表搜索功能。
```{r}
#| echo: false
#| message: false
#| warning: false
library(reactable)
library(jsonlite)
library(dplyr)
library(crosstalk)
library(htmltools)
data <- read.csv("files/gallery_data_zh.csv")
```
## 🎯 智能图表推荐
描述您的可视化目标,系统将推荐最适合的图表:
<div id="recommender-widget" class="recommender-container">
<textarea id="recommender-input" rows="3" placeholder="例如:我想比较不同实验组之间的基因表达差异..." style="width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; font-family: inherit;"></textarea>
<br>
<button id="recommender-btn" onclick="recommendChartsZh()" style="margin-top: 8px; padding: 8px 16px; background: #007899; color: white; border: none; border-radius: 4px; cursor: pointer;">推荐图表</button>
<div id="recommender-results" style="margin-top: 16px;"></div>
</div>
## 基础
### 分布图
```{r}
#| echo: false
data_Distribution <- data[data$Level2=="Distribution",]
tbl <- reactable(
data_Distribution,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
### 相关性图
```{r}
#| echo: false
data_Correlation <- data[data$Level2=="Correlation",]
tbl <- reactable(
data_Correlation,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
### 排序图
```{r}
#| echo: false
data_Ranking <- data[data$Level2=="Ranking",]
tbl <- reactable(
data_Ranking,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
### 整体与部分图
```{r}
#| echo: false
data_Ranking <- data[data$Level2=="Composition",]
tbl <- reactable(
data_Ranking,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
### 时间演化图
```{r}
#| echo: false
data_Ranking <- data[data$Level2=="Evolution",]
tbl <- reactable(
data_Ranking,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
### 流动图
```{r}
#| echo: false
data_Ranking <- data[data$Level2=="Proportion",]
tbl <- reactable(
data_Ranking,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
### 动画图
```{r}
#| echo: false
data_Ranking <- data[data$Level2=="Animation",]
tbl <- reactable(
data_Ranking,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
## 组学
```{r}
#| echo: false
data_OMICS <- data[data$Level1=="OMICS",]
tbl <- reactable(
data_OMICS,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
## 临床
```{r}
#| echo: false
data_OMICS <- data[data$Level1=="CLINICS",]
tbl <- reactable(
data_OMICS,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
## 𝐏𝐘𝐓𝐇𝐎𝐍
```{r}
#| echo: false
data_PYTHON <- data[data$Level1=="PYTHON",]
tbl <- reactable(
data_PYTHON,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
## 𝐉𝐔𝐋𝐈𝐀
```{r}
#| echo: false
data_JULIA <- data[data$Level1=="JULIA",]
tbl <- reactable(
data_JULIA,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
## 𝐇𝐈𝐏𝐋𝐎𝐓
### 基础
```{r}
#| echo: false
data_HIPLOT_BASICS <- data[data$Level1=="HIPLOT" & data$Level2=="BASICS",]
tbl <- reactable(
data_HIPLOT_BASICS,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
### 组学
```{r}
#| echo: false
data_HIPLOT_OMICS <- data[data$Level1=="HIPLOT" & data$Level2=="OMICS",]
tbl <- reactable(
data_HIPLOT_OMICS,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
### 临床
```{r}
#| echo: false
data_HIPLOT_CLINICS <- data[data$Level1=="HIPLOT" & data$Level2=="CLINICS",]
tbl <- reactable(
data_HIPLOT_CLINICS,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
### 地图
```{r}
#| echo: false
data_HIPLOT_MAP <- data[data$Level1=="HIPLOT" & data$Level2=="MAP",]
tbl <- reactable(
data_HIPLOT_MAP,
defaultColDef = colDef(vAlign = "center", headerClass = "header"),
columns = list(
Id = colDef(
name = "Id", align = "center", minWidth = 70, maxWidth = 90
),
Name = colDef(
name = "Graph", cell = JS("renderGraph"), html = TRUE, minWidth = 250
),
Image_url = colDef(show = FALSE),
Tutorial_url = colDef(show = FALSE),
Description =colDef(show = FALSE),
Type = colDef(name = "Type"),
Level1 =colDef(show = FALSE),
Level2 =colDef(show = FALSE)
),
searchable = TRUE,
defaultPageSize = 7
)
div(
class = "movies",
tbl,
div(id = "modal", class="modal", onclick="hideModal()",
img(
id="modal-image", class="modal-image"
))
)
```
```{js, echo=FALSE}
function renderGraph(cellInfo) {
const url = cellInfo.row['Tutorial_url']
const imageSrc = cellInfo.row['Image_url']
const altText = cellInfo.value
const description = cellInfo.row['Description']
const poster = `<img src="${imageSrc}" class="movie-poster" alt="${altText}" onclick="showModal(this)">`
const title = `<a href="${url}" target="_blank">${cellInfo.value}</a>`
const details = `<div class="movie-info-details">${description}</div>`
const text = `<div class="movie-info-text">${title}${details}</div>`
return `<div class="movie-info">${poster}${text}</div>`
}
function showModal(image) {
var modal = document.getElementById("modal");
var modalImage = document.getElementById("modal-image");
modal.style.display = "block";
modalImage.src = image.src;
}
function hideModal() {
var modal = document.getElementById("modal");
modal.style.display = "none";
}
// Smart Recommender Functions (Chinese + English bilingual support)
let keywordsDataZh = null;
let keywordsDataEn = null;
// XSS prevention: sanitize user-generated content
function sanitizeZh(str) {
if (!str) return '';
return String(str)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
async function loadKeywordsZh() {
if (!keywordsDataZh) {
try {
// Load both Chinese and English dictionaries for bilingual support
const responseZh = await fetch('../files/recommender_keywords_zh.json');
const responseEn = await fetch('../files/recommender_keywords.json');
if (!responseZh.ok || !responseEn.ok) throw new Error('加载关键词失败');
const dataZh = await responseZh.json();
const dataEn = await responseEn.json();
// Merge both dictionaries
keywordsDataZh = {
synonyms: { ...dataZh.synonyms, ...dataEn.synonyms },
intentKeywords: { ...dataZh.intentKeywords, ...dataEn.intentKeywords }
};
} catch (e) {
console.error('Error loading keywords:', e);
return null;
}
}
return keywordsDataZh;
}
function tokenizeZh(text) {
// Bilingual tokenization: handle both Chinese characters and English words
const englishTokens = text.toLowerCase().split(/[\s,.!?;:'"()\[\]]+/).filter(t => t.length > 0 && !/[\u4e00-\u9fa5]/.test(t));
// For Chinese, we use character-by-character scanning plus common phrases
const chineseTokens = text.match(/[\u4e00-\u9fa5]+/g) || [];
return [...englishTokens, ...chineseTokens];
}
function extractKeywordsZh(text, synonyms) {
// Instead of tokenizing, we scan the text for all known keywords
const found = new Set();
const textLower = text.toLowerCase();
// Check all synonym keys and their values
Object.keys(synonyms).forEach(key => {
// Check if key appears in text
if (text.includes(key) || textLower.includes(key.toLowerCase())) {
found.add(key);
synonyms[key].forEach(syn => found.add(syn));
}
// Check if any synonym value appears in text
synonyms[key].forEach(syn => {
if (text.includes(syn) || textLower.includes(syn.toLowerCase())) {
found.add(syn);
found.add(key);
synonyms[key].forEach(s => found.add(s));
}
});
});
// Also add English tokens for mixed input
const tokens = tokenizeZh(text);
tokens.forEach(t => found.add(t));
return Array.from(found);
}
function expandSynonymsZh(tokens, synonyms) {
// This function now receives pre-extracted keywords, just expand them
const expanded = new Set(tokens);
tokens.forEach(token => {
if (synonyms[token]) {
synonyms[token].forEach(syn => expanded.add(syn));
}
Object.keys(synonyms).forEach(key => {
if (synonyms[key].includes(token) || key === token) {
expanded.add(key);
synonyms[key].forEach(syn => expanded.add(syn));
}
});
});
return Array.from(expanded);
}
function matchIntentsZh(tokens, intentKeywords) {
const matched = [];
Object.keys(intentKeywords).forEach(intent => {
const keywords = intentKeywords[intent];
if (keywords.some(kw => tokens.includes(kw))) {
matched.push(intent);
}
});
return matched;
}
function calculateScoreZh(tokens, intents, text, chart) {
let score = 0;
// Base keyword match - check if any token appears in chart data
tokens.forEach(token => {
if (text.includes(token)) score += 1;
});
// Intent match bonus
intents.forEach(intent => {
score += 2;
});
// Type exact match bonus
if (tokens.some(t => chart.Type.includes(t))) score += 3;
return score;
}
async function recommendChartsZh() {
const input = document.getElementById('recommender-input').value.trim();
if (!input) {
document.getElementById('recommender-results').innerHTML = '<p style="color: #666;">请输入您的可视化目标描述。</p>';
return;
}
// Show loading indicator
const btn = document.getElementById('recommender-btn');
const originalText = btn.textContent;
btn.disabled = true;
btn.textContent = '搜索中...';
try {
// Load keywords
const keywords = await loadKeywordsZh();
if (!keywords) {
document.getElementById('recommender-results').innerHTML = '<p style="color: #cc0000;">加载关键词失败,请稍后重试。</p>';
return;
}
// Get chart data from Chinese CSV
const csvResponse = await fetch('../files/gallery_data_zh.csv');
if (!csvResponse.ok) throw new Error('加载图表数据失败');
const csvText = await csvResponse.text();
const chartData = parseCSV(csvText);
// Extract keywords from input using new scanning method
const extractedKeywords = extractKeywordsZh(input, keywords.synonyms);
const expandedTokens = expandSynonymsZh(extractedKeywords, keywords.synonyms);
const matchedIntents = matchIntentsZh(expandedTokens, keywords.intentKeywords);
// Score each chart
const results = chartData.map(chart => {
const searchableText = `${chart.Name} ${chart.Description} ${chart.Type} ${chart.Level1} ${chart.Level2}`;
const score = calculateScoreZh(expandedTokens, matchedIntents, searchableText, chart);
return { chart, score, matchedKeywords: expandedTokens.filter(t => searchableText.includes(t)) };
}).filter(r => r.score > 0)
.sort((a, b) => b.score - a.score)
.slice(0, 5);
// Display results
const resultsDiv = document.getElementById('recommender-results');
if (results.length === 0) {
resultsDiv.innerHTML = '<p style="color: #666;">未找到匹配的图表。请尝试其他关键词。</p>';
return;
}
resultsDiv.innerHTML = `<p style="font-weight: 600;">匹配结果 (${results.length}):</p>` +
results.map(r => `
<div class="recommender-card" style="display: flex; align-items: center; margin: 8px 0; padding: 12px; border: 1px solid #e0e0e0; border-radius: 4px; background: #fafafa;">
<img src="${sanitizeZh(r.chart.Image_url)}" style="width: 80px; height: 80px; object-fit: cover; border-radius: 4px; margin-right: 12px;" onclick="showModal(this)">
<div style="flex: 1;">
<a href="${sanitizeZh(r.chart.Tutorial_url)}" target="_blank" style="color: #007899; font-weight: 600; text-decoration: none;">${sanitizeZh(r.chart.Name)}</a>
<p style="margin: 4px 0 0 0; color: #666; font-size: 0.9em;">${sanitizeZh(r.chart.Description)}</p>
<p style="margin: 4px 0 0 0; color: #888; font-size: 0.8em;">匹配关键词: ${r.matchedKeywords.slice(0, 5).map(k => sanitizeZh(k)).join(', ')}</p>
</div>
</div>
`).join('');
} catch (e) {
console.error('Error in recommendChartsZh:', e);
document.getElementById('recommender-results').innerHTML = '<p style="color: #cc0000;">搜索时发生错误,请稍后重试。</p>';
} finally {
// Restore button state
btn.disabled = false;
btn.textContent = originalText;
}
}
function parseCSV(text) {
const lines = text.trim().split('\n');
const headers = lines[0].split(',');
return lines.slice(1).map(line => {
const values = line.split(',');
const obj = {};
headers.forEach((h, i) => obj[h] = values[i] || '');
return obj;
});
}
```
```{css, echo=FALSE}
/* Font from https://fontsarena.com/hanken-grotesk-by-hanken-design-co/ */
@font-face {
font-family: 'Hanken Grotesk';
font-style: normal;
font-weight: 400;
src: url("fonts/HKGrotesk-Regular.woff2") format("woff2"),
url("fonts/HKGrotesk-Regular.woff") format("woff");
}
@font-face {
font-family: 'Hanken Grotesk';
font-style: normal;
font-weight: 600;
src: url("fonts/HKGrotesk-SemiBold.woff2") format("woff2"),
url("fonts/HKGrotesk-SemiBold.woff") format("woff");
}
@font-face {
font-family: 'Hanken Grotesk';
font-style: normal;
font-weight: 700;
src: url("fonts/HKGrotesk-Bold.woff2") format("woff2"),
url("fonts/HKGrotesk-Bold.woff") format("woff");
}
.movies {
font-family: 'Hanken Grotesk', Helvetica, Arial, sans-serif;
}
.movies h2 {
font-weight: 600;
}
.movies a {
color: #007899;
text-decoration: none;
}
.movies a:hover,
.movies a:focus {
text-decoration: underline;
text-decoration-thickness: max(1px, 0.0625rem);
}
.movies-tbl {
margin-top: 1rem;
font-size: 1rem;
}
.header {
color: hsl(0, 0%, 45%);
font-weight: 700;
font-size: 0.8125rem;
letter-spacing: 0.4px;
text-transform: uppercase;
}
.header:hover[aria-sort],
.header[aria-sort='ascending'],
.header[aria-sort='descending'] {
color: hsl(0, 0%, 5%);
}
.movie-info {
display: flex;
align-items: center;
}
.movie-info-text {
margin-left: 0.75rem;
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
}
.movie-info-details {
margin-top: 0.125rem;
font-size: 0.875rem;
font-weight: 400;
color: hsl(0, 0%, 40%);
overflow: hidden;
text-overflow: ellipsis;
}
.movie-poster {
width: 100px;
height: 100px;
box-shadow: 0 0 0 1px hsl(0, 0%, 95%);
cursor: zoom-in;
}
.movie-runtime {
display: inline-block;
}
.movie-rating {
margin-right: 0.25rem;
padding: 0 0.25rem;
border: 1px solid hsl(0, 0%, 75%);
border-radius: 2px;
}
.user-score {
font-weight: 600;
}
.filters {
display: flex;
flex-wrap: wrap;
margin-top: 1rem;
margin-left: -32px;
}
.filter-input {
margin-top: 0.5rem;
margin-left: 32px;
flex: 1;
min-width: 250px;
}
.filter-input label {
color: hsl(0, 0%, 45%);
font-weight: 700;
font-size: 0.8125rem;
letter-spacing: 0.4px;
text-transform: uppercase;
}
.filter-input select,
.filter-input input[type="search"] {
padding: 0 0.375rem;
height: 2rem;
}
.filter-input input[type="search"] {
/* Revert Bootstrap 5's Reboot styles, which change native search input styling */
-webkit-appearance: searchfield;
outline-offset: revert;
border-color: revert;
}
.modal {
display: none;
position: fixed;
z-index: 9999;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8);
cursor: zoom-out;
}
.modal-image {
display: block;
max-width: 90%;
max-height: 90%;
margin: auto;
margin-top: 5%;
}
/* Smart Recommender Styles */
.recommender-container {
margin: 1.5rem 0;
padding: 1rem;
border: 1px solid #e0e0e0;
border-radius: 8px;
background: #f9f9f9;