Server returns query data, bar chart, styling charts

This commit is contained in:
Guntis Smaukstelis
2023-08-03 00:03:48 +03:00
parent cf57669830
commit b887317c6b
11 changed files with 295 additions and 96 deletions
+30
View File
@@ -0,0 +1,30 @@
import moment from "moment";
export function formatDateString(str: string): string {
const date = moment(new Date(str));
switch (str.length) {
// year: 2023
case 4: return date.format("yyyy");
// year-month: 2023-06
case 7: return date.format("yyyy-MM");
// year-month-day: 2023-06-23
case 10: return date.format("yyyy-MM-DD");
// year-month-day hour:minute 2023-06-23T23:59
default: return date.format("HH:mm");
}
}
export interface DataQuery {
cities: string[];
field: string;
granularity: string;
key: string;
}
export function isDataQuery(variable: any): variable is DataQuery {
return variable &&
Array.isArray(variable.cities) &&
typeof variable.field === 'string' &&
typeof variable.granularity === 'string' &&
typeof variable.key === 'string';
}