Skip to content
Snippets Groups Projects
MetricChart.vue 2.07 KiB
Newer Older
  • Learn to ignore specific revisions
  • <script setup lang="ts">
    
    import { onMounted, ref, watch } from "vue"
    import api from "@/helpers/api"
    
    import BaseTimelineChart from "@/components/timeline/BaseTimelineChart.vue"
    
    import { getMaxValueOfMetric } from '@/helpers/metrics'
    
    Paul Pestov's avatar
    Paul Pestov committed
    import type { EvaluationResultsDocumentWide, EvaluationRun, TimelineChartDataPoint } from "@/types"
    
    import { metricChartTooltipContent } from "@/helpers/metric-chart-tooltip-content"
    
    import OverlayPanel from 'primevue/overlaypanel'
    
    const props = defineProps(['gtId', 'workflowId', 'metric', 'startDate', 'endDate'])
    const runs = ref<EvaluationRun[]>([])
    
    const data = ref([])
    const maxY = ref(2)
    
    const op = ref<OverlayPanel | null>(null)
    
    
    
    onMounted(async () => {
      const { gtId, workflowId, metric } = props
      runs.value = await api.getRuns(gtId, workflowId)
      data.value = getTimelineData(runs.value, metric)
    
      maxY.value = getMaxValueOfMetric(metric)
    
    })
    
    watch(() => props.metric,
        (value) => {
          if (!runs.value) return
          data.value = getTimelineData(runs.value, value)
    
          maxY.value = getMaxValueOfMetric(value)
    
    function getTimelineData(runs: EvaluationRun[], metric: keyof EvaluationResultsDocumentWide) {
    
      return runs.map(({ metadata, evaluation_results }) => {
        const value = evaluation_results.document_wide[metric]
        return {
          date: new Date(metadata.timestamp),
          value
        }
      })
    }
    
    
    function tooltipContent(d: TimelineChartDataPoint) {
      return metricChartTooltipContent(d, props.metric)
    }
    
    
      <div @click="op?.toggle($event)" class="cursor-pointer">
        <BaseTimelineChart :data="data" :max-y="maxY" :start-date="startDate" :end-date="endDate" :tooltip-content="tooltipContent" />
      </div>
      <OverlayPanel
        ref="op"
        :pt="{
          root: {
            class: 'z-[9999] bg-white border rounded-md shadow-md'
          }
        }"
      >
        <BaseTimelineChart
          :data="data"
          :max-y="maxY"
          :start-date="startDate"
          :end-date="endDate"
          :tooltip-content="tooltipContent"
          :height="400"
          :width="660"
        />
      </OverlayPanel>
    
    </template>
    
    <style scoped lang="scss">
    
    </style>