@visionaris-bruno/vs-echarts 9.1.0 → 9.2.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.
@@ -4,7 +4,7 @@ import { BarChart, PieChart, LineChart, ScatterChart, FunnelChart, SunburstChart
4
4
  import { TooltipComponent, GridComponent, CalendarComponent, LegendComponent, GraphicComponent, PolarComponent, DatasetComponent, DataZoomComponent, VisualMapComponent } from 'echarts/components';
5
5
  import { CanvasRenderer, SVGRenderer } from 'echarts/renderers';
6
6
  import * as i0 from '@angular/core';
7
- import { InjectionToken, Inject, Injectable, EventEmitter, inject, Output, Input, ViewChild, Directive, Component } from '@angular/core';
7
+ import { Inject, Injectable, InjectionToken, EventEmitter, inject, Output, Input, ViewChild, Directive, Component } from '@angular/core';
8
8
  import langES from 'echarts/lib/i18n/langES.js';
9
9
  import langDE from 'echarts/lib/i18n/langDE.js';
10
10
  import langFR from 'echarts/lib/i18n/langFR.js';
@@ -17,6 +17,55 @@ import { CommonModule } from '@angular/common';
17
17
  import { merge as merge$1 } from 'lodash';
18
18
  import { TranslateService } from '@ngx-translate/core';
19
19
 
20
+ // TODO: Exportar valores por defecto de vs-echarts.config.ts por este servicio y actualizar en logica de frontend.
21
+ let activeLocale = undefined;
22
+ function getActiveLocale() {
23
+ return activeLocale;
24
+ }
25
+ function setActiveLocale(locale) {
26
+ activeLocale = locale;
27
+ }
28
+ class VSEchartsConfigService {
29
+ vsEchartsConfig;
30
+ mapping = {
31
+ es: 'ES',
32
+ en: 'EN',
33
+ us: 'EN',
34
+ de: 'DE',
35
+ fr: 'FR',
36
+ it: 'IT',
37
+ pt: 'PT-br',
38
+ br: 'PT-br',
39
+ };
40
+ constructor(vsEchartsConfig) {
41
+ this.vsEchartsConfig = vsEchartsConfig;
42
+ if (this.vsEchartsConfig?.locale) {
43
+ setActiveLocale(this.vsEchartsConfig.locale);
44
+ }
45
+ }
46
+ setLocale(language) {
47
+ if (!language) {
48
+ this.vsEchartsConfig.locale = 'ES';
49
+ setActiveLocale('ES');
50
+ return;
51
+ }
52
+ const echartsLocale = this.mapping[language.toLowerCase()] || 'ES';
53
+ this.vsEchartsConfig.locale = echartsLocale;
54
+ setActiveLocale(echartsLocale);
55
+ }
56
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: VSEchartsConfigService, deps: [{ token: VS_ECHARTS_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
57
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: VSEchartsConfigService, providedIn: 'root' });
58
+ }
59
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: VSEchartsConfigService, decorators: [{
60
+ type: Injectable,
61
+ args: [{
62
+ providedIn: 'root'
63
+ }]
64
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
65
+ type: Inject,
66
+ args: [VS_ECHARTS_CONFIG]
67
+ }] }] });
68
+
20
69
  /**
21
70
  * Global Design Tokens for ECharts
22
71
  */
