@visionaris-bruno/vs-echarts 8.4.1 → 8.5.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.
|
@@ -4,12 +4,13 @@ import { BarChart, PieChart, LineChart, ScatterChart, FunnelChart, SunburstChart
|
|
|
4
4
|
import { TitleComponent, TooltipComponent, GridComponent, LegendComponent, GraphicComponent, ToolboxComponent, PolarComponent, DatasetComponent, DataZoomComponent } from 'echarts/components';
|
|
5
5
|
import { CanvasRenderer, SVGRenderer } from 'echarts/renderers';
|
|
6
6
|
import * as i0 from '@angular/core';
|
|
7
|
-
import { EventEmitter, Output, Input, ViewChild, Directive, Component } from '@angular/core';
|
|
7
|
+
import { EventEmitter, Output, Input, ViewChild, Directive, inject, Component } from '@angular/core';
|
|
8
8
|
import { ReplaySubject } from 'rxjs';
|
|
9
9
|
import { debounceTime } from 'rxjs/operators';
|
|
10
10
|
import merge from 'lodash/merge';
|
|
11
11
|
import { CommonModule } from '@angular/common';
|
|
12
12
|
import { merge as merge$1 } from 'lodash';
|
|
13
|
+
import { TranslateService } from '@ngx-translate/core';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Global Design Tokens for ECharts
|
|
@@ -933,6 +934,7 @@ class RingBuilder {
|
|
|
933
934
|
|
|
934
935
|
class BoxPlotBuilder {
|
|
935
936
|
baseProduct;
|
|
937
|
+
translateService;
|
|
936
938
|
valueFormatter = (value, key) => value.toLocaleString();
|
|
937
939
|
palette = [];
|
|
938
940
|
// TODO: Hay que implementar un valor por defecto.
|
|
@@ -940,25 +942,24 @@ class BoxPlotBuilder {
|
|
|
940
942
|
result = {};
|
|
941
943
|
constructor(baseProduct) {
|
|
942
944
|
this.baseProduct = baseProduct;
|
|
945
|
+
try {
|
|
946
|
+
this.translateService = inject(TranslateService);
|
|
947
|
+
}
|
|
948
|
+
catch {
|
|
949
|
+
// Ignored if called outside an injection context (e.g. unit tests)
|
|
950
|
+
}
|
|
943
951
|
}
|
|
944
952
|
reset() {
|
|
945
953
|
this.result = {};
|
|
946
954
|
}
|
|
947
955
|
addDataset(data, opts) {
|
|
948
|
-
const statisticKeys = {
|
|
949
|
-
min: 'Min',
|
|
950
|
-
q1: 'Q1',
|
|
951
|
-
median: 'Median',
|
|
952
|
-
q3: 'Q3',
|
|
953
|
-
max: 'Max',
|
|
954
|
-
};
|
|
955
956
|
/**
|
|
956
957
|
*
|
|
957
958
|
* @param arr
|
|
958
959
|
* @param statisticsKeys etiquetas personalizadas para los valores de estadistica.
|
|
959
960
|
* @returns
|
|
960
961
|
*/
|
|
961
|
-
function calcularResumen5Numeros(arr
|
|
962
|
+
function calcularResumen5Numeros(arr) {
|
|
962
963
|
if (arr.length === 0)
|
|
963
964
|
return null;
|
|
964
965
|
// 1. Ordenar los números de menor a mayor
|
|
@@ -976,11 +977,11 @@ class BoxPlotBuilder {
|
|
|
976
977
|
}
|
|
977
978
|
};
|
|
978
979
|
return {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
980
|
+
min: ordenados[0],
|
|
981
|
+
q1: obtenerPercentil(0.25),
|
|
982
|
+
median: obtenerPercentil(0.50),
|
|
983
|
+
q3: obtenerPercentil(0.75),
|
|
984
|
+
max: ordenados[ordenados.length - 1],
|
|
984
985
|
};
|
|
985
986
|
}
|
|
986
987
|
;
|
|
@@ -990,7 +991,7 @@ class BoxPlotBuilder {
|
|
|
990
991
|
.filter(([key, val]) => key !== 'category' && !isNaN(val))
|
|
991
992
|
.map(([_, val]) => Number(val));
|
|
992
993
|
// resumen5NumerosXCat
|
|
993
|
-
const resObj = Object.assign({ category: s.category }, calcularResumen5Numeros(values
|
|
994
|
+
const resObj = Object.assign({ category: s.category }, calcularResumen5Numeros(values));
|
|
994
995
|
return resObj;
|
|
995
996
|
});
|
|
996
997
|
const dataset = [{
|
|
@@ -1032,17 +1033,31 @@ class BoxPlotBuilder {
|
|
|
1032
1033
|
addTooltip(data, overrides) {
|
|
1033
1034
|
const mainMeassureKey = data.dimensions.filter(d => d.name != 'category')[0].name;
|
|
1034
1035
|
const valueFormatter = this.valueFormatter;
|
|
1036
|
+
const translate = (key, fallback) => {
|
|
1037
|
+
if (!this.translateService)
|
|
1038
|
+
return fallback;
|
|
1039
|
+
const res = this.translateService.instant(key);
|
|
1040
|
+
return res === key ? fallback : res;
|
|
1041
|
+
};
|
|
1042
|
+
const labelMap = {
|
|
1043
|
+
min: translate('VS_ECHARTS.BOXPLOT.MIN', 'Min'),
|
|
1044
|
+
q1: translate('VS_ECHARTS.BOXPLOT.Q1', 'Q1'),
|
|
1045
|
+
median: translate('VS_ECHARTS.BOXPLOT.MEDIAN', 'Median'),
|
|
1046
|
+
q3: translate('VS_ECHARTS.BOXPLOT.Q3', 'Q3'),
|
|
1047
|
+
max: translate('VS_ECHARTS.BOXPLOT.MAX', 'Max'),
|
|
1048
|
+
};
|
|
1035
1049
|
function tooltipFormatter(params) {
|
|
1036
1050
|
const tooltipEventData = Array.isArray(params) ? params[0] : params;
|
|
1037
1051
|
const title = `<b>${tooltipEventData.name}</b></br>`;
|
|
1038
1052
|
let htmlbody = ``;
|
|
1039
1053
|
for (const datakey in tooltipEventData.data) {
|
|
1040
|
-
const
|
|
1054
|
+
const rawLabel = datakey;
|
|
1041
1055
|
const value = tooltipEventData.data[datakey];
|
|
1042
|
-
if (
|
|
1056
|
+
if (rawLabel == 'category') {
|
|
1043
1057
|
continue;
|
|
1044
1058
|
}
|
|
1045
1059
|
;
|
|
1060
|
+
const label = labelMap[rawLabel] || rawLabel;
|
|
1046
1061
|
const formattedValue = valueFormatter(value, mainMeassureKey);
|
|
1047
1062
|
const bodyText = `${tooltipEventData.marker}${label}: ${formattedValue}</br>`;
|
|
1048
1063
|
htmlbody += bodyText;
|
|
@@ -1313,7 +1328,7 @@ class VSECDirector {
|
|
|
1313
1328
|
const { valueFormatter = undefined, palette = undefined, colorResolver = undefined, axisTypes = {
|
|
1314
1329
|
x: 'value',
|
|
1315
1330
|
y: 'category',
|
|
1316
|
-
},
|
|
1331
|
+
}, } = opts;
|
|
1317
1332
|
this.builder.reset();
|
|
1318
1333
|
// El orden importa, primero callbacks y despues componentes.
|
|
1319
1334
|
this.builder.setValueFormatter(valueFormatter);
|
|
@@ -1324,7 +1339,7 @@ class VSECDirector {
|
|
|
1324
1339
|
// chart components
|
|
1325
1340
|
this.builder.addCommons();
|
|
1326
1341
|
const layoutOpts = { axisTypes };
|
|
1327
|
-
this.builder.addDataset(data
|
|
1342
|
+
this.builder.addDataset(data);
|
|
1328
1343
|
this.builder.addSeries(data, seriesOverrides, layoutOpts);
|
|
1329
1344
|
this.builder.addXAxis(data, overrides.axis, axisTypes.x);
|
|
1330
1345
|
this.builder.addYAxis(data, overrides.axis, axisTypes.y);
|