fix word cloud

This commit is contained in:
邱博亞 2023-03-25 21:47:24 +08:00
parent d147a0225f
commit 79d6fb55a3
2 changed files with 1273 additions and 13 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +1,38 @@
<div class="w-video_data video_data-widget-2">
<%= javascript_include_tag 'video_pro/jqcloud.min' %>
<%= stylesheet_link_tag 'video_pro/jqcloud.min' %>
<div class="my_favorite_latin_words jqcloud" style="height: 100px;"></div>
<%= javascript_include_tag 'video_pro/wordcloud2.js' %>
<div style="width: 100%; height: 60vw" class="my_favorite_latin_words jqcloud"><div>
<script>
$(document).ready(function(){
$('[data-subpart-id="{{subpart-id}}"] .my_favorite_latin_words').jQCloud({{jqcloud_words}}, {
autoResize: true,
afterCloudRender: function(){
var is_chinese = (window.I18n && I18n.locale == "zh_tw" || I18n.locale == "zh_cn");
$(this).find('a').each(function(i,v){
var $v = $(v);
$v.attr('title', is_chinese ? ('另開新視窗前往' + $v.text()) : ('Open ' + $v.text() + ' in new tab'));
$v.attr('target', '_blank');
})
}
var container = $('[data-subpart-id="{{subpart-id}}"] .my_favorite_latin_words');
var width = container.width();
container.attr('width', width)
var jqcloud_words = {{jqcloud_words}};
var text_map = {};
var max_value = 1;
$.each(jqcloud_words, function(i, v){
if (max_value < v.weight){
max_value = v.weight;
}
});
var list = $.map(jqcloud_words, function(v){
text_map[v.text] = v.link;
return [[v.text, Math.ceil(v.weight/max_value*3), v.link]];
});
container.on('wordcloudstop', function (e) {
$(this).children('span').each(function (i, v) {
var text = $(this).html();
$(this).html('<a title="'+ list[i][0] + '" style="color: inherit" href="' + list[i][2] +'">' + text + '</a>');
});
});
WordCloud(container[0], {
list: list,
gridSize: 3,
weightFactor: jqcloud_words.length * width / 550,
rotateRatio: 0,
shuffle: false,
drawOutOfBound: false,
shrinkToFit: true,
shape: 'square'
});
})
</script>