Skip to content

Commit e9c1857

Browse files
committed
initial globalTime config
1 parent 7e8c425 commit e9c1857

5 files changed

Lines changed: 61 additions & 2 deletions

File tree

client/src/MapStore.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
VectorMapLayer,
1818
} from './types';
1919
import UVdatApi from './api/UVDATApi';
20+
import { visibleNetCDFLayers } from './map/mapNetCDFLayer';
2021

2122
export const VECTOR_PMTILES_URL = '/public/vectortiles/us.pmtiles';
2223

@@ -34,6 +35,8 @@ export default class MapStore {
3435

3536
public static proModeButtonEnabled = ref(true);
3637

38+
public static globalTime = ref(new Date());
39+
3740
public static displayConfiguration: Ref<DisplayConfiguration> = ref(
3841
{ default_displayed_layers: [], enabled_ui: ['Collections', 'Datasets', 'Metadata'], default_tab: 'Scenarios' },
3942
);
@@ -353,4 +356,38 @@ export default class MapStore {
353356
}
354357
}
355358
};
359+
360+
// Graph Charts current Min/Max Values in unix_time
361+
public static graphChartsMinMax = ref({
362+
min: 0,
363+
max: 0,
364+
});
365+
366+
public static updateChartsMinMax = (min: number, max: number) => {
367+
MapStore.graphChartsMinMax.value.min = min;
368+
MapStore.graphChartsMinMax.value.max = max;
369+
};
370+
371+
// Computes in Unix Time
372+
public static globalTimeRange = computed(() => {
373+
let globalMin = Infinity;
374+
let globalMax = -Infinity;
375+
MapStore.visibleMapLayers.value.forEach((visibleMapLayer) => {
376+
const [type, layerId] = visibleMapLayer.split('_');
377+
const foundLayer = MapStore.selectedMapLayers.value.find((layer) => layer.id === parseInt(layerId, 10) && layer.type === type);
378+
if (type === 'netcdf' && foundLayer !== undefined) {
379+
const netCDFLayer = visibleNetCDFLayers.value.find((item) => item.netCDFLayer === foundLayer.id);
380+
if (netCDFLayer && netCDFLayer.sliding) {
381+
const { min, max } = netCDFLayer.sliding;
382+
globalMin = Math.min(globalMin, min);
383+
globalMax = Math.max(globalMax, max);
384+
}
385+
}
386+
});
387+
if (MapStore.mapLayerFeatureGraphsVisible.value && MapStore.mapLayerFeatureGraphs.value.length) {
388+
globalMin = Math.min(globalMin, MapStore.graphChartsMinMax.value.min);
389+
globalMax = Math.max(globalMax, MapStore.graphChartsMinMax.value.max);
390+
}
391+
return { min: globalMin, max: globalMax };
392+
});
356393
}

client/src/components/FeatureSelection/VectorFeatureChart.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export default defineComponent({
6666
confidenceLevel.value,
6767
false,
6868
movingAverageValue.value,
69-
7069
);
7170
if (data.graphs && Object.keys(data.graphs).length === 0) {
7271
noGraphData.value = true;

client/src/components/TabularData/MapLayerTableGraph.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,15 @@ export default defineComponent({
114114
movingAverageValue.value,
115115
);
116116
graphData.value = data;
117-
117+
let minGraph = Infinity;
118+
let maxGraph = -Infinity;
119+
Object.keys(data.graphs).forEach((key) => {
120+
const index = parseInt(key, 10);
121+
const [min, max] = data.graphs[index].xAxisRange;
122+
minGraph = Math.min(minGraph, min);
123+
maxGraph = Math.max(maxGraph, max);
124+
});
125+
MapStore.updateChartsMinMax(minGraph, maxGraph);
118126
if (graphContainer.value) {
119127
const colorMapping = renderVectorFeatureGraph(
120128
data,

client/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,8 @@ export interface FeatureGraphData {
802802
trendLine?:[number, number][];
803803
confidenceIntervals?:[number, number, number][];
804804
movingAverage?:[number, number][];
805+
xAxisRange:[number, number];
806+
yAxisRange:[number, number];
805807
}>
806808
}
807809

uvdat/core/rest/vector_feature_table_data.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ def get_graphs(
172172

173173
table_data = {'tableName': tables.first().name, 'graphs': {}}
174174
all_x_vals = {}
175+
all_x_list = [] # <<< Added
176+
all_y_list = [] # <<< Added
175177

176178
for table in tables:
177179
if y_axis not in table.columns or x_axis not in table.columns:
@@ -205,6 +207,10 @@ def get_graphs(
205207
x_vals = sorted_x_vals
206208
y_vals = [np.mean(data[x]) for x in sorted_x_vals]
207209

210+
# Add x and y values to global list for min/max later
211+
all_x_list.extend(x_vals)
212+
all_y_list.extend(y_vals)
213+
208214
for x, y in zip(x_vals, y_vals):
209215
if x not in all_x_vals:
210216
all_x_vals[x] = []
@@ -251,6 +257,9 @@ def get_graphs(
251257
avg_y_vals = [np.mean(all_x_vals[x]) for x in sorted_x_vals]
252258
aggregate_result = {'indexer': 'all', 'vectorFeatureId': 'all'}
253259

260+
all_x_list.extend(sorted_x_vals)
261+
all_y_list.extend(avg_y_vals)
262+
254263
if 'data' in data_types:
255264
aggregate_result['data'] = list(zip(sorted_x_vals, avg_y_vals))
256265

@@ -280,6 +289,10 @@ def get_graphs(
280289

281290
table_data['graphs'][-1] = aggregate_result
282291

292+
if all_x_list and all_y_list:
293+
table_data['xAxisRange'] = [min(all_x_list), max(all_x_list)]
294+
table_data['yAxisRange'] = [min(all_y_list), max(all_y_list)]
295+
283296
return table_data
284297

285298
@action(detail=False, methods=['get'], url_path='feature-graph')

0 commit comments

Comments
 (0)