@vixoniccom/kpi-chart 0.0.1-dev.4 → 0.0.1-dev.6

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.4",
11
+ "version": "0.0.1-dev.6",
12
12
  "scripts": {
13
13
  "prepublishOnly": "vixonic-module-packager --mode=build",
14
14
  "watch": "vixonic-module-packager --mode=watch",
@@ -24,11 +24,12 @@
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
- "@types/react": "^18.3.12",
31
- "@types/react-dom": "^18.3.1",
31
+ "@types/react": "^17.0.2",
32
+ "@types/react-dom": "^17.0.11",
32
33
  "@vixoniccom/module-packager": "^2.10.1",
33
34
  "@vixoniccom/modules": "^2.20.0",
34
35
  "standard-version": "^9.5.0"
@@ -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";
@@ -34,11 +35,12 @@ const fontPaths = [
34
35
  export const App: React.FunctionComponent<Props> = ({ data, start }) => {
35
36
  let updateTimer: any;
36
37
  const params = data.parameters;
37
- const appPadding = params?.appPadding || "0px";
38
- const updateTime = params?.updateTime || 3600000;
38
+ const appPadding = params?.appPadding ?? "0px";
39
+ const updateTime = params?.updateTime ?? 3600000;
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,18 +48,20 @@ 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
53
55
  // Definición de cantidad de columnas y filas para mostrar en la aplicación
54
- const rowsNumber = params?.maxRowsNumber || 6;
55
- const columnsNumber = params?.maxColumnsNumber || 3;
56
+ const rowsNumber = params?.maxRowsNumber ?? 6;
57
+ const columnsNumber = params?.maxColumnsNumber ?? 3;
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
@@ -1,7 +1,8 @@
1
1
  import React from "react";
2
- import { Chart, AxisOptions } from "react-charts";
2
+ import { Chart, AxisOptions, Position } from "react-charts";
3
3
  import { FormattedText } from "../FormattedText";
4
4
  import { ChartLegend } from "../ChartLegend";
5
+ import { getFontColor } from "../utils";
5
6
 
6
7
  type Props = {
7
8
  data: Series[];
@@ -10,6 +11,14 @@ type Props = {
10
11
 
11
12
  type elementType = "area" | "line" | "bar" | "bubble";
12
13
 
14
+ type AxisConfig = {
15
+ position: string;
16
+ show: boolean;
17
+ showLine: boolean;
18
+ stacked: boolean;
19
+ type: string;
20
+ };
21
+
13
22
  // Definición de colores que se utilizarán en el gráfico y leyenda
14
23
  const defaultColors = [
15
24
  "#1F77B4", // Azul
@@ -24,6 +33,41 @@ const defaultColors = [
24
33
  "#7F7F7F", // Gris
25
34
  ];
26
35
 
36
+ // Obtener configuraciones de ejes según parámetros de configuración
37
+ const getAxisConfig = (parameters: VixonicParameters) => {
38
+
39
+ const chartType = parameters?.chartType ?? "bar";
40
+ const isBarChart = chartType === "bar";
41
+ const barOrientation = parameters?.barOrientation ?? "vertical";
42
+ const isHorizontalBar = isBarChart && barOrientation === "horizontal";
43
+
44
+ const defaultConfig: AxisConfig = {
45
+ position: "left",
46
+ show: true,
47
+ showLine: true,
48
+ stacked: false,
49
+ type: chartType,
50
+ };
51
+
52
+ const xConfig = {
53
+ position: isHorizontalBar ? "left" : "bottom",
54
+ show: parameters?.xAxisEnabled ?? defaultConfig.show,
55
+ showLine: parameters?.showVerticalGrid ?? defaultConfig.showLine,
56
+ };
57
+
58
+ const yConfig = {
59
+ position: isHorizontalBar ? "bottom" : "left",
60
+ show: parameters?.yAxisEnabled ?? defaultConfig.show,
61
+ showLine: parameters?.showHorizontalGrid ?? defaultConfig.showLine,
62
+ stacked: isBarChart && (parameters?.barStacked ?? false),
63
+ };
64
+
65
+ return {
66
+ xAxisConfig: { ...defaultConfig, ...xConfig },
67
+ yAxisConfig: { ...defaultConfig, ...yConfig },
68
+ };
69
+ };
70
+
27
71
  /**
28
72
  * Componente para renderizar el gráfico, su título y su leyenda.
29
73
  * Se definen ejes principal y secundario en Memo para evitar problemas
@@ -33,28 +77,12 @@ export const ChartContainer: React.FunctionComponent<Props> = ({
33
77
  data,
34
78
  parameters,
35
79
  }) => {
36
- const chartTitle = parameters?.title || "";
37
- const legendGap = parameters?.legendMargin || 0;
38
- const titleMargin = parameters?.titlePadding || "0px";
39
- const legendPosition = parameters?.legendPosition || "left";
40
- const barOrientation = parameters?.barOrientation || "vertical";
41
- const chartElementType = (parameters?.chartType as elementType) || "bar";
42
- const titleFontColor = !parameters?.titleTextFormat?.fontColor
43
- ? parameters?.darkMode
44
- ? "white"
45
- : "black"
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";
80
+ const chartTitle = parameters?.title ?? "";
81
+ const legendGap = parameters?.legendMargin ?? 0;
82
+ const titleMargin = parameters?.titlePadding ?? "0px";
83
+ const legendPosition = parameters?.legendPosition ?? "left";
84
+ const titleFontColor = getFontColor(parameters);
85
+ const { xAxisConfig, yAxisConfig } = getAxisConfig(parameters);
58
86
 
59
87
  // Definición eje x
60
88
  const primaryAxis = React.useMemo(
@@ -62,11 +90,11 @@ export const ChartContainer: React.FunctionComponent<Props> = ({
62
90
  getValue: (datum: KeyIndicator) => datum.category,
63
91
  // Tipo band para variables categóricas
64
92
  scaleType: "band",
65
- showGrid: parameters?.showVerticalGrid,
66
- show: parameters?.xAxisEnabled,
67
- position: xAxisPosition,
93
+ show: xAxisConfig.show,
94
+ showGrid: xAxisConfig.showLine,
95
+ position: xAxisConfig.position as Position,
68
96
  }),
69
- [parameters.showVerticalGrid, parameters.xAxisEnabled, xAxisPosition]
97
+ [xAxisConfig]
70
98
  );
71
99
 
72
100
  // Definición eje y
@@ -74,33 +102,19 @@ export const ChartContainer: React.FunctionComponent<Props> = ({
74
102
  (): AxisOptions<KeyIndicator>[] => [
75
103
  {
76
104
  getValue: (datum: KeyIndicator) => datum.performance,
77
- // Se define tipo de gráfico según la configuración
78
- elementType: chartElementType,
79
- scaleType: "linear",
80
- showGrid: parameters?.showHorizontalGrid,
105
+ elementType: yAxisConfig.type as elementType,
81
106
  // Muestra de valores en número decimal
82
107
  formatters: {
83
108
  scale: (value) => value.toFixed(1),
84
109
  },
85
- show: parameters?.yAxisEnabled,
86
- // Para barras apiladas
87
- stacked:
88
- chartElementType === "bar"
89
- ? parameters?.barStacked
90
- ? true
91
- : false
92
- : false,
93
- position: yAxisPosition,
110
+ position: yAxisConfig.position as Position,
111
+ scaleType: "linear",
112
+ show: yAxisConfig.show,
113
+ showGrid: yAxisConfig.showLine,
114
+ stacked: yAxisConfig.stacked,
94
115
  },
95
116
  ],
96
- [
97
- parameters.darkMode,
98
- parameters.chartType,
99
- parameters.barStacked,
100
- parameters.yAxisEnabled,
101
- parameters.showHorizontalGrid,
102
- yAxisPosition,
103
- ]
117
+ [parameters.darkMode, yAxisConfig]
104
118
  );
105
119
 
106
120
  return (
@@ -137,7 +151,7 @@ export const ChartContainer: React.FunctionComponent<Props> = ({
137
151
  parameters: {
138
152
  textFormat: parameters?.legendTextFormat,
139
153
  circleSize: parameters?.circleSize,
140
- darkMode: parameters?.darkMode || false,
154
+ darkMode: parameters?.darkMode ?? false,
141
155
  legendGap: legendGap,
142
156
  legendPosition: legendPosition,
143
157
  },
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import { TextFormat } from "@vixoniccom/modules";
3
3
  import { FormattedText } from "../FormattedText";
4
+ import { getFontColor } from "../utils";
4
5
 
5
6
  type Props = {
6
7
  data: {
@@ -22,12 +23,11 @@ type Props = {
22
23
  */
23
24
  export const ChartLegend: React.FunctionComponent<Props> = ({ data }) => {
24
25
  const params = data.parameters;
25
- const circleSize = params?.circleSize || 8;
26
- const fontColor = !params?.textFormat?.fontColor
27
- ? params?.darkMode
28
- ? "white"
29
- : "black"
30
- : params?.textFormat?.fontColor;
26
+ const circleSize = params?.circleSize ?? 8;
27
+ const fontColor = getFontColor({
28
+ titleTextFormat: params?.textFormat,
29
+ darkMode: params.darkMode,
30
+ });
31
31
  return (
32
32
  // Renderizar contenedor con margen dependiendo de la posición provista en la config.
33
33
  <div
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Archivo que contiene funciones para el corte de datos, limpieza de datos
3
- * y otras verificaciones.
3
+ y otras verificaciones.
4
+ * Contiene además una función para obtener el color de la fuente según parámetros
4
5
  */
5
6
 
6
7
  // Limitar columnas de datos procesados (de izq a der. leyendo la planilla)
@@ -28,13 +29,9 @@ export const nameInHeaders = (name: string, headers: string[]) => {
28
29
 
29
30
  // Verificar integridad de los datos
30
31
  export const checkDataHealth = (headers: string[], rows: string[][]) => {
31
- // Verificar si no hay registros
32
- if (rows.length === 0) return false;
33
-
34
- // Verificar si solo existe la columna de categoría
35
- if (headers.length < 2) return false;
36
-
37
- return true;
32
+ // Verificar si no hay registros o si solo existe la columna de categoria
33
+ const checker = rows.length === 0 || headers.length < 2;
34
+ return !checker;
38
35
  };
39
36
 
40
37
  // Eliminar columnas (según el nombre) y filas duplicadas, conservando la primera aparición
@@ -158,7 +155,7 @@ export const getCleanData = (
158
155
  if (h === "" || h === undefined) {
159
156
  return `nn-feature-${index}`;
160
157
  }
161
- return h.trim().toLocaleLowerCase().replace(/ /g, "-");
158
+ return h.trim().toLocaleLowerCase();
162
159
  });
163
160
 
164
161
  // Eliminación de duplicados (columnas y registros)
@@ -236,3 +233,12 @@ export const dataToSeries = (
236
233
 
237
234
  return items;
238
235
  };
236
+
237
+ // Obtener color de fuente según configuración
238
+ export const getFontColor = (parameters: any) => {
239
+ // En caso de que se defina un color en la configuración, retornarlo
240
+ const fontColorFromFormat = parameters?.titleTextFormat?.fontColor;
241
+ if (fontColorFromFormat) return fontColorFromFormat;
242
+ // En caso contrario, retornar color según tema del gráfico
243
+ return parameters?.darkMode ? "white" : "black";
244
+ }
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%;
@@ -4,12 +4,12 @@
4
4
  "urlRedirectButton": "https://docs.google.com/spreadsheets/d/1IqRcXGIaPOamyMax1uS3-vurAzSI3QTKjABCAPNILGw/edit?usp=sharing",
5
5
  "appPadding": "8vh 8vw 8vh 32vw",
6
6
  "plotType": "bar",
7
+ "darkMode": true,
7
8
  "titleEnabled": false,
8
9
  "title": "Título del gráfico",
9
10
  "titlePadding": "0px 0px 20px 0px",
10
11
  "titleTextFormat": {
11
12
  "fontSize": 32,
12
- "fontColor": "#000000",
13
13
  "alignment": { "horizontal": "center" },
14
14
  "font": {
15
15
  "id": "default-font",