@vixoniccom/kpi-chart 0.0.1 → 0.0.2-dev.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.
@@ -1,244 +0,0 @@
1
- /**
2
- * Archivo que contiene funciones para el corte de datos, limpieza de datos
3
- y otras verificaciones.
4
- * Contiene además una función para obtener el color de la fuente según parámetros
5
- */
6
-
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
- // Verificar si existe nombre de columnas en los datos
26
- export const nameInHeaders = (name: string, headers: string[]) => {
27
- return headers.map((h) => h.trim().toLocaleLowerCase()).includes(name);
28
- };
29
-
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
- // Convertir datos a números, o bien, a fechas o string para la columna de categoría
104
- export const castRecords = (categoryIndex: number, rows: string[][]) => {
105
- return rows.map((row) =>
106
- row.map((value: string, index) => {
107
- if (value === "" || value === undefined) return 0;
108
- const trimmedValue = value.trim();
109
- const numberValue = parseFloat(trimmedValue);
110
- if (index === categoryIndex) {
111
- const date = new Date(trimmedValue);
112
- if (!isNaN(date.getTime())) return date;
113
- if (!isNaN(numberValue)) return numberValue;
114
- return trimmedValue;
115
- }
116
- return numberValue;
117
- })
118
- );
119
- };
120
-
121
- // Ordenar datos según columna de categoría
122
- export const sortRecordsByPeriod = (
123
- categoryIndex: number,
124
- rows: (string | number | Date)[][],
125
- asc: boolean = true
126
- ) => {
127
- return rows.sort((a, b) => {
128
- const valA = a[categoryIndex];
129
- const valB = b[categoryIndex];
130
-
131
- if (valA instanceof Date && valB instanceof Date) {
132
- return asc
133
- ? valA.getTime() - valB.getTime()
134
- : valB.getTime() - valA.getTime();
135
- } else if (typeof valA === "number" && typeof valB === "number") {
136
- return asc ? valA - valB : valB - valA;
137
- } else if (typeof valA === "string" && typeof valB === "string") {
138
- return asc ? valA.localeCompare(valB) : valB.localeCompare(valA);
139
- } else {
140
- return 0;
141
- }
142
- });
143
- };
144
-
145
- // Limpieza de datos provenientes de Google
146
- export const getCleanData = (
147
- categoryColumnName: string,
148
- maxColumnsNumber: number,
149
- data: string[][]
150
- ) => {
151
- const [rawHeaders, ...rawRows] = data;
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
- });
160
-
161
- // Eliminación de duplicados (columnas y registros)
162
- const [headers, ...rows] = removeDuplicates(standarizedHeaders, rawRows);
163
- // Verificar integridad
164
- if (!checkDataHealth(headers, rows)) return [];
165
-
166
- // Identificación del índice de la columna de categoría
167
- let categoryIndex = headers.indexOf(categoryColumnName);
168
-
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
- // Eliminar registros donde el valor en la columna de categoría es nulo
178
- const filteredRows = trimmedRows.filter(
179
- (row) => row && Array.isArray(row) && row[categoryIndex]?.trim() !== ""
180
- );
181
- // Verificar integridad de registros filtrados
182
- if (filteredRows.length === 0) return [];
183
-
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
- // Inputación para datos nulos y conversión numérica
197
- const nonNullRows = castRecords(categoryIndex, denseRows);
198
-
199
- // Ordenar datos ordenados según categoría y retornar
200
- const sortedRows = sortRecordsByPeriod(categoryIndex, nonNullRows);
201
- return [denseHeaders, ...sortedRows];
202
- };
203
-
204
- // Conversión de datos procesados a arreglo de Series para mostrar en gráfico
205
- export const dataToSeries = (
206
- categoryColumnName: string,
207
- data: any
208
- ): Series[] => {
209
- const [headers, ...rows] = data;
210
- const categoryIndex = headers.indexOf(categoryColumnName);
211
-
212
- const items: Series[] = [];
213
-
214
- headers.forEach((header: string, index: number) => {
215
- if (index !== categoryIndex) {
216
- const indicators: KeyIndicator[] = rows.map((row: (number | Date)[]) => {
217
- const categoryValue = row[categoryIndex];
218
- const categoryString =
219
- categoryValue instanceof Date
220
- ? (categoryValue as Date).toISOString().substring(0, 10)
221
- : String(categoryValue);
222
- return {
223
- category: categoryString,
224
- performance: row[index],
225
- };
226
- });
227
- items.push({
228
- label: header,
229
- data: indicators,
230
- });
231
- }
232
- });
233
-
234
- return items;
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/global.d.ts DELETED
@@ -1,9 +0,0 @@
1
- declare type KeyIndicator = {
2
- category: string;
3
- performance: number;
4
- };
5
-
6
- declare type Series = {
7
- label: string;
8
- data: KeyIndicator[];
9
- };
package/src/index.html DELETED
@@ -1,13 +0,0 @@
1
- <!DOCTYPE html>
2
- <html style="position: absolute; height: 100%; width: 100%; overflow: hidden">
3
- <head>
4
- <title>KPI Charts</title>
5
- <meta charset="utf-8" />
6
- </head>
7
- <body style="margin: 0">
8
- <div
9
- id="root"
10
- style="position: absolute; top: 0; right: 0; bottom: 0; left: 0"
11
- ></div>
12
- </body>
13
- </html>
package/src/main.ts DELETED
@@ -1,37 +0,0 @@
1
- import ReactDOM from "react-dom";
2
- import { App } from "./components/App";
3
- import React from "react";
4
- const { ipcRenderer } = require("electron");
5
-
6
- // Variable para controlar el estado de inicio de la aplicación
7
- let start: boolean = false;
8
-
9
- // Se escucha el evento preload recibido por el proceso principal
10
- ipcRenderer.on("preload", (_event: any, data: VixonicData) => {
11
- render(data);
12
- });
13
-
14
- // Se escucha el evento start recibido por el proceso principal
15
- ipcRenderer.on("start", (_event: any, data: VixonicData) => {
16
- // Determinar el inicio de la aplicación
17
- start = true;
18
- render(data);
19
- });
20
-
21
- // Se escucha el evento update que indica la actualización de la configuración
22
- ipcRenderer.on("update", (_event: any, data: VixonicData) => {
23
- render(data);
24
- });
25
-
26
- // Se escucha el evento finish indicando que ha terminado el proceso
27
- ipcRenderer.on("finish", (_event: VixonicData) => {
28
- console.log("finish");
29
- });
30
-
31
- // Función para renderizar la aplicación a través de la renderización del componente App
32
- function render(data: VixonicData) {
33
- ReactDOM.render(
34
- React.createElement(App, { data, start }),
35
- document.getElementById("root")
36
- );
37
- }
@@ -1,9 +0,0 @@
1
- declare type VixonicData = {
2
- downloadsPath: string
3
- services: { [key: string]: { data?: any, updatedAt?: number } }
4
- parameters: VixonicParameters
5
- }
6
-
7
- declare type VixonicParameters = Partial<{
8
- url: string | string, maxColumnsNumber: number, maxRowsNumber: number, updateTime: 300000 | 600000 | 900000 | 1800000 | 3600000, chartType: 'bar' | 'line' | 'area' | 'bubble', barOrientation: 'vertical' | 'horizontal', barStacked: boolean, darkMode: boolean, titleEnabled: boolean, title: string, titleTextFormat: { fontSize?: number, fontColor?: string, alignment?: { horizontal?: 'left' | 'right' | 'center' }, font?: { filename: string, id: string, __isAsset: true } }, titlePadding: string, legendEnabled: boolean, legendTextFormat: { fontSize?: number, fontColor?: string, alignment?: { horizontal?: 'left' | 'right' | 'center' }, font?: { filename: string, id: string, __isAsset: true } }, legendPosition: 'left' | 'right', legendMargin: number, circleSize: number, yAxisEnabled: boolean, showVerticalGrid: boolean, xAxisEnabled: boolean, showHorizontalGrid: boolean, appPadding: string, backgroundImage: {id?: string, filename?: string, extension?: string}, customMessageEnabled: boolean, customMessage: string, systemMessageTextFormat: { fontSize?: number, fontColor?: string, alignment?: { horizontal?: 'left' | 'right' | 'center' }, font?: { filename: string, id: string, __isAsset: true } }
9
- }>
package/src/style.css DELETED
@@ -1,72 +0,0 @@
1
- /* ==========================================
2
- Estilo del contenedor principal de la app
3
- ========================================== */
4
- .app-container {
5
- height: 100vh;
6
- width: 100vw;
7
- /* Fondo */
8
- background-size: cover;
9
- background-position: 50% 50%;
10
- box-sizing: border-box;
11
- }
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
-
22
- .chart-container {
23
- height: 100%;
24
- width: 100%;
25
- /* Flexbox */
26
- display: flex;
27
- flex-direction: column;
28
- align-items: stretch;
29
- justify-content: stretch;
30
- }
31
-
32
- .chart-elements {
33
- height: 100%;
34
- width: 100%;
35
- /* Flexbox */
36
- display: flex;
37
- flex-direction: row;
38
- align-items: stretch;
39
- justify-content: space-evenly;
40
- flex: 1;
41
- }
42
-
43
- .chart {
44
- height: 100%;
45
- width: 100%;
46
- }
47
-
48
- .legend-box {
49
- /* Flexbox */
50
- display: flex;
51
- flex-direction: column;
52
- justify-content: center;
53
- align-items: stretch;
54
- }
55
-
56
- .label-container {
57
- margin-bottom: 10px;
58
- /* Flexbox */
59
- display: flex;
60
- flex-direction: row;
61
- align-items: center;
62
- justify-content: flex-start;
63
- }
64
-
65
- .label-color {
66
- border-radius: 50%;
67
- margin-right: 10px;
68
- }
69
-
70
- .label-text {
71
- width: 100%;
72
- }
Binary file
Binary file
@@ -1,47 +0,0 @@
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
- }