cats-charts 0.0.90 → 0.0.92

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.
@@ -1447,6 +1447,19 @@ class Charts {
1447
1447
  return Math.max(...levelMap.values());
1448
1448
  }
1449
1449
  sankeyTooltipFormatter(params, config) {
1450
+ const showPercentage = config.styling?.labels?.showPercentage === true;
1451
+ const targetNames = new Set((config.links ?? []).map((link) => link.target));
1452
+ const sourceTotal = (config.links ?? [])
1453
+ .filter((link) => !targetNames.has(link.source))
1454
+ .reduce((sum, link) => sum + Number(link.value || 0), 0);
1455
+ const totalValue = sourceTotal || (config.links ?? []).reduce((sum, link) => sum + Number(link.value || 0), 0);
1456
+ const percentageRow = (item) => {
1457
+ const value = Number(item);
1458
+ if (!showPercentage || !Number.isFinite(value))
1459
+ return '';
1460
+ const percentage = totalValue ? ((value / totalValue) * 100).toFixed(1) : '0.0';
1461
+ return `${percentage}%`;
1462
+ };
1450
1463
  if (params.dataType === 'edge') {
1451
1464
  const { source, target, value, tooltip } = params.data;
1452
1465
  const escape = (item) => String(item ?? '').replace(/[&<>"']/g, (char) => ({
@@ -1481,7 +1494,7 @@ class Charts {
1481
1494
  />
1482
1495
  <span>${escape(target)}</span>
1483
1496
  </div>
1484
- <div style="font-size:12px;font-weight:600"">${formatKey(config?.activeMetric ?? '') || 'Value'}: <span style="font-size:12px;font-weight:400">${escape(typeof value === 'number' ? this.formatTooltipValue(value, config.tooltipCompactValue) : value)}</span></div>
1497
+ <div style="font-size:12px;font-weight:600">${formatKey(config?.activeMetric ?? '') || 'Value'}: <span style="font-size:12px;font-weight:400">${showPercentage ? '(' : ''}${escape(typeof value === 'number' ? this.formatTooltipValue(value, config.tooltipCompactValue) : value)}${showPercentage ? ')' : ''} ${showPercentage ? percentageRow(value) : ''}</span></div>
1485
1498
  ${tooltipRows}
1486
1499
  </div>
1487
1500
  `;
@@ -1493,7 +1506,8 @@ class Charts {
1493
1506
  border-radius: 8px;
1494
1507
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
1495
1508
  ">
1496
- ${params.name}: <b>${typeof params.value === 'number' ? this.formatTooltipValue(params.value, config.tooltipCompactValue) : params.value}</b>
1509
+ ${params.name}: <b>${showPercentage ? '(' : ''}${typeof params.value === 'number' ? this.formatTooltipValue(params.value, config.tooltipCompactValue) : params.value}${showPercentage ? ')' : ''}</b>
1510
+ ${percentageRow(params.value)}
1497
1511
  </div>
1498
1512
  `;
1499
1513
  }
@@ -4042,14 +4056,14 @@ class SankeyChart {
4042
4056
  bottom: legendEnabled && legendConfig?.position === 'bottom' ? 32 : 16,
4043
4057
  ...this.config.seriesOption,
4044
4058
  type: 'sankey',
4045
- ...(styling?.node?.thickness ?? this.config.seriesOption?.nodeWidth
4059
+ ...((styling?.node?.thickness ?? this.config.seriesOption?.nodeWidth)
4046
4060
  ? {
4047
- nodeWidth: this.clamp(styling?.node?.thickness ?? this.config.seriesOption?.nodeWidth, 1, 50)
4061
+ nodeWidth: this.clamp(styling?.node?.thickness ?? this.config.seriesOption?.nodeWidth, 1, 50),
4048
4062
  }
4049
4063
  : {}),
4050
- ...(styling?.node?.padding ?? this.config.seriesOption?.nodeGap
4064
+ ...((styling?.node?.padding ?? this.config.seriesOption?.nodeGap)
4051
4065
  ? {
4052
- nodeGap: this.clamp(styling?.node?.padding ?? this.config.seriesOption?.nodeGap, 0, 100)
4066
+ nodeGap: this.clamp(styling?.node?.padding ?? this.config.seriesOption?.nodeGap, 0, 100),
4053
4067
  }
4054
4068
  : {}),
4055
4069
  data: visibleNodes.map((n, index) => {
@@ -4105,8 +4119,16 @@ class SankeyChart {
4105
4119
  color: fontColor,
4106
4120
  fontFamily: labelTypography?.reset ? undefined : labelTypography?.fontFamily,
4107
4121
  fontSize: this.clamp(labelTypography?.reset ? undefined : labelTypography?.fontSize, 8, 40),
4108
- fontWeight: labelTypography?.reset ? undefined : labelTypography?.bold ? 'bold' : undefined,
4109
- fontStyle: labelTypography?.reset ? undefined : labelTypography?.italic ? 'italic' : undefined,
4122
+ fontWeight: labelTypography?.reset
4123
+ ? undefined
4124
+ : labelTypography?.bold
4125
+ ? 'bold'
4126
+ : undefined,
4127
+ fontStyle: labelTypography?.reset
4128
+ ? undefined
4129
+ : labelTypography?.italic
4130
+ ? 'italic'
4131
+ : undefined,
4110
4132
  textDecoration: labelTypography?.reset
4111
4133
  ? undefined
4112
4134
  : labelTypography?.underline
@@ -4287,8 +4309,8 @@ class SankeyChart {
4287
4309
  ? styling.individualColors?.source
4288
4310
  : meta.role === 'destination'
4289
4311
  ? styling.individualColors?.destination
4290
- : styling.individualColors?.middle?.[meta.depth] ??
4291
- styling.individualColors?.middle?.[String(meta.depth)];
4312
+ : (styling.individualColors?.middle?.[meta.depth] ??
4313
+ styling.individualColors?.middle?.[String(meta.depth)]);
4292
4314
  if (colorStop?.color) {
4293
4315
  return this.withOpacity(colorStop.color, this.percentToRatio(colorStop.opacity, 100));
4294
4316
  }
@@ -4302,9 +4324,13 @@ class SankeyChart {
4302
4324
  return {
4303
4325
  itemStyle: {
4304
4326
  ...(nodeStyle.color
4305
- ? { color: this.withOpacity(nodeStyle.color, this.percentToRatio(nodeStyle.opacity, 100)) }
4327
+ ? {
4328
+ color: this.withOpacity(nodeStyle.color, this.percentToRatio(nodeStyle.opacity, 100)),
4329
+ }
4330
+ : {}),
4331
+ ...(nodeStyle.opacity !== undefined
4332
+ ? { opacity: this.percentToRatio(nodeStyle.opacity, 100) }
4306
4333
  : {}),
4307
- ...(nodeStyle.opacity !== undefined ? { opacity: this.percentToRatio(nodeStyle.opacity, 100) } : {}),
4308
4334
  ...(nodeStyle.itemStyle || {}),
4309
4335
  },
4310
4336
  label: nodeStyle.label,
@@ -4348,14 +4374,16 @@ class SankeyChart {
4348
4374
  const text = this.applyCase(name, labels?.typography?.reset ? 'none' : labels?.typography?.case);
4349
4375
  const stats = [];
4350
4376
  if (labels?.showNumbers)
4351
- stats.push(String(meta?.value ?? 0));
4377
+ stats.push(String(`${labels?.showPercentage ? `(${meta?.value ?? 0})` : (meta?.value ?? 0)}`));
4352
4378
  if (labels?.showPercentage) {
4353
4379
  const percentage = totalValue ? (((meta?.value ?? 0) / totalValue) * 100).toFixed(1) : '0.0';
4354
4380
  stats.push(`${percentage}%`);
4355
4381
  }
4356
4382
  if (!stats.length)
4357
4383
  return text;
4358
- return labels?.splitLabelsAndStats ? `${text}\n${stats.join(' ')}` : `${text} ${stats.join(' ')}`;
4384
+ return labels?.splitLabelsAndStats
4385
+ ? `${text}\n${stats.join(' ')}`
4386
+ : `${text} ${stats.join(' ')}`;
4359
4387
  }
4360
4388
  resolveLabelPosition() {
4361
4389
  const alignment = this.config.styling?.labels?.alignment;
@@ -5299,7 +5327,10 @@ class GaugeChart {
5299
5327
  chartInstance;
5300
5328
  chartResizeObserver;
5301
5329
  previousReactiveSignature = '';
5302
- constructor(chartService) {
5330
+ // Keep direct construction backwards compatible for consumers that build chart
5331
+ // options outside Angular's DI context. Angular still injects the root service
5332
+ // when this class is created as a component.
5333
+ constructor(chartService = new Charts()) {
5303
5334
  this.chartService = chartService;
5304
5335
  }
5305
5336
  ngOnChanges(changes) {
@@ -5524,7 +5555,7 @@ class GaugeChart {
5524
5555
  axisLine: {
5525
5556
  lineStyle: {
5526
5557
  width: 0,
5527
- color: [1, 'transparent'],
5558
+ color: [[1, 'transparent']],
5528
5559
  },
5529
5560
  },
5530
5561
  pointer: {
@@ -6267,6 +6298,10 @@ class GanttChart {
6267
6298
  zoomWheelHandler;
6268
6299
  visibleRows = [];
6269
6300
  rowIndexMap = new Map();
6301
+ constructor(chartService, cdr) {
6302
+ this.chartService = chartService;
6303
+ this.cdr = cdr;
6304
+ }
6270
6305
  get deafultColors() {
6271
6306
  return this.chartService.defaultColors;
6272
6307
  }
@@ -6446,10 +6481,6 @@ class GanttChart {
6446
6481
  return (this.config?.customLegend?.position === 'left' ||
6447
6482
  this.config?.customLegend?.position === 'right');
6448
6483
  }
6449
- constructor(chartService, cdr) {
6450
- this.chartService = chartService;
6451
- this.cdr = cdr;
6452
- }
6453
6484
  /* ------------------ CHANGE HANDLING ------------------ */
6454
6485
  ngOnChanges(changes) {
6455
6486
  if (!this.config)