@gisce/react-ooui 1.1.55 → 1.1.56-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"GraphDefaults.d.ts","sourceRoot":"","sources":["GraphDefaults.ts"],"names":[],"mappings":"AAiCA,QAAA,MAAM,mBAAmB;;;;;;mCAvBK,GAAG;;;;;mCAAH,GAAG;;;;;;;;gCATf,GAAG;;;;;;;;;;;;mCA4DQ,GAAG;;;;;;;;;;;gCA5Dd,GAAG;;;;;;;;;;;;;;;;gCAAH,GAAG;;;;;;;mCASS,GAAG;;;;;mCAAH,GAAG;;;;;;;;;;CAwGhC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
1
+ {"version":3,"file":"GraphDefaults.d.ts","sourceRoot":"","sources":["GraphDefaults.ts"],"names":[],"mappings":"AA2CA,QAAA,MAAM,mBAAmB;;;;;;mCA/BK,GAAG;;;;;mCAAH,GAAG;;;;;;;;gCATf,GAAG;;;;;;;;;;;;mCAoEQ,GAAG;;;;;;;;;;;gCApEd,GAAG;;;;;;;;;;;;;;;;gCAAH,GAAG;;;;;;;mCASS,GAAG;;;;;mCAAH,GAAG;;;;;;;;;;CAgHhC,CAAC;AA6CF,eAAe,mBAAmB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/react-ooui",
3
- "version": "1.1.55",
3
+ "version": "1.1.56-rc.1",
4
4
  "files": [
5
5
  "dist",
6
6
  "src",
@@ -1,3 +1,5 @@
1
+ import moment from "moment";
2
+
1
3
  const formatter = (graphType: "pie" | "default" | "barGrouped") => {
2
4
  return (object: any) => {
3
5
  const formattedValue = object.value.toLocaleString("es-ES", {
@@ -17,6 +19,14 @@ const axisFormatter = (value: any) => {
17
19
  return value.toLocaleString("es-ES", {
18
20
  useGrouping: true,
19
21
  });
22
+ } else if (isValidDateString(value)) {
23
+ const dateType = getDateType(value);
24
+ if (dateType === null) {
25
+ return value;
26
+ }
27
+ return moment(value, (dateFormats.input as any)[dateType]).format(
28
+ (dateFormats.output as any)[dateType]
29
+ );
20
30
  } else {
21
31
  return value;
22
32
  }
@@ -114,4 +124,47 @@ const DefaultGraphOptions = {
114
124
  },
115
125
  };
116
126
 
127
+ function isValidDateString(variable: any): boolean {
128
+ // Check if the variable is defined and is a string
129
+ if (typeof variable !== "string" || variable === undefined) {
130
+ return false;
131
+ }
132
+
133
+ // Check if the string is a valid date
134
+ const date = new Date(variable);
135
+ return date.toString() !== "Invalid Date";
136
+ }
137
+
138
+ const dateFormats = {
139
+ input: {
140
+ hours: "YYYY-MM-DD HH:mm",
141
+ days: "YYYY-MM-DD",
142
+ weeks: "YYYY-[W]WW",
143
+ months: "YYYY-MM",
144
+ years: "YYYY",
145
+ },
146
+ output: {
147
+ hours: "DD/MM/YYYY HH:mm",
148
+ days: "DD/MM/YYYY",
149
+ weeks: "[W]WW/YYYY",
150
+ months: "MM/YYYY",
151
+ years: "YYYY",
152
+ },
153
+ };
154
+
155
+ function getDateType(dateString: string): string | null {
156
+ for (const format in dateFormats.input) {
157
+ const isValidFormat = moment(
158
+ dateString,
159
+ (dateFormats.input as any)[format],
160
+ true
161
+ ).isValid();
162
+ if (isValidFormat) {
163
+ return format;
164
+ }
165
+ }
166
+
167
+ return null;
168
+ }
169
+
117
170
  export default DefaultGraphOptions;