11<script lang="ts">
22import {
3- PropType , defineComponent , nextTick , ref , watch ,
3+ PropType , computed , defineComponent , nextTick , ref , watch ,
44} from ' vue' ;
5+ import { throttle } from ' lodash' ;
56import UVdatApi from ' ../../api/UVDATApi' ;
67import { FeatureGraphData , VectorFeatureTableGraph } from ' ../../types' ;
78import { renderVectorFeatureGraph } from ' ./vectorFeatureGraphUtils' ;
@@ -28,16 +29,44 @@ export default defineComponent({
2829 const graphData = ref <FeatureGraphData | null >(null );
2930 const dialogVisible = ref (false );
3031 const noGraphData = ref (false );
32+ const hideBaseData = ref (false );
33+ const trendLine = ref (false );
34+ const confidenceIntervalEnabled = ref (false );
35+ const confidenceLevel = ref (95 );
36+ const movingAverageEnabled = ref (false );
37+ const movingAverageValue = ref (12 );
3138
39+ const maxMovingAverage = computed (() => {
40+ if (graphData .value ) {
41+ const keys = Object .keys (graphData .value ?.graphs || []);
42+ if (keys .length === 1 && graphData .value ?.graphs ) {
43+ const dataLength = graphData .value .graphs [parseInt (keys [0 ], 10 )].data .length ;
44+ return Math .floor (dataLength / 4 );
45+ }
46+ }
47+ return 50 ;
48+ });
3249 // Fetch feature graph data when component is mounted or props change
3350 const fetchFeatureGraphData = async () => {
3451 noGraphData .value = false ;
3552 try {
53+ const display: (' data' | ' trendLine' | ' confidenceInterval' | ' movingAverage' )[] = [' data' , ' trendLine' ];
54+ if (confidenceIntervalEnabled .value ) {
55+ display .push (' confidenceInterval' );
56+ }
57+ if (movingAverageEnabled .value ) {
58+ display .push (' movingAverage' );
59+ }
3660 const data = await UVdatApi .getFeatureGraphData (
3761 props .graphInfo .type , // Use graphInfo.type (tableType) instead of mapLayerId
3862 props .vectorFeatureId ,
3963 props .graphInfo .xAxis ,
4064 props .graphInfo .yAxis ,
65+ display ,
66+ confidenceLevel .value ,
67+ false ,
68+ movingAverageValue .value ,
69+
4170 );
4271 if (data .graphs && Object .keys (data .graphs ).length === 0 ) {
4372 noGraphData .value = true ;
@@ -88,19 +117,60 @@ export default defineComponent({
88117 showXYValuesOnHover: true ,
89118 xAxisLabel: props .graphInfo .xAxisLabel ,
90119 yAxisLabel: props .graphInfo .yAxisLabel ,
120+ hideBaseData: hideBaseData .value ,
121+ showTrendline: trendLine .value ,
122+ showConfidenceInterval: confidenceIntervalEnabled .value ,
91123 },
92124 );
93125 }
94126 });
95127 };
96128
129+ const updateDialogGraph = async () => {
130+ await fetchFeatureGraphData ();
131+ if (graphData .value && graphDialogContainer .value && dialogVisible .value ) {
132+ renderVectorFeatureGraph (
133+ graphData .value ,
134+ graphDialogContainer .value ,
135+ {
136+ specificGraphKey: props .vectorFeatureId ,
137+ xAxisIsTime: props .graphInfo .xAxis === ' unix_time' ,
138+ showXYValuesOnHover: true ,
139+ xAxisLabel: props .graphInfo .xAxisLabel ,
140+ yAxisLabel: props .graphInfo .yAxisLabel ,
141+ hideBaseData: hideBaseData .value ,
142+ showTrendline: trendLine .value ,
143+ showConfidenceInterval: confidenceIntervalEnabled .value ,
144+ showMovingAverage: movingAverageEnabled .value ,
145+ },
146+ );
147+ }
148+ };
149+
150+ const throttledUpateDialogGraph = throttle (updateDialogGraph , 500 );
151+ watch ([
152+ hideBaseData ,
153+ trendLine ,
154+ confidenceIntervalEnabled ,
155+ confidenceLevel ,
156+ movingAverageEnabled ,
157+ movingAverageValue ,
158+ ], throttledUpateDialogGraph );
159+
97160 return {
98161 graphContainer ,
99162 graphDialogContainer ,
100163 graphData ,
101164 dialogVisible ,
102165 openDialog ,
103166 noGraphData ,
167+ hideBaseData ,
168+ trendLine ,
169+ confidenceIntervalEnabled ,
170+ confidenceLevel ,
171+ movingAverageEnabled ,
172+ movingAverageValue ,
173+ maxMovingAverage ,
104174 };
105175 },
106176});
@@ -119,16 +189,50 @@ export default defineComponent({
119189 </v-btn >
120190 </div >
121191 <svg ref =" graphContainer" width =" 100%" :height =" graphData ? 400 : 0" class =" selectedFeatureSVG" />
122- <v-dialog v-model =" dialogVisible" max-width =" 800px " >
192+ <v-dialog v-model =" dialogVisible" max-width =" 1200px " >
123193 <v-card >
124194 <v-card-title >
125- <v-row >
195+ <v-row dense >
126196 <v-spacer />
127197 <span class =" headline" >{{ graphInfo.name }}</span >
128198 <v-spacer />
129199 </v-row >
130200 </v-card-title >
131201 <v-card-text >
202+ <v-row >
203+ <v-col >
204+ <v-checkbox v-model =" hideBaseData" density =" compact" hide-details label =" Hide Data" />
205+ </v-col >
206+ <v-col >
207+ <v-checkbox v-model =" trendLine" density =" compact" hide-details label =" TrendLine" />
208+ </v-col >
209+ <v-col >
210+ <v-checkbox v-model =" confidenceIntervalEnabled" density =" compact" hide-details label =" Confidence" />
211+ <v-slider
212+ v-if =" confidenceIntervalEnabled"
213+ v-model =" confidenceLevel"
214+ color =" primary"
215+ :min =" 50"
216+ step =" 1"
217+ :max =" 99"
218+ :label =" `${confidenceLevel.toFixed(1)}%`"
219+ hide-details
220+ />
221+ </v-col >
222+ <v-col >
223+ <v-checkbox v-model =" movingAverageEnabled" density =" compact" hide-details label =" Moving Average" />
224+ <v-slider
225+ v-if =" movingAverageEnabled"
226+ v-model =" movingAverageValue"
227+ color =" primary"
228+ :min =" 2"
229+ step =" 1"
230+ :max =" maxMovingAverage"
231+ :label =" movingAverageValue.toFixed(0)"
232+ hide-details
233+ />
234+ </v-col >
235+ </v-row >
132236 <svg ref =" graphDialogContainer" width =" 100%" height =" 400" />
133237 </v-card-text >
134238 <v-card-actions >
0 commit comments