Skip to content

Commit 6aaa74f

Browse files
authored
Merge pull request #26 from OpenGeoscience/tabular-graph-enhancements
Tabular graph enhancements
2 parents 2b38226 + 92adbca commit 6aaa74f

6 files changed

Lines changed: 512 additions & 89 deletions

File tree

client/src/api/UVDATApi.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,25 @@ export default class UVdatApi {
506506
vectorFeatureId: number,
507507
xAxis: string = 'index',
508508
yAxis: string = 'mean_va',
509+
display: ('data' | 'trendLine' | 'confidenceInterval' | 'movingAverage')[] = ['data', 'trendLine'],
510+
confidenceLevel = 95,
511+
aggregate = false,
512+
movingAverage?: number,
509513
): Promise<FeatureGraphData> {
510-
const response = await UVdatApi.apiClient.get('/vectorfeature/tabledata/feature-graph/', {
511-
params: {
512-
tableType,
513-
vectorFeatureId,
514-
xAxis,
515-
yAxis,
516-
},
517-
});
514+
const params = new URLSearchParams();
515+
516+
display.forEach((item) => params.append('display', item.toString()));
517+
params.append('tableType', tableType);
518+
params.append('vectorFeatureId', vectorFeatureId.toString());
519+
params.append('xAxis', xAxis);
520+
params.append('yAxis', yAxis);
521+
params.append('confidenceLevel', confidenceLevel.toString());
522+
params.append('aggregate', aggregate.toString());
523+
if (movingAverage) {
524+
params.append('movingAverage', movingAverage.toString());
525+
}
526+
527+
const response = await UVdatApi.apiClient.get('/vectorfeature/tabledata/feature-graph/', { params });
518528
return response.data;
519529
}
520530

@@ -525,17 +535,29 @@ export default class UVdatApi {
525535
yAxis: string = 'mean_va',
526536
indexer: string = 'vectorFeatureId',
527537
bbox?: string,
538+
display: ('data' | 'trendLine' | 'confidenceInterval' | 'movingAverage')[] = ['data', 'trendLine'],
539+
confidenceLevel = 95,
540+
aggregate = false,
541+
movingAverage?: number,
528542
): Promise<FeatureGraphData> {
529-
const response = await UVdatApi.apiClient.get('/vectorfeature/tabledata/map-layer-feature-graph/', {
530-
params: {
531-
tableType,
532-
mapLayerId,
533-
xAxis,
534-
yAxis,
535-
indexer,
536-
bbox,
537-
},
538-
});
543+
const params = new URLSearchParams();
544+
545+
display.forEach((item) => params.append('display', item.toString()));
546+
params.append('tableType', tableType);
547+
params.append('mapLayerId', mapLayerId.toString());
548+
params.append('indexer', indexer.toString());
549+
params.append('xAxis', xAxis);
550+
params.append('yAxis', yAxis);
551+
if (bbox) {
552+
params.append('bbox', bbox.toString());
553+
}
554+
params.append('confidenceLevel', confidenceLevel.toString());
555+
params.append('aggregateAll', aggregate.toString());
556+
if (movingAverage) {
557+
params.append('movingAverage', movingAverage.toString());
558+
}
559+
560+
const response = await UVdatApi.apiClient.get('/vectorfeature/tabledata/map-layer-feature-graph/', { params });
539561
return response.data;
540562
}
541563

client/src/components/FeatureSelection/VectorFeatureChart.vue

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script lang="ts">
22
import {
3-
PropType, defineComponent, nextTick, ref, watch,
3+
PropType, computed, defineComponent, nextTick, ref, watch,
44
} from 'vue';
5+
import { throttle } from 'lodash';
56
import UVdatApi from '../../api/UVDATApi';
67
import { FeatureGraphData, VectorFeatureTableGraph } from '../../types';
78
import { 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

Comments
 (0)