@visionaris-bruno/vs-echarts 8.3.0 → 8.4.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,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,203 @@ 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 trigger = overrides.trigger;
1034
+ const mainMeassureKey = data.dimensions.filter(d => d.name != 'category')[0].name;
1035
+ const valueFormatter = this.valueFormatter;
1036
+ function tooltipFormatter(params) {
1037
+ const tooltipEventData = params[0];
1038
+ const title = `<b>${tooltipEventData.name}</b></br>`;
1039
+ let htmlbody = ``;
1040
+ for (const datakey in tooltipEventData.data) {
1041
+ const label = datakey;
1042
+ const value = tooltipEventData.data[datakey];
1043
+ if (label == 'category') {
1044
+ continue;
1045
+ }
1046
+ ;
1047
+ const formattedValue = valueFormatter(value, mainMeassureKey);
1048
+ const bodyText = `${tooltipEventData.marker}${label}: ${formattedValue}</br>`;
1049
+ htmlbody += bodyText;
1050
+ }
1051
+ ;
1052
+ const html = title + htmlbody;
1053
+ return html;
1054
+ }
1055
+ ;
1056
+ this.result.tooltip = getTooltipOptions(merge$1(overrides, { formatter: tooltipFormatter }));
1057
+ }
1058
+ addDataZoom() {
1059
+ this.result.dataZoom = [
1060
+ {
1061
+ type: 'inside'
1062
+ },
1063
+ {
1064
+ type: 'slider',
1065
+ height: 20,
1066
+ bottom: 10
1067
+ }
1068
+ ];
1069
+ }
1070
+ addXAxis(data, overrides, type = "value") {
1071
+ const boxplotXAxisOptions = {
1072
+ scale: true,
1073
+ };
1074
+ if (type === 'category') {
1075
+ const opts = overrides.categoryAxis[0];
1076
+ this.result.xAxis = getCategoryAxisOptions(opts);
1077
+ }
1078
+ else {
1079
+ const opts = overrides.valueAxis[0];
1080
+ this.result.xAxis = getValueAxisOptions(merge$1(opts, boxplotXAxisOptions));
1081
+ }
1082
+ }
1083
+ addYAxis(data, overrides, type = "category") {
1084
+ const boxplotYAxisOptions = {
1085
+ scale: true,
1086
+ };
1087
+ if (type === 'category') {
1088
+ const opts = overrides.categoryAxis[0];
1089
+ this.result.yAxis = getCategoryAxisOptions(opts);
1090
+ }
1091
+ else {
1092
+ const opts = overrides.valueAxis[0];
1093
+ this.result.yAxis = getValueAxisOptions(merge$1(opts, boxplotYAxisOptions));
1094
+ }
1095
+ }
1096
+ addRadiusAxis(data, overrides) { }
1097
+ addAngleAxis(data, overrides) { }
1098
+ addLegend() { }
1099
+ addGraphic() { }
1100
+ addPolar() { }
1101
+ // Setters
1102
+ /**
1103
+ * Permite inyectar un formateador de valores externo.
1104
+ */
1105
+ setValueFormatter(formatter) {
1106
+ if (formatter) {
1107
+ this.valueFormatter = formatter;
1108
+ }
1109
+ }
1110
+ /**
1111
+ * Permite inyectar una paleta de colores básica.
1112
+ */
1113
+ setPalette(palette) {
1114
+ if (palette) {
1115
+ this.palette = palette;
1116
+ }
1117
+ }
1118
+ /**
1119
+ * Permite inyectar un resolver de colores dinámico.
1120
+ */
1121
+ setColorResolver(resolver) {
1122
+ if (resolver) {
1123
+ this.colorResolver = resolver;
1124
+ }
1125
+ }
1126
+ getResult() {
1127
+ return this.result;
1128
+ }
1129
+ }
1130
+
927
1131
  /**
928
1132
  * Director de Builds.
929
1133
  */
