|
| 1 | +<template> |
| 2 | + <v-container> |
| 3 | + <h2 class="pb-10">NDVI (2018-2023)</h2> |
| 4 | + <v-row justify="center"> |
| 5 | + <v-col class="py-0" style="max-width: 350px"> |
| 6 | + <v-select |
| 7 | + v-model="temporalResolution" |
| 8 | + :items="temporalResolutionOptions" |
| 9 | + label="Temporal Resolution" |
| 10 | + variant="outlined" |
| 11 | + density="compact" |
| 12 | + required |
| 13 | + /> |
| 14 | + </v-col> |
| 15 | + <v-col |
| 16 | + v-if="temporalResolution !== 'Daily'" |
| 17 | + class="py-0" |
| 18 | + style="max-width: 350px" |
| 19 | + > |
| 20 | + <v-select |
| 21 | + v-model="aggregation" |
| 22 | + :items="aggregationOptions" |
| 23 | + label="Aggregation" |
| 24 | + variant="outlined" |
| 25 | + density="compact" |
| 26 | + required |
| 27 | + /> |
| 28 | + </v-col> |
| 29 | + </v-row> |
| 30 | + <v-row> |
| 31 | + <div |
| 32 | + id="plotlyGraphNdviComparison" |
| 33 | + v-show="ndviData" |
| 34 | + style="width: 100%" |
| 35 | + class="d-flex justify-center" |
| 36 | + ></div> |
| 37 | + </v-row> |
| 38 | + </v-container> |
| 39 | +</template> |
| 40 | + |
| 41 | +<script> |
| 42 | +import { ref, nextTick, watch, onMounted } from 'vue' |
| 43 | +import axios from 'axios' |
| 44 | +import Plotly from 'plotly.js-dist-min' |
| 45 | +
|
| 46 | +export default { |
| 47 | + name: 'NdviComparisonGraph', |
| 48 | + setup() { |
| 49 | + const ndviData = ref(null) |
| 50 | + const startDate = ref(1514761200) // 2018-01-01 |
| 51 | + const endDate = ref(1704063599) // 2023-12-31 |
| 52 | + const temporalResolution = ref("Monthly") |
| 53 | + const aggregation = ref("Mean") |
| 54 | + const temporalResolutionOptions = ["Monthly", "Daily"] |
| 55 | + const aggregationOptions = ["Mean", "Median", "Max", "Min"] |
| 56 | +
|
| 57 | + const fetchNdviData = async (params) => { |
| 58 | + const apiUrl = 'http://localhost:8000/index/ndvi' |
| 59 | + try { |
| 60 | + const response = await axios.get(apiUrl, { params }) |
| 61 | + ndviData.value = response.data |
| 62 | + await nextTick() |
| 63 | + renderPlot() |
| 64 | + } catch (error) { |
| 65 | + console.error("Error fetching NDVI data:", error) |
| 66 | + } |
| 67 | + } |
| 68 | +
|
| 69 | + const renderPlot = () => { |
| 70 | + if (ndviData.value && ndviData.value.data) { |
| 71 | + const timestamps = ndviData.value.data.map(d => new Date(d.timestamp * 1000)) |
| 72 | + const values = ndviData.value.data.map(d => d.value) |
| 73 | + const trace = { |
| 74 | + x: timestamps, |
| 75 | + y: values, |
| 76 | + mode: 'lines+markers', |
| 77 | + type: 'scatter', |
| 78 | + name: '', |
| 79 | + line: { color: 'green' } |
| 80 | + } |
| 81 | + const layout = { |
| 82 | + title: 'NDVI of Tempelhofer Feld', |
| 83 | + xaxis: { title: '', type: 'date' }, |
| 84 | + yaxis: { title: 'NDVI Value' }, |
| 85 | + } |
| 86 | + Plotly.newPlot('plotlyGraphNdviComparison', [trace], layout) |
| 87 | + } |
| 88 | + } |
| 89 | +
|
| 90 | + const updateGraph = () => { |
| 91 | + const params = { |
| 92 | + startDate: startDate.value, |
| 93 | + endDate: endDate.value, |
| 94 | + location: "TEMPELHOFER_FELD", |
| 95 | + temporalResolution: temporalResolution.value.toUpperCase(), |
| 96 | + aggregation: aggregation.value.toUpperCase(), |
| 97 | + } |
| 98 | + fetchNdviData(params) |
| 99 | + } |
| 100 | +
|
| 101 | + watch([temporalResolution, aggregation], updateGraph) |
| 102 | +
|
| 103 | + onMounted(() => { |
| 104 | + const defaultParams = { |
| 105 | + startDate: startDate.value, |
| 106 | + endDate: endDate.value, |
| 107 | + location: "TEMPELHOFER_FELD", |
| 108 | + temporalResolution: temporalResolution.value.toUpperCase(), |
| 109 | + aggregation: aggregation.value.toUpperCase(), |
| 110 | + } |
| 111 | + fetchNdviData(defaultParams) |
| 112 | + }) |
| 113 | +
|
| 114 | + return { |
| 115 | + ndviData, |
| 116 | + startDate, |
| 117 | + endDate, |
| 118 | + temporalResolution, |
| 119 | + aggregation, |
| 120 | + temporalResolutionOptions, |
| 121 | + aggregationOptions |
| 122 | + } |
| 123 | + } |
| 124 | +} |
| 125 | +</script> |
| 126 | + |
| 127 | +<style scoped> |
| 128 | +h2 { |
| 129 | + text-align: center; |
| 130 | +} |
| 131 | +</style> |
0 commit comments