|
| 1 | +<template> |
| 2 | + <table v-if="evidenceStrengthsForDisplay" class="mave-calibrations-table"> |
| 3 | + <tr> |
| 4 | + <td colspan="100" class="dropdown" > |
| 5 | + <Dropdown v-model="activeCalibrationKey" :options="Object.keys(calibrations)" :optionLabel="titleCase" style="width: 100%;" :disabled="Object.keys(calibrations).length < 2" /> |
| 6 | + </td> |
| 7 | + </tr> |
| 8 | + <tr> |
| 9 | + <th>Evidence Strength</th> |
| 10 | + <th v-for="evidenceStrength of evidenceStrengthsForDisplay" :key="evidenceStrength"><b>{{ evidenceStrength }}</b></th> |
| 11 | + </tr> |
| 12 | + <tr> |
| 13 | + <td>Likelihood Ratio+</td> |
| 14 | + <td v-for="likelihoodRatio of positiveLikelihoodRatiosForDisplay" :key="likelihoodRatio">{{ likelihoodRatio }}</td> |
| 15 | + </tr> |
| 16 | + <tr> |
| 17 | + <td>Score Threshold</td> |
| 18 | + <td v-for="threshold of thresholdsForDisplay" :key="threshold">{{ threshold }}</td> |
| 19 | + </tr> |
| 20 | + </table> |
| 21 | +</template> |
| 22 | + |
| 23 | +<script lang="ts"> |
| 24 | +import {defineComponent} from 'vue' |
| 25 | +import { Calibrations } from '@/lib/calibrations'; |
| 26 | +import Dropdown from 'primevue/dropdown'; |
| 27 | +
|
| 28 | +export default defineComponent({ |
| 29 | + name: 'CalibrationTable', |
| 30 | + components: { Dropdown }, |
| 31 | +
|
| 32 | + data: function() { |
| 33 | + const defaultCalibration = Object.keys(this.calibrations)[0] |
| 34 | + this.$emit('calibrationSelected', defaultCalibration) |
| 35 | +
|
| 36 | + return { |
| 37 | + activeCalibrationKey: defaultCalibration |
| 38 | + } |
| 39 | + }, |
| 40 | +
|
| 41 | + emits: ['calibrationSelected'], |
| 42 | +
|
| 43 | + props: { |
| 44 | + calibrations: { |
| 45 | + type: Object as () => {[key: string]: Calibrations}, |
| 46 | + required: true |
| 47 | + }, |
| 48 | + }, |
| 49 | +
|
| 50 | + computed: { |
| 51 | + selectedCalibrations: function () { |
| 52 | + return this.calibrations[this.activeCalibrationKey] |
| 53 | + }, |
| 54 | +
|
| 55 | + evidenceStrengthsForDisplay: function() { |
| 56 | + return this.selectedCalibrations.evidenceStrengths |
| 57 | + }, |
| 58 | +
|
| 59 | + positiveLikelihoodRatiosForDisplay: function() { |
| 60 | + return this.selectedCalibrations.positiveLikelihoodRatios |
| 61 | + }, |
| 62 | +
|
| 63 | + thresholdsForDisplay: function() { |
| 64 | + return this.selectedCalibrations.thresholds |
| 65 | + }, |
| 66 | + }, |
| 67 | +
|
| 68 | + methods: { |
| 69 | + titleCase(s: string) { |
| 70 | + return s.replace (/^[-_]*(.)/, (_, c) => c.toUpperCase()) // Initial char (after -/_) |
| 71 | + .replace (/[-_]+(.)/g, (_, c) => ' ' + c.toUpperCase()) // First char after each -/_ |
| 72 | + } |
| 73 | + }, |
| 74 | +
|
| 75 | + watch: { |
| 76 | + activeCalibrationKey: { |
| 77 | + handler: function() { |
| 78 | + this.$emit('calibrationSelected', this.activeCalibrationKey) |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | +}) |
| 83 | +</script> |
| 84 | + |
| 85 | +<style> |
| 86 | +table.mave-calibrations-table { |
| 87 | + border-collapse: collapse; |
| 88 | + margin: 1em auto 0.5em auto; |
| 89 | +} |
| 90 | +
|
| 91 | +table.mave-calibrations-table .dropdown { |
| 92 | + border-top-style: hidden; |
| 93 | + border-left-style: hidden; |
| 94 | + border-right-style: hidden; |
| 95 | +} |
| 96 | +
|
| 97 | +table.mave-calibrations-table td, |
| 98 | +table.mave-calibrations-table th { |
| 99 | + border: 1px solid gray; |
| 100 | + padding: 0.5em 1em; |
| 101 | + text-align: center; |
| 102 | +} |
| 103 | +</style> |
0 commit comments