@@ -2,6 +2,7 @@ import { isEqual, once, pick } from "lodash"
22import { Relation } from "./backend/types/relations"
33import { getWordPictureConfig } from "./settings"
44import { WordPictureDef , WordPictureDefItem } from "./settings/app-settings.types"
5+ import { fromKeys } from "./util"
56
67export type WordType = "word" | "lemgram"
78
@@ -44,7 +45,8 @@ export type MatchedRelation = {
4445 otherpos : string
4546 /** Copy of `depextra` if the search word matches `head` – a preposition or other string to show together with the related word */
4647 prefix ?: string
47- stats : Record < string , RelationStat >
48+ /** Measurements and sources for all segments */
49+ stats : Record < string , RelationStat | null >
4850}
4951
5052export type RelationStat = Pick < Relation , "freq" | "mi" | "source" >
@@ -64,7 +66,10 @@ export class WordPicture {
6466 const { head, headpos, dep, deppos, depextra } = item
6567 const base = {
6668 rel : item . rel ,
67- stats : { [ bin ] : pick ( item , [ "freq" , "mi" , "source" ] ) } ,
69+ // Copy item stats to this segment slot, fill rest of series with null.
70+ stats : fromKeys ( this . segments , ( segment ) =>
71+ segment == bin ? pick ( item , [ "freq" , "mi" , "source" ] ) : null ,
72+ ) ,
6873 }
6974 // For ordinary word search, include multi-word items beginning with the searched word
7075 const getMatch = ( word : string ) => ( type == "word" ? word . replace ( / _ .* / , "" ) : word )
@@ -84,7 +89,6 @@ export class WordPicture {
8489 }
8590
8691 const isItemEqual = ( a : MatchedRelation , b : MatchedRelation ) : boolean => {
87- // TODO Check correct?
8892 return (
8993 a . rel == b . rel &&
9094 a . other == b . other &&
0 commit comments