This commit is contained in:
邱博亞 2023-03-27 21:46:18 +08:00
parent 35395ea52d
commit b0b7e3f302
1 changed files with 17 additions and 19 deletions

View File

@ -1,10 +1,8 @@
<div class="w-video_data video_data-widget-2"> <div class="w-video_data video_data-widget-2">
<%= javascript_include_tag 'video_pro/wordcloud2.js' %> <%= javascript_include_tag 'video_pro/wordcloud2.js' %>
<div style="width: 100%; height: 40vw; max-height: 20em;" class="my_favorite_latin_words jqcloud wordcloud2"><div> <div style="width: 100%; height: 40vw; max-height: 17em;" class="my_favorite_latin_words jqcloud wordcloud2"><div>
<script> <script>
var container_{{subpart-id}} = $('[data-subpart-id="{{subpart-id}}"] .my_favorite_latin_words'); var container_{{subpart-id}} = $('[data-subpart-id="{{subpart-id}}"] .my_favorite_latin_words');
var width_{{subpart-id}} = container_{{subpart-id}}.width();
container_{{subpart-id}}.attr('width', width_{{subpart-id}})
var jqcloud_words_{{subpart-id}} = {{jqcloud_words}}; var jqcloud_words_{{subpart-id}} = {{jqcloud_words}};
var text_map_{{subpart-id}} = {}; var text_map_{{subpart-id}} = {};
var max_value_{{subpart-id}} = 1; var max_value_{{subpart-id}} = 1;
@ -15,6 +13,8 @@
}); });
var list_{{subpart-id}} = $.map(jqcloud_words_{{subpart-id}}, function(v){ var list_{{subpart-id}} = $.map(jqcloud_words_{{subpart-id}}, function(v){
text_map_{{subpart-id}}[v.text] = v.link; text_map_{{subpart-id}}[v.text] = v.link;
return [[v.text, Math.ceil(v.weight/max_value_{{subpart-id}}*3), v.link]]; return [[v.text, Math.ceil(v.weight/max_value_{{subpart-id}}*3), v.link]];
}); });
container_{{subpart-id}}.on('wordcloudstop', function (e) { container_{{subpart-id}}.on('wordcloudstop', function (e) {
@ -23,30 +23,28 @@
$(this).html('<a title="'+ list_{{subpart-id}}[i][0] + '" style="color: inherit" href="' + list_{{subpart-id}}[i][2] +'">' + text + '</a>'); $(this).html('<a title="'+ list_{{subpart-id}}[i][0] + '" style="color: inherit" href="' + list_{{subpart-id}}[i][2] +'">' + text + '</a>');
}); });
}); });
$(document).ready(function(){ function wordCloud_{{subpart-id}}(){
var width = container_{{subpart-id}}.width();
var height = container_{{subpart-id}}.height();
container_{{subpart-id}}.attr('width', width);
WordCloud(container_{{subpart-id}}[0], { WordCloud(container_{{subpart-id}}[0], {
list: list_{{subpart-id}}, list: list_{{subpart-id}},
gridSize: 3, gridSize: 3,
weightFactor: jqcloud_words_{{subpart-id}}.length * width_{{subpart-id}} / 550, weightFactor: jqcloud_words_{{subpart-id}}.length * Math.min(width, 1200) / 770,
rotateRatio: 0, rotateRatio: 0,
shuffle: false, shuffle: false,
drawOutOfBound: false, drawOutOfBound: false,
shrinkToFit: true, shrinkToFit: true,
shape: 'square' shape: 'square',
color: 'random-dark',
ellipticity: height/(width-40)
}); });
}) }
$(window).resize(function(){ $(window).resize(function(){
width_{{subpart-id}} = container_{{subpart-id}}.width(); wordCloud_{{subpart-id}}();
WordCloud(container_{{subpart-id}}[0], {
list: list_{{subpart-id}},
gridSize: 3,
weightFactor: jqcloud_words_{{subpart-id}}.length * width_{{subpart-id}} / 550,
rotateRatio: 0,
shuffle: false,
drawOutOfBound: false,
shrinkToFit: true,
shape: 'square'
});
}) })
$(document).ready(function(){
wordCloud_{{subpart-id}}();
});
</script> </script>
</div> </div>