@lobehub/charts 2.1.0 → 2.1.1

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.
@@ -30,7 +30,7 @@ import NoData from "../common/NoData";
30
30
  import { constructCategoryColors, deepEqual, getYAxisDomain } from "../common/utils";
31
31
  import { useThemeColorRange } from "../hooks/useThemeColorRange";
32
32
  import { defaultValueFormatter } from "../utils";
33
- import { getMaxLabelLength } from "../utils/getMaxLabelLength";
33
+ import { getMaxLabelLength, getTextWidth } from "../utils/getMaxLabelLength";
34
34
  import { useStyles } from "./styles";
35
35
  import { jsx as _jsx } from "react/jsx-runtime";
36
36
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -427,8 +427,13 @@ var AccuracyBarChart = /*#__PURE__*/forwardRef(function (props, ref) {
427
427
  var lx = labelProps.x,
428
428
  ly = labelProps.y,
429
429
  lh = labelProps.height,
430
+ lw = labelProps.width,
430
431
  value = labelProps.value;
431
- if (lx === null || lx === undefined || ly === null || ly === undefined || lh === null || lh === undefined) return null;
432
+ if (lx === null || lx === undefined || ly === null || ly === undefined || lh === null || lh === undefined || lw === null || lw === undefined) return null;
433
+ var text = accuracyFormatter(Number(value !== null && value !== void 0 ? value : 0));
434
+ var textWidth = getTextWidth(text);
435
+ var horizontalPadding = 16; // 8px left padding + 8px safe space
436
+ if (Number(lw) <= textWidth + horizontalPadding) return null;
432
437
  return /*#__PURE__*/_jsx("text", {
433
438
  className: styles.percentageLabel,
434
439
  dominantBaseline: "central",
@@ -437,7 +442,7 @@ var AccuracyBarChart = /*#__PURE__*/forwardRef(function (props, ref) {
437
442
  },
438
443
  x: Number(lx) + 8,
439
444
  y: Number(ly) + Number(lh) / 2,
440
- children: accuracyFormatter(Number(value !== null && value !== void 0 ? value : 0))
445
+ children: text
441
446
  });
442
447
  },
443
448
  dataKey: category,
@@ -445,7 +450,7 @@ var AccuracyBarChart = /*#__PURE__*/forwardRef(function (props, ref) {
445
450
  position: "insideLeft"
446
451
  }) : null, showErrorBars ? /*#__PURE__*/_jsx(ErrorBar, {
447
452
  dataKey: errorKey,
448
- direction: "x",
453
+ direction: layout === 'vertical' ? 'x' : 'y',
449
454
  stroke: theme.colorTextSecondary
450
455
  }) : null]
451
456
  }, category)]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/charts",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "React modern charts components built on recharts",
5
5
  "keywords": [
6
6
  "lobehub",