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
|
{{- define "title" }}{{ T .Data.Plural }} - {{ .Site.Title }}{{ end -}}
{{- define "content" -}}
{{ $name := .Data.Plural -}}
{{ $terms := .Data.Terms.ByCount -}}
{{ $length := len $terms -}}
<script src="https://code.highcharts.com.cn/highcharts/8.1.2/highcharts.js"></script>
<script src="https://code.highcharts.com.cn/highcharts/8.1.2/modules/exporting.js"></script>
<script src="https://code.highcharts.com.cn/highcharts/8.1.2/modules/wordcloud.js"></script>
<script src="https://code.highcharts.com.cn/highcharts/8.1.2/modules/oldie.js"></script>
{{ if eq $name "categories" -}}
<div class="terms">
<div class="terms-title">
{{ if eq $length 0 -}}
{{ T "zeroCategoryCounter" }}
{{- else -}}
{{ T "categoryCounter" $length }}
{{- end }}
</div>
<div id=categories></div>
<script>
var terms = {{ $terms }};
length = terms.length
var str = "";
for (i = 0; i < length; i++) {
str += terms[i].Name + ","
}
var text = str;
var data = text.split(/[,\. ]+/g)
.reduce(function (arr, word) {
var obj = arr.find(function (obj) {
return obj.name === word;
});
if (obj) {
obj.weight += 1;
} else {
obj = {
name: word,
weight: 1
};
arr.push(obj);
}
return arr;
}, []);
Highcharts.chart('categories', {
//highcharts logo
credits: { enabled: false },
series: [{
type: 'wordcloud',
data: data,
rotation: 0,//字体不旋转
maxFontSize: 10,//最大字体
minFontSize: 1,//最小字体
style: {
fontFamily: "微软雅黑",
fontWeight: '500'
}
}],
title: {
text: ''
},
//点击事件方法
plotOptions: {
series: {
cursor: 'pointer',
events: {
click: function (e) {
// 单条数据
var path = e.point.options.name;
window.location.href = "/categories/" + path;
}
}
}
},
});
</script>
</div>
{{- else if eq $name "tags" -}}
<div class="terms">
<div class="terms-title">
{{ if eq $length 0 -}}
{{ T "zeroTagCounter" }}
{{- else -}}
{{ T "tagCounter" $length }}
{{- end }}
</div>
<div id=tags></div>
<script>
var terms = {{ $terms }};
length = terms.length
var str = "";
for (i = 0; i < length; i++) {
str += terms[i].Name + ","
}
var text = str;
var data = text.split(/[,\. ]+/g)
.reduce(function (arr, word) {
var obj = arr.find(function (obj) {
return obj.name === word;
});
if (obj) {
obj.weight += 1;
} else {
obj = {
name: word,
weight: 1
};
arr.push(obj);
}
return arr;
}, []);
Highcharts.chart('tags', {
//highcharts logo
credits: { enabled: false },
series: [{
type: 'wordcloud',
data: data,
rotation: 0,//字体不旋转
maxFontSize: 10,//最大字体
minFontSize: 1,//最小字体
style: {
fontFamily: "微软雅黑",
fontWeight: '500'
}
}],
title: {
text: ''
},
//点击事件方法
plotOptions: {
series: {
cursor: 'pointer',
events: {
click: function (e) {
// 单条数据
var path = e.point.options.name;
window.location.href = "/tags/" + path;
}
}
}
},
});
</script>
</div>
{{- end }}
{{- end }}
|