@vixoniccom/kpi-chart 0.0.2-beta.0 → 0.0.2-dev.1

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,41 +0,0 @@
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
@@ -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
- }
@@ -1,74 +0,0 @@
1
- import React, { useEffect, useState } from "react";
2
- import { FontLoader } from "./FontLoader";
3
- import { ChartContainer } from "./ChartContainer";
4
- import { FormattedText } from "./FormattedText";
5
- import "../style.css";
6
- import { processData } from "./utils";
7
-
8
- interface Props {
9
- appData: VixonicData
10
- googleSheetsItems: GoogleSheetsItems
11
- start: boolean
12
- }
13
-
14
- // Definición de paths de las fuentes provenientes de la configuración
15
- const fontPaths = [
16
- "titleTextFormat.font",
17
- "legendTextFormat.font",
18
- "customMessageTextFormat.font",
19
- ];
20
-
21
- /**
22
- * Componente principal que muestra la aplicación y el gráfico.
23
- * Es llamada una vez ha sido inicializada (start == true).
24
- * Obtiene los datos según tiempo de actualización definido en la configuración.
25
- */
26
- export const App: React.FunctionComponent<Props> = ({ appData, googleSheetsItems, start }) => {
27
-
28
- if (!appData || !start) return null;
29
-
30
- const params = appData.parameters;
31
- const appPadding = params?.appPadding ?? "0px";
32
- const backgroundImageState = params?.backgroundImage
33
- ? `url("${appData.downloadsPath}/${params?.backgroundImage.filename}")`
34
- : "";
35
- const [sheetData, setSheetData] = useState<Series[]>([]);
36
- // Definición de mensaje del sistema
37
- const [systemMessage, setSystemMessage] = useState<string>(
38
- "Sin datos disponibles"
39
- );
40
- // Definición de nombre fijo de columna de categoría
41
- const categoryColumnName = "category";
42
-
43
- useEffect(() => {
44
- const { data, systemMessage } = processData(googleSheetsItems, categoryColumnName);
45
- setSheetData(data);
46
- setSystemMessage(systemMessage);
47
- }, [googleSheetsItems]);
48
-
49
- return (
50
- <div
51
- className="app-container"
52
- style={{
53
- padding: appPadding,
54
- backgroundImage: `${backgroundImageState}`,
55
- }}
56
- >
57
- {/* Carga de fuentes de texto */}
58
- <FontLoader
59
- paths={fontPaths}
60
- parameters={params}
61
- downloadsPath={appData.downloadsPath}
62
- />
63
- {/* Render de chart o mensaje del sistema/personalizado */}
64
- {sheetData.length > 0 ? (
65
- <ChartContainer data={sheetData} parameters={params} />
66
- ) : (
67
- <FormattedText
68
- text={params?.customMessage || systemMessage}
69
- format={params?.systemMessageTextFormat}
70
- />
71
- )}
72
- </div>
73
- );
74
- };
@@ -1,193 +0,0 @@
1
- import React from "react";
2
- import { Chart, AxisOptions, Position } from "react-charts";
3
- import { FormattedText } from "../FormattedText";
4
- import { ChartLegend } from "../ChartLegend";
5
- import { getFontColor } from "../utils";
6
-
7
- type Props = {
8
- data: Series[];
9
- parameters: VixonicParameters;
10
- };
11
-
12
- type elementType = "area" | "line" | "bar" | "bubble";
13
-
14
- type AxisConfig = {
15
- position: string;
16
- show: boolean;
17
- showLine: boolean;
18
- stacked: boolean;
19
- type: string;
20
- };
21
-
22
- // Definición de colores que se utilizarán en el gráfico y leyenda
23
- const defaultColors = [
24
- "#1F77B4", // Azul
25
- "#FF7F0E", // Naranja
26
- "#D62728", // Rojo
27
- "#2CA02C", // Verde
28
- "#9467BD", // Morado
29
- "#17BECF", // Cian
30
- "#8C564B", // Marrón
31
- "#E377C2", // Rosa
32
- "#BCBD22", // Amarillo oliva
33
- "#7F7F7F", // Gris
34
- ];
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
-
45
- // Obtener configuraciones de ejes según parámetros de configuración
46
- const getAxisConfig = (parameters: VixonicParameters) => {
47
-
48
- const chartType = parameters?.chartType ?? "bar";
49
- const isBarChart = chartType === "bar";
50
- const barOrientation = parameters?.barOrientation ?? "vertical";
51
- const isHorizontalBar = isBarChart && barOrientation === "horizontal";
52
-
53
- const defaultConfig: AxisConfig = {
54
- position: "left",
55
- show: true,
56
- showLine: true,
57
- stacked: false,
58
- type: chartType,
59
- };
60
-
61
- const xConfig = {
62
- position: isHorizontalBar ? "left" : "bottom",
63
- show: parameters?.xAxisEnabled ?? defaultConfig.show,
64
- showLine: parameters?.showVerticalGrid ?? defaultConfig.showLine,
65
- };
66
-
67
- const yConfig = {
68
- position: isHorizontalBar ? "bottom" : "left",
69
- show: parameters?.yAxisEnabled ?? defaultConfig.show,
70
- showLine: parameters?.showHorizontalGrid ?? defaultConfig.showLine,
71
- stacked: isBarChart && (parameters?.barStacked ?? false),
72
- };
73
-
74
- return {
75
- xAxisConfig: { ...defaultConfig, ...xConfig },
76
- yAxisConfig: { ...defaultConfig, ...yConfig },
77
- };
78
- };
79
-
80
- /**
81
- * Componente para renderizar el gráfico, su título y su leyenda.
82
- * Se definen ejes principal y secundario en Memo para evitar problemas
83
- de renderización.
84
- */
85
- export const ChartContainer: React.FunctionComponent<Props> = ({
86
- data,
87
- parameters,
88
- }) => {
89
- const chartTitle = parameters?.title ?? "";
90
- const legendGap = parameters?.legendMargin ?? 0;
91
- const titleMargin = parameters?.titlePadding ?? "0px";
92
- const legendPosition = parameters?.legendPosition ?? "left";
93
- const titleFontColor = getFontColor(parameters);
94
- const { xAxisConfig, yAxisConfig } = getAxisConfig(parameters);
95
-
96
- // Generar colores repetidos basándose en la cantidad de series
97
- const chartColors = generateRepeatedColors(data.length);
98
-
99
- // Definición eje x
100
- const primaryAxis = React.useMemo(
101
- (): AxisOptions<KeyIndicator> => ({
102
- getValue: (datum: KeyIndicator) => datum.category,
103
- // Tipo band para variables categóricas
104
- scaleType: "band",
105
- show: xAxisConfig.show,
106
- showGrid: xAxisConfig.showLine,
107
- position: xAxisConfig.position as Position,
108
- }),
109
- [xAxisConfig]
110
- );
111
-
112
- // Definición eje y
113
- const secondaryAxes = React.useMemo(
114
- (): AxisOptions<KeyIndicator>[] => [
115
- {
116
- getValue: (datum: KeyIndicator) => datum.performance,
117
- elementType: yAxisConfig.type as elementType,
118
- // Muestra de valores en número decimal
119
- formatters: {
120
- scale: (value) => value.toFixed(1),
121
- },
122
- position: yAxisConfig.position as Position,
123
- scaleType: "linear",
124
- show: yAxisConfig.show,
125
- showGrid: yAxisConfig.showLine,
126
- stacked: yAxisConfig.stacked,
127
- },
128
- ],
129
- [parameters.darkMode, yAxisConfig]
130
- );
131
-
132
- return (
133
- <div className="chart-container">
134
- {parameters?.titleEnabled && (
135
- // Renderización del título del gráfico
136
- <div
137
- className="title-container"
138
- style={{
139
- padding: titleMargin,
140
- }}
141
- >
142
- <FormattedText
143
- text={chartTitle}
144
- format={{
145
- ...parameters?.titleTextFormat,
146
- ...{ fontColor: titleFontColor },
147
- }}
148
- />
149
- </div>
150
- )}
151
- {/* Renderización de leyenda y gráfico */}
152
- <div
153
- className="chart-elements"
154
- style={{
155
- flexDirection: legendPosition === "left" ? "row" : "row-reverse",
156
- }}
157
- >
158
- {parameters?.legendEnabled && (
159
- <ChartLegend
160
- data={{
161
- labels: data.map((series) => series.label),
162
- colors: chartColors,
163
- parameters: {
164
- textFormat: parameters?.legendTextFormat,
165
- circleSize: parameters?.circleSize,
166
- darkMode: parameters?.darkMode ?? false,
167
- legendGap: legendGap,
168
- legendPosition: legendPosition,
169
- },
170
- }}
171
- />
172
- )}
173
- <div className="chart">
174
- <Chart<KeyIndicator>
175
- options={{
176
- data,
177
- primaryAxis,
178
- secondaryAxes,
179
- dark: parameters?.darkMode,
180
- defaultColors: chartColors,
181
- // Esconder leyenda por defecto e interacciones con cursor
182
- tooltip: {
183
- show: false,
184
- },
185
- primaryCursor: false,
186
- secondaryCursor: false,
187
- }}
188
- />
189
- </div>
190
- </div>
191
- </div>
192
- );
193
- };
@@ -1,66 +0,0 @@
1
- import React from "react";
2
- import { TextFormat } from "@vixoniccom/modules";
3
- import { FormattedText } from "../FormattedText";
4
- import { getFontColor } from "../utils";
5
-
6
- type Props = {
7
- data: {
8
- labels: string[];
9
- colors: string[];
10
- parameters: {
11
- textFormat?: TextFormat.Value;
12
- circleSize?: number;
13
- darkMode: boolean;
14
- legendPosition: string;
15
- legendGap: number;
16
- };
17
- };
18
- };
19
-
20
- /**
21
- * Componente para renderizar la leyenda del gráfico según los labels de
22
- los datos y los colores por defecto definidos.
23
- */
24
- export const ChartLegend: React.FunctionComponent<Props> = ({ data }) => {
25
- const params = data.parameters;
26
- const circleSize = params?.circleSize ?? 8;
27
- const fontColor = getFontColor({
28
- titleTextFormat: params?.textFormat,
29
- darkMode: params.darkMode,
30
- });
31
- return (
32
- // Renderizar contenedor con margen dependiendo de la posición provista en la config.
33
- <div
34
- className="legend-box"
35
- style={{
36
- marginLeft:
37
- params?.legendPosition === "left" ? "0px" : `${params?.legendGap}px`,
38
- marginRight:
39
- params?.legendPosition === "right" ? "0px" : `${params?.legendGap}px`,
40
- }}
41
- >
42
- {data.labels.map((label, index) => (
43
- // Contenedor con círculo de color y label
44
- <div key={index} className="label-container">
45
- <div
46
- className="label-color"
47
- style={{
48
- width: `${circleSize}px`,
49
- height: `${circleSize}px`,
50
- backgroundColor: data.colors[index],
51
- }}
52
- ></div>
53
- <div className="label-text">
54
- <FormattedText
55
- text={label}
56
- format={{
57
- ...params?.textFormat,
58
- ...{ fontColor: fontColor },
59
- }}
60
- />
61
- </div>
62
- </div>
63
- ))}
64
- </div>
65
- );
66
- };
@@ -1,47 +0,0 @@
1
- import React from "react";
2
-
3
- interface Props {
4
- paths: Array<string>;
5
- parameters: VixonicParameters;
6
- downloadsPath: string;
7
- }
8
-
9
- /**
10
- * Componente que carga a través de <style> las fuentes obtenidas
11
- desde la configuración
12
- */
13
- export const FontLoader: React.FunctionComponent<Props> = ({
14
- paths,
15
- parameters,
16
- downloadsPath,
17
- }: Props) => {
18
- const _getValueByPath = (path: any, obj: any): any => {
19
- const pathsArray = path.split(".");
20
- const propertyName = pathsArray[0];
21
- if (pathsArray.length === 1) return obj[propertyName];
22
- else {
23
- pathsArray.splice(0, 1);
24
- return _getValueByPath(pathsArray.join("."), obj[propertyName]);
25
- }
26
- };
27
-
28
- const fonts = paths.map((path: any) => {
29
- try {
30
- const fontParam = _getValueByPath(path, parameters);
31
- const font = {
32
- family: fontParam.filename.replace(".", "-"),
33
- src: `${downloadsPath}/${fontParam.filename}`,
34
- };
35
- return `
36
- @font-face {
37
- font-family: "${font.family}";
38
- src: url("${font.src}");
39
- }
40
- `;
41
- } catch (err) {
42
- return "";
43
- }
44
- });
45
-
46
- return <style>{fonts}</style>;
47
- };
@@ -1,88 +0,0 @@
1
- import React from "react";
2
-
3
- // Objeto con los tipos de alineaciones de texto
4
- const alignments = {
5
- center: "center",
6
- left: "flex-start",
7
- right: "flex-end",
8
- };
9
-
10
- // Tipado de alineación
11
- type aligment = {
12
- horizontal: keyof typeof alignments;
13
- vertical: keyof typeof alignments;
14
- };
15
-
16
- interface Props {
17
- format?: any;
18
- lineHeight?: number;
19
- style?: number;
20
- text: string;
21
- }
22
-
23
- /**
24
- * Componente para mostrar, a través de <span>, un texto que considera todo
25
- el formato indicado en la configuración
26
- */
27
- export const FormattedText: React.FunctionComponent<Props> = ({
28
- text,
29
- format,
30
- lineHeight,
31
- style,
32
- }: Props) => {
33
- // Función para verificar si propiedad pertenece al objeto
34
- const checkNested = (obj: any, path: string): boolean => {
35
- const arr = path.split(".");
36
- return arr.every((key, index) => {
37
- if (index === arr.length - 1) return key in obj;
38
- obj = obj[key];
39
- return obj && typeof obj === "object";
40
- });
41
- };
42
-
43
- // Función para obtener la alineación de texto basada en la configuración
44
- const getHorizontalAlignment = (alignment: aligment) => {
45
- if (alignment) {
46
- const hA = alignment.horizontal;
47
- return alignments.hasOwnProperty(hA)
48
- ? alignments[alignment.horizontal]
49
- : "flex-start";
50
- }
51
- return "flex-start";
52
- };
53
-
54
- const containerStyle = Object.assign(
55
- {
56
- display: "flex",
57
- justifyContent: getHorizontalAlignment(format?.alignment),
58
- flex: format?.flex || 0,
59
- },
60
- style
61
- );
62
-
63
- return (
64
- <div style={containerStyle}>
65
- <span
66
- style={{
67
- display: "inline-flex",
68
- color: format?.fontColor || "white",
69
- fontWeight: format?.fontWeight || "normal",
70
- fontFamily: format && checkNested(format, "font.filename")
71
- ? `"${format?.font?.filename?.replace(".", "-")}"`
72
- : "",
73
- fontSize: `${format?.fontSize || 18}px`,
74
- textAlign: format && checkNested(format, "alignment.horizontal")
75
- ? format?.alignment?.horizontal
76
- : "left",
77
- lineHeight: lineHeight ?? 1,
78
- marginTop: format?.marginTop || 0,
79
- marginLeft: format?.marginLeft || 0,
80
- marginBottom: format?.marginBottom || 0,
81
- marginRight: format?.marginRight || 0,
82
- }}
83
- >
84
- {text}
85
- </span>
86
- </div>
87
- );
88
- };