@@ -44,7 +93,7 @@ function getDefaultPalette() {
44
93
  * pero por algun motivo esto es distinto en este tipo de graficos.
45
94
  *
46
95
  * apache echarts version: 5.6.0
47
- */
96
+ * */
48
97
  const fixPieDataIndexInside = (e) => {
49
98
  /** selected serie index */
50
99
  const ssi = e.fromActionPayload.seriesIndex;
@@ -56,11 +105,47 @@ const fixPieDataIndexInside = (e) => {
56
105
  e.fromActionPayload.dataIndexInside = fixedDataIndex; // aplico corrección de index inside.
57
106
  return e;
58
107
  };
108
+ /**
109
+ * Retorna valor con formato local establecido por configuracion de biblioteca.
110
+ * Utilizara el del navegador si el locale y activeLocale es indefinido.
111
+ * @param value
112
+ * @param opts
113
+ * @returns
114
+ */
115
+ const valueToLocale = (value, opts) => {
116
+ const locale = opts?.locale ?? getActiveLocale();
117
+ const officialLocale = locale ? localeMapper[locale] : undefined;
118
+ // 1. Si ya es una instancia de Date
119
+ if (value instanceof Date) {
120
+ return value.toLocaleString(officialLocale);
121
+ }
122
+ // 2. Si es un string, intentamos ver si es una fecha válida
123
+ if (typeof value === 'string') {
124
+ const parsedDate = Date.parse(value);
125
+ if (!isNaN(parsedDate)) {
126
+ return new Date(parsedDate).toLocaleString(officialLocale);
127
+ }
128
+ // Si no era una fecha válida, devolvemos el string tal cual
129
+ return value;
130
+ }
131
+ // 3. Si es un número o bigint
132
+ if (typeof value === 'number' || typeof value === 'bigint') {
133
+ return value.toLocaleString(officialLocale);
134
+ }
135
+ // Fallback por si llega algo inesperado (null, undefined, etc.)
136
+ return String(value);
137
+ };
138
+ const defaultValueFormatter = (value) => {
139
+ return valueToLocale(value);
140
+ };
59
141
 
60
142
  /// <reference path="./typings.d.ts" />
61
143
  const VS_ECHARTS_CONFIG = new InjectionToken('VS_ECHARTS_CONFIG', {
62
144
  providedIn: 'root',
63
- factory: () => ({ renderer: 'svg' }),
145
+ factory: () => ({
146
+ renderer: 'svg',
147
+ locale: 'AR',
148
+ }),
64
149
  });
65
150
  /**
66
151
  * Inicialización centralizada de ECharts para evitar duplicación y efectos secundarios
@@ -105,6 +190,47 @@ function provideVSEcharts() {
105
190
  initializeEcharts();
106
191
  return provideEchartsCore({ echarts });
107
192
  }
193
+ // 2. Diccionario de mapeo interno a códigos BCP 47 oficiales
194
+ const localeMapper = {
195
+ ZH: 'zh-CN', // Chino Simplificado (puedes cambiarlo a zh-TW si prefieres)
196
+ EN: 'en-US', // Inglés (o en-GB)
197
+ AR: 'ar-EG', // Árabe
198
+ CS: 'cs-CZ', // Checo
199
+ DE: 'de-DE', // Alemán
200
+ EL: 'el-GR', // Griego
201
+ ES: 'es-ES', // Español
202
+ FA: 'fa-IR', // Persa
203
+ FI: 'fi-FI', // Finlandés
204
+ FR: 'fr-FR', // Francés
205
+ HU: 'hu-HU', // Húngaro
206
+ IT: 'it-IT', // Italiano
207
+ JA: 'ja-JP', // Japonés
208
+ KO: 'ko-KR', // Coreano
209
+ LV: 'lv-LV', // Letón
210
+ 'nb-NO': 'nb-NO', // Noruego Bokmål (ya es estándar)
211
+ NL: 'nl-NL', // Neerlandés
212
+ PL: 'pl-PL', // Polaco
213
+ 'PT-br': 'pt-BR', // Portugués de Brasil (corregido a camelCase estándar)
214
+ RO: 'ro-RO', // Rumano
215
+ RU: 'ru-RU', // Ruso
216
+ SI: 'si-LK', // Cingalés
217
+ SV: 'sv-SE', // Sueco
218
+ TH: 'th-TH', // Tailandés
219
+ TR: 'tr-TR', // Turco
220
+ UK: 'uk-UA', // Ucraniano
221
+ VI: 'vi-VN', // Vietnamita
222
+ };
223
+ // 3. Función formateadora universal (para números)
224
+ function formatNumberByLocale(value, customLocale, options) {
225
+ // Obtenemos el locale oficial, si no existe por alguna razón, usamos el del sistema
226
+ const officialLocale = localeMapper[customLocale] || undefined;
227
+ return value.toLocaleString(officialLocale, options);
228
+ }
229
+ // 4. Función formateadora universal (para fechas)
230
+ function formatDateByLocale(date, customLocale, options) {
231
+ const officialLocale = localeMapper[customLocale] || undefined;
232
+ return date.toLocaleString(officialLocale, options);
233
+ }
108
234
  function defaultOptionsOverrides() {
109
235
  return {
110
236
  tooltip: {
@@ -183,6 +309,9 @@ function defaultOptionsOverrides() {
183
309
  sankey: {
184
310
  series: {}
185
311
  },
312
+ boxplot: {
313
+ series: {},
314
+ },
186
315
  hBoxplot: {
187
316
  series: {}
188
317
  },
@@ -191,44 +320,6 @@ function defaultOptionsOverrides() {
191
320
  },
192
321
  };
193
322
  }
194
- const defaultValueFormatter = (value) => `${value}`;
195
-
196
- // TODO: Exportar valores por defecto de vs-echarts.config.ts por este servicio y actualizar en logica de frontend.
197
- class VSEchartsConfigService {
198
- vsEchartsConfig;
199
- mapping = {
200
- es: 'ES',
201
- en: 'EN',
202
- us: 'EN',
203
- de: 'DE',
204
- fr: 'FR',
205
- it: 'IT',
206
- pt: 'PT-br',
207
- br: 'PT-br',
208
- };
209
- constructor(vsEchartsConfig) {
210
- this.vsEchartsConfig = vsEchartsConfig;
211
- }
212
- setLocale(language) {
213
- if (!language) {
214
- this.vsEchartsConfig.locale = 'ES';
215
- return;
216
- }
217
- const echartsLocale = this.mapping[language.toLowerCase()] || 'ES';
218
- this.vsEchartsConfig.locale = echartsLocale;
219
- }
220
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: VSEchartsConfigService, deps: [{ token: VS_ECHARTS_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
221
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: VSEchartsConfigService, providedIn: 'root' });
222
- }
223
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: VSEchartsConfigService, decorators: [{
224
- type: Injectable,
225
- args: [{
226
- providedIn: 'root'
227
- }]
228
- }], ctorParameters: () => [{ type: undefined, decorators: [{
229
- type: Inject,
230
- args: [VS_ECHARTS_CONFIG]
231
- }] }] });
232
323
 
233
324
  /**
234
325
  * BaseEchartsComponent
@@ -445,12 +536,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
445
536
  *
446
537
  * @see {@link VisionarisFrontEnd/docs/technical/echarts-architecture.md}
447
538
  */
448
- // Pre-cached native formatter for performance in axis ticks
449
- const compactFormatter = new Intl.NumberFormat('es-AR', {
450
- notation: 'compact',
451
- compactDisplay: 'short',
452
- maximumFractionDigits: 1
453
- });
539
+ const formattersCache = new Map();
540
+ function getCompactFormatter() {
541
+ const locale = getActiveLocale();
542
+ const officialLocale = locale ? localeMapper[locale] : undefined;
543
+ const cacheKey = officialLocale || 'default';
544
+ let formatter = formattersCache.get(cacheKey);
545
+ if (!formatter) {
546
+ formatter = new Intl.NumberFormat(officialLocale, {
547
+ notation: 'compact',
548
+ compactDisplay: 'short',
549
+ maximumFractionDigits: 1
550
+ });
551
+ formattersCache.set(cacheKey, formatter);
552
+ }
553
+ return formatter;
554
+ }
555
+ // Wrap with custom formatter implementation to keep identical signature/API dynamically
556
+ const compactFormatter = {
557
+ format: (value) => getCompactFormatter().format(value)
558
+ };
454
559
  /**
455
560
  * Formats a value using native browser SI suffixes (k, M, B).
456
561
  */
@@ -998,7 +1103,7 @@ class RingBuilder {
998
1103
  }
999
1104
  }
1000
1105
 
1001
- class BoxPlotBuilder {
1106
+ class BoxplotBuilder {
1002
1107
  baseProduct;
1003
1108
  translateService;
1004
1109
  valueFormatter = defaultValueFormatter;
@@ -1137,15 +1242,30 @@ class BoxPlotBuilder {
1137
1242
  ;
1138
1243
  this.result.tooltip = getTooltipOptions(merge$1(overrides, { formatter: tooltipFormatter }));
1139
1244
  }
1140
- addDataZoom() {
1245
+ addDataZoom(opts) {
1246
+ const axisTypes = opts?.axisTypes || { x: 'value', y: 'category' };
1247
+ const isVertical = axisTypes.x === 'category';
1141
1248
  this.result.dataZoom = [
1142
1249
  {
1143
- type: 'inside'
1250
+ type: 'inside',
1251
+ ...(isVertical ? { yAxisIndex: 0 } : { xAxisIndex: 0 })
1144
1252
  },
1145
1253
  {
1146
1254
  type: 'slider',
1147
- height: 20,
1148
- bottom: 10
1255
+ ...(isVertical
1256
+ ? {
1257
+ yAxisIndex: 0,
1258
+ orient: 'horizontal',
1259
+ bottom: 10,
1260
+ height: 20
1261
+ }
1262
+ : {
1263
+ xAxisIndex: 0,
1264
+ orient: 'horizontal',
1265
+ bottom: 10,
1266
+ height: 20
1267
+ }),
1268
+ labelFormatter: (value) => formatAxisValue(value)
1149
1269
  }
1150
1270
  ];
1151
1271
  }
@@ -2305,7 +2425,7 @@ class VSECDirector {
2305
2425
  this.builder.addTooltip(data, overrides.tooltip);
2306
2426
  }
2307
2427
  makeBoxplot(data, overrides, opts = {}) {
2308
- if (this.builder instanceof BoxPlotBuilder == false) {
2428
+ if (this.builder instanceof BoxplotBuilder == false) {
2309
2429
  return;
2310
2430
  }
2311
2431
  const { valueFormatter = undefined, palette = undefined, colorResolver = undefined, axisTypes = {
@@ -2331,7 +2451,8 @@ class VSECDirector {
2331
2451
  this.builder.addXAxis(data, overrides.axis, axisTypes.x);
2332
2452
  this.builder.addYAxis(data, overrides.axis, axisTypes.y);
2333
2453
  this.builder.addTooltip(data, overrides.tooltip);
2334
- this.builder.addDataZoom();
2454
+ const dzConfigOpts = { axisTypes };
2455
+ this.builder.addDataZoom(dzConfigOpts);
2335
2456
  }
2336
2457
  makeHeatmapCalendar(data, overrides, opts = {}) {
2337
2458
  if (this.builder instanceof HeatmapCalendarBuilder == false) {
@@ -3121,20 +3242,52 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
3121
3242
  ], 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"] }]
3122
3243
  }] });
3123
3244
 
3124
- class EChartsHBoxplotComponent extends BaseEchartsComponent {
3245
+ class EChartsBoxplotComponent extends BaseEchartsComponent {
3125
3246
  baseSeriesOptions = {
3126
3247
  type: 'boxplot',
3127
3248
  itemStyle: {
3128
3249
  color: '#b8c5f2'
3129
3250
  },
3130
3251
  };
3252
+ baseProduct = {
3253
+ chartKey: 'boxplot',
3254
+ baseOptions: {
3255
+ series: this.baseSeriesOptions,
3256
+ }
3257
+ };
3258
+ builder = new BoxplotBuilder(this.baseProduct);
3259
+ director = new VSECDirector(this.builder);
3260
+ make() {
3261
+ const makeOpts = {
3262
+ palette: this.palette,
3263
+ colorResolver: this.colorResolver,
3264
+ valueFormatter: this.valueFormatter,
3265
+ axisTypes: {
3266
+ x: 'category',
3267
+ y: 'value',
3268
+ },
3269
+ };
3270
+ this.director.makeBoxplot(this.data, this.optionsOverrides, makeOpts);
3271
+ }
3272
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: EChartsBoxplotComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
3273
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.19", type: EChartsBoxplotComponent, isStandalone: true, selector: "vs-echarts-boxplot", 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"] }] });
3274
+ }
3275
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: EChartsBoxplotComponent, decorators: [{
3276
+ type: Component,
3277
+ args: [{ selector: 'vs-echarts-boxplot', imports: [
3278
+ CommonModule,
3279
+ NgxEchartsDirective,
3280
+ ], 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"] }]
3281
+ }] });
3282
+
3283
+ class EChartsHBoxplotComponent extends EChartsBoxplotComponent {
3131
3284
  baseProduct = {
3132
3285
  chartKey: 'hBoxplot',
3133
3286
  baseOptions: {
3134
3287
  series: this.baseSeriesOptions,
3135
3288
  }
3136
3289
  };
3137
- builder = new BoxPlotBuilder(this.baseProduct);
3290
+ builder = new BoxplotBuilder(this.baseProduct);
3138
3291
  director = new VSECDirector(this.builder);
3139
3292
  make() {
3140
3293
  const makeOpts = {
@@ -3187,7 +3340,7 @@ class EChartsHeatmapCalendar extends BaseEchartsComponent {
3187
3340
  top: this.calendarPaddings.visualMapTop,
3188
3341
  formatter: (dv) => {
3189
3342
  const value = dv ?? '';
3190
- return value.toLocaleString();
3343
+ return valueToLocale(value);
3191
3344
  },
3192
3345
  }, // dinamico
3193
3346
  calendar: {
@@ -3272,5 +3425,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImpo
3272
3425
  * Generated bundle index. Do not edit.
3273
3426
  */
3274
3427
 
3275
- export { BaseEchartsComponent, EChartsAreaComponent, EChartsAreaStackComponent, EChartsBarStackedComponent, EChartsBarStackedRadialComponent, EChartsHBarComponent, EChartsHBarStackedComponent, EChartsHBoxplotComponent, EChartsHeatmapCalendar, EChartsSunburstComponent, EchartsBarComponent, EchartsFunnelComponent, EchartsLineComponent, EchartsPieComponent, EchartsRingComponent, EchartsSankeyComponent, EchartsScatterComponent, VSEchartsConfigService, defaultOptionsOverrides, provideVSEcharts };
3428
+ export { BaseEchartsComponent, EChartsAreaComponent, EChartsAreaStackComponent, EChartsBarStackedComponent, EChartsBarStackedRadialComponent, EChartsBoxplotComponent, EChartsHBarComponent, EChartsHBarStackedComponent, EChartsHBoxplotComponent, EChartsHeatmapCalendar, EChartsSunburstComponent, EchartsBarComponent, EchartsFunnelComponent, EchartsLineComponent, EchartsPieComponent, EchartsRingComponent, EchartsSankeyComponent, EchartsScatterComponent, VSEchartsConfigService, defaultOptionsOverrides, getActiveLocale, provideVSEcharts, setActiveLocale };
3276
3429
  //# sourceMappingURL=visionaris-bruno-vs-echarts.mjs.map