oolib 2.194.1 → 2.195.1

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.
@@ -24,8 +24,17 @@ exports.usePrepareData = void 0;
24
24
  var react_1 = require("react");
25
25
  var _EXPORTS_1 = require("../../../../utils/_EXPORTS");
26
26
  var getTotalCount_1 = require("../../../../utils/getTotalCount");
27
+ var colors_1 = require("../../../themes/colors");
28
+ var getBarColorForBreakdownData = function (_a) {
29
+ var colorIdx = _a.colorIdx, index = _a.index;
30
+ return colors_1.dataVizColors[(colorIdx + index) % colors_1.dataVizColors.length];
31
+ };
32
+ var getTextColorForBreakdownData = function (_a) {
33
+ var colorIdx = _a.colorIdx, index = _a.index;
34
+ return colors_1.dataVizColorsText[(colorIdx + index) % colors_1.dataVizColorsText.length];
35
+ };
27
36
  var usePrepareData = function (_a) {
28
- var _data = _a._data, labelPath = _a.labelPath, valuePath = _a.valuePath, tooltipLabelsMapping = _a.tooltipLabelsMapping, tooltipLabelsPath = _a.tooltipLabelsPath, isBreakdown = _a.isBreakdown, showPercent = _a.showPercent, summarizeAfterIdx = _a.summarizeAfterIdx;
37
+ var _data = _a._data, labelPath = _a.labelPath, valuePath = _a.valuePath, tooltipLabelsMapping = _a.tooltipLabelsMapping, tooltipLabelsPath = _a.tooltipLabelsPath, isBreakdown = _a.isBreakdown, showPercent = _a.showPercent, summarizeAfterIdx = _a.summarizeAfterIdx, colorIdx = _a.colorIdx;
29
38
  return (0, react_1.useMemo)(function () {
30
39
  var finalData = __spreadArray([], _data, true);
31
40
  if (finalData.length === 0)
@@ -44,11 +53,17 @@ var usePrepareData = function (_a) {
44
53
  return {
45
54
  labels: __assign(__assign({}, (showPercent
46
55
  ? { percentage: (0, _EXPORTS_1.getPercentage)(count, totalCount) }
47
- : {})), { count: count, name: (0, _EXPORTS_1.getVal)(d, labelPath) }),
56
+ : {})), { count: count, name: (0, _EXPORTS_1.getVal)(d, labelPath), barColor: colors_1.dataVizColors[colorIdx], textColor: colors_1.dataVizColorsText[colorIdx] }),
48
57
  };
49
58
  }
50
59
  return valuePath.map(function (path, i) {
51
60
  var count = (0, _EXPORTS_1.getVal)(d, path) || 0;
61
+ /**
62
+ * for breakdown first we assign a color to each valuepath.
63
+ * and then that color stays consistent for that valuepath across different breakdown groups
64
+ */
65
+ var barColor = getBarColorForBreakdownData({ colorIdx: colorIdx, index: i });
66
+ var textColor = getTextColorForBreakdownData({ colorIdx: colorIdx, index: i });
52
67
  return {
53
68
  labels: __assign(__assign({}, (showPercent
54
69
  ? { percentage: (0, _EXPORTS_1.getPercentage)(count, totalCount[index]) }
@@ -56,7 +71,7 @@ var usePrepareData = function (_a) {
56
71
  ? tooltipLabelsPath[i]
57
72
  ? (0, _EXPORTS_1.getVal)(d, tooltipLabelsPath[i]) || tooltipLabelsPath[i]
58
73
  : path
59
- : (tooltipLabelsMapping === null || tooltipLabelsMapping === void 0 ? void 0 : tooltipLabelsMapping[path]) || path, name: (0, _EXPORTS_1.getVal)(d, labelPath) }),
74
+ : (tooltipLabelsMapping === null || tooltipLabelsMapping === void 0 ? void 0 : tooltipLabelsMapping[path]) || path, name: (0, _EXPORTS_1.getVal)(d, labelPath), barColor: barColor, textColor: textColor }),
60
75
  };
61
76
  });
62
77
  });
@@ -66,6 +81,10 @@ var usePrepareData = function (_a) {
66
81
  return b.labels.count - a.labels.count;
67
82
  }
68
83
  else {
84
+ /**
85
+ * this sorts the order of the entire breakdown group/stack
86
+ * putting the one with the total largest count first all the way to the least
87
+ */
69
88
  var bTotal = b
70
89
  .map(function (bItem) { return bItem.labels.count; })
71
90
  .reduce(function (acc, curr) { return acc + curr; }, 0);
@@ -75,34 +94,57 @@ var usePrepareData = function (_a) {
75
94
  return bTotal - aTotal;
76
95
  }
77
96
  });
97
+ // Sort inner arrays from largest to smallest when it's a breakdown
98
+ if (isBreakdown) {
99
+ finalData.forEach(function (innerArray) {
100
+ innerArray.sort(function (a, b) {
101
+ return b.labels.count - a.labels.count;
102
+ });
103
+ });
104
+ }
78
105
  finalData = isBreakdown
