oolib 2.197.4 → 2.197.5

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.
@@ -33,12 +33,63 @@ var getTextColorForBreakdownData = function (_a) {
33
33
  var colorIdx = _a.colorIdx, index = _a.index;
34
34
  return colors_1.dataVizColorsText[(colorIdx + index) % colors_1.dataVizColorsText.length];
35
35
  };
36
+ // Helper function to get identifier using tooltipLabel logic - reused in mapping and final step
37
+ var getIdentifierFromPath = function (d, path, i, tooltipLabelsPath, tooltipLabelsMapping) {
38
+ var identifier;
39
+ if (tooltipLabelsPath) {
40
+ // Use tooltipLabelsPath logic to get the identifier - matches original logic exactly
41
+ if (Array.isArray(tooltipLabelsPath)) {
42
+ // Check if tooltipLabelsPath[i] exists before using it
43
+ identifier = tooltipLabelsPath[i]
44
+ ? (0, _EXPORTS_1.getVal)(d, tooltipLabelsPath[i]) || tooltipLabelsPath[i]
45
+ : path; // fallback to path if tooltipLabelsPath[i] doesn't exist
46
+ }
47
+ else if (typeof tooltipLabelsPath === 'string') {
48
+ identifier = (0, _EXPORTS_1.getVal)(d, tooltipLabelsPath) || tooltipLabelsPath;
49
+ }
50
+ else {
51
+ identifier = path;
52
+ }
53
+ }
54
+ else if (tooltipLabelsMapping) {
55
+ identifier = tooltipLabelsMapping[path] || path;
56
+ }
57
+ else {
58
+ identifier = path;
59
+ }
60
+ return identifier;
61
+ };
62
+ // Create a consistent mapping of unique identifiers to color indices for breakdown data
63
+ var createValueToColorMapping = function (data, tooltipLabelsPath, valuePath, tooltipLabelsMapping) {
64
+ var uniqueValues = new Set();
65
+ // Find the longest children array to use as template
66
+ var longestChildrenArray = [];
67
+ var longestLength = 0;
68
+ data.forEach(function (d) {
69
+ if (d.children && d.children.length > longestLength) {
70
+ longestLength = d.children.length;
71
+ longestChildrenArray = d.children;
72
+ }
73
+ });
74
+ // Use the longest children array as template to collect unique identifiers
75
+ valuePath.forEach(function (path, i) {
76
+ var identifier = getIdentifierFromPath({ children: longestChildrenArray }, path, i, tooltipLabelsPath, tooltipLabelsMapping);
77
+ uniqueValues.add(identifier);
78
+ });
79
+ // Create consistent mapping
80
+ var valueToColorIndex = {};
81
+ Array.from(uniqueValues).sort().forEach(function (value, index) {
82
+ valueToColorIndex[value] = index;
83
+ });
84
+ return valueToColorIndex;
85
+ };
36
86
  var usePrepareData = function (_a) {
37
87
  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;
38
88
  return (0, react_1.useMemo)(function () {
39
89
  var finalData = __spreadArray([], _data, true);
40
90
  if (finalData.length === 0)
41
91
  return ({ data: finalData, dataToSummarize: [], dataMaxValue: 0 });
92
+ var valueToColorMapping = isBreakdown ? createValueToColorMapping(finalData, tooltipLabelsPath, valuePath, tooltipLabelsMapping) : {};
42
93
  var totalCount = !isBreakdown
43
94
  ? (0, getTotalCount_1.getTotalCount)({ data: finalData, countPath: valuePath })
44
95
  : finalData.map(function (d) {
@@ -58,20 +109,22 @@ var usePrepareData = function (_a) {
58
109
  }
59
110
  return valuePath.map(function (path, i) {
60
111
  var count = (0, _EXPORTS_1.getVal)(d, path) || 0;
112
+ // Get the identifier using the same logic as tooltipLabel for consistent coloring
113
+ var identifier = getIdentifierFromPath(d, path, i, tooltipLabelsPath, tooltipLabelsMapping);
114
+ // Use the consistent color mapping instead of array index
115
+ var colorIndex = valueToColorMapping[identifier] !== undefined
116
+ ? valueToColorMapping[identifier]
117
+ : i; // fallback to index if identifier not found
61
118
  /**
62
119
  * for breakdown first we assign a color to each valuepath.
63
120
  * and then that color stays consistent for that valuepath across different breakdown groups
64
121
  */
65
- var barColor = getBarColorForBreakdownData({ colorIdx: colorIdx, index: i });
66
- var textColor = getTextColorForBreakdownData({ colorIdx: colorIdx, index: i });
122
+ var barColor = getBarColorForBreakdownData({ colorIdx: colorIdx, index: colorIndex });
123
+ var textColor = getTextColorForBreakdownData({ colorIdx: colorIdx, index: colorIndex });
67
124
  return {
68
125
  labels: __assign(__assign({}, (showPercent
69
126
  ? { percentage: (0, _EXPORTS_1.getPercentage)(count, totalCount[index]) }
70
- : {})), { count: count, tooltipLabel: tooltipLabelsPath
71
- ? tooltipLabelsPath[i]
72
- ? (0, _EXPORTS_1.getVal)(d, tooltipLabelsPath[i]) || tooltipLabelsPath[i]
73
- : path
74
- : (tooltipLabelsMapping === null || tooltipLabelsMapping === void 0 ? void 0 : tooltipLabelsMapping[path]) || path, name: (0, _EXPORTS_1.getVal)(d, labelPath), barColor: barColor, textColor: textColor }),
127
+ : {})), { count: count, tooltipLabel: identifier, name: (0, _EXPORTS_1.getVal)(d, labelPath), barColor: barColor, textColor: textColor }),
75
128
  };
76
129
  });
77
130
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oolib",
3
- "version": "2.197.4",
3
+ "version": "2.197.5",
4
4
  "description": " OKE Component Library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",