Skip to content

Commit 6a8549c

Browse files
committed
Trends switch
1 parent 38ca321 commit 6a8549c

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

app/scripts/components/wordpicture/results-word-picture.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ type ResultsWordPictureScope = IScope & {
2828
sort: RelationsSort
2929
/** Model for the sort input. */
3030
sortLocal: RelationsSort
31+
/** Whether data should be split by timespans */
32+
split: boolean
33+
/** Model for the split-by-time input. */
34+
splitLocal: boolean
3135
warning?: string
3236
}
3337

@@ -40,6 +44,10 @@ angular.module("korpApp").component("resultsWordPicture", {
4044
4145
<div ng-show="!error && data">
4246
<div class="flex flex-wrap items-baseline mb-4 gap-4 bg-gray-100 p-2">
47+
<label>
48+
<input ng-model="splitLocal" type="checkbox" />
49+
{{'word_pic_split' | loc:$root.lang}}
50+
</label>
4351
<label>
4452
<input ng-model="showWordClass" type="checkbox" />
4553
{{'show_wordclass' | loc:$root.lang}}
@@ -108,11 +116,13 @@ angular.module("korpApp").component("resultsWordPicture", {
108116
$scope.limitOptions = LIMITS.slice(0, endIndex + 1)
109117
// Clamp previously selected value
110118
if (Number($scope.limit) > LIMITS[endIndex]) $scope.limit = String(LIMITS[endIndex])
111-
// Apply sort
119+
// Apply inputs
112120
$scope.sort = $scope.sortLocal
121+
$scope.split = $scope.splitLocal
113122
})
114123

115124
$scope.$watch("sortLocal", () => $scope.sortLocal && makeRequest())
125+
$scope.$watch("splitLocal", () => $scope.splitLocal != undefined && makeRequest())
116126

117127
store.watch("globalFilter", () => {
118128
if (store.globalFilter) $scope.warning = loc("word_pic_global_filter", store.lang)
@@ -166,7 +176,7 @@ angular.module("korpApp").component("resultsWordPicture", {
166176
$scope.warning = undefined
167177
$scope.proxy
168178
.setProgressHandler((progressObj) => $timeout(() => $ctrl.setProgress(true, progressObj.percent)))
169-
.makeRequest(query.type, query.word, $scope.sortLocal)
179+
.makeRequest(query.type, query.word, $scope.sortLocal, $scope.splitLocal)
170180
.then((data) => $timeout(() => ($scope.data = data)))
171181
.catch((error) => {
172182
// AbortError is expected if a new search is made before the previous one is finished

app/scripts/components/wordpicture/word-picture-column.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ angular.module("korpApp").component("wordPictureColumn", {
6565
const $ctrl = this as WordPictureColumnController
6666

6767
$ctrl.$onChanges = (changes) => {
68-
if (changes.limit?.currentValue) {
69-
$ctrl.rows = $ctrl.items.slice(0, Number($ctrl.limit))
68+
if (changes.limit?.currentValue || changes.items?.currentValue) {
69+
$ctrl.rows = $ctrl.items.filter((item) => item.stats[$ctrl.segment]).slice(0, Number($ctrl.limit))
7070
}
7171
}
7272

app/scripts/components/wordpicture/word-picture.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ angular.module("korpApp").component("wordPicture", {
4747
css-class="column.config.css_class"
4848
items="column.rows"
4949
limit="$ctrl.limit"
50-
segment="'all'"
50+
segment="$ctrl.data.segments[0]"
5151
show-word-class="$ctrl.showWordClass"
5252
sort="$ctrl.sort"
5353
></word-picture-column>

app/scripts/word-picture.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export class WordPicture {
5353
readonly config = getWordPictureConfig()
5454
readonly items: Record<string, MatchedRelation[]> = {}
5555
readonly headings: WordPictureSectionHeading[] = []
56+
readonly segments: string[]
5657

5758
constructor(
5859
readonly query: string,
@@ -93,6 +94,8 @@ export class WordPicture {
9394
)
9495
}
9596

97+
this.segments = Object.keys(itemsRaw)
98+
9699
// Convert items data: assign head/dep to match, sort timespans under relations
97100
for (const segment in itemsRaw) {
98101
for (const itemRaw of itemsRaw[segment]) {

app/translations/locale-eng.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
"word_pic_global_filter": "The word picture cannot be combined with global filters. Please clear the filters to continue.",
104104
"word_pic_description": "The Word picture shows words that tend to co-occur in syntactic relations with the search word.",
105105
"word_pic_result_description": "The part of speech of the search word determines what relations to show. Each list collects words that occur in the selected corpora and in the given relation to the search word.",
106+
"word_pic_split": "Show trends",
106107
"word_pic_show_all": "Show all hits",
107108
"word_pic_show_some": "Show up to",
108109
"word_pic_hits": "hits",

app/translations/locale-swe.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"word_pic_pos_not_supported": "Ordbilden stödjer inte sökordets ordklass.",
9696
"word_pic_description": "I ordbilden visas vilka ord som tenderar att förekomma i syntaktiska relationer med sökordet.",
9797
"word_pic_result_description": "Vilka relationer som visas beror på sökordets ordklass. Varje lista innehåller ord som i det valda korpusmaterialet står i den givna relationen med sökordet.",
98+
"word_pic_split": "Visa trender",
9899
"word_pic_show_all": "Visa alla träffar",
99100
"word_pic_show_some": "Visa upp till",
100101
"word_pic_hits": "träffar",

0 commit comments

Comments
 (0)