@trismegisto/charts 2.0.1 → 2.1.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.
package/README.md CHANGED
@@ -80,7 +80,9 @@ ativo) e `[(showTable)]`.
80
80
  **`hm-chart` (`HmChartComponent`)** é a saída de emergência para o que os tipados não cobrem: recebe a opção
81
81
  completa do motor (`option: HmChartOption`, tipada pelos `Hm*SeriesOption`), `label` e `points` (pontos
82
82
  navegáveis pelas setas). Ele cuida de ciclo de vida, tema, idioma, movimento reduzido e alto contraste, mas
83
- **não** monta resumo nem tabela: prefira sempre um tipado.
83
+ **não** monta resumo nem tabela: prefira sempre um tipado. O motor grava o retorno de um `tooltip.formatter` com
84
+ `innerHTML`: num `formatter` próprio, passe todo texto vindo de dados por `escapeHtml` (`@trismegisto/primitives`),
85
+ como os tipados fazem.
84
86
 
85
87
  ## Regras que o app precisa saber
86
88
 
@@ -1,7 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken, inject, computed, Injectable, input, model, Directive, ElementRef, signal, afterNextRender, effect, untracked, DestroyRef, ChangeDetectionStrategy, Component } from '@angular/core';
3
3
  import { HermesI18nService } from '@trismegisto/angular/i18n';
4
- import { mergeCatalog, formatMessage, pluralMessage } from '@trismegisto/primitives';
4
+ import { mergeCatalog, formatMessage, pluralMessage, escapeHtml } from '@trismegisto/primitives';
5
5
 
6
6
  const CHARTS_MESSAGES_EN = {
7
7
  meta: { locale: 'en-US' },
@@ -403,6 +403,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.24", ngImpo
403
403
  type: Directive
404
404
  }], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: true }] }], description: [{ type: i0.Input, args: [{ isSignal: true, alias: "description", required: false }] }], legend: [{ type: i0.Input, args: [{ isSignal: true, alias: "legend", required: false }] }], tooltip: [{ type: i0.Input, args: [{ isSignal: true, alias: "tooltip", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }], numberFormat: [{ type: i0.Input, args: [{ isSignal: true, alias: "numberFormat", required: false }] }], showTable: [{ type: i0.Input, args: [{ isSignal: true, alias: "showTable", required: false }] }, { type: i0.Output, args: ["showTableChange"] }] } });
405
405
  // ---- peças de opção compartilhadas -------------------------------------------------------------
406
+ /**
407
+ * Tooltip comum. O motor grava a saída de um `formatter` com `innerHTML`: todo gráfico que define o
408
+ * próprio `formatter` devolve `escapeHtml(...)` (`@trismegisto/primitives`) do texto montado com nomes
409
+ * vindos dos dados. O formatter padrão do motor já escapa.
410
+ */
406
411
  function tooltipOption(ctx, trigger) {
407
412
  return {
408
413
  show: ctx.tooltip,
@@ -75828,7 +75833,7 @@ class HmHeatmapChartComponent extends HmChartBase {
75828
75833
  ...tooltipOption(ctx, 'item'),
75829
75834
  formatter: (p) => {
75830
75835
  const value = p.value;
75831
- return `${ys[value[1]]} · ${xs[value[0]]}: ${ctx.num(value[2])}`;
75836
+ return escapeHtml(`${ys[value[1]]} · ${xs[value[0]]}: ${ctx.num(value[2])}`);
75832
75837
  },
75833
75838
  },
75834
75839
  xAxis: { type: 'category', data: [...xs], splitArea: { show: true } },
@@ -75906,7 +75911,7 @@ class HmCalendarHeatmapComponent extends HmChartBase {
75906
75911
  ...tooltipOption(ctx, 'item'),
75907
75912
  formatter: (p) => {
75908
75913
  const [day, value] = p.value;
75909
- return `${fmtDate(day)}: ${ctx.num(value)}`;
75914
+ return escapeHtml(`${fmtDate(day)}: ${ctx.num(value)}`);
75910
75915
  },
75911
75916
  },
75912
75917
  visualMap: {
@@ -75992,7 +75997,7 @@ class HmScatterChartComponent extends HmChartBase {
75992
75997
  formatter: (p) => {
75993
75998
  const { seriesIndex, dataIndex } = p;
75994
75999
  const s = series[seriesIndex];
75995
- return describe(s, s.data[dataIndex]);
76000
+ return escapeHtml(describe(s, s.data[dataIndex]));
75996
76001
  },
75997
76002
  },
75998
76003
  legend: legendOption(ctx, hasLegend),
@@ -76138,7 +76143,7 @@ class HmRadarChartComponent extends HmChartBase {
76138
76143
  const describe = (s) => `${s.name}: ${indicators.map((ind, i) => `${ind.name} ${ctx.num(s.values[i])}`).join(', ')}`;
76139
76144
  return {
76140
76145
  option: {
76141
- tooltip: { ...tooltipOption(ctx, 'item'), formatter: (p) => describe(series[p.dataIndex]) },
76146
+ tooltip: { ...tooltipOption(ctx, 'item'), formatter: (p) => escapeHtml(describe(series[p.dataIndex])) },
76142
76147
  legend: legendOption(ctx, series.length > 1),
76143
76148
  radar: {
76144
76149
  radius: '64%',
@@ -76317,7 +76322,7 @@ class HmBoxplotChartComponent extends HmChartBase {
76317
76322
  ...tooltipOption(ctx, 'item'),
76318
76323
  formatter: (p) => {
76319
76324
  const g = groups[p.dataIndex];
76320
- return describe(g.name, g.s);
76325
+ return escapeHtml(describe(g.name, g.s));
76321
76326
  },
76322
76327
  },
76323
76328
  xAxis: horizontal ? valueAxis : categoryAxis,