@@ -1103,6 +1307,31 @@ class VSECDirector {
1103
1307
  this.builder.addSeries(data, seriesOverrides, layoutOpts);
1104
1308
  this.builder.addTooltip(data, overrides.tooltip);
1105
1309
  }
1310
+ makeBoxplot(data, overrides, opts = {}) {
1311
+ if (this.builder instanceof BoxPlotBuilder == false) {
1312
+ return;
1313
+ }
1314
+ const { valueFormatter = undefined, palette = undefined, colorResolver = undefined, axisTypes = {
1315
+ x: 'value',
1316
+ y: 'category',
1317
+ }, statisticsKeys = undefined, } = opts;
1318
+ this.builder.reset();
1319
+ // El orden importa, primero callbacks y despues componentes.
1320
+ this.builder.setValueFormatter(valueFormatter);
1321
+ this.builder.setPalette(palette);
1322
+ this.builder.setColorResolver(colorResolver);
1323
+ const product = this.builder.baseProduct;
1324
+ const seriesOverrides = merge$1({}, product.baseOptions.series, overrides[product.chartKey].series);
1325
+ // chart components
1326
+ this.builder.addCommons();
1327
+ const layoutOpts = { axisTypes };
1328
+ this.builder.addDataset(data, { statisticsKeys });
1329
+ this.builder.addSeries(data, seriesOverrides, layoutOpts);
1330
+ this.builder.addXAxis(data, overrides.axis, axisTypes.x);
1331
+ this.builder.addYAxis(data, overrides.axis, axisTypes.y);
1332
+ this.builder.addTooltip(data, overrides.tooltip);
1333
+ this.builder.addDataZoom();
1334
+ }
1106
1335
  }
1107
1336
 
