diff --git a/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js b/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js index 42ecc7be..66163063 100644 --- a/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js +++ b/app/static/js/CorpusAnalysis/CorpusAnalysisApp.js @@ -42,16 +42,17 @@ class CorpusAnalysisApp { this.renderTextInfoList(data); this.renderTextProportionsGraphic(data); this.renderWordFrequenciesGraphic(data); + this.renderBoundsGraphic(data); } ); - this.data.corpus.o.getCorpusData() - .then(corpusData => { - // this.renderGeneralCorpusInfo(corpusData); - // this.renderTextInfoList(corpusData); - // this.renderTextProportionsGraphic(corpusData); - // this.renderWordFrequenciesGraphic(corpusData); - this.renderWordDistributionsGraphic(corpusData); - }); + // this.data.corpus.o.getCorpusData() + // .then(corpusData => { + // // this.renderGeneralCorpusInfo(corpusData); + // // this.renderTextInfoList(corpusData); + // // this.renderTextProportionsGraphic(corpusData); + // // this.renderWordFrequenciesGraphic(corpusData); + // // this.renderWordDistributionsGraphic(corpusData); + // }); // TODO: Don't do this hgere cQiCorpus.updateDb(); this.enableActionElements(); @@ -142,6 +143,7 @@ class CorpusAnalysisApp { textData.push(resource); } + corpusTextInfoList.add(textData); let textCountChipElement = document.querySelector('.text-count-chip'); @@ -160,7 +162,7 @@ class CorpusAnalysisApp { ]; let graphLayout = { height: 600, - width: 600 + width: 900 }; Plotly.newPlot(textProportionsGraphicElement, graphData, graphLayout); } @@ -169,8 +171,10 @@ class CorpusAnalysisApp { let wordFrequenciesGraphicElement = document.querySelector('#word-frequencies-graphic'); let words = Object.entries(corpusData.corpus.lexicon[0].freqs.word).sort((a, b) => b[1] - a[1]).slice(0, 5); let texts = Object.entries(corpusData.text.lexicon); + let graphData = []; for (let word of words) { + console.log(texts.map(text => text[1].freqs.word[word[0]])); let data = { x: texts.map(text => `${corpusData.lookups.text[text[0]].title} (${corpusData.lookups.text[text[0]].publishing_year})`), y: texts.map(text => text[1].freqs.word[word[0]]), @@ -182,30 +186,46 @@ class CorpusAnalysisApp { let graphLayout = { height: 600, - width: 600, + width: 900, barmode: 'stack', type: 'bar' }; Plotly.newPlot(wordFrequenciesGraphicElement, graphData, graphLayout); } - renderWordDistributionsGraphic(corpusData) { - // let wordDistributionGraphicElement = document.querySelector('#word-distributions-graphic'); - // var trace1 = { - // x: [1, 2, 3, 4], - // y: [10, 11, 12, 13], - // mode: 'markers', - // marker: { - // size: [40, 60, 80, 100] - // } - // }; - // var data = [trace1]; - // var layout = { - // title: 'Marker Size', - // showlegend: false, - // height: 500, - // width: 600 - // }; - // Plotly.newPlot(wordDistributionGraphicElement, data, layout); + renderBoundsGraphic(corpusData) { + let boundsGraphicElement = document.querySelector('#bounds-graphic'); + + let graphData = []; + let texts = Object.entries(corpusData.text.lexicon); + + 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), + 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})`), + orientation: 'h', + hovertemplate: '%{base} - %{x}
%{y}', + showlegend: false + }]; + + let graphLayout = { + height: 600, + width: 2000, + barmode: 'stack', + type: 'bar', + showgrid: false, + xaxis: { + rangemode: 'nonnegative', + autorange: true + }, + yaxis: { + autorange: true, + showticklabels: false + } + }; + + Plotly.newPlot(boundsGraphicElement, graphData, graphLayout); } } diff --git a/app/templates/_scripts.html.j2 b/app/templates/_scripts.html.j2 index 89cc1ca2..78ebd9f7 100644 --- a/app/templates/_scripts.html.j2 +++ b/app/templates/_scripts.html.j2 @@ -1,7 +1,7 @@ - + {%- assets filters='rjsmin', diff --git a/app/templates/corpora/analysis.html.j2 b/app/templates/corpora/analysis.html.j2 index 7aac79bd..80bd65a6 100644 --- a/app/templates/corpora/analysis.html.j2 +++ b/app/templates/corpora/analysis.html.j2 @@ -98,27 +98,31 @@
-
+
- Text proportions within the corpus + Proportions +

of texts within the corpus

-
+
Word frequencies +

within the texts of the 5 most frequent words in the corpus

-
+
+
+
- Word distributions -
+ Text Bounds +