79
106
  ? finalData.map(function (d, i) {
80
107
  return d.map(function (dd, ii) { return (__assign(__assign({}, dd), { labels: __assign(__assign({}, dd.labels), { dataIndex: i }) })); });
81
108
  })
82
109
  : finalData.map(function (d, i) { return (__assign(__assign({}, d), { labels: __assign(__assign({}, d.labels), { dataIndex: i }) })); });
83
110
  var mainData = !isBreakdown
84
- ? finalData.filter(function (_, i) { return i <= summarizeAfterIdx; })
111
+ ? (summarizeAfterIdx ? finalData.filter(function (_, i) { return i <= summarizeAfterIdx; }) : finalData)
85
112
  : finalData;
86
113
  var convertDataToSummrizeIntoBreakdownFormat = function (data) {
87
- var reshaped = data.map(function (d, i) { return (__assign(__assign({}, d), { labels: __assign(__assign({}, d.labels), { name: "Others", tooltipLabel: d.labels.name, dataIndex: i }) })); });
114
+ var reshaped = data.map(function (d, i) { return (__assign(__assign({}, d), { labels: __assign(__assign({}, d.labels), { name: "Others", tooltipLabel: d.labels.name, dataIndex: i, barColor: getBarColorForBreakdownData({ colorIdx: colorIdx + 1, index: i }), textColor: getTextColorForBreakdownData({ colorIdx: colorIdx + 1, index: i }) }) })); });
88
115
  return [reshaped];
89
116
  };
90
- var dataToSummarize = !isBreakdown
117
+ var dataToSummarize = (!isBreakdown && summarizeAfterIdx)
91
118
  ? convertDataToSummrizeIntoBreakdownFormat(finalData.filter(function (_, i) { return i > summarizeAfterIdx; }))
92
119
  : undefined;
93
120
  var calcDataMaxValue = function (mainData, dataToSummarize, isBreakdown) {
94
121
  //now if there is no data to summarize its simple. take the first element and get its count (for !isBreakdown) or accumulate to count for first element (isBreakdown)
95
122
  // with dataToSummarize, its interesting, because a summarized bar is a 'summation' of everything it is summarizing. sooo.. the summation (and not the individual values) should be taken into consideration while figuring out maxValue
123
+ var getHighestNumInArray = function (ary) {
124
+ var highest = 0;
125
+ ary.forEach(function (item) { if (item.labels.count > highest)
126
+ highest = item.labels.count; });
127
+ return highest;
128
+ };
129
+ var getHighestNumInArrayOfArrays = function (ary) {
130
+ var highest = 0;
131
+ ary.forEach(function (subAry) {
132
+ var subHighest = getHighestNumInArray(subAry);
133
+ if (subHighest > highest)
134
+ highest = subHighest;
135
+ });
136
+ return highest;
137
+ };
96
138
  if (!dataToSummarize) {
97
139
  return !isBreakdown
98
- ? mainData[0].labels.count
99
- : mainData[0].reduce(function (acc, b) { return acc + b.labels.count; }, 0);
140
+ ? getHighestNumInArray(mainData) //if not breakdown, simply get the highest count in this single level array structre : [ { labels: { count: <>, ... }}, ... ]
141
+ : getHighestNumInArrayOfArrays(mainData); // if breakdown, get the highest count across all the nested arrays in this structure : [ [ { labels: { count: <>, ... }}, ... ], ... ]
100
142
  }
101
143
  else {
102
144
  var totalCountOfSummarizedData = dataToSummarize[0].reduce(function (acc, b) { return acc + b.labels.count; }, 0);
103
145
  var maxCountFromMainData = !isBreakdown
104
- ? mainData[0].labels.count
105
- : mainData[0].reduce(function (acc, b) { return acc + b.labels.count; }, 0);
146
+ ? getHighestNumInArray(mainData)
147
+ : getHighestNumInArrayOfArrays(mainData);
106
148
  return maxCountFromMainData > totalCountOfSummarizedData
107
149
  ? maxCountFromMainData
108
150
  : totalCountOfSummarizedData;
@@ -105,5 +105,5 @@ exports.colors = {
105
105
  greenBG: greenBG,
106
106
  greenStroke: greenStroke,
107
107
  redBG: redBG,
108
- red: red
108
+ red: red,
109
109
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oolib",
3
- "version": "2.194.1",
3
+ "version": "2.195.1",
4
4
  "description": " OKE Component Library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -106,6 +106,6 @@
106
106
  "phosphor-react": "^1.4.1",
107
107
  "react-datepicker": "^7.6.0",
108
108
  "react-player": "^2.12.0",
109
- "recharts": "^2.12.7"
109
+ "recharts": "^2.15.3"
110
110
  }
111
111
  }