@vixoniccom/kpi-chart 0.0.1-dev.5 → 0.0.1-dev.7
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 +14 -0
- package/build/main.js +7 -7
- package/build.zip +0 -0
- package/icon.png +0 -0
- package/package.json +4 -4
- package/src/components/App.tsx +4 -4
- package/src/components/ChartContainer/index.tsx +63 -49
- package/src/components/ChartLegend/index.tsx +6 -6
- package/src/components/utils.ts +14 -8
- package/src/test/parameters.json +1 -1
package/build.zip
CHANGED
|
Binary file
|
package/icon.png
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"name": "@vixoniccom/kpi-chart",
|
|
3
3
|
"alias": "KPI Chart",
|
|
4
4
|
"description": "Muestra un gráfico según indicadores KPI.",
|
|
5
|
-
"color": "#
|
|
5
|
+
"color": "#009900",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"tags": [],
|
|
8
8
|
"author": {
|
|
9
9
|
"name": "Lorenzo Alfaro Bravo"
|
|
10
10
|
},
|
|
11
|
-
"version": "0.0.1-dev.
|
|
11
|
+
"version": "0.0.1-dev.7",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"prepublishOnly": "vixonic-module-packager --mode=build",
|
|
14
14
|
"watch": "vixonic-module-packager --mode=watch",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"react-loader-spinner": "^6.1.6"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/react": "^
|
|
32
|
-
"@types/react-dom": "^
|
|
31
|
+
"@types/react": "^17.0.2",
|
|
32
|
+
"@types/react-dom": "^17.0.11",
|
|
33
33
|
"@vixoniccom/module-packager": "^2.10.1",
|
|
34
34
|
"@vixoniccom/modules": "^2.20.0",
|
|
35
35
|
"standard-version": "^9.5.0"
|
package/src/components/App.tsx
CHANGED
|
@@ -35,8 +35,8 @@ const fontPaths = [
|
|
|
35
35
|
export const App: React.FunctionComponent<Props> = ({ data, start }) => {
|
|
36
36
|
let updateTimer: any;
|
|
37
37
|
const params = data.parameters;
|
|
38
|
-
const appPadding = params?.appPadding
|
|
39
|
-
const updateTime = params?.updateTime
|
|
38
|
+
const appPadding = params?.appPadding ?? "0px";
|
|
39
|
+
const updateTime = params?.updateTime ?? 3600000;
|
|
40
40
|
const backgroundImageState = params?.backgroundImage
|
|
41
41
|
? `url("${data.downloadsPath}/${params?.backgroundImage.filename}")`
|
|
42
42
|
: "";
|
|
@@ -53,8 +53,8 @@ export const App: React.FunctionComponent<Props> = ({ data, start }) => {
|
|
|
53
53
|
const fixedMaxRows = 100;
|
|
54
54
|
const fixedMaxColumns = 10; // 10 máx, no usar más, a menos que sea agreguen más colores en ChartContainer
|
|
55
55
|
// Definición de cantidad de columnas y filas para mostrar en la aplicación
|
|
56
|
-
const rowsNumber = params?.maxRowsNumber
|
|
57
|
-
const columnsNumber = params?.maxColumnsNumber
|
|
56
|
+
const rowsNumber = params?.maxRowsNumber ?? 6;
|
|
57
|
+
const columnsNumber = params?.maxColumnsNumber ?? 3;
|
|
58
58
|
|
|
59
59
|
// Función para hacer request de Google y almacenar los datos procesados en localforage
|
|
60
60
|
const getData = async () => {
|
|
@@ -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
|
|
38
|
-
const titleMargin = parameters?.titlePadding
|
|
39
|
-
const legendPosition = parameters?.legendPosition
|
|
40
|
-
const
|
|
41
|
-
const
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
position:
|
|
93
|
+
show: xAxisConfig.show,
|
|
94
|
+
showGrid: xAxisConfig.showLine,
|
|
95
|
+
position: xAxisConfig.position as Position,
|
|
68
96
|
}),
|
|
69
|
-
[
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
|
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
|
|
26
|
-
const fontColor =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
package/src/components/utils.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Archivo que contiene funciones para el corte de datos, limpieza de datos
|
|
3
|
-
|
|
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
|
-
|
|
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
|
|
@@ -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/test/parameters.json
CHANGED
|
@@ -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",
|