@yamada-ui/charts 2.0.0-next-20240706062355 → 2.0.0-next-20240716070106
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chart.types.d.mts +2 -2
- package/dist/chart.types.d.ts +2 -2
- package/dist/chart.types.js.map +1 -1
- package/dist/chunk-CPXE3PV4.mjs +84 -0
- package/dist/chunk-CPXE3PV4.mjs.map +1 -0
- package/dist/{chunk-YGKNNA34.mjs → chunk-ELXW3EQE.mjs} +35 -19
- package/dist/chunk-ELXW3EQE.mjs.map +1 -0
- package/dist/{chunk-P4MMHTAP.mjs → chunk-VVR3DSUX.mjs} +8 -5
- package/dist/chunk-VVR3DSUX.mjs.map +1 -0
- package/dist/{chunk-F2RBOLDY.mjs → chunk-XORRW2KT.mjs} +8 -5
- package/dist/chunk-XORRW2KT.mjs.map +1 -0
- package/dist/donut-chart.js +137 -43
- package/dist/donut-chart.js.map +1 -1
- package/dist/donut-chart.mjs +3 -2
- package/dist/index.js +161 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -3
- package/dist/pie-chart-label.d.mts +40 -0
- package/dist/pie-chart-label.d.ts +40 -0
- package/dist/pie-chart-label.js +108 -0
- package/dist/pie-chart-label.js.map +1 -0
- package/dist/pie-chart-label.mjs +10 -0
- package/dist/pie-chart-label.mjs.map +1 -0
- package/dist/pie-chart.js +137 -43
- package/dist/pie-chart.js.map +1 -1
- package/dist/pie-chart.mjs +3 -2
- package/dist/use-pie-chart.d.mts +12 -5
- package/dist/use-pie-chart.d.ts +12 -5
- package/dist/use-pie-chart.js +113 -24
- package/dist/use-pie-chart.js.map +1 -1
- package/dist/use-pie-chart.mjs +2 -1
- package/package.json +2 -2
- package/dist/chunk-F2RBOLDY.mjs.map +0 -1
- package/dist/chunk-P4MMHTAP.mjs.map +0 -1
- package/dist/chunk-YGKNNA34.mjs.map +0 -1
package/dist/index.mjs
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
"use client"
|
2
2
|
import {
|
3
3
|
DonutChart
|
4
|
-
} from "./chunk-
|
4
|
+
} from "./chunk-VVR3DSUX.mjs";
|
5
5
|
import {
|
6
6
|
LineChart
|
7
7
|
} from "./chunk-KPKLW25H.mjs";
|
8
8
|
import "./chunk-6L73M52L.mjs";
|
9
9
|
import {
|
10
10
|
PieChart
|
11
|
-
} from "./chunk-
|
12
|
-
import "./chunk-
|
11
|
+
} from "./chunk-XORRW2KT.mjs";
|
12
|
+
import "./chunk-ELXW3EQE.mjs";
|
13
|
+
import "./chunk-CPXE3PV4.mjs";
|
13
14
|
import {
|
14
15
|
RadarChart
|
15
16
|
} from "./chunk-CCFQC3T6.mjs";
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { HTMLUIProps, CSSUIObject } from '@yamada-ui/core';
|
2
|
+
import { Dict } from '@yamada-ui/utils';
|
3
|
+
|
4
|
+
type PieChartLabelProps = {
|
5
|
+
className?: string;
|
6
|
+
cx?: number;
|
7
|
+
cy?: number;
|
8
|
+
midAngle?: number;
|
9
|
+
innerRadius?: number;
|
10
|
+
outerRadius?: number;
|
11
|
+
middleRadius?: number;
|
12
|
+
percent?: number;
|
13
|
+
value?: number;
|
14
|
+
labelOffset?: number;
|
15
|
+
isParcent?: boolean;
|
16
|
+
labelProps?: HTMLUIProps<"text">;
|
17
|
+
valueFormatter?: (value: number) => string;
|
18
|
+
styles: Dict<CSSUIObject>;
|
19
|
+
};
|
20
|
+
declare const pieChartLabel: (props: PieChartLabelProps) => React.ReactNode;
|
21
|
+
type Point = {
|
22
|
+
x: number;
|
23
|
+
y: number;
|
24
|
+
};
|
25
|
+
type PieChartLabelLineProps = {
|
26
|
+
className?: string;
|
27
|
+
cx?: number;
|
28
|
+
cy?: number;
|
29
|
+
innerRadius?: number;
|
30
|
+
midAngle?: number;
|
31
|
+
middleRadius?: number;
|
32
|
+
outerRadius?: number;
|
33
|
+
points?: Array<Point>;
|
34
|
+
labelOffset?: number;
|
35
|
+
labelLineProps?: HTMLUIProps<"path">;
|
36
|
+
styles: Dict<CSSUIObject>;
|
37
|
+
};
|
38
|
+
declare const pieChartLabelLine: (props: PieChartLabelLineProps) => React.ReactElement<SVGElement>;
|
39
|
+
|
40
|
+
export { type PieChartLabelLineProps, type PieChartLabelProps, pieChartLabel, pieChartLabelLine };
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { HTMLUIProps, CSSUIObject } from '@yamada-ui/core';
|
2
|
+
import { Dict } from '@yamada-ui/utils';
|
3
|
+
|
4
|
+
type PieChartLabelProps = {
|
5
|
+
className?: string;
|
6
|
+
cx?: number;
|
7
|
+
cy?: number;
|
8
|
+
midAngle?: number;
|
9
|
+
innerRadius?: number;
|
10
|
+
outerRadius?: number;
|
11
|
+
middleRadius?: number;
|
12
|
+
percent?: number;
|
13
|
+
value?: number;
|
14
|
+
labelOffset?: number;
|
15
|
+
isParcent?: boolean;
|
16
|
+
labelProps?: HTMLUIProps<"text">;
|
17
|
+
valueFormatter?: (value: number) => string;
|
18
|
+
styles: Dict<CSSUIObject>;
|
19
|
+
};
|
20
|
+
declare const pieChartLabel: (props: PieChartLabelProps) => React.ReactNode;
|
21
|
+
type Point = {
|
22
|
+
x: number;
|
23
|
+
y: number;
|
24
|
+
};
|
25
|
+
type PieChartLabelLineProps = {
|
26
|
+
className?: string;
|
27
|
+
cx?: number;
|
28
|
+
cy?: number;
|
29
|
+
innerRadius?: number;
|
30
|
+
midAngle?: number;
|
31
|
+
middleRadius?: number;
|
32
|
+
outerRadius?: number;
|
33
|
+
points?: Array<Point>;
|
34
|
+
labelOffset?: number;
|
35
|
+
labelLineProps?: HTMLUIProps<"path">;
|
36
|
+
styles: Dict<CSSUIObject>;
|
37
|
+
};
|
38
|
+
declare const pieChartLabelLine: (props: PieChartLabelLineProps) => React.ReactElement<SVGElement>;
|
39
|
+
|
40
|
+
export { type PieChartLabelLineProps, type PieChartLabelProps, pieChartLabel, pieChartLabelLine };
|
@@ -0,0 +1,108 @@
|
|
1
|
+
"use client"
|
2
|
+
"use strict";
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
+
var __export = (target, all) => {
|
8
|
+
for (var name in all)
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
+
};
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
+
for (let key of __getOwnPropNames(from))
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
+
}
|
17
|
+
return to;
|
18
|
+
};
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
20
|
+
|
21
|
+
// src/pie-chart-label.tsx
|
22
|
+
var pie_chart_label_exports = {};
|
23
|
+
__export(pie_chart_label_exports, {
|
24
|
+
pieChartLabel: () => pieChartLabel,
|
25
|
+
pieChartLabelLine: () => pieChartLabelLine
|
26
|
+
});
|
27
|
+
module.exports = __toCommonJS(pie_chart_label_exports);
|
28
|
+
var import_core = require("@yamada-ui/core");
|
29
|
+
var import_utils = require("@yamada-ui/utils");
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
31
|
+
var RADIAN = Math.PI / 180;
|
32
|
+
var DEFAULT_LABEL_OFFSET = 22;
|
33
|
+
var pieChartLabel = ({
|
34
|
+
className: cellClassName,
|
35
|
+
cx: cxProp = 0,
|
36
|
+
cy: cyProp = 0,
|
37
|
+
midAngle = 0,
|
38
|
+
innerRadius = 0,
|
39
|
+
outerRadius = 0,
|
40
|
+
middleRadius = 0,
|
41
|
+
percent = 0,
|
42
|
+
value = 0,
|
43
|
+
labelOffset: labelOffsetProp,
|
44
|
+
isParcent,
|
45
|
+
labelProps,
|
46
|
+
valueFormatter,
|
47
|
+
styles
|
48
|
+
}) => {
|
49
|
+
const labelOffset = labelOffsetProp != null ? labelOffsetProp : (outerRadius - innerRadius) * 0.5 + DEFAULT_LABEL_OFFSET;
|
50
|
+
const x = cxProp + (middleRadius + labelOffset) * Math.cos(-midAngle * RADIAN);
|
51
|
+
const y = cyProp + (middleRadius + labelOffset) * Math.sin(-midAngle * RADIAN);
|
52
|
+
const textAnchor = x > cxProp ? "start" : x < cxProp ? "end" : "middle";
|
53
|
+
const displayLabel = () => {
|
54
|
+
if (isParcent) {
|
55
|
+
return parseFloat((percent * 100).toFixed(0)) > 0 && `${(percent * 100).toFixed(0)}%`;
|
56
|
+
} else if (!(0, import_utils.isUndefined)(valueFormatter)) {
|
57
|
+
return valueFormatter(value);
|
58
|
+
} else {
|
59
|
+
return value;
|
60
|
+
}
|
61
|
+
};
|
62
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
63
|
+
import_core.ui.text,
|
64
|
+
{
|
65
|
+
className: (0, import_utils.cx)(cellClassName, "ui-chart__label"),
|
66
|
+
x,
|
67
|
+
y,
|
68
|
+
textAnchor,
|
69
|
+
dominantBaseline: "central",
|
70
|
+
__css: styles,
|
71
|
+
...labelProps,
|
72
|
+
children: displayLabel()
|
73
|
+
}
|
74
|
+
);
|
75
|
+
};
|
76
|
+
var pieChartLabelLine = ({
|
77
|
+
className: cellClassName,
|
78
|
+
cx: cxProp = 0,
|
79
|
+
cy: cyProp = 0,
|
80
|
+
innerRadius = 0,
|
81
|
+
midAngle = 0,
|
82
|
+
middleRadius = 0,
|
83
|
+
outerRadius = 0,
|
84
|
+
points = [{ x: 0, y: 0 }],
|
85
|
+
labelOffset: labelOffsetProp,
|
86
|
+
labelLineProps,
|
87
|
+
styles
|
88
|
+
}) => {
|
89
|
+
const labelOffset = labelOffsetProp != null ? labelOffsetProp : (outerRadius - innerRadius) * 0.5 + DEFAULT_LABEL_OFFSET;
|
90
|
+
const x = cxProp + (middleRadius + labelOffset) * Math.cos(-midAngle * RADIAN);
|
91
|
+
const y = cyProp + (middleRadius + labelOffset) * Math.sin(-midAngle * RADIAN);
|
92
|
+
const d = `M ${points[0].x} ${points[0].y} L ${x} ${y}`;
|
93
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
94
|
+
import_core.ui.path,
|
95
|
+
{
|
96
|
+
className: (0, import_utils.cx)(cellClassName, "ui-chart__label-line"),
|
97
|
+
d,
|
98
|
+
__css: styles,
|
99
|
+
...labelLineProps
|
100
|
+
}
|
101
|
+
);
|
102
|
+
};
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
104
|
+
0 && (module.exports = {
|
105
|
+
pieChartLabel,
|
106
|
+
pieChartLabelLine
|
107
|
+
});
|
108
|
+
//# sourceMappingURL=pie-chart-label.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/pie-chart-label.tsx"],"sourcesContent":["import type { CSSUIObject, HTMLUIProps } from \"@yamada-ui/core\"\nimport { ui } from \"@yamada-ui/core\"\nimport type { Dict } from \"@yamada-ui/utils\"\nimport { cx, isUndefined } from \"@yamada-ui/utils\"\n\nconst RADIAN = Math.PI / 180\nconst DEFAULT_LABEL_OFFSET = 22\n\nexport type PieChartLabelProps = {\n className?: string\n cx?: number\n cy?: number\n midAngle?: number\n innerRadius?: number\n outerRadius?: number\n middleRadius?: number\n percent?: number\n value?: number\n labelOffset?: number\n isParcent?: boolean\n labelProps?: HTMLUIProps<\"text\">\n valueFormatter?: (value: number) => string\n styles: Dict<CSSUIObject>\n}\n\nexport const pieChartLabel: (props: PieChartLabelProps) => React.ReactNode = ({\n className: cellClassName,\n cx: cxProp = 0,\n cy: cyProp = 0,\n midAngle = 0,\n innerRadius = 0,\n outerRadius = 0,\n middleRadius = 0,\n percent = 0,\n value = 0,\n labelOffset: labelOffsetProp,\n isParcent,\n labelProps,\n valueFormatter,\n styles,\n}) => {\n const labelOffset =\n labelOffsetProp ?? (outerRadius - innerRadius) * 0.5 + DEFAULT_LABEL_OFFSET\n\n const x = cxProp + (middleRadius + labelOffset) * Math.cos(-midAngle * RADIAN)\n const y = cyProp + (middleRadius + labelOffset) * Math.sin(-midAngle * RADIAN)\n\n const textAnchor = x > cxProp ? \"start\" : x < cxProp ? \"end\" : \"middle\"\n const displayLabel = () => {\n if (isParcent) {\n return (\n parseFloat((percent * 100).toFixed(0)) > 0 &&\n `${(percent * 100).toFixed(0)}%`\n )\n } else if (!isUndefined(valueFormatter)) {\n return valueFormatter(value)\n } else {\n return value\n }\n }\n\n return (\n <ui.text\n className={cx(cellClassName, \"ui-chart__label\")}\n x={x}\n y={y}\n textAnchor={textAnchor}\n dominantBaseline=\"central\"\n __css={styles}\n {...labelProps}\n >\n {displayLabel()}\n </ui.text>\n )\n}\n\ntype Point = { x: number; y: number }\n\nexport type PieChartLabelLineProps = {\n className?: string\n cx?: number\n cy?: number\n innerRadius?: number\n midAngle?: number\n middleRadius?: number\n outerRadius?: number\n points?: Array<Point>\n labelOffset?: number\n labelLineProps?: HTMLUIProps<\"path\">\n styles: Dict<CSSUIObject>\n}\n\nexport const pieChartLabelLine: (\n props: PieChartLabelLineProps,\n) => React.ReactElement<SVGElement> = ({\n className: cellClassName,\n cx: cxProp = 0,\n cy: cyProp = 0,\n innerRadius = 0,\n midAngle = 0,\n middleRadius = 0,\n outerRadius = 0,\n points = [{ x: 0, y: 0 }],\n labelOffset: labelOffsetProp,\n labelLineProps,\n styles,\n}) => {\n const labelOffset =\n labelOffsetProp ?? (outerRadius - innerRadius) * 0.5 + DEFAULT_LABEL_OFFSET\n\n const x = cxProp + (middleRadius + labelOffset) * Math.cos(-midAngle * RADIAN)\n const y = cyProp + (middleRadius + labelOffset) * Math.sin(-midAngle * RADIAN)\n\n const d: string = `M ${points[0].x} ${points[0].y} L ${x} ${y}`\n\n return (\n <ui.path\n className={cx(cellClassName, \"ui-chart__label-line\")}\n d={d}\n __css={styles}\n {...labelLineProps}\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAmB;AAEnB,mBAAgC;AA2D5B;AAzDJ,IAAM,SAAS,KAAK,KAAK;AACzB,IAAM,uBAAuB;AAmBtB,IAAM,gBAAgE,CAAC;AAAA,EAC5E,WAAW;AAAA,EACX,IAAI,SAAS;AAAA,EACb,IAAI,SAAS;AAAA,EACb,WAAW;AAAA,EACX,cAAc;AAAA,EACd,cAAc;AAAA,EACd,eAAe;AAAA,EACf,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,aAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,cACJ,6CAAoB,cAAc,eAAe,MAAM;AAEzD,QAAM,IAAI,UAAU,eAAe,eAAe,KAAK,IAAI,CAAC,WAAW,MAAM;AAC7E,QAAM,IAAI,UAAU,eAAe,eAAe,KAAK,IAAI,CAAC,WAAW,MAAM;AAE7E,QAAM,aAAa,IAAI,SAAS,UAAU,IAAI,SAAS,QAAQ;AAC/D,QAAM,eAAe,MAAM;AACzB,QAAI,WAAW;AACb,aACE,YAAY,UAAU,KAAK,QAAQ,CAAC,CAAC,IAAI,KACzC,IAAI,UAAU,KAAK,QAAQ,CAAC,CAAC;AAAA,IAEjC,WAAW,KAAC,0BAAY,cAAc,GAAG;AACvC,aAAO,eAAe,KAAK;AAAA,IAC7B,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SACE;AAAA,IAAC,eAAG;AAAA,IAAH;AAAA,MACC,eAAW,iBAAG,eAAe,iBAAiB;AAAA,MAC9C;AAAA,MACA;AAAA,MACA;AAAA,MACA,kBAAiB;AAAA,MACjB,OAAO;AAAA,MACN,GAAG;AAAA,MAEH,uBAAa;AAAA;AAAA,EAChB;AAEJ;AAkBO,IAAM,oBAEyB,CAAC;AAAA,EACrC,WAAW;AAAA,EACX,IAAI,SAAS;AAAA,EACb,IAAI,SAAS;AAAA,EACb,cAAc;AAAA,EACd,WAAW;AAAA,EACX,eAAe;AAAA,EACf,cAAc;AAAA,EACd,SAAS,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC;AAAA,EACxB,aAAa;AAAA,EACb;AAAA,EACA;AACF,MAAM;AACJ,QAAM,cACJ,6CAAoB,cAAc,eAAe,MAAM;AAEzD,QAAM,IAAI,UAAU,eAAe,eAAe,KAAK,IAAI,CAAC,WAAW,MAAM;AAC7E,QAAM,IAAI,UAAU,eAAe,eAAe,KAAK,IAAI,CAAC,WAAW,MAAM;AAE7E,QAAM,IAAY,KAAK,OAAO,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;AAE7D,SACE;AAAA,IAAC,eAAG;AAAA,IAAH;AAAA,MACC,eAAW,iBAAG,eAAe,sBAAsB;AAAA,MACnD;AAAA,MACA,OAAO;AAAA,MACN,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/pie-chart.js
CHANGED
@@ -24,8 +24,8 @@ __export(pie_chart_exports, {
|
|
24
24
|
PieChart: () => PieChart
|
25
25
|
});
|
26
26
|
module.exports = __toCommonJS(pie_chart_exports);
|
27
|
-
var
|
28
|
-
var
|
27
|
+
var import_core8 = require("@yamada-ui/core");
|
28
|
+
var import_utils9 = require("@yamada-ui/utils");
|
29
29
|
var import_react5 = require("react");
|
30
30
|
var import_recharts = require("recharts");
|
31
31
|
|
@@ -358,13 +358,94 @@ var useChartTooltip = ({
|
|
358
358
|
};
|
359
359
|
|
360
360
|
// src/use-pie-chart.ts
|
361
|
+
var import_core7 = require("@yamada-ui/core");
|
362
|
+
var import_utils8 = require("@yamada-ui/utils");
|
363
|
+
var import_react4 = require("react");
|
364
|
+
|
365
|
+
// src/pie-chart-label.tsx
|
361
366
|
var import_core6 = require("@yamada-ui/core");
|
362
367
|
var import_utils7 = require("@yamada-ui/utils");
|
363
|
-
var
|
368
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
369
|
+
var RADIAN = Math.PI / 180;
|
370
|
+
var DEFAULT_LABEL_OFFSET = 22;
|
371
|
+
var pieChartLabel = ({
|
372
|
+
className: cellClassName,
|
373
|
+
cx: cxProp = 0,
|
374
|
+
cy: cyProp = 0,
|
375
|
+
midAngle = 0,
|
376
|
+
innerRadius = 0,
|
377
|
+
outerRadius = 0,
|
378
|
+
middleRadius = 0,
|
379
|
+
percent = 0,
|
380
|
+
value = 0,
|
381
|
+
labelOffset: labelOffsetProp,
|
382
|
+
isParcent,
|
383
|
+
labelProps,
|
384
|
+
valueFormatter,
|
385
|
+
styles
|
386
|
+
}) => {
|
387
|
+
const labelOffset = labelOffsetProp != null ? labelOffsetProp : (outerRadius - innerRadius) * 0.5 + DEFAULT_LABEL_OFFSET;
|
388
|
+
const x = cxProp + (middleRadius + labelOffset) * Math.cos(-midAngle * RADIAN);
|
389
|
+
const y = cyProp + (middleRadius + labelOffset) * Math.sin(-midAngle * RADIAN);
|
390
|
+
const textAnchor = x > cxProp ? "start" : x < cxProp ? "end" : "middle";
|
391
|
+
const displayLabel = () => {
|
392
|
+
if (isParcent) {
|
393
|
+
return parseFloat((percent * 100).toFixed(0)) > 0 && `${(percent * 100).toFixed(0)}%`;
|
394
|
+
} else if (!(0, import_utils7.isUndefined)(valueFormatter)) {
|
395
|
+
return valueFormatter(value);
|
396
|
+
} else {
|
397
|
+
return value;
|
398
|
+
}
|
399
|
+
};
|
400
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
401
|
+
import_core6.ui.text,
|
402
|
+
{
|
403
|
+
className: (0, import_utils7.cx)(cellClassName, "ui-chart__label"),
|
404
|
+
x,
|
405
|
+
y,
|
406
|
+
textAnchor,
|
407
|
+
dominantBaseline: "central",
|
408
|
+
__css: styles,
|
409
|
+
...labelProps,
|
410
|
+
children: displayLabel()
|
411
|
+
}
|
412
|
+
);
|
413
|
+
};
|
414
|
+
var pieChartLabelLine = ({
|
415
|
+
className: cellClassName,
|
416
|
+
cx: cxProp = 0,
|
417
|
+
cy: cyProp = 0,
|
418
|
+
innerRadius = 0,
|
419
|
+
midAngle = 0,
|
420
|
+
middleRadius = 0,
|
421
|
+
outerRadius = 0,
|
422
|
+
points = [{ x: 0, y: 0 }],
|
423
|
+
labelOffset: labelOffsetProp,
|
424
|
+
labelLineProps,
|
425
|
+
styles
|
426
|
+
}) => {
|
427
|
+
const labelOffset = labelOffsetProp != null ? labelOffsetProp : (outerRadius - innerRadius) * 0.5 + DEFAULT_LABEL_OFFSET;
|
428
|
+
const x = cxProp + (middleRadius + labelOffset) * Math.cos(-midAngle * RADIAN);
|
429
|
+
const y = cyProp + (middleRadius + labelOffset) * Math.sin(-midAngle * RADIAN);
|
430
|
+
const d = `M ${points[0].x} ${points[0].y} L ${x} ${y}`;
|
431
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
432
|
+
import_core6.ui.path,
|
433
|
+
{
|
434
|
+
className: (0, import_utils7.cx)(cellClassName, "ui-chart__label-line"),
|
435
|
+
d,
|
436
|
+
__css: styles,
|
437
|
+
...labelLineProps
|
438
|
+
}
|
439
|
+
);
|
440
|
+
};
|
441
|
+
|
442
|
+
// src/use-pie-chart.ts
|
364
443
|
var usePieChart = ({
|
365
444
|
data,
|
366
445
|
withLabels = false,
|
367
446
|
withLabelLines = false,
|
447
|
+
labelOffset,
|
448
|
+
isParcent = false,
|
368
449
|
strokeWidth = 1,
|
369
450
|
fillOpacity = 1,
|
370
451
|
innerRadius = "0%",
|
@@ -372,19 +453,20 @@ var usePieChart = ({
|
|
372
453
|
paddingAngle = 0,
|
373
454
|
startAngle = 90,
|
374
455
|
endAngle = -270,
|
456
|
+
valueFormatter,
|
375
457
|
styles,
|
376
458
|
...rest
|
377
459
|
}) => {
|
378
460
|
var _a, _b;
|
379
|
-
const { theme } = (0,
|
461
|
+
const { theme } = (0, import_core7.useTheme)();
|
380
462
|
const [highlightedArea, setHighlightedArea] = (0, import_react4.useState)(null);
|
381
463
|
const shouldHighlight = highlightedArea !== null;
|
382
464
|
const { dimCell, ...computedCellProps } = (_a = rest.cellProps) != null ? _a : {};
|
383
465
|
const {
|
384
466
|
activeShape = {},
|
385
467
|
inactiveShape = {},
|
386
|
-
label,
|
387
|
-
labelLine,
|
468
|
+
label: labelProps,
|
469
|
+
labelLine: labelLineProps,
|
388
470
|
...computedPieProps
|
389
471
|
} = (_b = rest.pieProps) != null ? _b : {};
|
390
472
|
const cellColors = (0, import_react4.useMemo)(
|
@@ -446,13 +528,27 @@ var usePieChart = ({
|
|
446
528
|
)(theme, true),
|
447
529
|
[inactiveShape, styles.inactiveShape, theme]
|
448
530
|
);
|
449
|
-
const
|
450
|
-
() =>
|
451
|
-
|
531
|
+
const label = (0, import_react4.useCallback)(
|
532
|
+
(props) => pieChartLabel({
|
533
|
+
labelOffset,
|
534
|
+
isParcent,
|
535
|
+
labelProps,
|
536
|
+
valueFormatter,
|
537
|
+
styles: styles.label,
|
538
|
+
...props
|
539
|
+
}),
|
540
|
+
[isParcent, labelOffset, labelProps, styles.label, valueFormatter]
|
452
541
|
);
|
453
|
-
const
|
454
|
-
() =>
|
455
|
-
|
542
|
+
const labelLine = (0, import_react4.useCallback)(
|
543
|
+
(props) => {
|
544
|
+
return pieChartLabelLine({
|
545
|
+
labelOffset,
|
546
|
+
labelLineProps,
|
547
|
+
styles: styles.labelLine,
|
548
|
+
...props
|
549
|
+
});
|
550
|
+
},
|
551
|
+
[labelLineProps, labelOffset, styles.labelLine]
|
456
552
|
);
|
457
553
|
const cellPropList = (0, import_react4.useMemo)(
|
458
554
|
() => data.map((props, index) => {
|
@@ -487,21 +583,16 @@ var usePieChart = ({
|
|
487
583
|
const getPieChartProps = (0, import_react4.useCallback)(
|
488
584
|
({ className, ...props } = {}, ref = null) => ({
|
489
585
|
ref,
|
490
|
-
className: (0,
|
586
|
+
className: (0, import_utils8.cx)(className, chartClassName),
|
491
587
|
...props,
|
492
588
|
...chartProps
|
493
589
|
}),
|
494
590
|
[chartProps, chartClassName]
|
495
591
|
);
|
496
592
|
const getPieProps = (0, import_react4.useCallback)(
|
497
|
-
({
|
498
|
-
className,
|
499
|
-
labelClassName: labelClassNameProp,
|
500
|
-
labelLineClassName: labelLineClassNameProp,
|
501
|
-
...props
|
502
|
-
}, ref = null) => ({
|
593
|
+
({ className, ...props }, ref = null) => ({
|
503
594
|
ref,
|
504
|
-
className: (0,
|
595
|
+
className: (0, import_utils8.cx)(className, pieClassName),
|
505
596
|
dataKey: "value",
|
506
597
|
data,
|
507
598
|
rootTabIndex: -1,
|
@@ -511,8 +602,8 @@ var usePieChart = ({
|
|
511
602
|
startAngle,
|
512
603
|
endAngle,
|
513
604
|
isAnimationActive: false,
|
514
|
-
label: withLabels ?
|
515
|
-
labelLine: withLabelLines ?
|
605
|
+
label: withLabels ? label : false,
|
606
|
+
labelLine: withLabelLines ? labelLine : false,
|
516
607
|
activeShape: activeShapeProps,
|
517
608
|
inactiveShape: inactiveShapeProps,
|
518
609
|
...props,
|
@@ -527,9 +618,9 @@ var usePieChart = ({
|
|
527
618
|
startAngle,
|
528
619
|
endAngle,
|
529
620
|
withLabels,
|
530
|
-
|
621
|
+
label,
|
531
622
|
withLabelLines,
|
532
|
-
|
623
|
+
labelLine,
|
533
624
|
activeShapeProps,
|
534
625
|
inactiveShapeProps,
|
535
626
|
pieProps
|
@@ -540,7 +631,7 @@ var usePieChart = ({
|
|
540
631
|
const { className, color } = cellPropList[index];
|
541
632
|
return {
|
542
633
|
ref,
|
543
|
-
className: (0,
|
634
|
+
className: (0, import_utils8.cx)(classNameProp, className),
|
544
635
|
fill: color,
|
545
636
|
stroke: color,
|
546
637
|
strokeWidth,
|
@@ -559,9 +650,9 @@ var usePieChart = ({
|
|
559
650
|
};
|
560
651
|
|
561
652
|
// src/pie-chart.tsx
|
562
|
-
var
|
563
|
-
var PieChart = (0,
|
564
|
-
const [styles, mergedProps] = (0,
|
653
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
654
|
+
var PieChart = (0, import_core8.forwardRef)((props, ref) => {
|
655
|
+
const [styles, mergedProps] = (0, import_core8.useMultiComponentStyle)("PieChart", props);
|
565
656
|
const {
|
566
657
|
className,
|
567
658
|
data,
|
@@ -583,10 +674,12 @@ var PieChart = (0, import_core7.forwardRef)((props, ref) => {
|
|
583
674
|
endAngle,
|
584
675
|
withLabels,
|
585
676
|
withLabelLines,
|
677
|
+
labelOffset,
|
678
|
+
isParcent,
|
586
679
|
strokeWidth,
|
587
680
|
legendProps,
|
588
681
|
...rest
|
589
|
-
} = (0,
|
682
|
+
} = (0, import_core8.omitThemeProps)(mergedProps);
|
590
683
|
const {
|
591
684
|
pieVars,
|
592
685
|
getPieProps,
|
@@ -606,6 +699,9 @@ var PieChart = (0, import_core7.forwardRef)((props, ref) => {
|
|
606
699
|
strokeWidth,
|
607
700
|
withLabels,
|
608
701
|
withLabelLines,
|
702
|
+
labelOffset,
|
703
|
+
isParcent,
|
704
|
+
valueFormatter,
|
609
705
|
styles
|
610
706
|
});
|
611
707
|
const { getContainerProps } = useChart({ containerProps });
|
@@ -618,7 +714,7 @@ var PieChart = (0, import_core7.forwardRef)((props, ref) => {
|
|
618
714
|
legendProps
|
619
715
|
});
|
620
716
|
const cells = (0, import_react5.useMemo)(
|
621
|
-
() => data.map(({ name }, index) => /* @__PURE__ */ (0,
|
717
|
+
() => data.map(({ name }, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
622
718
|
import_recharts.Cell,
|
623
719
|
{
|
624
720
|
...getCellProps({ index, className: "ui-pie-chart__cell" })
|
@@ -627,38 +723,36 @@ var PieChart = (0, import_core7.forwardRef)((props, ref) => {
|
|
627
723
|
)),
|
628
724
|
[data, getCellProps]
|
629
725
|
);
|
630
|
-
return /* @__PURE__ */ (0,
|
631
|
-
|
726
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChartProvider, { value: { styles }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
727
|
+
import_core8.ui.div,
|
632
728
|
{
|
633
729
|
ref,
|
634
|
-
className: (0,
|
730
|
+
className: (0, import_utils9.cx)("ui-pie-chart", className),
|
635
731
|
var: pieVars,
|
636
732
|
__css: { ...styles.container },
|
637
733
|
...rest,
|
638
|
-
children: /* @__PURE__ */ (0,
|
734
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
639
735
|
import_recharts.ResponsiveContainer,
|
640
736
|
{
|
641
737
|
...getContainerProps({ className: "ui-pie-chart__container" }),
|
642
|
-
children: /* @__PURE__ */ (0,
|
738
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
643
739
|
import_recharts.PieChart,
|
644
740
|
{
|
645
741
|
...getPieChartProps({ className: "ui-pie-chart__chart" }),
|
646
742
|
children: [
|
647
|
-
/* @__PURE__ */ (0,
|
743
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
648
744
|
import_recharts.Pie,
|
649
745
|
{
|
650
746
|
...getPieProps({
|
651
|
-
className: "ui-pie-chart__pie"
|
652
|
-
labelClassName: "ui-pie-chart__label",
|
653
|
-
labelLineClassName: "ui-pie-chart__label-line"
|
747
|
+
className: "ui-pie-chart__pie"
|
654
748
|
}),
|
655
749
|
children: cells
|
656
750
|
}
|
657
751
|
),
|
658
|
-
withLegend ? /* @__PURE__ */ (0,
|
752
|
+
withLegend ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
659
753
|
import_recharts.Legend,
|
660
754
|
{
|
661
|
-
content: ({ payload }) => /* @__PURE__ */ (0,
|
755
|
+
content: ({ payload }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
662
756
|
ChartLegend,
|
663
757
|
{
|
664
758
|
className: "ui-pie-chart__legend",
|
@@ -670,10 +764,10 @@ var PieChart = (0, import_core7.forwardRef)((props, ref) => {
|
|
670
764
|
...getLegendProps()
|
671
765
|
}
|
672
766
|
) : null,
|
673
|
-
withTooltip ? /* @__PURE__ */ (0,
|
767
|
+
withTooltip ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
674
768
|
import_recharts.Tooltip,
|
675
769
|
{
|
676
|
-
content: ({ label, payload }) => /* @__PURE__ */ (0,
|
770
|
+
content: ({ label, payload }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
677
771
|
ChartTooltip,
|
678
772
|
{
|
679
773
|
className: "ui-pie-chart__tooltip",
|