@vixoniccom/kpi-chart 0.0.1-dev.8 → 0.0.2-beta.0
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/CHANGELOG.md +10 -0
- package/build/index.html +1 -1
- package/build/main.js +2 -129
- package/build/main.js.LICENSE.txt +41 -0
- package/build/test/downloads/background.jpg +0 -0
- package/build/test/downloads/monserrat.ttf +0 -0
- package/build/test/parameters.json +47 -0
- package/build/test/services.json +33 -0
- package/build.zip +0 -0
- package/configuration/generalGroup/index.ts +5 -27
- package/configuration.json +4 -24
- package/package.json +3 -5
- package/src/components/App.tsx +17 -134
- package/src/components/ChartContainer/index.tsx +14 -2
- package/src/components/utils.ts +30 -130
- package/src/data-loader.ts +43 -0
- package/src/global.d.ts +5 -0
- package/src/parameters.d.ts +1 -1
- package/src/test/services.json +33 -0
- package/tsconfig.json +4 -4
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
object-assign
|
|
3
|
+
(c) Sindre Sorhus
|
|
4
|
+
@license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** @license React v0.20.2
|
|
8
|
+
* scheduler.production.min.js
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
11
|
+
*
|
|
12
|
+
* This source code is licensed under the MIT license found in the
|
|
13
|
+
* LICENSE file in the root directory of this source tree.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** @license React v17.0.2
|
|
17
|
+
* react-dom.production.min.js
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
20
|
+
*
|
|
21
|
+
* This source code is licensed under the MIT license found in the
|
|
22
|
+
* LICENSE file in the root directory of this source tree.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** @license React v17.0.2
|
|
26
|
+
* react-jsx-runtime.production.min.js
|
|
27
|
+
*
|
|
28
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
29
|
+
*
|
|
30
|
+
* This source code is licensed under the MIT license found in the
|
|
31
|
+
* LICENSE file in the root directory of this source tree.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/** @license React v17.0.2
|
|
35
|
+
* react.production.min.js
|
|
36
|
+
*
|
|
37
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
38
|
+
*
|
|
39
|
+
* This source code is licensed under the MIT license found in the
|
|
40
|
+
* LICENSE file in the root directory of this source tree.
|
|
41
|
+
*/
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parameters": {
|
|
3
|
+
"url": "https://docs.google.com/spreadsheets/d/1IqRcXGIaPOamyMax1uS3-vurAzSI3QTKjABCAPNILGw/edit?usp=sharing",
|
|
4
|
+
"urlRedirectButton": "https://docs.google.com/spreadsheets/d/1IqRcXGIaPOamyMax1uS3-vurAzSI3QTKjABCAPNILGw/edit?usp=sharing",
|
|
5
|
+
"appPadding": "8vh 8vw 8vh 32vw",
|
|
6
|
+
"plotType": "bar",
|
|
7
|
+
"darkMode": true,
|
|
8
|
+
"titleEnabled": false,
|
|
9
|
+
"title": "Título del gráfico",
|
|
10
|
+
"titlePadding": "0px 0px 20px 0px",
|
|
11
|
+
"titleTextFormat": {
|
|
12
|
+
"fontSize": 32,
|
|
13
|
+
"alignment": { "horizontal": "center" },
|
|
14
|
+
"font": {
|
|
15
|
+
"id": "default-font",
|
|
16
|
+
"filename": "monserrat.ttf",
|
|
17
|
+
"__isAsset": true
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"legendEnabled": true,
|
|
21
|
+
"legendMargin": 20,
|
|
22
|
+
"legendTextFormat": {
|
|
23
|
+
"fontSize": 12,
|
|
24
|
+
"alignment": { "horizontal": "center" },
|
|
25
|
+
"font": {
|
|
26
|
+
"id": "default-font",
|
|
27
|
+
"filename": "monserrat.ttf",
|
|
28
|
+
"__isAsset": true
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"systemMessageTextFormat": {
|
|
32
|
+
"fontSize": 36,
|
|
33
|
+
"fontColor": "#000000",
|
|
34
|
+
"alignment": { "horizontal": "center" },
|
|
35
|
+
"font": {
|
|
36
|
+
"id": "default-font",
|
|
37
|
+
"filename": "monserrat.ttf",
|
|
38
|
+
"__isAsset": true
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"backgroundImage": {
|
|
42
|
+
"id": "background",
|
|
43
|
+
"filename": "background.jpg",
|
|
44
|
+
"__isAsset": true
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"services": {
|
|
3
|
+
"testService": {
|
|
4
|
+
"id": "c3f92c8b-7b1d-44d4-8e79-6d92b87cf4f1",
|
|
5
|
+
"data": [{
|
|
6
|
+
"headers": [
|
|
7
|
+
"category",
|
|
8
|
+
"Agents",
|
|
9
|
+
"Longest Wait Time (min)",
|
|
10
|
+
"Avg Vote to Agents",
|
|
11
|
+
"Call abounded",
|
|
12
|
+
"Call Presented",
|
|
13
|
+
"Call Handled"
|
|
14
|
+
],
|
|
15
|
+
"rows": [
|
|
16
|
+
["2022-5-9", "9", "4", "8", "3", "3", "0"],
|
|
17
|
+
["2022-5-8", "8", "1", "1", "9", "1", "2"],
|
|
18
|
+
["2022-5-7", "6", "6", "3", "6", "1", "5"],
|
|
19
|
+
["2022-5-6", "8", "8", "9", "8", "7", "9"],
|
|
20
|
+
["2022-5-5", "9", "8", "4", "6", "9", "3"],
|
|
21
|
+
["2022-5-4", "9", "6", "3", "4", "4", "0"],
|
|
22
|
+
["2022-5-3", "9", "3", "7", "3", "0", "0"],
|
|
23
|
+
["2022-5-24", "10", "7", "9", "8", "7", "9"],
|
|
24
|
+
["2022-5-23", "8", "1", "2", "6", "5", "7"],
|
|
25
|
+
["2022-5-22", "8", "8", "5", "3", "0", "0"],
|
|
26
|
+
["2022-5-21", "9", "8", "6", "1", "4", "4"],
|
|
27
|
+
["2022-5-20", "9", "3", "6", "3", "7", "4"],
|
|
28
|
+
["2022-5-2", "9", "3", "7", "9", "5", "6"]
|
|
29
|
+
]
|
|
30
|
+
}]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
package/build.zip
CHANGED
|
Binary file
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Group,
|
|
3
3
|
Label,
|
|
4
|
-
NumberInput,
|
|
5
|
-
NumberRangeValue,
|
|
6
|
-
RedirectButton,
|
|
7
4
|
SelectInput,
|
|
8
|
-
|
|
5
|
+
ServiceInput,
|
|
9
6
|
} from "@vixoniccom/modules";
|
|
10
7
|
|
|
11
8
|
// Configuración general: URL fuente, cantidad de columnas y filas, tiempo de actualización y mensaje por defecto
|
|
@@ -14,29 +11,10 @@ export const generalGroup = new Group({
|
|
|
14
11
|
label: "General",
|
|
15
12
|
items: [
|
|
16
13
|
new Label({ label: "Datos" }),
|
|
17
|
-
new
|
|
18
|
-
id:
|
|
19
|
-
label:
|
|
20
|
-
|
|
21
|
-
required: true,
|
|
22
|
-
}),
|
|
23
|
-
new RedirectButton({
|
|
24
|
-
id: "url",
|
|
25
|
-
label: "Ir al documento",
|
|
26
|
-
}),
|
|
27
|
-
new NumberInput({
|
|
28
|
-
id: "maxColumnsNumber",
|
|
29
|
-
label: "Cantidad de columnas",
|
|
30
|
-
range: new NumberRangeValue(1, 10, 1),
|
|
31
|
-
description:
|
|
32
|
-
"Máxima cantidad de columnas por mostrar (sin considerar categoría). Entre 1 y 10 (3 por defecto).",
|
|
33
|
-
}),
|
|
34
|
-
new NumberInput({
|
|
35
|
-
id: "maxRowsNumber",
|
|
36
|
-
label: "Cantidad de filas",
|
|
37
|
-
range: new NumberRangeValue(1, 100, 1),
|
|
38
|
-
description:
|
|
39
|
-
"Máxima cantidad de filas por mostrar. Entre 1 y 100 (6 por defecto).",
|
|
14
|
+
new ServiceInput({
|
|
15
|
+
id: 'documentService',
|
|
16
|
+
label: 'Documento',
|
|
17
|
+
serviceType: 'SheetsReaderService',
|
|
40
18
|
}),
|
|
41
19
|
new SelectInput({
|
|
42
20
|
id: "updateTime",
|
package/configuration.json
CHANGED
|
@@ -10,30 +10,10 @@
|
|
|
10
10
|
"label": "Datos"
|
|
11
11
|
},
|
|
12
12
|
{
|
|
13
|
-
"id": "
|
|
14
|
-
"label": "
|
|
15
|
-
"type": "
|
|
16
|
-
"
|
|
17
|
-
"required": true
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"id": "url",
|
|
21
|
-
"label": "Ir al documento",
|
|
22
|
-
"type": "redirect-button"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"id": "maxColumnsNumber",
|
|
26
|
-
"label": "Cantidad de columnas",
|
|
27
|
-
"type": "number-input",
|
|
28
|
-
"range": "[1:10:1]",
|
|
29
|
-
"description": "Máxima cantidad de columnas por mostrar (sin considerar categoría). Entre 1 y 10 (3 por defecto)."
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"id": "maxRowsNumber",
|
|
33
|
-
"label": "Cantidad de filas",
|
|
34
|
-
"type": "number-input",
|
|
35
|
-
"range": "[1:100:1]",
|
|
36
|
-
"description": "Máxima cantidad de filas por mostrar. Entre 1 y 100 (6 por defecto)."
|
|
13
|
+
"id": "documentService",
|
|
14
|
+
"label": "Documento",
|
|
15
|
+
"type": "service-input",
|
|
16
|
+
"serviceType": "SheetsReaderService"
|
|
37
17
|
},
|
|
38
18
|
{
|
|
39
19
|
"id": "updateTime",
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"author": {
|
|
9
9
|
"name": "Lorenzo Alfaro Bravo"
|
|
10
10
|
},
|
|
11
|
-
"version": "0.0.
|
|
11
|
+
"version": "0.0.2-beta.0",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"prepublishOnly": "vixonic-module-packager --mode=build",
|
|
14
14
|
"watch": "vixonic-module-packager --mode=watch",
|
|
@@ -20,8 +20,6 @@
|
|
|
20
20
|
"prerelease-dev": "standard-version --prerelease dev"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"axios": "^1.6.0",
|
|
24
|
-
"localforage": "^1.10.0",
|
|
25
23
|
"react": "^17.0.2",
|
|
26
24
|
"react-charts": "^3.0.0-beta.57",
|
|
27
25
|
"react-dom": "^17.0.2",
|
|
@@ -30,8 +28,8 @@
|
|
|
30
28
|
"devDependencies": {
|
|
31
29
|
"@types/react": "^17.0.2",
|
|
32
30
|
"@types/react-dom": "^17.0.11",
|
|
33
|
-
"@vixoniccom/module-packager": "^2.
|
|
34
|
-
"@vixoniccom/modules": "
|
|
31
|
+
"@vixoniccom/module-packager": "^2.13.0",
|
|
32
|
+
"@vixoniccom/modules": "2.23.0-dev.6",
|
|
35
33
|
"standard-version": "^9.5.0"
|
|
36
34
|
}
|
|
37
35
|
}
|
package/src/components/App.tsx
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import localforage from "localforage";
|
|
4
|
-
import { Circles } from "react-loader-spinner";
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
5
2
|
import { FontLoader } from "./FontLoader";
|
|
6
3
|
import { ChartContainer } from "./ChartContainer";
|
|
7
4
|
import { FormattedText } from "./FormattedText";
|
|
8
5
|
import "../style.css";
|
|
9
|
-
import {
|
|
10
|
-
checkDataHealth,
|
|
11
|
-
dataToSeries,
|
|
12
|
-
getCleanData,
|
|
13
|
-
nameInHeaders,
|
|
14
|
-
sliceFeatures,
|
|
15
|
-
sliceRecords,
|
|
16
|
-
} from "./utils";
|
|
6
|
+
import { processData } from "./utils";
|
|
17
7
|
|
|
18
8
|
interface Props {
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
appData: VixonicData
|
|
10
|
+
googleSheetsItems: GoogleSheetsItems
|
|
11
|
+
start: boolean
|
|
21
12
|
}
|
|
22
13
|
|
|
23
14
|
// Definición de paths de las fuentes provenientes de la configuración
|
|
@@ -32,16 +23,15 @@ const fontPaths = [
|
|
|
32
23
|
* Es llamada una vez ha sido inicializada (start == true).
|
|
33
24
|
* Obtiene los datos según tiempo de actualización definido en la configuración.
|
|
34
25
|
*/
|
|
35
|
-
export const App: React.FunctionComponent<Props> = ({
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
export const App: React.FunctionComponent<Props> = ({ appData, googleSheetsItems, start }) => {
|
|
27
|
+
|
|
28
|
+
if (!appData || !start) return null;
|
|
29
|
+
|
|
30
|
+
const params = appData.parameters;
|
|
38
31
|
const appPadding = params?.appPadding ?? "0px";
|
|
39
|
-
const updateTime = params?.updateTime ?? 3600000;
|
|
40
32
|
const backgroundImageState = params?.backgroundImage
|
|
41
|
-
? `url("${
|
|
33
|
+
? `url("${appData.downloadsPath}/${params?.backgroundImage.filename}")`
|
|
42
34
|
: "";
|
|
43
|
-
const [loading, setLoading] = useState<boolean>(false);
|
|
44
|
-
// Definición de variable que contiene los datos procesados provenientes de la URL
|
|
45
35
|
const [sheetData, setSheetData] = useState<Series[]>([]);
|
|
46
36
|
// Definición de mensaje del sistema
|
|
47
37
|
const [systemMessage, setSystemMessage] = useState<string>(
|
|
@@ -49,115 +39,12 @@ export const App: React.FunctionComponent<Props> = ({ data, start }) => {
|
|
|
49
39
|
);
|
|
50
40
|
// Definición de nombre fijo de columna de categoría
|
|
51
41
|
const categoryColumnName = "category";
|
|
52
|
-
// Definición de cantidad máxima de columnas y filas para procesar desde Google
|
|
53
|
-
const fixedMaxRows = 100;
|
|
54
|
-
const fixedMaxColumns = 10; // 10 máx, no usar más, a menos que sea agreguen más colores en ChartContainer
|
|
55
|
-
// Definición de cantidad de columnas y filas para mostrar en la aplicación
|
|
56
|
-
const rowsNumber = params?.maxRowsNumber ?? 6;
|
|
57
|
-
const columnsNumber = params?.maxColumnsNumber ?? 3;
|
|
58
|
-
|
|
59
|
-
// Función para hacer request de Google y almacenar los datos procesados en localforage
|
|
60
|
-
const getData = async () => {
|
|
61
|
-
setLoading(true);
|
|
62
|
-
const googleID = params?.url?.split("/")[5];
|
|
63
|
-
const key = getStorageKey(googleID);
|
|
64
|
-
localforage.clear();
|
|
65
|
-
const storedData: any = await localforage.getItem(key);
|
|
66
|
-
if (!storedData?.items || storedData?.items?.length === 0) {
|
|
67
|
-
const data = await requestData(googleID);
|
|
68
|
-
localforage.setItem(key, { items: data, date: Date.now() });
|
|
69
|
-
setDataAndTime(data, updateTime);
|
|
70
|
-
} else {
|
|
71
|
-
const now = Date.now();
|
|
72
|
-
const targetDate = storedData.date + updateTime;
|
|
73
|
-
if (now >= targetDate) {
|
|
74
|
-
const data = await requestData(googleID);
|
|
75
|
-
setDataAndTime(data, targetDate - now);
|
|
76
|
-
localforage.setItem(key, { items: data, date: now });
|
|
77
|
-
} else {
|
|
78
|
-
setDataAndTime(storedData.items, targetDate - now);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
setLoading(false);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// Función para actualizar el estado de los datos y el tiempo de actualización
|
|
85
|
-
const setDataAndTime = (data: Series[], time: number) => {
|
|
86
|
-
setSheetData(
|
|
87
|
-
// Slice de columnas
|
|
88
|
-
sliceFeatures(
|
|
89
|
-
columnsNumber,
|
|
90
|
-
// Slice de filas
|
|
91
|
-
sliceRecords(rowsNumber, data)
|
|
92
|
-
)
|
|
93
|
-
);
|
|
94
|
-
setUpdateTime(time);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const setUpdateTime = (milliseconds: number) => {
|
|
98
|
-
clearTimeout(updateTimer);
|
|
99
|
-
if (milliseconds === null) return;
|
|
100
|
-
updateTimer = setTimeout(getData, milliseconds);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const requestData = async (googleID?: string) => {
|
|
104
|
-
const URL = `https://sheets.googleapis.com/v4/spreadsheets/${googleID}/values`;
|
|
105
|
-
try {
|
|
106
|
-
const response = await axios.get(`${URL}/data`, {
|
|
107
|
-
params: { key: "AIzaSyDQcTlxfd5IyjbeSJooRtNt6OF04DLykqc" },
|
|
108
|
-
});
|
|
109
|
-
return processData(response.data.values);
|
|
110
|
-
} catch (error: unknown) {
|
|
111
|
-
if (error instanceof Error) {
|
|
112
|
-
setSystemMessage(error.message);
|
|
113
|
-
} else {
|
|
114
|
-
setSystemMessage("Error al cargar los datos");
|
|
115
|
-
}
|
|
116
|
-
return [];
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// Función para procesar datos (slice de filas, revisar integridad de datos y
|
|
121
|
-
// limpiar los datos)
|
|
122
|
-
const processData = (data: string[][]) => {
|
|
123
|
-
const [rawHeaders, ...rawRows] = data;
|
|
124
|
-
const rows = rawRows.slice(-fixedMaxRows);
|
|
125
|
-
if (isDataHealthy(rawHeaders, rows)) {
|
|
126
|
-
const cleanedData = getCleanData(categoryColumnName, fixedMaxColumns, [
|
|
127
|
-
rawHeaders,
|
|
128
|
-
...rows,
|
|
129
|
-
]);
|
|
130
|
-
// Si hay datos limpios, convertirlos a un arreglo de Series
|
|
131
|
-
if (cleanedData.length !== 0) {
|
|
132
|
-
return dataToSeries(categoryColumnName, cleanedData);
|
|
133
|
-
}
|
|
134
|
-
setSystemMessage("Después de limpieza, no hay datos para mostrar");
|
|
135
|
-
}
|
|
136
|
-
return [];
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// Función para verificar si existe la columna de categoría y revisar la integridad de datos
|
|
140
|
-
const isDataHealthy = (headers: string[], rows: string[][]) => {
|
|
141
|
-
if (!nameInHeaders(categoryColumnName, headers)) {
|
|
142
|
-
setSystemMessage(`Columna '${categoryColumnName}' no existente`);
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
if (!checkDataHealth(headers, rows)) {
|
|
146
|
-
setSystemMessage("Falta de registros o columna con datos");
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
return true;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const getStorageKey = (googleID?: string) => {
|
|
153
|
-
const key = googleID?.replace(/[^a-z0-9]/gi, "");
|
|
154
|
-
return `sheets${key?.toLowerCase()}`;
|
|
155
|
-
};
|
|
156
42
|
|
|
157
43
|
useEffect(() => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
44
|
+
const { data, systemMessage } = processData(googleSheetsItems, categoryColumnName);
|
|
45
|
+
setSheetData(data);
|
|
46
|
+
setSystemMessage(systemMessage);
|
|
47
|
+
}, [googleSheetsItems]);
|
|
161
48
|
|
|
162
49
|
return (
|
|
163
50
|
<div
|
|
@@ -171,14 +58,10 @@ export const App: React.FunctionComponent<Props> = ({ data, start }) => {
|
|
|
171
58
|
<FontLoader
|
|
172
59
|
paths={fontPaths}
|
|
173
60
|
parameters={params}
|
|
174
|
-
downloadsPath={
|
|
61
|
+
downloadsPath={appData.downloadsPath}
|
|
175
62
|
/>
|
|
176
63
|
{/* Render de chart o mensaje del sistema/personalizado */}
|
|
177
|
-
{
|
|
178
|
-
<div className="loading-container">
|
|
179
|
-
<Circles ariaLabel="loading-indicator" color="gray" />
|
|
180
|
-
</div>
|
|
181
|
-
) : sheetData.length > 0 ? (
|
|
64
|
+
{sheetData.length > 0 ? (
|
|
182
65
|
<ChartContainer data={sheetData} parameters={params} />
|
|
183
66
|
) : (
|
|
184
67
|
<FormattedText
|
|
@@ -33,6 +33,15 @@ const defaultColors = [
|
|
|
33
33
|
"#7F7F7F", // Gris
|
|
34
34
|
];
|
|
35
35
|
|
|
36
|
+
// Función para generar colores repetidos según la cantidad de series
|
|
37
|
+
const generateRepeatedColors = (seriesCount: number): string[] => {
|
|
38
|
+
const colors: string[] = [];
|
|
39
|
+
for (let i = 0; i < seriesCount; i++) {
|
|
40
|
+
colors.push(defaultColors[i % defaultColors.length]);
|
|
41
|
+
}
|
|
42
|
+
return colors;
|
|
43
|
+
};
|
|
44
|
+
|
|
36
45
|
// Obtener configuraciones de ejes según parámetros de configuración
|
|
37
46
|
const getAxisConfig = (parameters: VixonicParameters) => {
|
|
38
47
|
|
|
@@ -84,6 +93,9 @@ export const ChartContainer: React.FunctionComponent<Props> = ({
|
|
|
84
93
|
const titleFontColor = getFontColor(parameters);
|
|
85
94
|
const { xAxisConfig, yAxisConfig } = getAxisConfig(parameters);
|
|
86
95
|
|
|
96
|
+
// Generar colores repetidos basándose en la cantidad de series
|
|
97
|
+
const chartColors = generateRepeatedColors(data.length);
|
|
98
|
+
|
|
87
99
|
// Definición eje x
|
|
88
100
|
const primaryAxis = React.useMemo(
|
|
89
101
|
(): AxisOptions<KeyIndicator> => ({
|
|
@@ -147,7 +159,7 @@ export const ChartContainer: React.FunctionComponent<Props> = ({
|
|
|
147
159
|
<ChartLegend
|
|
148
160
|
data={{
|
|
149
161
|
labels: data.map((series) => series.label),
|
|
150
|
-
colors:
|
|
162
|
+
colors: chartColors,
|
|
151
163
|
parameters: {
|
|
152
164
|
textFormat: parameters?.legendTextFormat,
|
|
153
165
|
circleSize: parameters?.circleSize,
|
|
@@ -165,7 +177,7 @@ export const ChartContainer: React.FunctionComponent<Props> = ({
|
|
|
165
177
|
primaryAxis,
|
|
166
178
|
secondaryAxes,
|
|
167
179
|
dark: parameters?.darkMode,
|
|
168
|
-
defaultColors:
|
|
180
|
+
defaultColors: chartColors,
|
|
169
181
|
// Esconder leyenda por defecto e interacciones con cursor
|
|
170
182
|
tooltip: {
|
|
171
183
|
show: false,
|
package/src/components/utils.ts
CHANGED
|
@@ -1,105 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Archivo que contiene funciones
|
|
3
|
-
y otras verificaciones.
|
|
2
|
+
* Archivo que contiene funciones de verificaciones.
|
|
4
3
|
* Contiene además una función para obtener el color de la fuente según parámetros
|
|
5
4
|
*/
|
|
6
5
|
|
|
7
|
-
// Limitar columnas de datos procesados (de izq a der. leyendo la planilla)
|
|
8
|
-
export const sliceFeatures = (columnsNumber: number, data: Series[]) => {
|
|
9
|
-
return data.slice(0, columnsNumber);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// Limitar la cantidad de filas, con opción para considerar las primeras o últimas n
|
|
13
|
-
export const sliceRecords = (
|
|
14
|
-
rowsNumber: number,
|
|
15
|
-
data: Series[],
|
|
16
|
-
period: string = "newer"
|
|
17
|
-
) => {
|
|
18
|
-
const nToSlice = period === "newer" ? -rowsNumber : rowsNumber;
|
|
19
|
-
return data.map((series) => ({
|
|
20
|
-
label: series.label,
|
|
21
|
-
data: series.data.slice(nToSlice),
|
|
22
|
-
}));
|
|
23
|
-
};
|
|
24
|
-
|
|
25
6
|
// Verificar si existe nombre de columnas en los datos
|
|
26
7
|
export const nameInHeaders = (name: string, headers: string[]) => {
|
|
27
8
|
return headers.map((h) => h.trim().toLocaleLowerCase()).includes(name);
|
|
28
9
|
};
|
|
29
10
|
|
|
30
|
-
// Verificar integridad de los datos
|
|
31
|
-
export const checkDataHealth = (headers: string[], rows: string[][]) => {
|
|
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;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// Eliminar columnas (según el nombre) y filas duplicadas, conservando la primera aparición
|
|
38
|
-
export const removeDuplicates = (headers: string[], rows: string[][]) => {
|
|
39
|
-
const seenCol = new Set<string>();
|
|
40
|
-
const seenRow = new Set<string>();
|
|
41
|
-
|
|
42
|
-
const uniqueColumnIndices = headers
|
|
43
|
-
.map((col, i) => (seenCol.has(col) ? -1 : (seenCol.add(col), i)))
|
|
44
|
-
.filter((i) => i !== -1);
|
|
45
|
-
|
|
46
|
-
const filterColumns = (row: string[]) =>
|
|
47
|
-
uniqueColumnIndices.map((i) => row[i]);
|
|
48
|
-
|
|
49
|
-
const uniqueHeaders = filterColumns(headers);
|
|
50
|
-
|
|
51
|
-
const newRows = rows.map(filterColumns);
|
|
52
|
-
const uniqueRows = newRows.filter((row) => {
|
|
53
|
-
const rowString = JSON.stringify(row);
|
|
54
|
-
if (seenRow.has(rowString)) return false;
|
|
55
|
-
seenRow.add(rowString);
|
|
56
|
-
return true;
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
return [uniqueHeaders, ...uniqueRows];
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// Eliminar columnas que no cumplan con una cantidad de datos
|
|
63
|
-
export const removePartialData = (
|
|
64
|
-
categoryIndex: number,
|
|
65
|
-
headers: string[],
|
|
66
|
-
rows: string[][],
|
|
67
|
-
threshold: number = 0.9
|
|
68
|
-
) => {
|
|
69
|
-
const validColumnIndices = headers.map((_, colIndex) => {
|
|
70
|
-
if (colIndex === categoryIndex) return true;
|
|
71
|
-
const totalRows = rows.length;
|
|
72
|
-
const nonNullCount = rows.reduce((count, row) => {
|
|
73
|
-
const value = row[colIndex];
|
|
74
|
-
return count + (value !== undefined && value !== "" ? 1 : 0);
|
|
75
|
-
}, 0);
|
|
76
|
-
return nonNullCount / totalRows >= threshold;
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const denseHeaders = headers.filter((_, i) => validColumnIndices[i]);
|
|
80
|
-
const denseRows = rows.map((row) =>
|
|
81
|
-
row.filter((_, i) => validColumnIndices[i])
|
|
82
|
-
);
|
|
83
|
-
return [denseHeaders, ...denseRows];
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// Limitar columnas de datos provenientes de Google (de izq. a der. leyendo la planilla)
|
|
87
|
-
export const sliceColumns = (
|
|
88
|
-
categoryIndex: number,
|
|
89
|
-
maxColumnsNumber: number,
|
|
90
|
-
headers: string[],
|
|
91
|
-
rows: string[][]
|
|
92
|
-
) => {
|
|
93
|
-
const selectedColumns = headers
|
|
94
|
-
.map((_, i) => i)
|
|
95
|
-
.filter((i) => i === categoryIndex || i <= maxColumnsNumber);
|
|
96
|
-
const filterColumns = (row: string[]) => selectedColumns.map((i) => row[i]);
|
|
97
|
-
const trimmedHeaders = filterColumns(headers);
|
|
98
|
-
const trimmedRows = rows.map(filterColumns);
|
|
99
|
-
|
|
100
|
-
return [trimmedHeaders, ...trimmedRows];
|
|
101
|
-
};
|
|
102
|
-
|
|
103
11
|
// Convertir datos a números, o bien, a fechas o string para la columna de categoría
|
|
104
12
|
export const castRecords = (categoryIndex: number, rows: string[][]) => {
|
|
105
13
|
return rows.map((row) =>
|
|
@@ -145,60 +53,29 @@ export const sortRecordsByPeriod = (
|
|
|
145
53
|
// Limpieza de datos provenientes de Google
|
|
146
54
|
export const getCleanData = (
|
|
147
55
|
categoryColumnName: string,
|
|
148
|
-
maxColumnsNumber: number,
|
|
149
56
|
data: string[][]
|
|
150
57
|
) => {
|
|
151
|
-
const [
|
|
152
|
-
|
|
153
|
-
// Estandarización de headers
|
|
154
|
-
const standarizedHeaders = rawHeaders.map((h, index) => {
|
|
155
|
-
if (h === "" || h === undefined) {
|
|
156
|
-
return `nn-feature-${index}`;
|
|
157
|
-
}
|
|
158
|
-
return h.trim().toLocaleLowerCase();
|
|
159
|
-
});
|
|
58
|
+
const [headers, ...rows] = data;
|
|
160
59
|
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
// Verificar integridad
|
|
164
|
-
if (!checkDataHealth(headers, rows)) return [];
|
|
60
|
+
// Verificar integridad de headers
|
|
61
|
+
if (headers.length < 2) return [];
|
|
165
62
|
|
|
166
63
|
// Identificación del índice de la columna de categoría
|
|
167
64
|
let categoryIndex = headers.indexOf(categoryColumnName);
|
|
168
65
|
|
|
169
|
-
// Conservar un máximo de columnas (sin considerar categoría)
|
|
170
|
-
const [trimmedHeaders, ...trimmedRows] = sliceColumns(
|
|
171
|
-
categoryIndex,
|
|
172
|
-
maxColumnsNumber,
|
|
173
|
-
headers,
|
|
174
|
-
rows
|
|
175
|
-
);
|
|
176
|
-
|
|
177
66
|
// Eliminar registros donde el valor en la columna de categoría es nulo
|
|
178
|
-
const filteredRows =
|
|
67
|
+
const filteredRows = rows.filter(
|
|
179
68
|
(row) => row && Array.isArray(row) && row[categoryIndex]?.trim() !== ""
|
|
180
69
|
);
|
|
181
70
|
// Verificar integridad de registros filtrados
|
|
182
71
|
if (filteredRows.length === 0) return [];
|
|
183
72
|
|
|
184
|
-
// Eliminar columnas que poseen menos del 90% de información (sin considerar categoría)
|
|
185
|
-
const [denseHeaders, ...denseRows] = removePartialData(
|
|
186
|
-
categoryIndex,
|
|
187
|
-
trimmedHeaders,
|
|
188
|
-
filteredRows
|
|
189
|
-
);
|
|
190
|
-
// Verificar integridad de headers
|
|
191
|
-
if (denseHeaders.length < 2) return [];
|
|
192
|
-
|
|
193
|
-
// Update del índice de la columna de categoría
|
|
194
|
-
categoryIndex = denseHeaders.indexOf(categoryColumnName);
|
|
195
|
-
|
|
196
73
|
// Inputación para datos nulos y conversión numérica
|
|
197
|
-
const nonNullRows = castRecords(categoryIndex,
|
|
74
|
+
const nonNullRows = castRecords(categoryIndex, filteredRows);
|
|
198
75
|
|
|
199
76
|
// Ordenar datos ordenados según categoría y retornar
|
|
200
77
|
const sortedRows = sortRecordsByPeriod(categoryIndex, nonNullRows);
|
|
201
|
-
return [
|
|
78
|
+
return [headers, ...sortedRows];
|
|
202
79
|
};
|
|
203
80
|
|
|
204
81
|
// Conversión de datos procesados a arreglo de Series para mostrar en gráfico
|
|
@@ -242,3 +119,26 @@ export const getFontColor = (parameters: any) => {
|
|
|
242
119
|
// En caso contrario, retornar color según tema del gráfico
|
|
243
120
|
return parameters?.darkMode ? "white" : "black";
|
|
244
121
|
}
|
|
122
|
+
|
|
123
|
+
// Función para validar, procesar y castear datos
|
|
124
|
+
export const processData = (data: GoogleSheetsItems, categoryColumnName: string) => {
|
|
125
|
+
|
|
126
|
+
let result = {data: [] as Series[], systemMessage: "Después de procesar, no hay datos para mostrar"};
|
|
127
|
+
|
|
128
|
+
const categoryInHeaders = nameInHeaders(categoryColumnName, data.headers);
|
|
129
|
+
if (!categoryInHeaders) {
|
|
130
|
+
result.systemMessage = `Columna '${categoryColumnName}' no existente`;
|
|
131
|
+
} else {
|
|
132
|
+
const cleanedData = getCleanData(
|
|
133
|
+
categoryColumnName,
|
|
134
|
+
[data.headers, ...data.rows]
|
|
135
|
+
);
|
|
136
|
+
// Si pasa la verificación, convertirlos a un arreglo de Series
|
|
137
|
+
if (cleanedData.length !== 0) {
|
|
138
|
+
result.data = dataToSeries(categoryColumnName, cleanedData);
|
|
139
|
+
result.systemMessage = "Datos cargados correctamente";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return result;
|
|
144
|
+
};
|