cx 23.5.2 → 23.6.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/dist/charts.js CHANGED
@@ -272,7 +272,7 @@ var Axis = /*#__PURE__*/ (function (_BoundedObject) {
272
272
  if (isUndefined(this.minLabelDistance))
273
273
  this.minLabelDistance = this.vertical ? this.minLabelDistanceVertical : this.minLabelDistanceHorizontal;
274
274
  if (this.labelLineCountDyFactor == "auto")
275
- this.labelLineCountDyFactor = this.vertical ? -0.5 : this.secondary ? -1 : 0;
275
+ this.labelLineCountDyFactor = this.vertical ? -this.labelLineHeight / 2 : this.secondary ? -1 : 0;
276
276
  this.lineStyle = parseStyle(this.lineStyle);
277
277
  this.tickStyle = parseStyle(this.tickStyle);
278
278
  this.labelStyle = parseStyle(this.labelStyle);
@@ -301,6 +301,11 @@ var Axis = /*#__PURE__*/ (function (_BoundedObject) {
301
301
  ].concat(Array.prototype.slice.call(arguments))
302
302
  );
303
303
  };
304
+ _proto.prepareData = function prepareData(context, instance) {
305
+ _BoundedObject.prototype.prepareData.call(this, context, instance);
306
+ if (this.onCreateLabelFormatter)
307
+ instance.labelFormatter = instance.invoke("onCreateLabelFormatter", context, instance);
308
+ };
304
309
  _proto.report = function report(context, instance) {
305
310
  return instance.calculator;
306
311
  };
@@ -308,7 +313,8 @@ var Axis = /*#__PURE__*/ (function (_BoundedObject) {
308
313
  var _this = this;
309
314
  if (this.hidden) return false;
310
315
  var data = instance.data,
311
- calculator = instance.calculator;
316
+ calculator = instance.calculator,
317
+ labelFormatter = instance.labelFormatter;
312
318
  var bounds = data.bounds;
313
319
  var CSS = this.CSS,
314
320
  baseClass = this.baseClass;
@@ -371,6 +377,8 @@ var Axis = /*#__PURE__*/ (function (_BoundedObject) {
371
377
  y = _this.vertical ? s : bounds.b + _this.labelOffset;
372
378
  }
373
379
  var transform = data.labelRotation ? "rotate(" + data.labelRotation + " " + x + " " + y + ")" : null;
380
+ var formattedValue = valueFormatter(v);
381
+ var lines = labelFormatter ? labelFormatter(formattedValue, v) : _this.wrapLines(formattedValue);
374
382
  res.push(
375
383
  /*#__PURE__*/ jsx(
376
384
  "text",
@@ -379,10 +387,9 @@ var Axis = /*#__PURE__*/ (function (_BoundedObject) {
379
387
  style: data.labelStyle,
380
388
  x: x,
381
389
  y: y,
382
- dx: _this.labelDx,
383
390
  textAnchor: data.labelAnchor,
384
391
  transform: transform,
385
- children: _this.wrapLines(valueFormatter(v), x, _this.labelDy, offsetClass),
392
+ children: _this.renderLabels(lines, x, _this.labelDy, _this.labelDx, offsetClass),
386
393
  },
387
394
  "label-" + si + "-" + i
388
395
  )
@@ -403,13 +410,13 @@ var Axis = /*#__PURE__*/ (function (_BoundedObject) {
403
410
  }
404
411
  return res;
405
412
  };
406
- _proto.wrapLines = function wrapLines(str, x, dy, offsetClass) {
413
+ _proto.wrapLines = function wrapLines(str) {
407
414
  if (!this.labelWrap || typeof str != "string")
408
- return /*#__PURE__*/ jsx("tspan", {
409
- x: x,
410
- dy: dy,
411
- children: str,
412
- });
415
+ return [
416
+ {
417
+ text: str,
418
+ },
419
+ ];
413
420
  var parts = str.split(" ");
414
421
  if (parts.length == 0) return null;
415
422
  var lines = [];
@@ -418,20 +425,23 @@ var Axis = /*#__PURE__*/ (function (_BoundedObject) {
418
425
  if (!line) line = parts[i];
419
426
  else if (parts[i].length + line.length < this.labelMaxLineLength) line += " " + parts[i];
420
427
  else {
421
- lines.push(line);
428
+ lines.push({
429
+ text: line,
430
+ });
422
431
  line = parts[i];
423
432
  }
424
433
  }
425
- lines.push(line);
426
- if (lines.length == 1)
427
- return /*#__PURE__*/ jsx("tspan", {
428
- x: x,
429
- dy: dy,
430
- children: str,
431
- });
434
+ lines.push({
435
+ text: line,
436
+ });
437
+ return lines;
438
+ };
439
+ _proto.renderLabels = function renderLabels(lines, x, dy, dx, offsetClass) {
440
+ var _this2 = this;
432
441
  var offset = this.labelLineCountDyFactor * (lines.length - 1);
433
- var result = [
434
- dy != null &&
442
+ var result = [];
443
+ if (lines.length > 1 && dy != null) {
444
+ result.push(
435
445
  /*#__PURE__*/ jsx(
436
446
  "tspan",
437
447
  {
@@ -440,16 +450,20 @@ var Axis = /*#__PURE__*/ (function (_BoundedObject) {
440
450
  children: "_",
441
451
  },
442
452
  -2
443
- ),
444
- ];
453
+ )
454
+ );
455
+ }
445
456
  lines.forEach(function (p, i) {
446
457
  result.push(
447
458
  /*#__PURE__*/ jsx(
448
459
  "tspan",
449
460
  {
450
- dy: (i == 0 ? offset : 1) + "em",
461
+ dy: lines.length > 1 ? (i == 0 ? offset : _this2.labelLineHeight) + "em" : dy,
451
462
  x: x,
452
- children: p,
463
+ style: p.style,
464
+ className: p.className,
465
+ dx: dx,
466
+ children: p.text,
453
467
  },
454
468
  i
455
469
  )
@@ -494,6 +508,7 @@ Axis.prototype.labelDx = "auto";
494
508
  Axis.prototype.labelDy = "auto";
495
509
  Axis.prototype.labelWrap = false;
496
510
  Axis.prototype.labelLineCountDyFactor = "auto";
511
+ Axis.prototype.labelLineHeight = 1;
497
512
  Axis.prototype.labelMaxLineLength = 10;
498
513
  Axis.namespace = "ui.svg.chart.axis";
499
514