1mpacto-react-ui 2.0.23 → 2.0.24
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/components/Chart/PieChart.cjs +1 -1
- package/dist/components/Chart/PieChart.mjs +126 -107
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.d.ts +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/interfaces/components/Chart/index.d.ts +10 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const x=require("react/jsx-runtime"),v=require("chart.js"),h=require("react"),T=require("react-chartjs-2"),M=require("../../utils/common.cjs"),k=require("../PortalComponent/PortalComponent.cjs");v.Chart.register(v.ArcElement,v.Tooltip);const O=(t,n,e)=>{const a=n>0?t/n*100:0;switch(e){case"decimal":return M.formatNumber(t,"decimal");case"currency":return M.formatNumber(t,"currency");default:return`${Math.round(a)}%`}},D=()=>{const t=Math.floor(Math.random()*360),n=60+Math.floor(Math.random()*30),e=45+Math.floor(Math.random()*20);return((s,r,o)=>{r/=100,o/=100;const l=r*Math.min(o,1-o),u=d=>{const i=(d+s/30)%12,c=o-l*Math.max(Math.min(i-3,9-i,1),-1);return Math.round(255*c).toString(16).padStart(2,"0")};return`#${u(0)}${u(8)}${u(4)}`})(t,n,e)},q=(t,n)=>Array.isArray(t)?t[n]||D():typeof t=="string"?t:D(),P=t=>t!=="data"&&t.startsWith("data"),B=t=>{const n=t.data?.length??0;return Object.keys(t).filter(e=>{const a=t[e];return P(e)&&Array.isArray(a)&&a.length===n})},j=(t,n,e)=>n.reduce((a,s)=>{const r=t[s];return Array.isArray(r)&&(a[s]=r[e]),a},{}),E=t=>Object.keys(t[0]??{}).filter(P).reduce((e,a)=>(e[a]=t.map(s=>s[a]),e),{}),C=(t,n={})=>({labels:t.map(e=>e.label),values:t.map(e=>e.value),colors:t.map(e=>e.backgroundColor||D()),extraDatasetData:E(t),mergedMap:n}),K=t=>{const n=t.labels??[],e=t.datasets[0];if(!e)return[];const a=e.data??[],s=B(e);return a.map((r,o)=>({label:n[o]??"",value:r,backgroundColor:q(e.backgroundColor,o),...j(e,s,o)}))},R=(t,n)=>{if(!n)return C(t);const{mode:e,value:a,otherLabel:s="Other",otherBackgroundColor:r="#B0BEC5"}=n,o=t.reduce((c,f)=>c+f.value,0),l=[],u=[];let d=0;t.forEach(c=>{(e==="percentage"?c.value/o*100<a:c.value<a)?(d+=c.value,u.push(c)):l.push(c)});const i={};if(d>0){const c=E(u);l.push({...c,label:s,value:d,backgroundColor:r}),i[l.length-1]=u}return C(l,i)},F=(t,n,e)=>({chart:a,tooltip:s})=>{const r={};if(s.opacity===0){t(g=>({...g,style:{...g.style,opacity:0,pointerEvents:"none"}}));return}if(!s.dataPoints||s.dataPoints.length===0)return;r.opacity="1",r.position="absolute",r.pointerEvents="none";const o=a.canvas.getBoundingClientRect();r.left=o.left+window.pageXOffset+s.caretX+"px",r.top=o.top+window.pageYOffset+s.caretY+"px";const l=s.dataPoints[0].dataIndex,u=s.dataPoints[0].dataset,d=s.dataPoints?.[0]?.label??"",i=s.dataPoints?.[0]?.raw??0,c=u.backgroundColor?.[l]??"",f=u.data?.reduce((g,y)=>g+y,0)||1,p=f>0?i/f*100:0,b=Object.keys(u).filter(P),m=j(u,b,l);t({label:d,value:i,percentage:p,formattedValue:O(i,f,n),backgroundColor:typeof c=="string"?c:"#000",mergedItems:e[l]??[],style:r,dataPoints:s.dataPoints,...m})},L=(t,n)=>({id:"pieLabelPlugin",afterDraw(e){const{ctx:a}=e,s=e.getDatasetMeta(0),r=e.data.datasets[0].data.reduce((o,l)=>o+l,0);s.data.forEach((o,l)=>{const d=e.data.datasets[0].data[l]??0;if((r>0?d/r*100:0)<n)return;const{x:c,y:f}=o.tooltipPosition(!1),p=e.data.labels?.[l];a.save(),a.textAlign="center",a.textBaseline="middle",a.fillStyle="#FFFFFF",a.font="bold 10px Inter, sans-serif",a.fillText(p,c||0,(f||0)-6),a.fillText(O(d,r,t),c||0,(f||0)+8),a.restore()})}}),V={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{enabled:!0}},elements:{arc:{hoverOffset:8,borderWidth:0}}},$=({data:t,height:n,classNameContainer:e,id:a,options:s,CustomTooltip:r,threshold:o,valueFormat:l,hideLabelBelowPercentage:u=5})=>{const[d,i]=h.useState({style:{opacity:0,position:"absolute",left:0,top:0},label:"",value:0,percentage:0,formattedValue:"",backgroundColor:"",mergedItems:[],dataPoints:[]}),c=h.useMemo(()=>K(t),[t]),{labels:f,values:p,colors:b,extraDatasetData:m,mergedMap:g}=h.useMemo(()=>R(c,o),[c,o]),y=h.useMemo(()=>({labels:f,datasets:[{...t.datasets[0],...m,data:p,backgroundColor:b,hoverOffset:8,borderWidth:0}]}),[f,p,b,m,t.datasets]),w=h.useMemo(()=>{const A={plugins:{tooltip:{enabled:!r,external:r?({chart:I,tooltip:S})=>F(i,l,g)({chart:I,tooltip:S}):void 0}}};return M.mergeObjects(V,A,s??{})},[s,r,l,g]);return x.jsxs("div",{id:a,className:e,style:{height:n||"300px"},children:[r&&x.jsx(k.default,{selector:"body",children:x.jsx(r,{...d})}),x.jsx(T.Pie,{data:y,options:w,plugins:[L(l,u)]})]})};exports.default=$;
|
|
@@ -1,94 +1,111 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { Chart as
|
|
3
|
-
import
|
|
4
|
-
import { Pie as
|
|
5
|
-
import { mergeObjects as
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
switch (
|
|
1
|
+
import { jsxs as T, jsx as y } from "react/jsx-runtime";
|
|
2
|
+
import { Chart as j, ArcElement as k, Tooltip as B } from "chart.js";
|
|
3
|
+
import h from "react";
|
|
4
|
+
import { Pie as K } from "react-chartjs-2";
|
|
5
|
+
import { mergeObjects as S, formatNumber as D } from "../../utils/common.mjs";
|
|
6
|
+
import R from "../PortalComponent/PortalComponent.mjs";
|
|
7
|
+
j.register(k, B);
|
|
8
|
+
const C = (t, s, e) => {
|
|
9
|
+
const a = s > 0 ? t / s * 100 : 0;
|
|
10
|
+
switch (e) {
|
|
11
11
|
case "decimal":
|
|
12
|
-
return
|
|
12
|
+
return D(t, "decimal");
|
|
13
13
|
case "currency":
|
|
14
|
-
return
|
|
14
|
+
return D(t, "currency");
|
|
15
15
|
default:
|
|
16
|
-
return `${Math.round(
|
|
16
|
+
return `${Math.round(a)}%`;
|
|
17
17
|
}
|
|
18
|
-
},
|
|
19
|
-
const t = Math.floor(Math.random() * 360),
|
|
20
|
-
return ((
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const i = (
|
|
24
|
-
return Math.round(255 *
|
|
18
|
+
}, v = () => {
|
|
19
|
+
const t = Math.floor(Math.random() * 360), s = 60 + Math.floor(Math.random() * 30), e = 45 + Math.floor(Math.random() * 20);
|
|
20
|
+
return ((r, o, n) => {
|
|
21
|
+
o /= 100, n /= 100;
|
|
22
|
+
const c = o * Math.min(n, 1 - n), d = (u) => {
|
|
23
|
+
const i = (u + r / 30) % 12, l = n - c * Math.max(Math.min(i - 3, 9 - i, 1), -1);
|
|
24
|
+
return Math.round(255 * l).toString(16).padStart(2, "0");
|
|
25
25
|
};
|
|
26
|
-
return `#${
|
|
27
|
-
})(t,
|
|
28
|
-
},
|
|
29
|
-
const
|
|
30
|
-
return
|
|
31
|
-
|
|
26
|
+
return `#${d(0)}${d(8)}${d(4)}`;
|
|
27
|
+
})(t, s, e);
|
|
28
|
+
}, F = (t, s) => Array.isArray(t) ? t[s] || v() : typeof t == "string" ? t : v(), M = (t) => t !== "data" && t.startsWith("data"), L = (t) => {
|
|
29
|
+
const s = t.data?.length ?? 0;
|
|
30
|
+
return Object.keys(t).filter((e) => {
|
|
31
|
+
const a = t[e];
|
|
32
|
+
return M(e) && Array.isArray(a) && a.length === s;
|
|
33
|
+
});
|
|
34
|
+
}, O = (t, s, e) => s.reduce((a, r) => {
|
|
35
|
+
const o = t[r];
|
|
36
|
+
return Array.isArray(o) && (a[r] = o[e]), a;
|
|
37
|
+
}, {}), E = (t) => Object.keys(t[0] ?? {}).filter(M).reduce((e, a) => (e[a] = t.map((r) => r[a]), e), {}), P = (t, s = {}) => ({
|
|
38
|
+
labels: t.map((e) => e.label),
|
|
39
|
+
values: t.map((e) => e.value),
|
|
40
|
+
colors: t.map((e) => e.backgroundColor || v()),
|
|
41
|
+
extraDatasetData: E(t),
|
|
42
|
+
mergedMap: s
|
|
43
|
+
}), V = (t) => {
|
|
44
|
+
const s = t.labels ?? [], e = t.datasets[0];
|
|
45
|
+
if (!e) return [];
|
|
46
|
+
const a = e.data ?? [], r = L(e);
|
|
47
|
+
return a.map((o, n) => ({
|
|
48
|
+
label: s[n] ?? "",
|
|
32
49
|
value: o,
|
|
33
|
-
backgroundColor:
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
const { mode: n, value: r, otherLabel: o = "Other", otherBackgroundColor: a = "#B0BEC5" } = l, c = t.reduce((e, p) => e + p.value, 0), s = [], u = [];
|
|
44
|
-
let d = 0;
|
|
45
|
-
t.forEach((e) => {
|
|
46
|
-
(n === "percentage" ? e.value / c * 100 < r : e.value < r) ? (d += e.value, u.push(e)) : s.push({
|
|
47
|
-
label: e.label,
|
|
48
|
-
value: e.value,
|
|
49
|
-
color: e.backgroundColor || h()
|
|
50
|
-
});
|
|
50
|
+
backgroundColor: F(e.backgroundColor, n),
|
|
51
|
+
...O(e, r, n)
|
|
52
|
+
}));
|
|
53
|
+
}, $ = (t, s) => {
|
|
54
|
+
if (!s) return P(t);
|
|
55
|
+
const { mode: e, value: a, otherLabel: r = "Other", otherBackgroundColor: o = "#B0BEC5" } = s, n = t.reduce((l, f) => l + f.value, 0), c = [], d = [];
|
|
56
|
+
let u = 0;
|
|
57
|
+
t.forEach((l) => {
|
|
58
|
+
(e === "percentage" ? l.value / n * 100 < a : l.value < a) ? (u += l.value, d.push(l)) : c.push(l);
|
|
51
59
|
});
|
|
52
60
|
const i = {};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
if (u > 0) {
|
|
62
|
+
const l = E(d);
|
|
63
|
+
c.push({
|
|
64
|
+
...l,
|
|
65
|
+
label: r,
|
|
66
|
+
value: u,
|
|
67
|
+
backgroundColor: o
|
|
68
|
+
}), i[c.length - 1] = d;
|
|
69
|
+
}
|
|
70
|
+
return P(c, i);
|
|
71
|
+
}, W = (t, s, e) => ({ chart: a, tooltip: r }) => {
|
|
72
|
+
const o = {};
|
|
73
|
+
if (r.opacity === 0) {
|
|
74
|
+
t((p) => ({ ...p, style: { ...p.style, opacity: 0, pointerEvents: "none" } }));
|
|
63
75
|
return;
|
|
64
76
|
}
|
|
65
|
-
if (!
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
const
|
|
77
|
+
if (!r.dataPoints || r.dataPoints.length === 0) return;
|
|
78
|
+
o.opacity = "1", o.position = "absolute", o.pointerEvents = "none";
|
|
79
|
+
const n = a.canvas.getBoundingClientRect();
|
|
80
|
+
o.left = n.left + window.pageXOffset + r.caretX + "px", o.top = n.top + window.pageYOffset + r.caretY + "px";
|
|
81
|
+
const c = r.dataPoints[0].dataIndex, d = r.dataPoints[0].dataset, u = r.dataPoints?.[0]?.label ?? "", i = r.dataPoints?.[0]?.raw ?? 0, l = d.backgroundColor?.[c] ?? "", f = d.data?.reduce((p, x) => p + x, 0) || 1, g = f > 0 ? i / f * 100 : 0, m = Object.keys(d).filter(M), b = O(
|
|
82
|
+
d,
|
|
83
|
+
m,
|
|
84
|
+
c
|
|
85
|
+
);
|
|
70
86
|
t({
|
|
71
87
|
label: u,
|
|
72
|
-
value:
|
|
73
|
-
percentage:
|
|
74
|
-
formattedValue:
|
|
75
|
-
backgroundColor: typeof
|
|
76
|
-
mergedItems:
|
|
77
|
-
style:
|
|
78
|
-
dataPoints:
|
|
88
|
+
value: i,
|
|
89
|
+
percentage: g,
|
|
90
|
+
formattedValue: C(i, f, s),
|
|
91
|
+
backgroundColor: typeof l == "string" ? l : "#000",
|
|
92
|
+
mergedItems: e[c] ?? [],
|
|
93
|
+
style: o,
|
|
94
|
+
dataPoints: r.dataPoints,
|
|
95
|
+
...b
|
|
79
96
|
});
|
|
80
|
-
},
|
|
97
|
+
}, G = (t, s) => ({
|
|
81
98
|
id: "pieLabelPlugin",
|
|
82
|
-
afterDraw(
|
|
83
|
-
const { ctx:
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
if ((
|
|
87
|
-
const { x:
|
|
88
|
-
|
|
99
|
+
afterDraw(e) {
|
|
100
|
+
const { ctx: a } = e, r = e.getDatasetMeta(0), o = e.data.datasets[0].data.reduce((n, c) => n + c, 0);
|
|
101
|
+
r.data.forEach((n, c) => {
|
|
102
|
+
const u = e.data.datasets[0].data[c] ?? 0;
|
|
103
|
+
if ((o > 0 ? u / o * 100 : 0) < s) return;
|
|
104
|
+
const { x: l, y: f } = n.tooltipPosition(!1), g = e.data.labels?.[c];
|
|
105
|
+
a.save(), a.textAlign = "center", a.textBaseline = "middle", a.fillStyle = "#FFFFFF", a.font = "bold 10px Inter, sans-serif", a.fillText(g, l || 0, (f || 0) - 6), a.fillText(C(u, o, t), l || 0, (f || 0) + 8), a.restore();
|
|
89
106
|
});
|
|
90
107
|
}
|
|
91
|
-
}),
|
|
108
|
+
}), H = {
|
|
92
109
|
responsive: !0,
|
|
93
110
|
maintainAspectRatio: !1,
|
|
94
111
|
plugins: {
|
|
@@ -105,18 +122,18 @@ const x = (t, l, n) => {
|
|
|
105
122
|
borderWidth: 0
|
|
106
123
|
}
|
|
107
124
|
}
|
|
108
|
-
},
|
|
125
|
+
}, U = ({
|
|
109
126
|
data: t,
|
|
110
|
-
height:
|
|
111
|
-
classNameContainer:
|
|
112
|
-
id:
|
|
113
|
-
options:
|
|
114
|
-
CustomTooltip:
|
|
115
|
-
threshold:
|
|
116
|
-
valueFormat:
|
|
117
|
-
hideLabelBelowPercentage:
|
|
127
|
+
height: s,
|
|
128
|
+
classNameContainer: e,
|
|
129
|
+
id: a,
|
|
130
|
+
options: r,
|
|
131
|
+
CustomTooltip: o,
|
|
132
|
+
threshold: n,
|
|
133
|
+
valueFormat: c,
|
|
134
|
+
hideLabelBelowPercentage: d = 5
|
|
118
135
|
}) => {
|
|
119
|
-
const [
|
|
136
|
+
const [u, i] = h.useState({
|
|
120
137
|
style: { opacity: 0, position: "absolute", left: 0, top: 0 },
|
|
121
138
|
label: "",
|
|
122
139
|
value: 0,
|
|
@@ -125,45 +142,47 @@ const x = (t, l, n) => {
|
|
|
125
142
|
backgroundColor: "",
|
|
126
143
|
mergedItems: [],
|
|
127
144
|
dataPoints: []
|
|
128
|
-
}),
|
|
129
|
-
labels:
|
|
130
|
-
values:
|
|
131
|
-
colors:
|
|
132
|
-
|
|
133
|
-
|
|
145
|
+
}), l = h.useMemo(() => V(t), [t]), {
|
|
146
|
+
labels: f,
|
|
147
|
+
values: g,
|
|
148
|
+
colors: m,
|
|
149
|
+
extraDatasetData: b,
|
|
150
|
+
mergedMap: p
|
|
151
|
+
} = h.useMemo(() => $(l, n), [l, n]), x = h.useMemo(
|
|
134
152
|
() => ({
|
|
135
|
-
labels:
|
|
153
|
+
labels: f,
|
|
136
154
|
datasets: [
|
|
137
155
|
{
|
|
138
156
|
...t.datasets[0],
|
|
139
|
-
|
|
140
|
-
|
|
157
|
+
...b,
|
|
158
|
+
data: g,
|
|
159
|
+
backgroundColor: m,
|
|
141
160
|
hoverOffset: 8,
|
|
142
161
|
borderWidth: 0
|
|
143
162
|
}
|
|
144
163
|
]
|
|
145
164
|
}),
|
|
146
|
-
[
|
|
147
|
-
),
|
|
165
|
+
[f, g, m, b, t.datasets]
|
|
166
|
+
), w = h.useMemo(() => S(H, {
|
|
148
167
|
plugins: {
|
|
149
168
|
tooltip: {
|
|
150
|
-
enabled: !
|
|
151
|
-
external:
|
|
169
|
+
enabled: !o,
|
|
170
|
+
external: o ? ({ chart: A, tooltip: I }) => W(i, c, p)({ chart: A, tooltip: I }) : void 0
|
|
152
171
|
}
|
|
153
172
|
}
|
|
154
|
-
},
|
|
155
|
-
return /* @__PURE__ */
|
|
156
|
-
|
|
157
|
-
/* @__PURE__ */
|
|
158
|
-
|
|
173
|
+
}, r ?? {}), [r, o, c, p]);
|
|
174
|
+
return /* @__PURE__ */ T("div", { id: a, className: e, style: { height: s || "300px" }, children: [
|
|
175
|
+
o && /* @__PURE__ */ y(R, { selector: "body", children: /* @__PURE__ */ y(o, { ...u }) }),
|
|
176
|
+
/* @__PURE__ */ y(
|
|
177
|
+
K,
|
|
159
178
|
{
|
|
160
|
-
data:
|
|
161
|
-
options:
|
|
162
|
-
plugins: [
|
|
179
|
+
data: x,
|
|
180
|
+
options: w,
|
|
181
|
+
plugins: [G(c, d)]
|
|
163
182
|
}
|
|
164
183
|
)
|
|
165
184
|
] });
|
|
166
185
|
};
|
|
167
186
|
export {
|
|
168
|
-
|
|
187
|
+
U as default
|
|
169
188
|
};
|
package/dist/package.json.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e="2.0.
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e="2.0.24",o={version:e};exports.default=o;exports.version=e;
|
package/dist/package.json.d.ts
CHANGED
package/dist/package.json.mjs
CHANGED
|
@@ -692,6 +692,11 @@ export interface IPieChartThreshold {
|
|
|
692
692
|
* [EN] : Interface for pie chart dataset, extends ChartDataset<'pie'>.
|
|
693
693
|
*/
|
|
694
694
|
export interface IPieChartDataSet extends ChartDataset<'pie'> {
|
|
695
|
+
/**
|
|
696
|
+
* [ID] : Properti dinamis lainnya.
|
|
697
|
+
* [EN] : Other dynamic properties.
|
|
698
|
+
*/
|
|
699
|
+
[key: string]: unknown;
|
|
695
700
|
/**
|
|
696
701
|
* [ID] : background untuk slice pie chart
|
|
697
702
|
* [EN] : background for slice pie chart
|
|
@@ -828,5 +833,10 @@ export interface IDataPieChartCustomTooltip {
|
|
|
828
833
|
* [EN] : Tooltip data points.
|
|
829
834
|
*/
|
|
830
835
|
dataPoints: TooltipItem<'pie'>[];
|
|
836
|
+
/**
|
|
837
|
+
* [ID] : Properti dinamis lainnya.
|
|
838
|
+
* [EN] : Other dynamic properties.
|
|
839
|
+
*/
|
|
840
|
+
[key: string]: unknown;
|
|
831
841
|
}
|
|
832
842
|
export {};
|