1108
1337
  /**
@@ -1375,6 +1604,8 @@ class PieBuilder {
1375
1604
  addRadiusAxis(data, overrides) { }
1376
1605
  addAngleAxis(data, overrides) { }
1377
1606
  addGraphic() { }
1607
+ addDataZoom() { }
1608
+ addDataset(data, opts) { }
1378
1609
  // Callback setters
1379
1610
  setValueFormatter(formatter) {
1380
1611
  if (formatter) {
@@ -1537,6 +1768,8 @@ class FunnelBuilder {
1537
1768
  addRadiusAxis(data, overrides) { }
1538
1769
  addAngleAxis(data, overrides) { }
1539
1770
  addGraphic() { }
1771
+ addDataZoom() { }
1772
+ addDataset(data, opts) { }
1540
1773
  // Callback setters
1541
1774
  setValueFormatter(formatter) {
1542
1775
  if (formatter) {
@@ -1803,6 +2036,19 @@ class EChartBuilder {
1803
2036
  }
1804
2037
  // No-ops for ring charts
1805
2038
  addGraphic() { }
2039
+ addDataset(data, opts) { }
2040
+ addDataZoom() {
2041
+ this.result.dataZoom = [
2042
+ {
2043
+ type: 'inside'
2044
+ },
2045
+ {
2046
+ type: 'slider',
2047
+ height: 20,
2048
+ bottom: 60
2049
+ }
2050
+ ];
2051
+ }
1806
2052
  getResult() {
1807
2053
  return this.result;
1808
2054
  }
@@ -2305,12 +2551,6 @@ class SunburstBuilder {
2305
2551
  const tooltip = getTooltipOptions(overrides);
2306
2552
  this.result.tooltip = tooltip;
2307
2553
  }
2308
- addPolar() { }
2309
- addXAxis(data, overrides, type) { }
2310
- addYAxis(data, overrides, type) { }
2311
- addRadiusAxis(data, overrides) { }
2312
- addAngleAxis(data, overrides) { }
2313
- addLegend() { }
2314
2554
  addCommons() {
2315
2555
  const opts = {
2316
2556
  palette: this.palette,
@@ -2322,6 +2562,14 @@ class SunburstBuilder {
2322
2562
  return this.result;
2323
2563
  }
2324
2564
  ;
2565
+ addPolar() { }
2566
+ addXAxis(data, overrides, type) { }
2567
+ addYAxis(data, overrides, type) { }
2568
+ addRadiusAxis(data, overrides) { }
2569
+ addAngleAxis(data, overrides) { }
2570
+ addLegend() { }
2571
+ addDataZoom() { }
2572
+ addDataset(data, opts) { }
2325
2573
  // Setters
2326
2574
  /**
2327
2575
  * Permite inyectar un formateador de valores externo.
@@ -2520,6 +2768,8 @@ class SankeyBuilder {
2520
2768
  addRadiusAxis(data, overrides) { }
2521
2769
  addAngleAxis(data, overrides) { }
2522
2770
  addLegend() { }
2771
+ addDataZoom() { }
2772
+ addDataset(data, opts) { }
2523
2773
  addCommons() {
2524
2774
  const opts = {
2525
2775
  palette: this.palette,
@@ -2594,6 +2844,44 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
2594
2844
  ], 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
2845
  }] });
2596
2846
 
2847
+ class EChartsHBoxplotComponent extends BaseEchartsComponent {
2848
+ baseSeriesOptions = {
2849
+ type: 'boxplot',
2850
+ itemStyle: {
2851
+ color: '#b8c5f2'
2852
+ },
2853
+ };
2854
+ baseProduct = {
2855
+ chartKey: 'hBoxplot',
2856
+ baseOptions: {
2857
+ series: this.baseSeriesOptions,
2858
+ }
2859
+ };
2860
+ builder = new BoxPlotBuilder(this.baseProduct);
2861
+ director = new VSECDirector(this.builder);
2862
+ make() {
2863
+ const makeOpts = {
2864
+ palette: this.palette,
2865
+ colorResolver: this.colorResolver,
2866
+ valueFormatter: this.valueFormatter,
2867
+ axisTypes: {
2868
+ x: 'value',
2869
+ y: 'category',
2870
+ },
2871
+ };
2872
+ this.director.makeBoxplot(this.data, this.optionsOverrides, makeOpts);
2873
+ }
2874
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: EChartsHBoxplotComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
2875
+ 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"] }] });
2876
+ }
2877
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: EChartsHBoxplotComponent, decorators: [{
2878
+ type: Component,
2879
+ args: [{ selector: 'vs-echarts-hboxplot', imports: [
2880
+ CommonModule,
2881
+ NgxEchartsDirective,
2882
+ ], 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"] }]
2883
+ }] });
2884
+
2597
2885
  // Interfaces de Inputs de Base EChart Component //
2598
2886
 
2599
2887
  ;
@@ -2608,5 +2896,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
2608
2896
  * Generated bundle index. Do not edit.
2609
2897
  */
2610
2898
 
2611
- export { BaseEchartsComponent, EChartsAreaComponent, EChartsAreaStackComponent, EChartsBarStackedComponent, EChartsBarStackedRadialComponent, EChartsHBarComponent, EChartsHBarStackedComponent, EChartsSunburstComponent, EchartsBarComponent, EchartsFunnelComponent, EchartsLineComponent, EchartsPieComponent, EchartsRingComponent, EchartsSankeyComponent, EchartsScatterComponent, defaultOptionsOverrides, initializeEcharts, provideVSEcharts };
2899
+ export { BaseEchartsComponent, EChartsAreaComponent, EChartsAreaStackComponent, EChartsBarStackedComponent, EChartsBarStackedRadialComponent, EChartsHBarComponent, EChartsHBarStackedComponent, EChartsHBoxplotComponent, EChartsSunburstComponent, EchartsBarComponent, EchartsFunnelComponent, EchartsLineComponent, EchartsPieComponent, EchartsRingComponent, EchartsSankeyComponent, EchartsScatterComponent, defaultOptionsOverrides, initializeEcharts, provideVSEcharts };
2612
2900
  //# sourceMappingURL=visionaris-bruno-vs-echarts.mjs.map