@vixoniccom/kpi-chart 0.0.2-beta.0 → 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,144 +0,0 @@
1
- /**
2
- * Archivo que contiene funciones de verificaciones.
3
- * Contiene además una función para obtener el color de la fuente según parámetros
4
- */
5
-
6
- // Verificar si existe nombre de columnas en los datos
7
- export const nameInHeaders = (name: string, headers: string[]) => {
8
- return headers.map((h) => h.trim().toLocaleLowerCase()).includes(name);
9
- };
10
-
11
- // Convertir datos a números, o bien, a fechas o string para la columna de categoría
12
- export const castRecords = (categoryIndex: number, rows: string[][]) => {
13
- return rows.map((row) =>
14
- row.map((value: string, index) => {
15
- if (value === "" || value === undefined) return 0;
16
- const trimmedValue = value.trim();
17
- const numberValue = parseFloat(trimmedValue);
18
- if (index === categoryIndex) {
19
- const date = new Date(trimmedValue);
20
- if (!isNaN(date.getTime())) return date;
21
- if (!isNaN(numberValue)) return numberValue;
22
- return trimmedValue;
23
- }
24
- return numberValue;
25
- })
26
- );
27
- };
28
-
29
- // Ordenar datos según columna de categoría
30
- export const sortRecordsByPeriod = (
31
- categoryIndex: number,
32
- rows: (string | number | Date)[][],
33
- asc: boolean = true
34
- ) => {
35
- return rows.sort((a, b) => {
36
- const valA = a[categoryIndex];
37
- const valB = b[categoryIndex];
38
-
39
- if (valA instanceof Date && valB instanceof Date) {
40
- return asc
41
- ? valA.getTime() - valB.getTime()
42
- : valB.getTime() - valA.getTime();
43
- } else if (typeof valA === "number" && typeof valB === "number") {
44
- return asc ? valA - valB : valB - valA;
45
- } else if (typeof valA === "string" && typeof valB === "string") {
46
- return asc ? valA.localeCompare(valB) : valB.localeCompare(valA);
47
- } else {
48
- return 0;
49
- }
50
- });
51
- };
52
-
53
- // Limpieza de datos provenientes de Google
54
- export const getCleanData = (
55
- categoryColumnName: string,
56
- data: string[][]
57
- ) => {
58
- const [headers, ...rows] = data;
59
-
60
- // Verificar integridad de headers
61
- if (headers.length < 2) return [];
62
-
63
- // Identificación del índice de la columna de categoría
64
- let categoryIndex = headers.indexOf(categoryColumnName);
65
-
66
- // Eliminar registros donde el valor en la columna de categoría es nulo
67
- const filteredRows = rows.filter(
68
- (row) => row && Array.isArray(row) && row[categoryIndex]?.trim() !== ""
69
- );
70
- // Verificar integridad de registros filtrados
71
- if (filteredRows.length === 0) return [];
72
-
73
- // Inputación para datos nulos y conversión numérica
74
- const nonNullRows = castRecords(categoryIndex, filteredRows);
75
-
76
- // Ordenar datos ordenados según categoría y retornar
77
- const sortedRows = sortRecordsByPeriod(categoryIndex, nonNullRows);
78
- return [headers, ...sortedRows];
79
- };
80
-
81
- // Conversión de datos procesados a arreglo de Series para mostrar en gráfico
82
- export const dataToSeries = (
83
- categoryColumnName: string,
84
- data: any
85
- ): Series[] => {
86
- const [headers, ...rows] = data;
87
- const categoryIndex = headers.indexOf(categoryColumnName);
88
-
89
- const items: Series[] = [];
90
-
91
- headers.forEach((header: string, index: number) => {
92
- if (index !== categoryIndex) {
93
- const indicators: KeyIndicator[] = rows.map((row: (number | Date)[]) => {
94
- const categoryValue = row[categoryIndex];
95
- const categoryString =
96
- categoryValue instanceof Date
97
- ? (categoryValue as Date).toISOString().substring(0, 10)
98
- : String(categoryValue);
99
- return {
100
- category: categoryString,
101
- performance: row[index],
102
- };
103
- });
104
- items.push({
105
- label: header,
106
- data: indicators,
107
- });
108
- }
109
- });
110
-
111
- return items;
112
- };
113
-
114
- // Obtener color de fuente según configuración
115
- export const getFontColor = (parameters: any) => {
116
- // En caso de que se defina un color en la configuración, retornarlo
117
- const fontColorFromFormat = parameters?.titleTextFormat?.fontColor;
118
- if (fontColorFromFormat) return fontColorFromFormat;
119
- // En caso contrario, retornar color según tema del gráfico
120
- return parameters?.darkMode ? "white" : "black";
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
- };
@@ -1,43 +0,0 @@
1
- export class GoogleSheetsDataLoader {
2
-
3
- public onData: ((items: GoogleSheetsItems) => void) | undefined = undefined
4
- private updateTime: number = 86400000
5
- private updateTimer: number | undefined = undefined
6
- private googleData: GoogleSheetsItems = { headers: [], rows: [] }
7
-
8
- update(appData: VixonicData) {
9
-
10
- const selectedServiceId = appData.parameters.documentService?.id
11
- if (!selectedServiceId || !appData.services[selectedServiceId]) return
12
- const serviceData = appData.services[selectedServiceId].data as GoogleSheetsItems[] | undefined
13
-
14
- if (Array.isArray(serviceData)) {
15
- this.googleData = serviceData[0]
16
- } else {
17
- this.googleData = { headers: [], rows: [] } as GoogleSheetsItems
18
- }
19
-
20
- this.updateTime = appData.parameters.updateTime ?? 86400000
21
- this.requestGoogleData()
22
- }
23
-
24
- stop() {
25
- this.setUpdateTime(undefined)
26
- }
27
-
28
- private setUpdateTime(milliseconds: number | undefined) {
29
- window.clearTimeout(this.updateTimer)
30
- if (milliseconds === undefined) return
31
- this.updateTimer = window.setTimeout(this.requestGoogleData, milliseconds)
32
- }
33
-
34
- private dispatchData(items: GoogleSheetsItems) {
35
- this.onData && this.onData(items)
36
- }
37
-
38
- private readonly requestGoogleData = () => {
39
- window.clearTimeout(this.updateTimer)
40
- this.dispatchData(this.googleData)
41
- this.setUpdateTime(this.updateTime > 10000 ? this.updateTime : 10000)
42
- }
43
- }
package/src/global.d.ts DELETED
@@ -1,14 +0,0 @@
1
- declare type GoogleSheetsItems = {
2
- headers: string[]
3
- rows: string[][]
4
- }
5
-
6
- declare type KeyIndicator = {
7
- category: string;
8
- performance: number;
9
- };
10
-
11
- declare type Series = {
12
- label: string;
13
- data: KeyIndicator[];
14
- };
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
- documentService: { id: string }, 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
- }
@@ -1,33 +0,0 @@
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
- }