@yamada-ui/charts 1.2.1-dev-20240708010533 → 1.3.0-dev-20240711094251

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/index.js CHANGED
@@ -2914,19 +2914,100 @@ var RadarChart = (0, import_core16.forwardRef)((props, ref) => {
2914
2914
  });
2915
2915
 
2916
2916
  // src/donut-chart.tsx
2917
- var import_core18 = require("@yamada-ui/core");
2918
- var import_utils19 = require("@yamada-ui/utils");
2917
+ var import_core19 = require("@yamada-ui/core");
2918
+ var import_utils20 = require("@yamada-ui/utils");
2919
2919
  var import_react16 = require("react");
2920
2920
  var import_recharts5 = require("recharts");
2921
2921
 
2922
2922
  // src/use-pie-chart.ts
2923
+ var import_core18 = require("@yamada-ui/core");
2924
+ var import_utils19 = require("@yamada-ui/utils");
2925
+ var import_react15 = require("react");
2926
+
2927
+ // src/pie-chart-label.tsx
2923
2928
  var import_core17 = require("@yamada-ui/core");
2924
2929
  var import_utils18 = require("@yamada-ui/utils");
2925
- var import_react15 = require("react");
2930
+ var import_jsx_runtime9 = require("react/jsx-runtime");
2931
+ var RADIAN = Math.PI / 180;
2932
+ var DEFAULT_LABEL_OFFSET = 22;
2933
+ var pieChartLabel = ({
2934
+ className: cellClassName,
2935
+ cx: cxProp = 0,
2936
+ cy: cyProp = 0,
2937
+ midAngle = 0,
2938
+ innerRadius = 0,
2939
+ outerRadius = 0,
2940
+ middleRadius = 0,
2941
+ percent = 0,
2942
+ value = 0,
2943
+ labelOffset: labelOffsetProp,
2944
+ isParcent,
2945
+ labelProps,
2946
+ valueFormatter,
2947
+ styles
2948
+ }) => {
2949
+ const labelOffset = labelOffsetProp != null ? labelOffsetProp : (outerRadius - innerRadius) * 0.5 + DEFAULT_LABEL_OFFSET;
2950
+ const x = cxProp + (middleRadius + labelOffset) * Math.cos(-midAngle * RADIAN);
2951
+ const y = cyProp + (middleRadius + labelOffset) * Math.sin(-midAngle * RADIAN);
2952
+ const textAnchor = x > cxProp ? "start" : x < cxProp ? "end" : "middle";
2953
+ const displayLabel = () => {
2954
+ if (isParcent) {
2955
+ return parseFloat((percent * 100).toFixed(0)) > 0 && `${(percent * 100).toFixed(0)}%`;
2956
+ } else if (!(0, import_utils18.isUndefined)(valueFormatter)) {
2957
+ return valueFormatter(value);
2958
+ } else {
2959
+ return value;
2960
+ }
2961
+ };
2962
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
2963
+ import_core17.ui.text,
2964
+ {
2965
+ className: (0, import_utils18.cx)(cellClassName, "ui-chart__label"),
2966
+ x,
2967
+ y,
2968
+ textAnchor,
2969
+ dominantBaseline: "central",
2970
+ __css: styles,
2971
+ ...labelProps,
2972
+ children: displayLabel()
2973
+ }
2974
+ );
2975
+ };
2976
+ var pieChartLabelLine = ({
2977
+ className: cellClassName,
2978
+ cx: cxProp = 0,
2979
+ cy: cyProp = 0,
2980
+ innerRadius = 0,
2981
+ midAngle = 0,
2982
+ middleRadius = 0,
2983
+ outerRadius = 0,
2984
+ points = [{ x: 0, y: 0 }],
2985
+ labelOffset: labelOffsetProp,
2986
+ labelLineProps,
2987
+ styles
2988
+ }) => {
2989
+ const labelOffset = labelOffsetProp != null ? labelOffsetProp : (outerRadius - innerRadius) * 0.5 + DEFAULT_LABEL_OFFSET;
2990
+ const x = cxProp + (middleRadius + labelOffset) * Math.cos(-midAngle * RADIAN);
2991
+ const y = cyProp + (middleRadius + labelOffset) * Math.sin(-midAngle * RADIAN);
2992
+ const d = `M ${points[0].x} ${points[0].y} L ${x} ${y}`;
2993
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
2994
+ import_core17.ui.path,
2995
+ {
2996
+ className: (0, import_utils18.cx)(cellClassName, "ui-chart__label-line"),
2997
+ d,
2998
+ __css: styles,
2999
+ ...labelLineProps
3000
+ }
3001
+ );
3002
+ };
3003
+
3004
+ // src/use-pie-chart.ts
2926
3005
  var usePieChart = ({
2927
3006
  data,
2928
3007
  withLabels = false,
2929
3008
  withLabelLines = false,
3009
+ labelOffset,
3010
+ isParcent = false,
2930
3011
  strokeWidth = 1,
2931
3012
  fillOpacity = 1,
2932
3013
  innerRadius = "0%",
@@ -2934,19 +3015,20 @@ var usePieChart = ({
2934
3015
  paddingAngle = 0,
2935
3016
  startAngle = 90,
2936
3017
  endAngle = -270,
3018
+ valueFormatter,
2937
3019
  styles,
2938
3020
  ...rest
2939
3021
  }) => {
2940
3022
  var _a, _b;
2941
- const { theme } = (0, import_core17.useTheme)();
3023
+ const { theme } = (0, import_core18.useTheme)();
2942
3024
  const [highlightedArea, setHighlightedArea] = (0, import_react15.useState)(null);
2943
3025
  const shouldHighlight = highlightedArea !== null;
2944
3026
  const { dimCell, ...computedCellProps } = (_a = rest.cellProps) != null ? _a : {};
2945
3027
  const {
2946
3028
  activeShape = {},
2947
3029
  inactiveShape = {},
2948
- label,
2949
- labelLine,
3030
+ label: labelProps,
3031
+ labelLine: labelLineProps,
2950
3032
  ...computedPieProps
2951
3033
  } = (_b = rest.pieProps) != null ? _b : {};
2952
3034
  const cellColors = (0, import_react15.useMemo)(
@@ -3008,13 +3090,27 @@ var usePieChart = ({
3008
3090
  )(theme, true),
3009
3091
  [inactiveShape, styles.inactiveShape, theme]
3010
3092
  );
3011
- const labelClassName = (0, import_react15.useMemo)(
3012
- () => getClassName({ fillOpacity: 1, ...styles.label, ...label })(theme),
3013
- [label, styles.label, theme]
3014
- );
3015
- const labelLineClassName = (0, import_react15.useMemo)(
3016
- () => getClassName({ ...styles.labelLine, ...labelLine })(theme),
3017
- [labelLine, styles.labelLine, theme]
3093
+ const label = (0, import_react15.useCallback)(
3094
+ (props) => pieChartLabel({
3095
+ labelOffset,
3096
+ isParcent,
3097
+ labelProps,
3098
+ valueFormatter,
3099
+ styles: styles.label,
3100
+ ...props
3101
+ }),
3102
+ [isParcent, labelOffset, labelProps, styles.label, valueFormatter]
3103
+ );
3104
+ const labelLine = (0, import_react15.useCallback)(
3105
+ (props) => {
3106
+ return pieChartLabelLine({
3107
+ labelOffset,
3108
+ labelLineProps,
3109
+ styles: styles.labelLine,
3110
+ ...props
3111
+ });
3112
+ },
3113
+ [labelLineProps, labelOffset, styles.labelLine]
3018
3114
  );
3019
3115
  const cellPropList = (0, import_react15.useMemo)(
3020
3116
  () => data.map((props, index) => {
@@ -3049,21 +3145,16 @@ var usePieChart = ({
3049
3145
  const getPieChartProps = (0, import_react15.useCallback)(
3050
3146
  ({ className, ...props } = {}, ref = null) => ({
3051
3147
  ref,
3052
- className: (0, import_utils18.cx)(className, chartClassName),
3148
+ className: (0, import_utils19.cx)(className, chartClassName),
3053
3149
  ...props,
3054
3150
  ...chartProps
3055
3151
  }),
3056
3152
  [chartProps, chartClassName]
3057
3153
  );
3058
3154
  const getPieProps = (0, import_react15.useCallback)(
3059
- ({
3060
- className,
3061
- labelClassName: labelClassNameProp,
3062
- labelLineClassName: labelLineClassNameProp,
3063
- ...props
3064
- }, ref = null) => ({
3155
+ ({ className, ...props }, ref = null) => ({
3065
3156
  ref,
3066
- className: (0, import_utils18.cx)(className, pieClassName),
3157
+ className: (0, import_utils19.cx)(className, pieClassName),
3067
3158
  dataKey: "value",
3068
3159
  data,
3069
3160
  rootTabIndex: -1,
@@ -3073,8 +3164,8 @@ var usePieChart = ({
3073
3164
  startAngle,
3074
3165
  endAngle,
3075
3166
  isAnimationActive: false,
3076
- label: withLabels ? { className: (0, import_utils18.cx)(labelClassNameProp, labelClassName) } : false,
3077
- labelLine: withLabelLines ? { className: (0, import_utils18.cx)(labelLineClassNameProp, labelLineClassName) } : false,
3167
+ label: withLabels ? label : false,
3168
+ labelLine: withLabelLines ? labelLine : false,
3078
3169
  activeShape: activeShapeProps,
3079
3170
  inactiveShape: inactiveShapeProps,
3080
3171
  ...props,
@@ -3089,9 +3180,9 @@ var usePieChart = ({
3089
3180
  startAngle,
3090
3181
  endAngle,
3091
3182
  withLabels,
3092
- labelClassName,
3183
+ label,
3093
3184
  withLabelLines,
3094
- labelLineClassName,
3185
+ labelLine,
3095
3186
  activeShapeProps,
3096
3187
  inactiveShapeProps,
3097
3188
  pieProps
@@ -3102,7 +3193,7 @@ var usePieChart = ({
3102
3193
  const { className, color } = cellPropList[index];
3103
3194
  return {
3104
3195
  ref,
3105
- className: (0, import_utils18.cx)(classNameProp, className),
3196
+ className: (0, import_utils19.cx)(classNameProp, className),
3106
3197
  fill: color,
3107
3198
  stroke: color,
3108
3199
  strokeWidth,
@@ -3121,9 +3212,9 @@ var usePieChart = ({
3121
3212
  };
3122
3213
 
3123
3214
  // src/donut-chart.tsx
3124
- var import_jsx_runtime9 = require("react/jsx-runtime");
3125
- var DonutChart = (0, import_core18.forwardRef)((props, ref) => {
3126
- const [styles, mergedProps] = (0, import_core18.useMultiComponentStyle)("DonutChart", props);
3215
+ var import_jsx_runtime10 = require("react/jsx-runtime");
3216
+ var DonutChart = (0, import_core19.forwardRef)((props, ref) => {
3217
+ const [styles, mergedProps] = (0, import_core19.useMultiComponentStyle)("DonutChart", props);
3127
3218
  const {
3128
3219
  className,
3129
3220
  data,
@@ -3143,12 +3234,14 @@ var DonutChart = (0, import_core18.forwardRef)((props, ref) => {
3143
3234
  endAngle,
3144
3235
  withLabels,
3145
3236
  withLabelLines,
3237
+ labelOffset,
3238
+ isParcent,
3146
3239
  innerRadius = withLabels ? "60%" : "80%",
3147
3240
  outerRadius,
3148
3241
  strokeWidth,
3149
3242
  legendProps,
3150
3243
  ...rest
3151
- } = (0, import_core18.omitThemeProps)(mergedProps);
3244
+ } = (0, import_core19.omitThemeProps)(mergedProps);
3152
3245
  const {
3153
3246
  pieVars,
3154
3247
  getPieProps,
@@ -3168,6 +3261,9 @@ var DonutChart = (0, import_core18.forwardRef)((props, ref) => {
3168
3261
  strokeWidth,
3169
3262
  withLabels,
3170
3263
  withLabelLines,
3264
+ labelOffset,
3265
+ isParcent,
3266
+ valueFormatter,
3171
3267
  styles
3172
3268
  });
3173
3269
  const { getContainerProps } = useChart({ containerProps });
@@ -3180,7 +3276,7 @@ var DonutChart = (0, import_core18.forwardRef)((props, ref) => {
3180
3276
  legendProps
3181
3277
  });
3182
3278
  const cells = (0, import_react16.useMemo)(
3183
- () => data.map(({ name }, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3279
+ () => data.map(({ name }, index) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3184
3280
  import_recharts5.Cell,
3185
3281
  {
3186
3282
  ...getCellProps({ index, className: "ui-donut-chart__cell" })
@@ -3189,38 +3285,36 @@ var DonutChart = (0, import_core18.forwardRef)((props, ref) => {
3189
3285
  )),
3190
3286
  [data, getCellProps]
3191
3287
  );
3192
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ChartProvider, { value: { styles }, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3193
- import_core18.ui.div,
3288
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ChartProvider, { value: { styles }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3289
+ import_core19.ui.div,
3194
3290
  {
3195
3291
  ref,
3196
- className: (0, import_utils19.cx)("ui-donut-chart", className),
3292
+ className: (0, import_utils20.cx)("ui-donut-chart", className),
3197
3293
  var: pieVars,
3198
3294
  __css: { maxW: "full", ...styles.container },
3199
3295
  ...rest,
3200
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3296
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3201
3297
  import_recharts5.ResponsiveContainer,
3202
3298
  {
3203
3299
  ...getContainerProps({ className: "ui-donut-chart__container" }),
3204
- children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
3300
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
3205
3301
  import_recharts5.PieChart,
3206
3302
  {
3207
3303
  ...getPieChartProps({ className: "ui-donut-chart__chart" }),
3208
3304
  children: [
3209
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3305
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3210
3306
  import_recharts5.Pie,
3211
3307
  {
3212
3308
  ...getPieProps({
3213
- className: "ui-donut-chart__donut",
3214
- labelClassName: "ui-donut-chart__label",
3215
- labelLineClassName: "ui-donut-chart__label-line"
3309
+ className: "ui-donut-chart__donut"
3216
3310
  }),
3217
3311
  children: cells
3218
3312
  }
3219
3313
  ),
3220
- withLegend ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3314
+ withLegend ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3221
3315
  import_recharts5.Legend,
3222
3316
  {
3223
- content: ({ payload }) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3317
+ content: ({ payload }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3224
3318
  ChartLegend,
3225
3319
  {
3226
3320
  className: "ui-donut-chart__legend",
@@ -3232,10 +3326,10 @@ var DonutChart = (0, import_core18.forwardRef)((props, ref) => {
3232
3326
  ...getLegendProps()
3233
3327
  }
3234
3328
  ) : null,
3235
- withTooltip ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3329
+ withTooltip ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3236
3330
  import_recharts5.Tooltip,
3237
3331
  {
3238
- content: ({ label, payload }) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3332
+ content: ({ label, payload }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3239
3333
  ChartTooltip,
3240
3334
  {
3241
3335
  className: "ui-donut-chart__tooltip",
@@ -3259,13 +3353,13 @@ var DonutChart = (0, import_core18.forwardRef)((props, ref) => {
3259
3353
  });
3260
3354
 
3261
3355
  // src/pie-chart.tsx
3262
- var import_core19 = require("@yamada-ui/core");
3263
- var import_utils20 = require("@yamada-ui/utils");
3356
+ var import_core20 = require("@yamada-ui/core");
3357
+ var import_utils21 = require("@yamada-ui/utils");
3264
3358
  var import_react17 = require("react");
3265
3359
  var import_recharts6 = require("recharts");
3266
- var import_jsx_runtime10 = require("react/jsx-runtime");
3267
- var PieChart = (0, import_core19.forwardRef)((props, ref) => {
3268
- const [styles, mergedProps] = (0, import_core19.useMultiComponentStyle)("PieChart", props);
3360
+ var import_jsx_runtime11 = require("react/jsx-runtime");
3361
+ var PieChart = (0, import_core20.forwardRef)((props, ref) => {
3362
+ const [styles, mergedProps] = (0, import_core20.useMultiComponentStyle)("PieChart", props);
3269
3363
  const {
3270
3364
  className,
3271
3365
  data,
@@ -3287,10 +3381,12 @@ var PieChart = (0, import_core19.forwardRef)((props, ref) => {
3287
3381
  endAngle,
3288
3382
  withLabels,
3289
3383
  withLabelLines,
3384
+ labelOffset,
3385
+ isParcent,
3290
3386
  strokeWidth,
3291
3387
  legendProps,
3292
3388
  ...rest
3293
- } = (0, import_core19.omitThemeProps)(mergedProps);
3389
+ } = (0, import_core20.omitThemeProps)(mergedProps);
3294
3390
  const {
3295
3391
  pieVars,
3296
3392
  getPieProps,
@@ -3310,6 +3406,9 @@ var PieChart = (0, import_core19.forwardRef)((props, ref) => {
3310
3406
  strokeWidth,
3311
3407
  withLabels,
3312
3408
  withLabelLines,
3409
+ labelOffset,
3410
+ isParcent,
3411
+ valueFormatter,
3313
3412
  styles
3314
3413
  });
3315
3414
  const { getContainerProps } = useChart({ containerProps });
@@ -3322,7 +3421,7 @@ var PieChart = (0, import_core19.forwardRef)((props, ref) => {
3322
3421
  legendProps
3323
3422
  });
3324
3423
  const cells = (0, import_react17.useMemo)(
3325
- () => data.map(({ name }, index) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3424
+ () => data.map(({ name }, index) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3326
3425
  import_recharts6.Cell,
3327
3426
  {
3328
3427
  ...getCellProps({ index, className: "ui-pie-chart__cell" })
@@ -3331,38 +3430,36 @@ var PieChart = (0, import_core19.forwardRef)((props, ref) => {
3331
3430
  )),
3332
3431
  [data, getCellProps]
3333
3432
  );
3334
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ChartProvider, { value: { styles }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3335
- import_core19.ui.div,
3433
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ChartProvider, { value: { styles }, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3434
+ import_core20.ui.div,
3336
3435
  {
3337
3436
  ref,
3338
- className: (0, import_utils20.cx)("ui-pie-chart", className),
3437
+ className: (0, import_utils21.cx)("ui-pie-chart", className),
3339
3438
  var: pieVars,
3340
3439
  __css: { maxW: "full", ...styles.container },
3341
3440
  ...rest,
3342
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3441
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3343
3442
  import_recharts6.ResponsiveContainer,
3344
3443
  {
3345
3444
  ...getContainerProps({ className: "ui-pie-chart__container" }),
3346
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
3445
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3347
3446
  import_recharts6.PieChart,
3348
3447
  {
3349
3448
  ...getPieChartProps({ className: "ui-pie-chart__chart" }),
3350
3449
  children: [
3351
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3450
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3352
3451
  import_recharts6.Pie,
3353
3452
  {
3354
3453
  ...getPieProps({
3355
- className: "ui-pie-chart__pie",
3356
- labelClassName: "ui-pie-chart__label",
3357
- labelLineClassName: "ui-pie-chart__label-line"
3454
+ className: "ui-pie-chart__pie"
3358
3455
  }),
3359
3456
  children: cells
3360
3457
  }
3361
3458
  ),
3362
- withLegend ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3459
+ withLegend ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3363
3460
  import_recharts6.Legend,
3364
3461
  {
3365
- content: ({ payload }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3462
+ content: ({ payload }) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3366
3463
  ChartLegend,
3367
3464
  {
3368
3465
  className: "ui-pie-chart__legend",
@@ -3374,10 +3471,10 @@ var PieChart = (0, import_core19.forwardRef)((props, ref) => {
3374
3471
  ...getLegendProps()
3375
3472
  }
3376
3473
  ) : null,
3377
- withTooltip ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3474
+ withTooltip ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3378
3475
  import_recharts6.Tooltip,
3379
3476
  {
3380
- content: ({ label, payload }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3477
+ content: ({ label, payload }) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3381
3478
  ChartTooltip,
3382
3479
  {
3383
3480
  className: "ui-pie-chart__tooltip",