@vixoniccom/kpi-chart 0.0.1-dev.3 → 0.0.1-dev.5

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.
package/build.zip CHANGED
Binary file
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "author": {
9
9
  "name": "Lorenzo Alfaro Bravo"
10
10
  },
11
- "version": "0.0.1-dev.3",
11
+ "version": "0.0.1-dev.5",
12
12
  "scripts": {
13
13
  "prepublishOnly": "vixonic-module-packager --mode=build",
14
14
  "watch": "vixonic-module-packager --mode=watch",
@@ -24,7 +24,8 @@
24
24
  "localforage": "^1.10.0",
25
25
  "react": "^17.0.2",
26
26
  "react-charts": "^3.0.0-beta.57",
27
- "react-dom": "^17.0.2"
27
+ "react-dom": "^17.0.2",
28
+ "react-loader-spinner": "^6.1.6"
28
29
  },
29
30
  "devDependencies": {
30
31
  "@types/react": "^18.3.12",
@@ -1,6 +1,7 @@
1
+ import React, { useState, useEffect } from "react";
1
2
  import axios from "axios";
2
3
  import localforage from "localforage";
3
- import React, { useState, useEffect } from "react";
4
+ import { Circles } from "react-loader-spinner";
4
5
  import { FontLoader } from "./FontLoader";
5
6
  import { ChartContainer } from "./ChartContainer";
6
7
  import { FormattedText } from "./FormattedText";
@@ -39,6 +40,7 @@ export const App: React.FunctionComponent<Props> = ({ data, start }) => {
39
40
  const backgroundImageState = params?.backgroundImage
40
41
  ? `url("${data.downloadsPath}/${params?.backgroundImage.filename}")`
41
42
  : "";
43
+ const [loading, setLoading] = useState<boolean>(false);
42
44
  // Definición de variable que contiene los datos procesados provenientes de la URL
43
45
  const [sheetData, setSheetData] = useState<Series[]>([]);
44
46
  // Definición de mensaje del sistema
@@ -46,7 +48,7 @@ export const App: React.FunctionComponent<Props> = ({ data, start }) => {
46
48
  "Sin datos disponibles"
47
49
  );
48
50
  // Definición de nombre fijo de columna de categoría
49
- const categoryColumnName = "categoria";
51
+ const categoryColumnName = "category";
50
52
  // Definición de cantidad máxima de columnas y filas para procesar desde Google
51
53
  const fixedMaxRows = 100;
52
54
  const fixedMaxColumns = 10; // 10 máx, no usar más, a menos que sea agreguen más colores en ChartContainer
@@ -56,8 +58,10 @@ export const App: React.FunctionComponent<Props> = ({ data, start }) => {
56
58
 
57
59
  // Función para hacer request de Google y almacenar los datos procesados en localforage
58
60
  const getData = async () => {
61
+ setLoading(true);
59
62
  const googleID = params?.url?.split("/")[5];
60
63
  const key = getStorageKey(googleID);
64
+ localforage.clear();
61
65
  const storedData: any = await localforage.getItem(key);
62
66
  if (!storedData?.items || storedData?.items?.length === 0) {
63
67
  const data = await requestData(googleID);
@@ -74,6 +78,7 @@ export const App: React.FunctionComponent<Props> = ({ data, start }) => {
74
78
  setDataAndTime(storedData.items, targetDate - now);
75
79
  }
76
80
  }
81
+ setLoading(false);
77
82
  };
78
83
 
79
84
  // Función para actualizar el estado de los datos y el tiempo de actualización
@@ -169,7 +174,11 @@ export const App: React.FunctionComponent<Props> = ({ data, start }) => {
169
174
  downloadsPath={data.downloadsPath}
170
175
  />
171
176
  {/* Render de chart o mensaje del sistema/personalizado */}
172
- {sheetData.length > 0 ? (
177
+ {loading ? (
178
+ <div className="loading-container">
179
+ <Circles ariaLabel="loading-indicator" color="gray" />
180
+ </div>
181
+ ) : sheetData.length > 0 ? (
173
182
  <ChartContainer data={sheetData} parameters={params} />
174
183
  ) : (
175
184
  <FormattedText
@@ -37,12 +37,24 @@ export const ChartContainer: React.FunctionComponent<Props> = ({
37
37
  const legendGap = parameters?.legendMargin || 0;
38
38
  const titleMargin = parameters?.titlePadding || "0px";
39
39
  const legendPosition = parameters?.legendPosition || "left";
40
+ const barOrientation = parameters?.barOrientation || "vertical";
40
41
  const chartElementType = (parameters?.chartType as elementType) || "bar";
41
42
  const titleFontColor = !parameters?.titleTextFormat?.fontColor
42
43
  ? parameters?.darkMode
43
44
  ? "white"
44
45
  : "black"
45
46
  : parameters?.titleTextFormat?.fontColor;
47
+ // Posición de los ejes según formato de barras
48
+ const yAxisPosition = !(chartElementType === "bar")
49
+ ? "left"
50
+ : barOrientation === "vertical"
51
+ ? "left"
52
+ : "bottom";
53
+ const xAxisPosition = !(chartElementType === "bar")
54
+ ? "bottom"
55
+ : barOrientation === "vertical"
56
+ ? "bottom"
57
+ : "left";
46
58
 
47
59
  // Definición eje x
48
60
  const primaryAxis = React.useMemo(
@@ -52,19 +64,9 @@ export const ChartContainer: React.FunctionComponent<Props> = ({
52
64
  scaleType: "band",
53
65
  showGrid: parameters?.showVerticalGrid,
54
66
  show: parameters?.xAxisEnabled,
55
- // Para barras horizontales
56
- position:
57
- chartElementType === "bar"
58
- ? parameters?.barOrientation === "horizontal"
59
- ? "left"
60
- : "bottom"
61
- : "bottom",
67
+ position: xAxisPosition,
62
68
  }),
63
- [
64
- parameters.showVerticalGrid,
65
- parameters.xAxisEnabled,
66
- parameters.barOrientation,
67
- ]
69
+ [parameters.showVerticalGrid, parameters.xAxisEnabled, xAxisPosition]
68
70
  );
69
71
 
70
72
  // Definición eje y
@@ -88,13 +90,7 @@ export const ChartContainer: React.FunctionComponent<Props> = ({
88
90
  ? true
89
91
  : false
90
92
  : false,
91
- // Para barras horizontales
92
- position:
93
- chartElementType === "bar"
94
- ? parameters?.barOrientation === "horizontal"
95
- ? "bottom"
96
- : "left"
97
- : "left",
93
+ position: yAxisPosition,
98
94
  },
99
95
  ],
100
96
  [
@@ -103,7 +99,7 @@ export const ChartContainer: React.FunctionComponent<Props> = ({
103
99
  parameters.barStacked,
104
100
  parameters.yAxisEnabled,
105
101
  parameters.showHorizontalGrid,
106
- parameters.barOrientation,
102
+ yAxisPosition,
107
103
  ]
108
104
  );
109
105
 
@@ -158,7 +158,7 @@ export const getCleanData = (
158
158
  if (h === "" || h === undefined) {
159
159
  return `nn-feature-${index}`;
160
160
  }
161
- return h.trim().toLocaleLowerCase().replace(/ /g, "-");
161
+ return h.trim().toLocaleLowerCase();
162
162
  });
163
163
 
164
164
  // Eliminación de duplicados (columnas y registros)
package/src/style.css CHANGED
@@ -10,6 +10,15 @@
10
10
  box-sizing: border-box;
11
11
  }
12
12
 
13
+ .loading-container {
14
+ height: 100%;
15
+ width: 100%;
16
+ /* Flexbox */
17
+ display: flex;
18
+ align-items: center;
19
+ justify-content: center;
20
+ }
21
+
13
22
  .chart-container {
14
23
  height: 100%;
15
24
  width: 100%;