@visionaris-bruno/vs-echarts 8.3.0 → 8.4.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,7 +1,7 @@
1
1
  import { provideEchartsCore, NgxEchartsDirective } from 'ngx-echarts';
2
2
  import * as echarts from 'echarts/core';
3
- import { BarChart, PieChart, LineChart, ScatterChart, FunnelChart, SunburstChart, SankeyChart } from 'echarts/charts';
4
- import { TitleComponent, TooltipComponent, GridComponent, LegendComponent, GraphicComponent, ToolboxComponent, PolarComponent, DatasetComponent } from 'echarts/components';
3
+ import { BarChart, PieChart, LineChart, ScatterChart, FunnelChart, SunburstChart, SankeyChart, BoxplotChart } from 'echarts/charts';
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
7
  import { EventEmitter, Output, Input, ViewChild, Directive, Component } from '@angular/core';
@@ -67,6 +67,7 @@ function initializeEcharts() {
67
67
  FunnelChart,
68
68
  SunburstChart,
69
69
  SankeyChart,
70
+ BoxplotChart,
70
71
  TitleComponent,
71
72
  TooltipComponent,
72
73
  GridComponent,
@@ -77,6 +78,7 @@ function initializeEcharts() {
77
78
  ToolboxComponent,
78
79
  PolarComponent,
79
80
  DatasetComponent,
81
+ DataZoomComponent,
80
82
  ]);
81
83
  initialized = true;
82
84
  }
@@ -166,6 +168,9 @@ function defaultOptionsOverrides() {
166
168
  sankey: {
167
169
  series: {}
168
170
  },
171
+ hBoxplot: {
172
+ series: {}
173
+ },
169
174
  };
170
175
  }
171
176
 
