init() var tsvPath = '' var titlePath = '' var defaultStartDate var defaultEndDate var totalPosts var startDate var endDate var wordTitleList var randId var globKeyword = '' var stopwords = [] var tsvString function init() { $.ajax({ type: 'POST', url: '/init', dataType: 'json', success: function (data) { console.log(data) setDate(data.Result.startDate, data.Result.endDate) document.getElementById('keywordBox').value = data.Result.keyword titlePath = data.Result.titlePath tsvString = data.Result.info.tsv defaultStartDate = data.Result.startDate defaultEndDate = data.Result.endDate json = JSON.parse(data.Result.info.json) console.log(json) wordTitleList = json keywordCountString = '' stopwords = data.Result.info.stopWords if (json.info.keyword != '') { keywordCountString = ' 關鍵字出現次數:' + json.info.count } $('#graphInfo').empty() $('#graphInfo').attr('style', 'margin: 10px;').append('總文章數:' + json.info.posts + ',' + keywordCountString) totalPosts = json.info.posts buildSentetree() } }) $(document).ready(function () { $(window).keydown(function (event) { if (event.keyCode == 13) { event.preventDefault() sendRequest() } }); }); $(window).on('mousemove', function (e) { $('#nodeTitle').css({ left: e.pageX, top: e.pageY }) }) $('#titleListContainer').hover( function () { // Run on hover/mouseenter $(this).css('overflow', 'auto') }, function () { // Run on mouseleave $(this).css('overflow', 'hidden') } ) $('#titleListLayer').click(function (e) { if ($('#titleListLayer').is(e.target)) { hideTitles() } }) $('#stopWordEditorLayer').click(function (e) { if ($('#stopWordEditorLayer').is(e.target)) { hideStopWordEditor() } }) $('#idfEditorLayer').click(function (e) { if ($('#idfEditorLayer').is(e.target)) { hideIdfEditor() } }) $('#pttPageWindow').click(function (e) { if ($('#pttPageWindow').is(e.target)) { hidePTTPage() } }) changeMode(0) destroyCurrentGraph() buildSentetree() } function loadTemplate(num) { templates = [{ startDate: '2020-12-01', endDate: '2020-12-31', keyword: '', mode: 1 }, { startDate: '2020-01-01', endDate: '2020-03-01', keyword: '衛生紙', mode: 2 }, { startDate: '2020-01-11', endDate: '2020-01-12', keyword: '', mode: 2 } ] chosenTemp = templates[num] setDate(chosenTemp.startDate, chosenTemp.endDate) $('#keywordBox').val(chosenTemp.keyword) changeMode(chosenTemp.mode) sendRequest() } function clearStopWord() { stopwords = [] $('#sweContainer').html('') } function addStopWord() { newswRaw = $('#newStopWord').val() newswList = newswRaw.split(' ') for (newsw of newswList) { if (newsw != '') { if (stopwords.includes(newsw)) { } else { stopwords.push(newsw) $('#sweContainer').append($('
  • ').attr('class', 'w3-display-container').append($('').append(newsw)).append($('').attr('class', 'w3-button w3-hover-red w3-transparent w3-display-right').click(function (e) { var index = $(this).parent().index() console.log(stopwords[index]) stopwords.splice(index, 1) console.log(stopwords) $('#sweContainer li').eq(index).remove() }).append("×"))) console.log(document.getElementById('sweContainer').children[stopwords.indexOf(newsw)]) } document.getElementById("sweContainer").scrollTop = document.getElementById('sweContainer').children[stopwords.indexOf(newsw)].offsetTop } } $('#newStopWord').val('') } function changeMode(_mode) { for (i = 0; i < 4; i++) { if (i == _mode) { $('#modeSelector button').eq(i).css("color", "#aaa") } else { $('#modeSelector button').eq(i).css("color", "#000") } } mode = _mode } function scrollIdfList() { let targetWord = $('#idfTarget').val() let wordList = $("#ieContainer").find("tr").slice(1).map((_, a) => { return $($(a).find("td")[0]).html() }).get() console.log({ "targetWord": targetWord, 'list': wordList }) if (targetWord != '') { if (wordList.indexOf(targetWord) >= 0) { } else { wordList.push(targetWord) $('#ieContainer').find('tbody').append($('').attr('class', 'w3-display-container').append($('').attr('style', 'vertical-align: middle;').append(targetWord)).append($('').attr('class', 'w3-right-align').attr('style', 'vertical-align: middle;').append($('').attr('type', 'number').val(Object.keys(idfTable).indexOf(targetWord) < 0 ? 0 : idfTable[targetWord])))) } console.log($($('#ieContainer').children('tbody').find('tr')[[wordList.indexOf(targetWord)]]).position()) $("#ieTableContainer").scrollTop($($('#ieContainer').children('tbody').find('tr')[[wordList.indexOf(targetWord)]]).position().top - 50) } $('#newStopWord').val('') } function showStopwordEditor() { $(window).unbind('keydown') $(window).keydown(function (event) { if (event.keyCode == 13) { addStopWord() } }) $('#sweContainer').empty() for (word of stopwords) { $('#sweContainer').append($('
  • ').append($('').append(word)).append($('').attr('class', 'w3-button w3-hover-red w3-transparent w3-display-right').click(function (e) { var index = $(this).parent().index() console.log(stopwords[index]) stopwords.splice(index, 1) console.log(stopwords) $('#sweContainer li').eq(index).remove() }).append("×"))) } $('#stopWordEditorLayer').removeClass('hidden') } function showIdfEditor() { $(window).unbind('keydown') $(window).keydown(function (event) { if (event.keyCode == 13) { scrollIdfList() } }) $('#ieContainer').empty().append( $('').append($('') .append($('') .attr('style', 'position: sticky; top: 0; background: white;') .append('單詞')) .append($('') .attr('class', 'w3-center-align') .attr('style', 'position: sticky; top: 0; background: white;') .append('操作')) .append($('') .attr('class', 'w3-right-align') .attr('style', 'position: sticky; top: 0; background: white;') .append('單詞頻率') ) ) ) .append($('')) for (word of Object.entries(idfTable).sort((a, b) => { return (b[1] - a[1]) }).map((a) => { return a[0] }).slice(0, 1000)) { $('#ieContainer').find('tbody') .append($('') .attr('class', 'w3-display-container') .append($('') .attr('style', 'vertical-align: middle;') .append(word)) .append($('') .attr('class', 'w3-right-align') .append($('