datastake-daf 0.6.309 → 0.6.310

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.
@@ -45782,7 +45782,9 @@ const Chart = _ref => {
45782
45782
  mouseXOffset = 30,
45783
45783
  mouseYOffset = 50,
45784
45784
  children = null,
45785
- legend
45785
+ legend,
45786
+ isPdf = false,
45787
+ isPercentage = false
45786
45788
  } = _ref;
45787
45789
  const [hoveredGroup, setHoveredGroup] = React.useState(null);
45788
45790
  const svgRef = React.useRef();
@@ -45814,17 +45816,17 @@ const Chart = _ref => {
45814
45816
  }
45815
45817
  }, [svgRef, containerRef, hoveredGroup, mouseLocked]);
45816
45818
  const legendConfig = React.useMemo(() => {
45817
- if (legend === undefined || legend === null || legend === false) {
45818
- return null;
45819
- }
45820
- if (legend === true) {
45821
- return {};
45819
+ if (legend === false || legend === null) {
45820
+ return isPdf ? {} : null;
45822
45821
  }
45823
45822
  if (typeof legend === 'object') {
45824
45823
  return legend;
45825
45824
  }
45825
+ if (legend === true || legend === undefined || isPdf) {
45826
+ return {};
45827
+ }
45826
45828
  return null;
45827
- }, [legend]);
45829
+ }, [legend, isPdf]);
45828
45830
  const legendItems = React.useMemo(() => {
45829
45831
  const items = Array.isArray(data) ? data : [];
45830
45832
  if (!legendConfig) {
@@ -45840,46 +45842,61 @@ const Chart = _ref => {
45840
45842
  }, [data, legendConfig]);
45841
45843
  const dataToShow = React.useMemo(() => {
45842
45844
  let cumulativePercent = 0;
45845
+ function getRotationAngle(percent) {
45846
+ let angle = percent * 360 - 90;
45847
+ if (angle > 90 && angle < 270) {
45848
+ angle += 180;
45849
+ }
45850
+ const tilt = 30;
45851
+ return angle + tilt;
45852
+ }
45843
45853
  return data.map((d, i) => {
45844
45854
  const [startX, startY] = getCoordinatesForPercent(cumulativePercent);
45845
- cumulativePercent += d.percent - 0;
45855
+ const startPercent = cumulativePercent;
45856
+ cumulativePercent += d.percent;
45846
45857
  const [endX, endY] = getCoordinatesForPercent(cumulativePercent);
45847
- const [borderStartX, borderStartY] = getCoordinatesForPercent(cumulativePercent);
45848
- cumulativePercent += 0;
45849
- const [borderEndX, borderEndY] = getCoordinatesForPercent(cumulativePercent);
45850
- const largeArcFlag = d.percent > .5 ? 1 : 0;
45858
+
45859
+ // Midpoint of this slice
45860
+ const midPercent = startPercent + d.percent / 2;
45861
+ const [labelX, labelY] = getCoordinatesForPercent(midPercent);
45862
+ const largeArcFlag = d.percent > 0.5 ? 1 : 0;
45851
45863
  const pathData = ["M ".concat(startX, " ").concat(startY), "A 1 1 0 ".concat(largeArcFlag, " 1 ").concat(endX, " ").concat(endY), "L 0 0"].join(' ');
45852
- const borderPathData = ["M ".concat(borderStartX, " ").concat(borderStartY), "A 1 1 0 0 1 ".concat(borderEndX, " ").concat(borderEndY), "L 0 0"].join(' ');
45853
45864
  return /*#__PURE__*/jsxRuntime.jsxs(React.Fragment, {
45854
45865
  children: [/*#__PURE__*/jsxRuntime.jsx("path", {
45855
45866
  d: pathData,
45856
- "data-bs-toggle": "tooltip",
45857
- "data-bs-placement": "top",
45858
- title: "Tooltip on top",
45859
45867
  fill: d.color,
45860
45868
  style: {
45861
45869
  opacity: changeOpacityOnHover ? hoveredGroup === null ? 1 : hoveredGroup.id === i ? 1 : 0.4 : 1
45862
45870
  },
45863
45871
  onMouseEnter: () => {
45864
- if (mouseLocked) {
45865
- return;
45872
+ if (!mouseLocked) {
45873
+ setHoveredGroup(_objectSpread2(_objectSpread2({}, d), {}, {
45874
+ id: i
45875
+ }));
45866
45876
  }
45867
- setHoveredGroup(_objectSpread2(_objectSpread2({}, d), {}, {
45868
- id: i
45869
- }));
45870
45877
  },
45871
45878
  onMouseLeave: () => {
45872
- if (mouseLocked) {
45873
- return;
45879
+ if (!mouseLocked) {
45880
+ setHoveredGroup(null);
45874
45881
  }
45875
- setHoveredGroup(null);
45876
45882
  },
45877
45883
  onMouseMove: e => onMouseLeaveHandler(e, d, i),
45878
45884
  onClick: () => setMouseLocked(prev => !prev)
45879
45885
  }), /*#__PURE__*/jsxRuntime.jsx("path", {
45880
- d: borderPathData,
45881
- fill: "white"
45882
- })]
45886
+ d: pathData,
45887
+ fill: "none",
45888
+ stroke: "white",
45889
+ strokeWidth: "0.001"
45890
+ }), isPdf ? /*#__PURE__*/jsxRuntime.jsx("text", {
45891
+ x: labelX * 0.6,
45892
+ y: labelY * 0.6,
45893
+ textAnchor: "middle",
45894
+ dominantBaseline: "middle",
45895
+ fontSize: "0.1",
45896
+ fill: "#000",
45897
+ transform: "rotate(".concat(getRotationAngle(midPercent), ", ").concat(labelX * 0.6, ", ").concat(labelY * 0.6, ")"),
45898
+ children: d.percent ? isPercentage ? "".concat(Math.round(d.percent * 100), "%") : d.percent : d.label
45899
+ }) : null]
45883
45900
  }, i.toString());
45884
45901
  });
45885
45902
  }, [data, hoveredGroup, getCoordinatesForPercent, mouseLocked]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datastake-daf",
3
- "version": "0.6.309",
3
+ "version": "0.6.310",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -39,6 +39,8 @@ export const Primary = {
39
39
  "color": "#C04B19"
40
40
  }
41
41
  ],
42
- legend: true,
42
+ legend: false,
43
+ isPdf: true,
44
+ isPercentage: true,
43
45
  },
