From bd626df914d00bccf7cc02ef64491d84b8f76f9b Mon Sep 17 00:00:00 2001 From: David Straub Date: Mon, 6 Nov 2023 21:49:24 +0100 Subject: [PATCH] Add DNA match table --- src/components/GrampsjsDnaMatches.js | 139 +++++++++++++++++++++++++++ src/lang/en.json | 8 +- src/views/GrampsjsViewPersonDna.js | 12 +++ 3 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 src/components/GrampsjsDnaMatches.js diff --git a/src/components/GrampsjsDnaMatches.js b/src/components/GrampsjsDnaMatches.js new file mode 100644 index 00000000..6a9049bf --- /dev/null +++ b/src/components/GrampsjsDnaMatches.js @@ -0,0 +1,139 @@ +import {html, css, LitElement} from 'lit' + +import '@material/mwc-menu' +import '@material/mwc-list/mwc-list-item' + +import {sharedStyles} from '../SharedStyles.js' +import {GrampsjsTranslateMixin} from '../mixins/GrampsjsTranslateMixin.js' +import {personDisplayName} from '../util.js' + +class GrampsjsDnaMatches extends GrampsjsTranslateMixin(LitElement) { + static get styles() { + return [ + sharedStyles, + css` + .match { + border-top: 1px solid rgba(0, 0, 0, 0.1); + padding: 0 20px; + } + + .match:last-child { + border-bottom: 1px solid rgba(0, 0, 0, 0.1); + } + .head { + display: inline-block; + margin-right: 2em; + vertical-align: middle; + width: 10rem; + padding: 20px 0; + } + + .name { + font-weight: 350; + font-size: 17px; + } + + dl { + display: inline-block; + vertical-align: middle; + } + + dd { + font-size: 15px; + } + `, + ] + } + + static get properties() { + return { + data: {type: Array}, + person: {type: Object}, + } + } + + constructor() { + super() + this.data = [] + this.person = {} + } + + render() { + return html` + + ${this.data + .filter(match => match.segments && match.segments.length > 0) + .map(match => this._personCard(match))} +
+ ` + } + + _personCard(match) { + return html` +
+ +
+
+
${this._('Relationship')}
+
${match.relation || this._('Unknown')}
+
+
+
${this._('Shared DNA')}
+
+ ${match.segments.reduce( + (accumulator, currentValue) => accumulator + currentValue.cM, + 0 + )} + cM +
+
+
+
${this._('Shared Segments')}
+
${match.segments.length}
+
+
+
${this._('Largest Segment')}
+
+ ${match.segments.reduce( + (accumulator, currentValue) => + Math.max(accumulator, currentValue.cM), + 0 + )} + cM +
+
+
+
+ ` + } + + _getNameFromHandle(handle) { + const people = this.person?.extended?.people || [] + let person = people.filter(p => p.handle === handle) + if (person.length === 0) { + return '' + } + // eslint-disable-next-line prefer-destructuring + person = person[0] + return personDisplayName(person) + } + + _getGidFromHandle(handle) { + const people = this.person?.extended?.people || [] + let person = people.filter(p => p.handle === handle) + if (person.length === 0) { + return '' + } + // eslint-disable-next-line prefer-destructuring + person = person[0] + return person.gramps_id + } +} + +window.customElements.define('grampsjs-dna-matches', GrampsjsDnaMatches) diff --git a/src/lang/en.json b/src/lang/en.json index 70d2d5b6..2f3ada3e 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -125,5 +125,11 @@ "Edit event type": "Edit event type", "Edit place type": "Edit place type", "Text Recognition": "Text Recognition", - "Save as Note": "Save as Note" + "Save as Note": "Save as Note", + "DNA": "DNA", + "Matches": "Matches", + "Chromosome Browser": "Chromosome Browser", + "Shared DNA": "Shared DNA", + "Shared Segments": "Shared Segments", + "Largest Segment": "Largest Segment" } \ No newline at end of file diff --git a/src/views/GrampsjsViewPersonDna.js b/src/views/GrampsjsViewPersonDna.js index fc2cedd7..94fb4959 100644 --- a/src/views/GrampsjsViewPersonDna.js +++ b/src/views/GrampsjsViewPersonDna.js @@ -3,6 +3,7 @@ import {html, css} from 'lit' import {GrampsjsView} from './GrampsjsView.js' import {apiGet} from '../api.js' import '../components/GrampsjsChromosomeBrowser.js' +import '../components/GrampsjsDnaMatches.js' export class GrampsjsViewPersonDna extends GrampsjsView { static get styles() { @@ -12,6 +13,10 @@ export class GrampsjsViewPersonDna extends GrampsjsView { :host { margin: 0; } + + h3 { + margin: 1.2em 0; + } `, ] } @@ -37,6 +42,13 @@ export class GrampsjsViewPersonDna extends GrampsjsView { renderElements() { return html` +

${this._('Matches')}

+ +

${this._('Chromosome Browser')}