| |
| |
| |
| |
| |
| |
|
|
| <template> |
| <div class="noComparison"> |
| <MetricValue |
| :title="title" |
| :value="primaryValue" |
| :secondary-value="secondaryValue" |
| :secondary-label="secondaryLabel" |
| :documentation="documentation" |
| > |
| <template |
| v-if="sparkline.evolution" |
| #evolution |
| > |
| <EvolutionBadge |
| :percent="sparkline.evolution.percent" |
| :trend="sparkline.evolution.trend" |
| :is-lower-value-better="sparkline.evolution.isLowerValueBetter" |
| :tooltip="sparkline.evolution.tooltip || ''" |
| /> |
| </template> |
| </MetricValue> |
| <div class="sparklineSlot"> |
| <Sparkline :width="380" :height="40" |
| :params="sparkline.url" |
| :series-indices="sparkline.seriesIndices" |
| /> |
| </div> |
| </div> |
| </template> |
|
|
| <script lang="ts"> |
| import { computed, defineComponent, PropType } from 'vue'; |
| import { Sparkline, NumberFormatter } from 'CoreHome'; |
| import MetricValue from '../MetricValue/MetricValue.vue'; |
| import EvolutionBadge from '../EvolutionBadge/EvolutionBadge.vue'; |
| import { SparklineEntry, SparklineMetric } from './types'; |
| |
| |
| |
| |
| |
| |
| export default defineComponent({ |
| name: 'NoComparison', |
| components: { |
| MetricValue, |
| EvolutionBadge, |
| Sparkline, |
| }, |
| props: { |
| sparkline: { |
| type: Object as PropType<SparklineEntry>, |
| required: true, |
| }, |
| |
| allMetricsDocumentation: { |
| type: Object as PropType<Record<string, string>>, |
| default: () => ({}), |
| }, |
| }, |
| setup(props) { |
| const primaryMetric = computed<SparklineMetric | undefined>( |
| () => props.sparkline.metrics?.['']?.[0], |
| ); |
| |
| |
| |
| const secondaryMetric = computed<SparklineMetric | undefined>( |
| () => props.sparkline.metrics?.['']?.[1], |
| ); |
| |
| |
| const title = computed( |
| () => primaryMetric.value?.title || primaryMetric.value?.description || '', |
| ); |
| |
| |
| |
| const documentation = computed( |
| () => props.allMetricsDocumentation[primaryMetric.value?.column ?? ''] || undefined, |
| ); |
| |
| |
| const formatValue = ( |
| value?: string | number, |
| ): string | number | undefined => ( |
| typeof value === 'number' ? NumberFormatter.formatNumber(value, 2) : value |
| ); |
| const primaryValue = computed(() => formatValue(primaryMetric.value?.value) ?? ''); |
| const secondaryValue = computed(() => formatValue(secondaryMetric.value?.value)); |
| const secondaryLabel = computed(() => secondaryMetric.value?.description); |
| |
| return { |
| title, |
| documentation, |
| primaryValue, |
| secondaryValue, |
| secondaryLabel, |
| }; |
| }, |
| }); |
| </script> |
|
|