44
46
  };
@@ -17,6 +17,8 @@ const Chart = ({
17
17
  mouseYOffset = 50,
18
18
  children = null,
19
19
  legend,
20
+ isPdf = false,
21
+ isPercentage = false,
20
22
  }) => {
21
23
  const [hoveredGroup, setHoveredGroup] = useState(null);
22
24
  const svgRef = useRef();
@@ -56,21 +58,22 @@ const Chart = ({
56
58
  }, [svgRef, containerRef, hoveredGroup, mouseLocked]);
57
59
 
58
60
  const legendConfig = useMemo(() => {
59
- if (legend === undefined || legend === null || legend === false) {
60
- return null;
61
+ if (legend === false || legend === null) {
62
+ return isPdf ? {} : null;
61
63
  }
62
-
63
- if (legend === true) {
64
- return {};
65
- }
66
-
64
+
67
65
  if (typeof legend === 'object') {
68
66
  return legend;
69
67
  }
70
-
68
+
69
+ if (legend === true || legend === undefined || isPdf) {
70
+ return {};
71
+ }
72
+
71
73
  return null;
72
- }, [legend]);
73
-
74
+ }, [legend, isPdf]);
75
+
76
+
74
77
  const legendItems = useMemo(() => {
75
78
  const items = Array.isArray(data) ? data : [];
76
79
 
@@ -91,62 +94,80 @@ const Chart = ({
91
94
 
92
95
  const dataToShow = useMemo(() => {
93
96
  let cumulativePercent = 0;
97
+ function getRotationAngle(percent) {
98
+ let angle = percent * 360 - 90;
99
+
100
+ if (angle > 90 && angle < 270) {
101
+ angle += 180;
102
+ }
103
+
104
+ const tilt = 30;
105
+ return angle + tilt;
106
+ }
107
+
94
108
 
95
109
  return data.map((d, i) => {
96
110
  const [startX, startY] = getCoordinatesForPercent(cumulativePercent);
97
- cumulativePercent += d.percent - 0;
111
+ const startPercent = cumulativePercent;
112
+
113
+ cumulativePercent += d.percent;
98
114
  const [endX, endY] = getCoordinatesForPercent(cumulativePercent);
99
- const [borderStartX, borderStartY] = getCoordinatesForPercent(cumulativePercent);
100
- cumulativePercent += 0;
101
- const [borderEndX, borderEndY] = getCoordinatesForPercent(cumulativePercent);
102
- const largeArcFlag = d.percent > .5 ? 1 : 0;
103
-
115
+
116
+ // Midpoint of this slice
117
+ const midPercent = startPercent + d.percent / 2;
118
+ const [labelX, labelY] = getCoordinatesForPercent(midPercent);
119
+
120
+ const largeArcFlag = d.percent > 0.5 ? 1 : 0;
121
+
104
122
  const pathData = [
105
123
  `M ${startX} ${startY}`,
106
124
  `A 1 1 0 ${largeArcFlag} 1 ${endX} ${endY}`,
107
125
  `L 0 0`,
108
126
  ].join(' ');
109
-
110
- const borderPathData = [
111
- `M ${borderStartX} ${borderStartY}`,
112
- `A 1 1 0 0 1 ${borderEndX} ${borderEndY}`,
113
- `L 0 0`,
114
- ].join(' ');
115
-
127
+
116
128
  return (
117
129
  <Fragment key={i.toString()}>
118
130
  <path
119
131
  d={pathData}
120
- data-bs-toggle="tooltip"
121
- data-bs-placement="top"
122
- title="Tooltip on top"
123
132
  fill={d.color}
124
133
  style={{
125
134
  opacity: changeOpacityOnHover
126
- ? hoveredGroup === null ? 1 : hoveredGroup.id === i ? 1 : 0.4
135
+ ? hoveredGroup === null
136
+ ? 1
137
+ : hoveredGroup.id === i
138
+ ? 1
139
+ : 0.4
127
140
  : 1,
128
141
  }}
129
142
  onMouseEnter={() => {
130
- if (mouseLocked) {
131
- return;
143
+ if (!mouseLocked) {
144
+ setHoveredGroup({ ...d, id: i });
132
145
  }
133
-
134
- setHoveredGroup({ ...d, id: i })
135
146
  }}
136
147
  onMouseLeave={() => {
137
- if (mouseLocked) {
138
- return;
148
+ if (!mouseLocked) {
149
+ setHoveredGroup(null);
139
150
  }
140
-
141
- setHoveredGroup(null)
142
151
  }}
143
152
  onMouseMove={(e) => onMouseLeaveHandler(e, d, i)}
144
153
  onClick={() => setMouseLocked((prev) => !prev)}
145
154
  />
146
- <path
147
- d={borderPathData}
148
- fill="white"
149
- />
155
+
156
+ {/* White border if needed */}
157
+ <path d={pathData} fill="none" stroke="white" strokeWidth="0.001" />
158
+
159
+ {/* Label */}
160
+ {isPdf ? <text
161
+ x={labelX * 0.6}
162
+ y={labelY * 0.6}
163
+ textAnchor="middle"
164
+ dominantBaseline="middle"
165
+ fontSize="0.1"
166
+ fill="#000"
167
+ transform={`rotate(${getRotationAngle(midPercent)}, ${labelX * 0.6}, ${labelY * 0.6})`}
168
+ >
169
+ {d.percent ? isPercentage ? `${Math.round(d.percent * 100)}%` : d.percent : d.label}
170
+ </text> : null}
150
171
  </Fragment>
151
172
  );
152
173
  });