|
| 1 | +<template> |
| 2 | + <v-container> |
| 3 | + |
| 4 | + <h2 class="mb-0">NDVI of Tempelhofer Feld</h2> |
| 5 | + <v-row class="pb-4"> |
| 6 | + <div |
| 7 | + id="plotlyGraph" |
| 8 | + v-show="!loading && ndviData" |
| 9 | + style="width: 100%" |
| 10 | + class="d-flex justify-center" |
| 11 | + ></div> |
| 12 | + </v-row> |
| 13 | + <!-- <v-progress-circular |
| 14 | + v-if="loading" |
| 15 | + indeterminate |
| 16 | + class="d-flex mx-auto py-10" |
| 17 | + ></v-progress-circular> --> |
| 18 | + |
| 19 | + <v-form @submit.prevent="handleSubmit" class="pb-6"> |
| 20 | + <v-row> |
| 21 | + <v-col> |
| 22 | + <v-text-field |
| 23 | + v-model="startDate" |
| 24 | + label="Start Date" |
| 25 | + type="number" |
| 26 | + required |
| 27 | + /> |
| 28 | + </v-col> |
| 29 | + <v-col> |
| 30 | + <v-text-field |
| 31 | + v-model="endDate" |
| 32 | + label="End Date" |
| 33 | + type="number" |
| 34 | + required |
| 35 | + /> |
| 36 | + </v-col> |
| 37 | + <v-col> |
| 38 | + <v-select |
| 39 | + v-model="temporalResolution" |
| 40 | + :items="temporalResolutionOptions" |
| 41 | + label="Temporal Resolution" |
| 42 | + required |
| 43 | + /> |
| 44 | + </v-col> |
| 45 | + <v-col> |
| 46 | + <v-select |
| 47 | + v-model="aggregation" |
| 48 | + :items="aggregationOptions" |
| 49 | + label="Aggregation" |
| 50 | + required |
| 51 | + /> |
| 52 | + </v-col> |
| 53 | + </v-row> |
| 54 | + <v-btn type="submit" color="blue">Update</v-btn> |
| 55 | + </v-form> |
| 56 | + |
| 57 | + </v-container> |
| 58 | +</template> |
| 59 | + |
| 60 | +<script> |
| 61 | +import { ref, nextTick, onMounted } from 'vue' |
| 62 | +import axios from 'axios' |
| 63 | +import Plotly from 'plotly.js-dist-min' |
| 64 | +
|
| 65 | +export default { |
| 66 | + name: 'NdviComparisonGraph', |
| 67 | + setup() { |
| 68 | + const ndviData = ref(null) |
| 69 | + const startDate = ref(1514761200) |
| 70 | + const endDate = ref(1704063599) |
| 71 | + const temporalResolution = ref("MONTHLY") |
| 72 | + const aggregation = ref("MEAN") |
| 73 | + const temporalResolutionOptions = ["MONTHLY", "DAILY"] |
| 74 | + const aggregationOptions = ["MEAN", "MEDIAN", "MAX", "MIN"] |
| 75 | + const loading = ref(false) |
| 76 | +
|
| 77 | + const fetchNdviData = async (params, ) => { |
| 78 | + const apiUrl = 'http://localhost:8000/index/ndvi' |
| 79 | + try { |
| 80 | + loading.value = true |
| 81 | + const response = await axios.get(apiUrl, { params: params }) |
| 82 | + ndviData.value = response.data |
| 83 | + // Wait for DOM to update before rendering Plotly graph |
| 84 | + await nextTick() |
| 85 | + renderPlot() |
| 86 | + } catch (error) { |
| 87 | + console.error("Error fetching NDVI data:", error) |
| 88 | + } finally { |
| 89 | + loading.value = false |
| 90 | + } |
| 91 | + } |
| 92 | +
|
| 93 | + const renderPlot = () => { |
| 94 | + if (ndviData.value && ndviData.value.data) { |
| 95 | + const timestamps = ndviData.value.data.map(d => new Date(d.timestamp * 1000)) |
| 96 | + const values = ndviData.value.data.map(d => d.value) |
| 97 | + const trace = { |
| 98 | + x: timestamps, |
| 99 | + y: values, |
| 100 | + mode: 'lines+markers', |
| 101 | + type: 'scatter', |
| 102 | + name: 'NDVI', |
| 103 | + line: { |
| 104 | + color: 'blue', |
| 105 | + width: 2, |
| 106 | + dash: 'solid', |
| 107 | + }, |
| 108 | + marker: { |
| 109 | + color: 'red', |
| 110 | + size: 6, |
| 111 | + } |
| 112 | + } |
| 113 | + const layout = { |
| 114 | + title: 'NDVI of Tempelhofer Feld (2018 - 2023)', |
| 115 | + xaxis: { title: 'Date' }, |
| 116 | + yaxis: { title: 'NDVI Value' }, |
| 117 | + } |
| 118 | + Plotly.newPlot('plotlyGraph', [trace], layout) |
| 119 | + } |
| 120 | + } |
| 121 | +
|
| 122 | + // Handle form submission |
| 123 | + const handleSubmit = () => { |
| 124 | + const params = { |
| 125 | + startDate: startDate.value, |
| 126 | + endDate: endDate.value, |
| 127 | + location: "TEMPELHOFER_FELD", |
| 128 | + temporalResolution: temporalResolution.value, |
| 129 | + aggregation: aggregation.value, |
| 130 | + } |
| 131 | + fetchNdviData(params) |
| 132 | + } |
| 133 | +
|
| 134 | + onMounted(() => { |
| 135 | + const defaultParams = { |
| 136 | + startDate: startDate.value, |
| 137 | + endDate: endDate.value, |
| 138 | + location: "TEMPELHOFER_FELD", |
| 139 | + temporalResolution: temporalResolution.value, |
| 140 | + aggregation: aggregation.value, |
| 141 | + } |
| 142 | + fetchNdviData(defaultParams) |
| 143 | + }) |
| 144 | +
|
| 145 | + return { |
| 146 | + ndviData, |
| 147 | + startDate, |
| 148 | + endDate, |
| 149 | + temporalResolution, |
| 150 | + aggregation, |
| 151 | + loading, |
| 152 | + temporalResolutionOptions, |
| 153 | + aggregationOptions, |
| 154 | + handleSubmit, |
| 155 | + } |
| 156 | + } |
| 157 | +} |
| 158 | +</script> |
| 159 | + |
| 160 | +<style scoped> |
| 161 | +h2 { |
| 162 | + text-align: center; |
| 163 | + margin-bottom: 10px; |
| 164 | +} |
| 165 | +</style> |
0 commit comments