@@ -900,6 +905,8 @@ class RingBuilder {
900
905
  addYAxis(data, overrides, type) { }
901
906
  addRadiusAxis(data, overrides) { }
902
907
  addAngleAxis(data, overrides) { }
908
+ addDataZoom() { }
909
+ addDataset(data, opts) { }
903
910
  // Callback setters
904
911
  setValueFormatter(formatter) {
905
912
  if (formatter) {
@@ -924,6 +931,202 @@ class RingBuilder {
924
931
  }
925
932
  }
926
933
 
934
+ class BoxPlotBuilder {
935
+ baseProduct;
936
+ valueFormatter = (value, key) => value.toLocaleString();
937
+ palette = [];
938
+ // TODO: Hay que implementar un valor por defecto.
939
+ colorResolver;
940
+ result = {};
941
+ constructor(baseProduct) {
942
+ this.baseProduct = baseProduct;
943
+ }
944
+ reset() {
945
+ this.result = {};
946
+ }
947
+ addDataset(data, opts) {
948
+ const statisticKeys = {
949
+ min: 'Min',
950
+ q1: 'Q1',
951
+ median: 'Median',
952
+ q3: 'Q3',
953
+ max: 'Max',
954
+ };
955
+ /**
956
+ *
957
+ * @param arr
958
+ * @param statisticsKeys etiquetas personalizadas para los valores de estadistica.
959
+ * @returns
960
+ */
961
+ function calcularResumen5Numeros(arr, statisticsKeys) {
962
+ if (arr.length === 0)
963
+ return null;
964
+ // 1. Ordenar los números de menor a mayor
965
+ const ordenados = [...arr].sort((a, b) => a - b);
966
+ // Función auxiliar para encontrar la mediana/cuartil en una posición
967
+ const obtenerPercentil = (p) => {
968
+ const pos = (ordenados.length - 1) * p;
969
+ const base = Math.floor(pos);
970
+ const resto = pos - base;
971
+ if (ordenados[base + 1] !== undefined) {
972
+ return ordenados[base] + resto * (ordenados[base + 1] - ordenados[base]);
973
+ }
974
+ else {
975
+ return ordenados[base];
976
+ }
977
+ };
978
+ return {
979
+ [statisticsKeys.min]: ordenados[0],
980
+ [statisticsKeys.q1]: obtenerPercentil(0.25),
981
+ [statisticsKeys.median]: obtenerPercentil(0.50),
982
+ [statisticsKeys.q3]: obtenerPercentil(0.75),
983
+ [statisticsKeys.max]: ordenados[ordenados.length - 1],
984
+ };
985
+ }
986
+ ;
987
+ const resumen5NumerosXCat = data.source.map(s => {
988
+ // filtro category para excluirlo de la lista de métricas
989
+ const values = Object.entries(s)
990
+ .filter(([key, val]) => key !== 'category' && !isNaN(val))
991
+ .map(([_, val]) => Number(val));
992
+ // resumen5NumerosXCat
993
+ const resObj = Object.assign({ category: s.category }, calcularResumen5Numeros(values, statisticKeys));
994
+ return resObj;
995
+ });
996
+ const dataset = [{
997
+ // id: 'resumen5NumerosXCat',
998
+ source: resumen5NumerosXCat,
999
+ },
1000
+ {
1001
+ // id: 'resumen5NumerosXCatOrder',
1002
+ transform: {
1003
+ type: 'sort',
1004
+ config: {
1005
+ dimension: 3,
1006
+ order: 'asc',
1007
+ },
1008
+ },
1009
+ }
1010
+ ];
1011
+ this.result.dataset = dataset;
1012
+ }
1013
+ addCommons() {
1014
+ const opts = {
1015
+ palette: this.palette,
1016
+ };
1017
+ const commons = getCommons(opts);
1018
+ merge$1(this.result, commons);
1019
+ }
1020
+ addSeries(data, overrides, opts) {
1021
+ const axisTypes = opts?.axisTypes || { x: 'value', y: 'category' };
1022
+ const isVertical = axisTypes.x === 'category';
1023
+ const dynamicOptions = {
1024
+ encode: {
1025
+ x: isVertical ? 0 : [1, 2, 3, 4, 5],
1026
+ y: isVertical ? [1, 2, 3, 4, 5] : 0,
1027
+ },
1028
+ };
1029
+ const serie = merge$1({}, dynamicOptions, overrides);
1030
+ this.result.series = [serie];
1031
+ }
1032
+ addTooltip(data, overrides) {
1033
+ const mainMeassureKey = data.dimensions.filter(d => d.name != 'category')[0].name;
1034
+ const valueFormatter = this.valueFormatter;
1035
+ function tooltipFormatter(params) {
1036
+ const tooltipEventData = Array.isArray(params) ? params[0] : params;
1037
+ const title = `<b>${tooltipEventData.name}</b></br>`;
1038
+ let htmlbody = ``;
1039
+ for (const datakey in tooltipEventData.data) {
1040
+ const label = datakey;
1041
+ const value = tooltipEventData.data[datakey];
1042
+ if (label == 'category') {
1043
+ continue;
1044
+ }
1045
+ ;
1046
+ const formattedValue = valueFormatter(value, mainMeassureKey);
1047
+ const bodyText = `${tooltipEventData.marker}${label}: ${formattedValue}</br>`;
1048
+ htmlbody += bodyText;
1049
+ }
1050
+ ;
1051
+ const html = title + htmlbody;
1052
+ return html;
1053
+ }
1054
+ ;
1055
+ this.result.tooltip = getTooltipOptions(merge$1(overrides, { formatter: tooltipFormatter }));
1056
+ }
1057
+ addDataZoom() {
1058
+ this.result.dataZoom = [
1059
+ {
1060
+ type: 'inside'
1061
+ },
1062
+ {
1063
+ type: 'slider',
1064
+ height: 20,
1065
+ bottom: 10
1066
+ }
1067
+ ];
1068
+ }
1069
+ addXAxis(data, overrides, type = "value") {
1070
+ const boxplotXAxisOptions = {
1071
+ scale: true,
1072
+ };
1073
+ if (type === 'category') {
1074
+ const opts = overrides.categoryAxis[0];
1075
+ this.result.xAxis = getCategoryAxisOptions(opts);
1076
+ }
1077
+ else {
1078
+ const opts = overrides.valueAxis[0];
1079
+ this.result.xAxis = getValueAxisOptions(merge$1(opts, boxplotXAxisOptions));
1080
+ }
1081
+ }
1082
+ addYAxis(data, overrides, type = "category") {
1083
+ const boxplotYAxisOptions = {
1084
+ scale: true,
1085
+ };
1086
+ if (type === 'category') {
1087
+ const opts = overrides.categoryAxis[0];
1088
+ this.result.yAxis = getCategoryAxisOptions(opts);
1089
+ }
1090
+ else {
1091
+ const opts = overrides.valueAxis[0];
1092
+ this.result.yAxis = getValueAxisOptions(merge$1(opts, boxplotYAxisOptions));
1093
+ }
1094
+ }
1095
+ addRadiusAxis(data, overrides) { }
1096
+ addAngleAxis(data, overrides) { }
1097
+ addLegend() { }
1098
+ addGraphic() { }
1099
+ addPolar() { }
1100
+ // Setters
1101
+ /**
1102
+ * Permite inyectar un formateador de valores externo.
1103
+ */
1104
+ setValueFormatter(formatter) {
1105
+ if (formatter) {
1106
+ this.valueFormatter = formatter;
1107
+ }
1108
+ }
1109
+ /**
1110
+ * Permite inyectar una paleta de colores básica.
1111
+ */
1112
+ setPalette(palette) {
1113
+ if (palette) {
1114
+ this.palette = palette;
1115
+ }
1116
+ }
1117
+ /**
1118
+ * Permite inyectar un resolver de colores dinámico.
1119
+ */
1120
+ setColorResolver(resolver) {
1121
+ if (resolver) {
1122
+ this.colorResolver = resolver;
1123
+ }
1124
+ }
1125
+ getResult() {
1126
+ return this.result;
1127
+ }
1128
+ }
1129
+
927
1130
  /**
928
1131
  * Director de Builds.
929
1132
  */
@@ -1103,6 +1306,31 @@ class VSECDirector {
1103
1306
  this.builder.addSeries(data, seriesOverrides, layoutOpts);
1104
1307
  this.builder.addTooltip(data, overrides.tooltip);
1105
1308
  }
1309
+ makeBoxplot(data, overrides, opts = {}) {
1310
+ if (this.builder instanceof BoxPlotBuilder == false) {
1311
+ return;
1312
+ }
1313
+ const { valueFormatter = undefined, palette = undefined, colorResolver = undefined, axisTypes = {
1314
+ x: 'value',
1315
+ y: 'category',
1316
+ }, statisticsKeys = undefined, } = opts;
1317
+ this.builder.reset();
1318
+ // El orden importa, primero callbacks y despues componentes.
1319
+ this.builder.setValueFormatter(valueFormatter);
1320
+ this.builder.setPalette(palette);
1321
+ this.builder.setColorResolver(colorResolver);
1322
+ const product = this.builder.baseProduct;
1323
+ const seriesOverrides = merge$1({}, product.baseOptions.series, overrides[product.chartKey].series);
1324
+ // chart components
1325
+ this.builder.addCommons();
1326
+ const layoutOpts = { axisTypes };
1327
+ this.builder.addDataset(data, { statisticsKeys });
1328
+ this.builder.addSeries(data, seriesOverrides, layoutOpts);
1329
+ this.builder.addXAxis(data, overrides.axis, axisTypes.x);
1330
+ this.builder.addYAxis(data, overrides.axis, axisTypes.y);
1331
+ this.builder.addTooltip(data, overrides.tooltip);
1332
+ this.builder.addDataZoom();
1333
+ }
1106
1334
  }
1107
1335
 
1108
1336
  /**
@@ -1375,6 +1603,8 @@ class PieBuilder {
1375
1603
  addRadiusAxis(data, overrides) { }
1376
1604
  addAngleAxis(data, overrides) { }
1377
1605
  addGraphic() { }
1606
+ addDataZoom() { }
1607
+ addDataset(data, opts) { }
1378
1608
  // Callback setters
1379
1609
  setValueFormatter(formatter) {
1380
1610
  if (formatter) {
@@ -1537,6 +1767,8 @@ class FunnelBuilder {
1537
1767
  addRadiusAxis(data, overrides) { }
1538
1768
  addAngleAxis(data, overrides) { }
1539
1769
  addGraphic() { }
1770
+ addDataZoom() { }
1771
+ addDataset(data, opts) { }
1540
1772
  // Callback setters
1541
1773
  setValueFormatter(formatter) {
1542
1774
  if (formatter) {
@@ -1803,6 +2035,19 @@ class EChartBuilder {
1803
2035
  }
1804
2036
  // No-ops for ring charts
1805
2037
  addGraphic() { }
2038
+ addDataset(data, opts) { }
2039
+ addDataZoom() {
2040
+ this.result.dataZoom = [
2041
+ {
2042
+ type: 'inside'
2043
+ },
2044
+ {
2045
+ type: 'slider',
2046
+ height: 20,
2047
+ bottom: 60
2048
+ }
2049
+ ];
2050
+ }
1806
2051
  getResult() {
1807
2052
  return this.result;
1808
2053
  }
@@ -2305,12 +2550,6 @@ class SunburstBuilder {
2305
2550
  const tooltip = getTooltipOptions(overrides);
2306
2551
  this.result.tooltip = tooltip;
2307
2552
  }
2308
- addPolar() { }
2309
- addXAxis(data, overrides, type) { }
2310
- addYAxis(data, overrides, type) { }
2311
- addRadiusAxis(data, overrides) { }
2312
- addAngleAxis(data, overrides) { }
2313
- addLegend() { }
2314
2553
  addCommons() {
2315
2554
  const opts = {
2316
2555
  palette: this.palette,
@@ -2322,6 +2561,14 @@ class SunburstBuilder {
2322
2561
  return this.result;
2323
2562
  }
2324
2563
  ;
2564
+ addPolar() { }
2565
+ addXAxis(data, overrides, type) { }
2566
+ addYAxis(data, overrides, type) { }
2567
+ addRadiusAxis(data, overrides) { }
2568
+ addAngleAxis(data, overrides) { }
2569
+ addLegend() { }
2570
+ addDataZoom() { }
2571
+ addDataset(data, opts) { }
2325
2572
  // Setters
2326
2573
  /**
2327
2574
  * Permite inyectar un formateador de valores externo.
@@ -2520,6 +2767,8 @@ class SankeyBuilder {
2520
2767
  addRadiusAxis(data, overrides) { }
2521
2768
  addAngleAxis(data, overrides) { }
2522
2769
  addLegend() { }
2770
+ addDataZoom() { }
2771
+ addDataset(data, opts) { }
2523
2772
  addCommons() {
2524
2773
  const opts = {
2525
2774
  palette: this.palette,
@@ -2594,6 +2843,44 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
2594
2843
  ], providers: [provideVSEcharts()], template: "<div\n class=\"echarts-container\"\n echarts\n [options]=\"{}\"\n [initOpts]=\"initOptions\"\n [autoResize]=\"true\"\n (chartInit)=\"onChartInit($event)\"\n (chartClick)=\"onChartClick($event)\"\n></div>\n", styles: [".echarts-container{width:100%;height:100%;position:relative}\n"] }]
2595
2844
  }] });
2596
2845
 
2846
+ class EChartsHBoxplotComponent extends BaseEchartsComponent {
2847
+ baseSeriesOptions = {
2848
+ type: 'boxplot',
2849
+ itemStyle: {
2850
+ color: '#b8c5f2'
2851
+ },
2852
+ };
2853
+ baseProduct = {
2854
+ chartKey: 'hBoxplot',
2855
+ baseOptions: {
2856
+ series: this.baseSeriesOptions,
2857
+ }
2858
+ };
2859
+ builder = new BoxPlotBuilder(this.baseProduct);
2860
+ director = new VSECDirector(this.builder);
2861
+ make() {
2862
+ const makeOpts = {
2863
+ palette: this.palette,
2864
+ colorResolver: this.colorResolver,
2865
+ valueFormatter: this.valueFormatter,
2866
+ axisTypes: {
2867
+ x: 'value',
2868
+ y: 'category',
2869
+ },
2870
+ };
2871
+ this.director.makeBoxplot(this.data, this.optionsOverrides, makeOpts);
2872
+ }
2873
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: EChartsHBoxplotComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
2874
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.19", type: EChartsHBoxplotComponent, isStandalone: true, selector: "vs-echarts-hboxplot", providers: [provideVSEcharts()], usesInheritance: true, ngImport: i0, template: "<div\n class=\"echarts-container\"\n echarts\n [options]=\"{}\"\n [initOpts]=\"initOptions\"\n [autoResize]=\"true\"\n (chartInit)=\"onChartInit($event)\"\n></div>\n", styles: [".echarts-container{width:100%;height:100%;position:relative}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: NgxEchartsDirective, selector: "echarts, [echarts]", inputs: ["options", "theme", "initOpts", "merge", "autoResize", "loading", "loadingType", "loadingOpts"], outputs: ["chartInit", "optionsError", "chartClick", "chartDblClick", "chartMouseDown", "chartMouseMove", "chartMouseUp", "chartMouseOver", "chartMouseOut", "chartGlobalOut", "chartContextMenu", "chartHighlight", "chartDownplay", "chartSelectChanged", "chartLegendSelectChanged", "chartLegendSelected", "chartLegendUnselected", "chartLegendLegendSelectAll", "chartLegendLegendInverseSelect", "chartLegendScroll", "chartDataZoom", "chartDataRangeSelected", "chartGraphRoam", "chartGeoRoam", "chartTreeRoam", "chartTimelineChanged", "chartTimelinePlayChanged", "chartRestore", "chartDataViewChanged", "chartMagicTypeChanged", "chartGeoSelectChanged", "chartGeoSelected", "chartGeoUnselected", "chartAxisAreaSelected", "chartBrush", "chartBrushEnd", "chartBrushSelected", "chartGlobalCursorTaken", "chartRendered", "chartFinished"], exportAs: ["echarts"] }] });
2875
+ }
2876
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: EChartsHBoxplotComponent, decorators: [{
2877
+ type: Component,
2878
+ args: [{ selector: 'vs-echarts-hboxplot', imports: [
2879
+ CommonModule,
2880
+ NgxEchartsDirective,
2881
+ ], providers: [provideVSEcharts()], template: "<div\n class=\"echarts-container\"\n echarts\n [options]=\"{}\"\n [initOpts]=\"initOptions\"\n [autoResize]=\"true\"\n (chartInit)=\"onChartInit($event)\"\n></div>\n", styles: [".echarts-container{width:100%;height:100%;position:relative}\n"] }]
2882
+ }] });
2883
+
2597
2884
  // Interfaces de Inputs de Base EChart Component //
2598
2885
 
2599
2886
  ;
@@ -2608,5 +2895,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
2608
2895
  * Generated bundle index. Do not edit.
2609
2896
  */
2610
2897
 
2611
- export { BaseEchartsComponent, EChartsAreaComponent, EChartsAreaStackComponent, EChartsBarStackedComponent, EChartsBarStackedRadialComponent, EChartsHBarComponent, EChartsHBarStackedComponent, EChartsSunburstComponent, EchartsBarComponent, EchartsFunnelComponent, EchartsLineComponent, EchartsPieComponent, EchartsRingComponent, EchartsSankeyComponent, EchartsScatterComponent, defaultOptionsOverrides, initializeEcharts, provideVSEcharts };
2898
+ export { BaseEchartsComponent, EChartsAreaComponent, EChartsAreaStackComponent, EChartsBarStackedComponent, EChartsBarStackedRadialComponent, EChartsHBarComponent, EChartsHBarStackedComponent, EChartsHBoxplotComponent, EChartsSunburstComponent, EchartsBarComponent, EchartsFunnelComponent, EchartsLineComponent, EchartsPieComponent, EchartsRingComponent, EchartsSankeyComponent, EchartsScatterComponent, defaultOptionsOverrides, initializeEcharts, provideVSEcharts };
2612
2899
  //# sourceMappingURL=visionaris-bruno-vs-echarts.mjs.map