From 6c31788402820ac5a544100cac70663254ac2900 Mon Sep 17 00:00:00 2001 From: Inga Kirschnick Date: Thu, 22 Jun 2023 16:38:06 +0200 Subject: [PATCH] Visualization fix for real data --- .../js/CorpusAnalysis/CorpusAnalysisApp.js | 58 +++++++++---------- .../js/ResourceLists/CorpusTextInfoList.js | 1 + 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js b/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js index 712f4a74..5248b0ba 100644 --- a/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js +++ b/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js @@ -34,26 +34,26 @@ class CorpusAnalysisApp { .then( cQiCorpus => { this.data.corpus = {o: cQiCorpus}; - // this.data.corpus.o.getVisualizationData() - // .then( - // (data) => { - // console.log(data); - // this.renderGeneralCorpusInfo(data); - // this.renderTextInfoList(data); - // this.renderTextProportionsGraphic(data); - // this.renderWordFrequenciesGraphic(data); - // this.renderBoundsGraphic(data); - // } - // ); - this.data.corpus.o.getCorpusData() - .then(corpusData => { - console.log(corpusData); - this.renderGeneralCorpusInfo(corpusData); - this.renderTextInfoList(corpusData); - this.renderTextProportionsGraphic(corpusData); - this.renderFrequenciesGraphic(corpusData); - this.renderBoundsGraphic(corpusData); - }); + this.data.corpus.o.getVisualizationData() + .then( + (data) => { + console.log(data); + this.renderGeneralCorpusInfo(data); + this.renderTextInfoList(data); + this.renderTextProportionsGraphic(data); + this.renderFrequenciesGraphic(data); + this.renderBoundsGraphic(data); + } + ); + // this.data.corpus.o.getCorpusData() + // .then(corpusData => { + // console.log(corpusData); + // this.renderGeneralCorpusInfo(corpusData); + // this.renderTextInfoList(corpusData); + // this.renderTextProportionsGraphic(corpusData); + // this.renderFrequenciesGraphic(corpusData); + // this.renderBoundsGraphic(corpusData); + // }); // TODO: Don't do this hgere cQiCorpus.updateDb(); this.enableActionElements(); @@ -132,10 +132,8 @@ class CorpusAnalysisApp { let textData = []; for (let i = 0; i < Object.entries(texts).length; i++) { let resource = { - // title: "corpusData.values.text[i].title", - // publishing_year: "corpusData.lookups.text[i].publishing_year", - title: `Text ${i}`, - publishing_year: "2023", + title: corpusData.values.s_attrs.text[i].title, + publishing_year: corpusData.values.s_attrs.text[i].publishing_year, num_tokens: corpusData.s_attrs.text.lexicon[i].counts.token, num_sentences: corpusData.s_attrs.text.lexicon[i].counts.s, num_unique_words: Object.entries(corpusData.s_attrs.text.lexicon[i].freqs.word).length, @@ -159,8 +157,7 @@ class CorpusAnalysisApp { let graphData = [ { values: texts.map(text => text[1].counts.token), - // labels: texts.map(text => `${corpusData.lookups.text[text[0]].title} (${corpusData.lookups.text[text[0]].publishing_year})`), - labels: texts.map(text => text[0]), + labels: texts.map(text => `${corpusData.values.s_attrs.text[text[0]].title} (${corpusData.values.s_attrs.text[text[0]].publishing_year})`), type: 'pie' } ]; @@ -199,8 +196,7 @@ class CorpusAnalysisApp { for (let item of sortedData) { let data = { - // x: texts.map(text => `${corpusData.lookups.text[text[0]].title} (${corpusData.lookups.text[text[0]].publishing_year})`), - x: texts.map(text => text[0]), + x: texts.map(text => `${corpusData.values.s_attrs.text[text[0]].title} (${corpusData.values.s_attrs.text[text[0]].publishing_year})`), y: texts.map(text => text[1].freqs[category][item[0]]), name: corpusData.values.p_attrs[category][item[0]], type: 'bar' @@ -220,11 +216,9 @@ class CorpusAnalysisApp { graphData = [{ type: 'bar', x: texts.map(text => text[1].bounds[1] - text[1].bounds[0]), - // y: texts.map(text => corpusData.lookups.text[text[0]].title), - y: texts.map(text => text[0]), + y: texts.map(text => corpusData.values.s_attrs.text[text[0]].title), base: texts.map(text => text[1].bounds[0]), - // text: texts.map(text => `${corpusData.lookups.text[text[0]].title} (${corpusData.lookups.text[text[0]].publishing_year})`), - text: texts.map(text => text[0]), + text: texts.map(text => `${corpusData.values.s_attrs.text[text[0]].title} (${corpusData.values.s_attrs.text[text[0]].publishing_year})`), orientation: 'h', hovertemplate: '%{base} - %{x}
%{y}', showlegend: false diff --git a/app/static/js/ResourceLists/CorpusTextInfoList.js b/app/static/js/ResourceLists/CorpusTextInfoList.js index 7cab68eb..8338c70a 100644 --- a/app/static/js/ResourceLists/CorpusTextInfoList.js +++ b/app/static/js/ResourceLists/CorpusTextInfoList.js @@ -103,6 +103,7 @@ class CorpusTextInfoList extends ResourceList { if (sortElement !== clickedSortElement) { sortElement.classList.remove('asc', 'desc'); sortElement.style.color = 'black'; + sortElement.innerHTML = 'arrow_drop_down'; }; }); clickedSortElement.style.color = '#aa9cc9';