impaktapps-design 0.2.87 → 0.2.88

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impaktapps-design",
3
- "version": "0.2.87",
3
+ "version": "0.2.88",
4
4
  "dependencies": {
5
5
  "@babel/core": "^7.16.12",
6
6
  "@emotion/react": "^11.11.4",
@@ -9,16 +9,24 @@ import ToolTip from "../ToolTip";
9
9
 
10
10
  const DrawPieGraph = ({ value, parentWidth, parentHeight }: any) => {
11
11
  const letters = value?.main?.data;
12
+ const keys = Object.keys(letters[0]);
12
13
  const arr =
13
14
  value?.main?.xAxisValue && value?.main?.yAxisValue
14
15
  ? [value?.main?.xAxisValue, value?.main?.yAxisValue]
15
- : Object.keys(letters[0]);
16
- const frequency = (d: any) => d[arr[1]];
17
- const getLetterFrequencyColor = scaleOrdinal({
18
- domain: letters.map((l:[any]) => l[arr[0]]),
19
- range: value?.style?.pieStyle?.colorRange,
20
- });
16
+ : keys;
21
17
 
18
+ const labelKeyIndex = keys.indexOf('label');
19
+ const valueKeyIndex = (labelKeyIndex === 0) ? 1 : 0;
20
+ const frequency = (d: any) => d[arr[valueKeyIndex]];
21
+
22
+
23
+ const getLetterFrequencyColor = (letter: any, index: number) =>
24
+ scaleOrdinal({
25
+ domain: letters.map((l: any) => l[arr[index]]),
26
+ range: value?.style?.pieStyle?.colorRange,
27
+ })(letter);
28
+
29
+ const dataKeyArray = letters.map((data: any) => data.label);
22
30
  const {
23
31
  tooltipData,
24
32
  tooltipLeft,
@@ -47,6 +55,7 @@ const DrawPieGraph = ({ value, parentWidth, parentHeight }: any) => {
47
55
  {value?.main?.legendAvailable && (
48
56
  <Legend
49
57
  value={value}
58
+ dataKeyArray={dataKeyArray}
50
59
  />
51
60
  )}
52
61
  <svg
@@ -66,10 +75,11 @@ const DrawPieGraph = ({ value, parentWidth, parentHeight }: any) => {
66
75
  >
67
76
  {(pie) => {
68
77
  return pie.arcs.map((arc, index) => {
69
- const letter = value?.style?.pieStyle?.showPieLabel?arc.data[arr[0]]:arc.data[arr[1]];
78
+ const indexParam = value?.style?.pieStyle?.showPieLabel ? labelKeyIndex : valueKeyIndex;
79
+ const letter = arc.data[arr[indexParam]];
70
80
  const [centriodX, centriodY] = pie.path.centroid(arc);
71
81
  const arcPath = pie.path(arc);
72
- const arcFill: any = getLetterFrequencyColor(letter);
82
+ const arcFill: any = getLetterFrequencyColor(letter,indexParam);
73
83
  return (
74
84
  <g
75
85
  key={`arc-${letter}-${index}`}
@@ -91,7 +91,8 @@ export const finalDataProvider = (type: string, value: any,theme?:any) => {
91
91
  case "PieGraph":
92
92
  return {
93
93
  main: {
94
- data: value?.main?.data || [{ branch: "Kotak", value: 500 }, { branch: "SBI", value: 700 }, { branch: "HDFC", value: 900 }],
94
+ data: (value?.main?.data && value.main.data.length > 0) ? value?.main?.data
95
+ : [{ label: "Kotak", value: 500 }, { label: "SBI", value: 700 }, { label: "HDFC", value: 900 }],
95
96
  // [{}] ,
96
97
  // || letterFrequency.slice(0, 3),
97
98
  header: "Pie Graph",
@@ -170,6 +171,7 @@ export const finalDataProvider = (type: string, value: any,theme?:any) => {
170
171
  innerRadius: 60,
171
172
  cornerRadius: 2,
172
173
  padAngle: 0.006,
174
+ showPieLabel: true,
173
175
  ...value?.style?.pieStyle,
174
176
  },
175
177
  },