oolib 2.195.0 → 2.195.2

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.
@@ -39,92 +39,159 @@ var BarChart = function (args) {
39
39
  var handleBarClick = function (name) {
40
40
  console.log("Bar clicked: ".concat(name));
41
41
  };
42
- return (react_1.default.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: "20px" } },
43
- react_1.default.createElement("div", null,
44
- react_1.default.createElement(BarChart_1.BarChart, { showPercent: args.showPercent, data: [
42
+ return (react_1.default.createElement("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: "20px", padding: '20px' } },
43
+ react_1.default.createElement("div", { style: { border: '1px solid black', padding: '10px' } },
44
+ react_1.default.createElement(BarChart_1.BarChart, { overflowAfterHeight: 300, showPercent: args.showPercent, data: [
45
45
  {
46
46
  display: "Logged In Once",
47
- // stack1: 60,
48
- stack2: 20,
49
- stack3: 40,
50
- stack4: 10,
51
- stack5: 40,
52
- stack6: 10,
47
+ stack1: 45, stack2: 23, stack3: 67, stack4: 12, stack5: 89,
48
+ stack6: 34, stack7: 56, stack8: 78, stack9: 21, stack10: 43,
49
+ stack11: 65, stack12: 87, stack13: 32, stack14: 54, stack15: 76,
50
+ stack16: 19, stack17: 41, stack18: 63, stack19: 85, stack20: 28,
53
51
  stack2Display: 'Labels Path Stack 2 Display'
54
52
  },
55
53
  {
56
54
  display: "Registered Users",
57
- stack1: 100,
58
- stack2: 50,
59
- stack3: 10,
60
- stack4: 15,
61
- stack5: 40,
62
- stack6: 10,
55
+ stack1: 92, stack3: 71, stack4: 25, stack5: 84,
56
+ stack6: 47, stack7: 69, stack8: 13, stack9: 56, stack10: 91,
57
+ stack11: 29, stack12: 73, stack13: 46, stack14: 82, stack15: 17,
58
+ stack16: 64, stack17: 39, stack18: 75, stack19: 22, stack20: 58
63
59
  },
64
60
  {
65
61
  display: "Created Profile",
66
- stack1: 20,
67
- stack2: 5,
68
- stack3: 10,
69
- stack4: 15,
70
- stack5: 40,
71
- stack6: 10,
62
+ stack1: 33, stack2: 77, stack3: 14, stack4: 59, stack5: 86,
63
+ stack6: 31, stack7: 68, stack8: 42, stack9: 95, stack10: 26,
64
+ stack11: 71, stack12: 48, stack13: 83, stack14: 16, stack15: 62,
65
+ stack16: 37, stack17: 74, stack18: 29, stack19: 85, stack20: 51
72
66
  },
73
67
  {
74
68
  display: "Wrote at least 3 story",
75
- stack1: 8,
76
- stack2: 2,
77
- stack3: 1,
78
- stack4: 1,
79
- stack5: 40,
80
- stack6: 10,
69
+ stack1: 18, stack2: 52, stack3: 79, stack4: 35, stack5: 61,
70
+ stack6: 93, stack7: 24, stack8: 67, stack9: 41, stack10: 88,
71
+ stack11: 15, stack12: 53, stack13: 76, stack14: 32, stack15: 68,
72
+ stack16: 94, stack17: 27, stack18: 49, stack19: 81, stack20: 36
81
73
  },
82
74
  {
83
75
  display: "Created Profile again",
84
- stack1: 20,
85
- stack2: 5,
86
- stack3: 10,
87
- stack4: 15,
88
- stack5: 40,
89
- stack6: 10,
76
+ stack1: 44, stack2: 87, stack3: 21, stack4: 63, stack5: 96,
77
+ stack6: 38, stack7: 72, stack8: 55, stack9: 19, stack10: 81,
78
+ stack11: 46, stack12: 92, stack13: 28, stack14: 65, stack15: 37,
79
+ stack16: 74, stack17: 51, stack18: 83, stack19: 26, stack20: 69
90
80
  },
91
81
  {
92
82
  display: "Wrote at least 1 story",
93
- stack1: 8,
94
- stack2: 2,
95
- stack3: 1,
96
- stack4: 1,
97
- stack5: 40,
98
- stack6: 10,
83
+ stack1: 57, stack2: 23, stack3: 89, stack4: 41, stack5: 76,
84
+ stack6: 12, stack7: 64, stack8: 98, stack9: 33, stack10: 78,
85
+ stack11: 55, stack12: 17, stack13: 91, stack14: 48, stack15: 82,
86
+ stack16: 26, stack17: 69, stack18: 43, stack19: 95, stack20: 31
87
+ }
88
+ ], plotDataPoint: "percentage", valuePath: [
89
+ "stack1", "stack2", "stack3", "stack4", "stack5",
90
+ // "stack6", "stack7", "stack8", "stack9", "stack10",
91
+ // "stack11", "stack12", "stack13", "stack14", "stack15",
92
+ // "stack16", "stack17", "stack18", "stack19", "stack20"
93
+ ], breakdownCategoryName: "Age of org.", tooltipLabelsMapping: {
94
+ stack1: 'Stack 1', stack2: 'Stack 2', stack3: 'Stack 3', stack4: 'Stack 4', stack5: 'Stack 5',
95
+ stack6: 'Stack 6', stack7: 'Stack 7', stack8: 'Stack 8', stack9: 'Stack 9', stack10: 'Stack 10',
96
+ stack11: 'Stack 11', stack12: 'Stack 12', stack13: 'Stack 13', stack14: 'Stack 14', stack15: 'Stack 15',
97
+ stack16: 'Stack 16', stack17: 'Stack 17', stack18: 'Stack 18', stack19: 'Stack 19', stack20: 'Stack 20'
98
+ }, labelPath: "display", title: "This is a Stacked BarChart with 20 Stacks", onClick: handleBarClick, colorIdx: 2 })),
99
+ react_1.default.createElement("div", { style: { border: '1px solid black', padding: '10px' } },
100
+ react_1.default.createElement(BarChart_1.BarChart, { data: [
101
+ {
102
+ display: "Logged In Once During the First Week of Registration and Completed the Basic Profile Section Without Abandoning the Process",
103
+ stack1: 60
104
+ },
105
+ {
106
+ display: "Registered Users Who Successfully Verified Their Email Address and Set Up Two-Factor Authentication for Enhanced Account Security",
107
+ stack1: 100
108
+ },
109
+ {
110
+ display: "Created Profile With All Recommended Fields Including Biography, Education History, Work Experience, and Personal Interests",
111
+ stack1: 20
112
+ },
113
+ {
114
+ display: "Wrote at least 3 stories With Over 2,000 Words Each and Received More Than 50 Positive Engagements from Other Community Members",
115
+ stack1: 8
116
+ },
117
+ {
118
+ display: "Created Profile again After Deleting Their Previous One Due to Privacy Concerns or Desire to Start Fresh with New Information",
119
+ stack1: 20
120
+ },
121
+ {
122
+ display: "Wrote at least 1 story That Was Featured on the Homepage and Remained in the Top Trending Section for More Than 48 Hours",
123
+ stack1: 8
124
+ },
125
+ {
126
+ display: "Completed Onboarding Including All Optional Tutorials and Achieved a Perfect Score on the Platform Knowledge Assessment Test",
127
+ stack1: 78
128
+ },
129
+ {
130
+ display: "Added Payment Method and Set Up Recurring Billing for Premium Subscription Without Encountering Any Technical Issues During Checkout",
131
+ stack1: 42
132
+ },
133
+ {
134
+ display: "Made First Purchase Within 24 Hours of Creating Their Account and Left a Five-Star Review for the Product or Service",
135
+ stack1: 35
136
+ },
137
+ {
138
+ display: "Referred a Friend Through the Official Referral Program and Both Received the Maximum Possible Bonus Credits as a Result",
139
+ stack1: 27
140
+ },
141
+ {
142
+ display: "Participated in the Annual User Satisfaction Survey and Provided Detailed Feedback on Potential Platform Improvements",
143
+ stack1: 54
144
+ },
145
+ {
146
+ display: "Downloaded the Mobile Application on Multiple Devices and Enabled Cross-Platform Synchronization for Seamless User Experience",
147
+ stack1: 89
148
+ },
149
+ {
150
+ display: "Configured Advanced Notification Preferences to Receive Real-Time Alerts for Specific Activities Relevant to Their Interests",
151
+ stack1: 31
152
+ },
153
+ {
154
+ display: "Successfully Recovered Account After Forgetting Password by Following the Secure Password Reset Protocol Without Support Assistance",
155
+ stack1: 46
99
156
  },
157
+ {
158
+ display: "Achieved Gold Tier Status in the Loyalty Program by Consistently Engaging with the Platform for More Than Six Consecutive Months",
159
+ stack1: 15
160
+ },
161
+ {
162
+ display: "Converted From Free Trial to Paid Subscription Before the Trial Period Ended and Opted for the Annual Payment Plan with Auto-Renewal",
163
+ stack1: 67
164
+ },
165
+ {
166
+ display: "Customized Their Dashboard Layout to Optimize Workflow Efficiency Based on Their Unique Usage Patterns and Preferences",
167
+ stack1: 72
168
+ },
169
+ {
170
+ display: "Signed Up for Beta Testing Program and Provided Valuable Feedback on Experimental Features Before General Public Release",
171
+ stack1: 19
172
+ },
173
+ {
174
+ display: "Linked All Available Social Media Accounts to Enable Cross-Platform Sharing and Enhanced Social Networking Capabilities",
175
+ stack1: 38
176
+ },
177
+ {
178
+ display: "Reported a Critical Bug That Was Subsequently Fixed in the Next Software Update and Received Official Recognition for the Contribution",
179
+ stack1: 5
180
+ }
100
181
  ], plotDataPoint: "percentage" // This can be changed to count
101
- , valuePath: [
102
- "stack1",
103
- "stack2",
104
- "stack3",
105
- "stack4",
106
- "stack5",
107
- "stack6",
108
- ], tooltipLabelsMapping: {
109
- stack1: 'Stack 1',
110
- stack2: 'Stack 2',
111
- stack3: 'Stack 3',
112
- stack4: 'Stack 4',
113
- stack5: 'Stack 5',
114
- stack6: 'Stack 6',
115
- },
116
- // valuePath="stack1"
117
- labelPath: "display", title: "This is a Stacked BarChart", onClick: handleBarClick, colorIdx: 2 }),
118
- react_1.default.createElement(BarGraphCollection_1.BarGraphCollection, { showPercent: args.showPercent, showCount: args.showCount, data: [
182
+ ,
183
+ // valuePath={["stack1", "stack2", "stack3", "stack4", "stack5", "stack6"]}
184
+ valuePath: "stack1", labelPath: "display", title: "This is a Stacked BarChart", onClick: handleBarClick, showPercent: args.showPercent, colorIdx: 2 })),
185
+ react_1.default.createElement("div", { style: { border: '1px solid black', padding: '10px' } },
186
+ react_1.default.createElement(BarChart_1.BarChart, { data: [
119
187
  {
120
188
  display: "Logged In Once",
121
- // stack1: 60,
189
+ stack1: 60,
122
190
  stack2: 20,
123
191
  stack3: 40,
124
192
  stack4: 10,
125
193
  stack5: 40,
126
194
  stack6: 10,
127
- stack2Display: 'Labels Path Stack 2 Display'
128
195
  },
129
196
  {
130
197
  display: "Registered Users",
@@ -180,168 +247,7 @@ var BarChart = function (args) {
180
247
  "stack5",
181
248
  "stack6",
182
249
  ],
183
- // tooltipLabelsMapping={{
184
- // stack1: 'Stack 1',
185
- // stack2: 'Stack 2',
186
- // stack3: 'Stack 3',
187
- // stack4: 'Stack 4',
188
- // stack5: 'Stack 5',
189
- // stack6: 'Stack 6',
190
- // }}
191
250
  // valuePath="stack1"
192
- labelPath: "display", title: "This is a Stacked BarChart", onClick: handleBarClick, colorIdx: 2 })),
193
- react_1.default.createElement("div", null,
194
- react_1.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "40px" } },
195
- react_1.default.createElement(BarChart_1.BarChart, { data: [
196
- {
197
- display: "Logged In Once During the First Week of Registration and Completed the Basic Profile Section Without Abandoning the Process",
198
- stack1: 60
199
- },
200
- {
201
- display: "Registered Users Who Successfully Verified Their Email Address and Set Up Two-Factor Authentication for Enhanced Account Security",
202
- stack1: 100
203
- },
204
- {
205
- display: "Created Profile With All Recommended Fields Including Biography, Education History, Work Experience, and Personal Interests",
206
- stack1: 20
207
- },
208
- {
209
- display: "Wrote at least 3 stories With Over 2,000 Words Each and Received More Than 50 Positive Engagements from Other Community Members",
210
- stack1: 8
211
- },
212
- {
213
- display: "Created Profile again After Deleting Their Previous One Due to Privacy Concerns or Desire to Start Fresh with New Information",
214
- stack1: 20
215
- },
216
- {
217
- display: "Wrote at least 1 story That Was Featured on the Homepage and Remained in the Top Trending Section for More Than 48 Hours",
218
- stack1: 8
219
- },
220
- {
221
- display: "Completed Onboarding Including All Optional Tutorials and Achieved a Perfect Score on the Platform Knowledge Assessment Test",
222
- stack1: 78
223
- },
224
- {
225
- display: "Added Payment Method and Set Up Recurring Billing for Premium Subscription Without Encountering Any Technical Issues During Checkout",
226
- stack1: 42
227
- },
228
- {
229
- display: "Made First Purchase Within 24 Hours of Creating Their Account and Left a Five-Star Review for the Product or Service",
230
- stack1: 35
231
- },
232
- {
233
- display: "Referred a Friend Through the Official Referral Program and Both Received the Maximum Possible Bonus Credits as a Result",
234
- stack1: 27
235
- },
236
- {
237
- display: "Participated in the Annual User Satisfaction Survey and Provided Detailed Feedback on Potential Platform Improvements",
238
- stack1: 54
239
- },
240
- {
241
- display: "Downloaded the Mobile Application on Multiple Devices and Enabled Cross-Platform Synchronization for Seamless User Experience",
242
- stack1: 89
243
- },
244
- {
245
- display: "Configured Advanced Notification Preferences to Receive Real-Time Alerts for Specific Activities Relevant to Their Interests",
246
- stack1: 31
247
- },
248
- {
249
- display: "Successfully Recovered Account After Forgetting Password by Following the Secure Password Reset Protocol Without Support Assistance",
250
- stack1: 46
251
- },
252
- {
253
- display: "Achieved Gold Tier Status in the Loyalty Program by Consistently Engaging with the Platform for More Than Six Consecutive Months",
254
- stack1: 15
255
- },
256
- {
257
- display: "Converted From Free Trial to Paid Subscription Before the Trial Period Ended and Opted for the Annual Payment Plan with Auto-Renewal",
258
- stack1: 67
259
- },
260
- {
261
- display: "Customized Their Dashboard Layout to Optimize Workflow Efficiency Based on Their Unique Usage Patterns and Preferences",
262
- stack1: 72
263
- },
264
- {
265
- display: "Signed Up for Beta Testing Program and Provided Valuable Feedback on Experimental Features Before General Public Release",
266
- stack1: 19
267
- },
268
- {
269
- display: "Linked All Available Social Media Accounts to Enable Cross-Platform Sharing and Enhanced Social Networking Capabilities",
270
- stack1: 38
271
- },
272
- {
273
- display: "Reported a Critical Bug That Was Subsequently Fixed in the Next Software Update and Received Official Recognition for the Contribution",
274
- stack1: 5
275
- }
276
- ], plotDataPoint: "percentage" // This can be changed to count
277
- ,
278
- // valuePath={["stack1", "stack2", "stack3", "stack4", "stack5", "stack6"]}
279
- valuePath: "stack1", labelPath: "display", title: "This is a Stacked BarChart", onClick: handleBarClick, showPercent: args.showPercent, colorIdx: 2 }),
280
- react_1.default.createElement(BarChart_1.BarChart, { data: [
281
- {
282
- display: "Logged In Once",
283
- stack1: 60,
284
- stack2: 20,
285
- stack3: 40,
286
- stack4: 10,
287
- stack5: 40,
288
- stack6: 10,
289
- },
290
- {
291
- display: "Registered Users",
292
- stack1: 100,
293
- stack2: 50,
294
- stack3: 10,
295
- stack4: 15,
296
- stack5: 40,
297
- stack6: 10,
298
- },
299
- {
300
- display: "Created Profile",
301
- stack1: 20,
302
- stack2: 5,
303
- stack3: 10,
304
- stack4: 15,
305
- stack5: 40,
306
- stack6: 10,
307
- },
308
- {
309
- display: "Wrote at least 3 story",
310
- stack1: 8,
311
- stack2: 2,
312
- stack3: 1,
313
- stack4: 1,
314
- stack5: 40,
315
- stack6: 10,
316
- },
317
- {
318
- display: "Created Profile again",
319
- stack1: 20,
320
- stack2: 5,
321
- stack3: 10,
322
- stack4: 15,
323
- stack5: 40,
324
- stack6: 10,
325
- },
326
- {
327
- display: "Wrote at least 1 story",
328
- stack1: 8,
329
- stack2: 2,
330
- stack3: 1,
331
- stack4: 1,
332
- stack5: 40,
333
- stack6: 10,
334
- },
335
- ], plotDataPoint: "percentage" // This can be changed to count
336
- , valuePath: [
337
- "stack1",
338
- "stack2",
339
- "stack3",
340
- "stack4",
341
- "stack5",
342
- "stack6",
343
- ],
344
- // valuePath="stack1"
345
- breakdownDisplayType: "stacked", labelPath: "display", title: "This is a Stacked BarChart", onClick: handleBarClick, showPercent: args.showPercent, colorIdx: 2 })))));
251
+ breakdownDisplayType: "stacked", labelPath: "display", title: "This is a Stacked BarChart", onClick: handleBarClick, showPercent: args.showPercent, colorIdx: 2 }))));
346
252
  };
347
253
  exports.BarChart = BarChart;
@@ -2,6 +2,7 @@ export interface BaseBarChartUIConfigs {
2
2
  barHeight: number;
3
3
  labelToBarGap: number;
4
4
  labelHeight: number;
5
+ gapBetweenTwoLabels: number;
5
6
  labelToNextBarGap: number;
6
7
  barRadius: number;
7
8
  gapBetweenBarSections: number;
@@ -11,6 +11,7 @@ exports._base_barchart_ui_configs = {
11
11
  barHeight: 10,
12
12
  labelToBarGap: 6,
13
13
  labelHeight: 16.5667,
14
+ gapBetweenTwoLabels: 2,
14
15
  labelToNextBarGap: 14,
15
16
  //other bar section related properties
16
17
  barRadius: 2,
@@ -4,6 +4,8 @@ import { CountVizLabels } from "../../../types";
4
4
  interface CustomTooltipProps extends TooltipProps<number, string> {
5
5
  value?: CountVizLabels[];
6
6
  showPercent?: boolean;
7
+ activeBar?: string;
8
+ breakdownCategoryName?: string;
7
9
  mousePosition?: {
8
10
  x: number;
9
11
  y: number;
@@ -53,12 +53,14 @@ var react_1 = __importStar(require("react"));
53
53
  var styled_components_1 = __importDefault(require("styled-components"));
54
54
  var __1 = require("../../../../../..");
55
55
  var Typo2_1 = require("../../../../Typo2");
56
+ var LegendTooltipGlyph_1 = require("../LegendTooltipGlyph");
56
57
  var UI_CAPTION_DF_WITH_LINE_CLAMP = (0, styled_components_1.default)(Typo2_1.UI_CAPTION_DF)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n \n ", "\n"], ["\n \n ", "\n"])), function (_a) {
57
58
  var clampT = _a.clampT;
58
59
  return clampT ? (0, __1.clampText)(3) : '';
59
60
  });
60
61
  var CustomTooltip = function (props) {
61
- var active = props.active, value = props.value, showPercent = props.showPercent, mousePosition = props.mousePosition;
62
+ var value = props.value, showPercent = props.showPercent, mousePosition = props.mousePosition, activeBar = props.activeBar, breakdownCategoryName = props.breakdownCategoryName;
63
+ var isActive = props.active; //activeBar && value?.[0]?.name === activeBar
62
64
  var tooltipWrapperRef = (0, react_1.useRef)(null);
63
65
  var calcTooltipTop = function (_a) {
64
66
  var _b, _c;
@@ -113,28 +115,24 @@ var CustomTooltip = function (props) {
113
115
  });
114
116
  setRowHeights(rowHeightsToSet);
115
117
  }, [tooltipTextClampStates.join()]);
116
- if (!active)
118
+ if (!isActive)
117
119
  return null;
118
120
  return (react_1.default.createElement(react_1.Fragment, null,
119
121
  react_1.default.createElement("div", { ref: tooltipWrapperRef, style: style },
122
+ breakdownCategoryName && react_1.default.createElement(Typo2_1.UI_CAPTION_BOLD_DF, null, breakdownCategoryName),
120
123
  react_1.default.createElement("div", { style: {
121
124
  display: "grid",
122
125
  gridTemplateColumns: showPercent ? "auto auto auto" : "auto auto",
123
126
  gap: "0.6rem",
124
127
  } },
125
- react_1.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "1rem" } }, value.map(function (entry, index) { return (react_1.default.createElement("div", { style: { height: rowHeights[index] ? rowHeights[index] + "px" : "auto" } },
128
+ react_1.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "1rem" } }, value.map(function (entry, index) { return (react_1.default.createElement("div", { key: index, style: { height: rowHeights[index] ? rowHeights[index] + "px" : "auto" } },
126
129
  react_1.default.createElement("div", { style: {
127
130
  display: "flex",
128
131
  alignItems: "center",
129
132
  gap: "0.6rem",
130
133
  } },
131
- react_1.default.createElement("div", { key: index, style: {
132
- width: "1.2rem",
133
- height: "1.2rem",
134
- borderRadius: "50%",
135
- backgroundColor: entry.color,
136
- } }),
137
- react_1.default.createElement(Typo2_1.UI_CAPTION_BOLD_DF, { key: index }, showPercent ? entry.percentage + "%" : entry.count || "0")))); })),
134
+ react_1.default.createElement(LegendTooltipGlyph_1.LegendTooltipGlyph, { color: entry.barColor }),
135
+ react_1.default.createElement(Typo2_1.UI_CAPTION_BOLD_DF, null, showPercent ? entry.percentage + "%" : entry.count || "0")))); })),
138
136
  showPercent && (react_1.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: "1rem" } }, value.map(function (entry, index) { return (react_1.default.createElement("div", { style: {
139
137
  height: rowHeights[index]
140
138
  ? rowHeights[index] + "px"
@@ -16,12 +16,14 @@ interface CustomizedLabelProps {
16
16
  _base_barchart_ui_configs: BaseBarChartUIConfigs;
17
17
  _debug_controls: DebugControls;
18
18
  TOT_HEIGHT_SINGLE_BAR_SECTION: number;
19
+ TOT_HEIGHT_STACKED_BAR_SECTION: number;
19
20
  TOT_HEIGHT_GROUPED_BAR_SECTION: number;
20
21
  CALC_SINGLE_BAR_SECTION_Y_POS: (index: number) => number;
22
+ CALC_STACKED_BAR_SECTION_Y_POS: (index: number) => number;
21
23
  showSumOfBreakdownValues?: boolean;
22
24
  onMouseOver?: (e: React.MouseEvent<SVGRectElement, MouseEvent>, v: CustomizedLabelValue) => void;
23
25
  onMouseOut?: (e: React.MouseEvent<SVGRectElement, MouseEvent>, v: CustomizedLabelValue) => void;
24
26
  onMouseDown?: (e: React.MouseEvent<SVGRectElement, MouseEvent>, v: CustomizedLabelValue) => void;
25
27
  }
26
- export declare const CustomizedLabel: ({ y, width, height, value, showPercent, showCount, opacity, _base_barchart_ui_configs, _debug_controls, onMouseOver, onMouseOut, onMouseDown, activeBar, TOT_HEIGHT_SINGLE_BAR_SECTION, TOT_HEIGHT_GROUPED_BAR_SECTION, CALC_SINGLE_BAR_SECTION_Y_POS, breakdownDisplayType, showSumOfBreakdownValues }: CustomizedLabelProps) => React.JSX.Element;
28
+ export declare const CustomizedLabel: ({ y, width, height, value, showPercent, showCount, opacity, _base_barchart_ui_configs, _debug_controls, onMouseOver, onMouseOut, onMouseDown, activeBar, TOT_HEIGHT_SINGLE_BAR_SECTION, TOT_HEIGHT_STACKED_BAR_SECTION, TOT_HEIGHT_GROUPED_BAR_SECTION, CALC_SINGLE_BAR_SECTION_Y_POS, CALC_STACKED_BAR_SECTION_Y_POS, breakdownDisplayType, showSumOfBreakdownValues, }: CustomizedLabelProps) => React.JSX.Element;
27
29
  export {};
@@ -1,44 +1,13 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
35
5
  Object.defineProperty(exports, "__esModule", { value: true });
36
6
  exports.CustomizedLabel = void 0;
37
- var react_1 = __importStar(require("react"));
7
+ var react_1 = __importDefault(require("react"));
38
8
  var themes_1 = require("../../../../../themes");
39
- var TruncatedSVGText_1 = require("../TruncatedSVGText");
40
9
  var CustomizedLabel = function (_a) {
41
- var y = _a.y, width = _a.width, height = _a.height, value = _a.value, showPercent = _a.showPercent, showCount = _a.showCount, opacity = _a.opacity, _base_barchart_ui_configs = _a._base_barchart_ui_configs, _debug_controls = _a._debug_controls, onMouseOver = _a.onMouseOver, onMouseOut = _a.onMouseOut, onMouseDown = _a.onMouseDown, activeBar = _a.activeBar, TOT_HEIGHT_SINGLE_BAR_SECTION = _a.TOT_HEIGHT_SINGLE_BAR_SECTION, TOT_HEIGHT_GROUPED_BAR_SECTION = _a.TOT_HEIGHT_GROUPED_BAR_SECTION, CALC_SINGLE_BAR_SECTION_Y_POS = _a.CALC_SINGLE_BAR_SECTION_Y_POS, breakdownDisplayType = _a.breakdownDisplayType, _b = _a.showSumOfBreakdownValues, showSumOfBreakdownValues = _b === void 0 ? false : _b;
10
+ var y = _a.y, width = _a.width, height = _a.height, value = _a.value, showPercent = _a.showPercent, showCount = _a.showCount, opacity = _a.opacity, _base_barchart_ui_configs = _a._base_barchart_ui_configs, _debug_controls = _a._debug_controls, onMouseOver = _a.onMouseOver, onMouseOut = _a.onMouseOut, onMouseDown = _a.onMouseDown, activeBar = _a.activeBar, TOT_HEIGHT_SINGLE_BAR_SECTION = _a.TOT_HEIGHT_SINGLE_BAR_SECTION, TOT_HEIGHT_STACKED_BAR_SECTION = _a.TOT_HEIGHT_STACKED_BAR_SECTION, TOT_HEIGHT_GROUPED_BAR_SECTION = _a.TOT_HEIGHT_GROUPED_BAR_SECTION, CALC_SINGLE_BAR_SECTION_Y_POS = _a.CALC_SINGLE_BAR_SECTION_Y_POS, CALC_STACKED_BAR_SECTION_Y_POS = _a.CALC_STACKED_BAR_SECTION_Y_POS, breakdownDisplayType = _a.breakdownDisplayType, _b = _a.showSumOfBreakdownValues, showSumOfBreakdownValues = _b === void 0 ? false : _b;
42
11
  if (!value)
43
12
  return null;
44
13
  var yOffset = -(_base_barchart_ui_configs.labelToBarGap + (_base_barchart_ui_configs.barHeight / 2));
@@ -57,7 +26,7 @@ var CustomizedLabel = function (_a) {
57
26
  return totValue;
58
27
  }
59
28
  else { //only used while showing the summarized data as a stacked bar
60
- return values_1.map(function (v, index) { return (react_1.default.createElement("tspan", { key: index, fill: v.color, className: "UI_BODY_BOLD_SM" },
29
+ return values_1.map(function (v, index) { return (react_1.default.createElement("tspan", { key: index, fill: v.textColor, className: "UI_BODY_BOLD_SM" },
61
30
  showPercent ? v.percentage.toFixed(1) + '%' : v.count,
62
31
  index < values_1.length - 1 && (react_1.default.createElement("tspan", { fill: themes_1.colors.grey80 }, " + ")))); });
63
32
  }
@@ -77,17 +46,28 @@ var CustomizedLabel = function (_a) {
77
46
  return value.count;
78
47
  }
79
48
  };
80
- var widthRef = (0, react_1.useRef)(null);
81
- var textContainerRef = (0, react_1.useRef)(null);
82
49
  return (react_1.default.createElement("g", null,
83
- react_1.default.createElement("text", { ref: textContainerRef, opacity: opacity, x: _base_barchart_ui_configs.marginLeft, dy: y - (_base_barchart_ui_configs.labelToBarGap), fill: themes_1.colors.grey80, textAnchor: "start", className: "UI_BODY_BOLD_SM" },
50
+ (isBreakdown && !showSumOfBreakdownValues) && //meaning if its a breakdown and we are showing values as v1 + v2 + v3 which occupies too much space and hence we need double line
51
+ react_1.default.createElement("text", { className: "UI_BODY_SM", opacity: opacity, x: _base_barchart_ui_configs.marginLeft, dy: y - (_base_barchart_ui_configs.labelToBarGap + _base_barchart_ui_configs.labelHeight + _base_barchart_ui_configs.gapBetweenTwoLabels), fill: themes_1.colors.grey80, textAnchor: "start" }, name),
52
+ react_1.default.createElement("text", { opacity: opacity, x: _base_barchart_ui_configs.marginLeft, dy: y - (_base_barchart_ui_configs.labelToBarGap), fill: themes_1.colors.grey80, textAnchor: "start", className: "UI_BODY_BOLD_SM" },
84
53
  formatValue(),
85
54
  showPercent && !isBreakdown && (react_1.default.createElement("tspan", { className: "UI_BODY_SM", dx: xOffsetRelative, fill: themes_1.colors.grey80 }, getCount())),
86
- react_1.default.createElement("tspan", { className: "UI_BODY_SM", dx: xOffsetRelative, fill: themes_1.colors.grey80 },
87
- react_1.default.createElement(TruncatedSVGText_1.TruncatedSVGText, { text: name, textContainerRef: textContainerRef, widthRef: widthRef, widthOffset: -(_base_barchart_ui_configs.marginLeft + _base_barchart_ui_configs.marginRight) }))),
88
- react_1.default.createElement("rect", { ref: widthRef, style: onMouseDown ? { cursor: 'pointer' } : {}, onMouseDown: function (e) { return onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(e, value); }, onMouseOver: function (e) { return onMouseOver === null || onMouseOver === void 0 ? void 0 : onMouseOver(e, value); }, onMouseOut: function (e) { return onMouseOut === null || onMouseOut === void 0 ? void 0 : onMouseOut(e, value); }, x: _base_barchart_ui_configs.hoverRectStrokeWidth, y: (!isBreakdown || breakdownDisplayType === 'stacked')
55
+ (isBreakdown && !showSumOfBreakdownValues) ? null : react_1.default.createElement("tspan", { className: "UI_BODY_SM", dx: xOffsetRelative, fill: themes_1.colors.grey80 }, name)),
56
+ react_1.default.createElement("rect", { style: onMouseDown ? { cursor: 'pointer' } : {}, onMouseDown: function (e) { return onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(e, value); }, onMouseOver: function (e) {
57
+ onMouseOver === null || onMouseOver === void 0 ? void 0 : onMouseOver(e, value);
58
+ }, onMouseOut: function (e) {
59
+ onMouseOut === null || onMouseOut === void 0 ? void 0 : onMouseOut(e, value);
60
+ }, x: _base_barchart_ui_configs.hoverRectStrokeWidth, y: (!isBreakdown || showSumOfBreakdownValues)
89
61
  ? _base_barchart_ui_configs.hoverRectStrokeWidth + CALC_SINGLE_BAR_SECTION_Y_POS(value.dataIndex)
90
- : _base_barchart_ui_configs.hoverRectStrokeWidth + (TOT_HEIGHT_GROUPED_BAR_SECTION + _base_barchart_ui_configs.gapBetweenBarSections) * value[0].dataIndex, width: "calc(100% - ".concat(_base_barchart_ui_configs.hoverRectStrokeWidth * 2, "px)"), height: (!isBreakdown || breakdownDisplayType === 'stacked') ? TOT_HEIGHT_SINGLE_BAR_SECTION : TOT_HEIGHT_GROUPED_BAR_SECTION, opacity: _debug_controls.mouseEventDetectorOpacity ||
62
+ : breakdownDisplayType === 'stacked'
63
+ ? _base_barchart_ui_configs.hoverRectStrokeWidth + CALC_STACKED_BAR_SECTION_Y_POS(value[0].dataIndex)
64
+ : breakdownDisplayType === 'grouped' &&
65
+ _base_barchart_ui_configs.hoverRectStrokeWidth + (TOT_HEIGHT_GROUPED_BAR_SECTION + _base_barchart_ui_configs.gapBetweenBarSections) * value[0].dataIndex, width: "calc(100% - ".concat(_base_barchart_ui_configs.hoverRectStrokeWidth * 2, "px)"), height: (!isBreakdown || showSumOfBreakdownValues)
66
+ ? TOT_HEIGHT_SINGLE_BAR_SECTION
67
+ : breakdownDisplayType === 'stacked'
68
+ ? TOT_HEIGHT_STACKED_BAR_SECTION
69
+ : breakdownDisplayType === 'grouped' &&
70
+ TOT_HEIGHT_GROUPED_BAR_SECTION, opacity: _debug_controls.mouseEventDetectorOpacity ||
91
71
  (activeBar === name ? 1 : 0), stroke: themes_1.colors.grey30, rx: 5, ry: 5, strokeWidth: "".concat(_base_barchart_ui_configs.hoverRectStrokeWidth, "px"), fillOpacity: _debug_controls.mouseEventDetectorOpacity })));
92
72
  };
93
73
  exports.CustomizedLabel = CustomizedLabel;
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ interface LegendData {
3
+ color: string;
4
+ text: string;
5
+ }
6
+ interface LegendProps {
7
+ data: LegendData[];
8
+ label?: string;
9
+ orientation?: "vertical" | "horizontal";
10
+ }
11
+ export declare const Legend: React.FC<LegendProps>;
12
+ export {};
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Legend = void 0;
18
+ var react_1 = __importDefault(require("react"));
19
+ var __1 = require("../../../../../..");
20
+ var Typo2_1 = require("../../../../Typo2");
21
+ var LegendTooltipGlyph_1 = require("../LegendTooltipGlyph");
22
+ var Legend = function (_a) {
23
+ var data = _a.data, label = _a.label, _b = _a.orientation, orientation = _b === void 0 ? "vertical" : _b;
24
+ return (react_1.default.createElement("div", { style: __assign(__assign({}, (orientation === 'vertical' ? { maxWidth: '200px' } : {})), { padding: "12px", borderRadius: '8px', border: "1px solid ".concat(__1.colors2.grey5), background: "linear-gradient(to bottom, hsla(0, 0%, 96%, 1), hsla(0, 0%, 100%, 0))", maxHeight: orientation === 'vertical' ? '100%' : '150px', overflow: 'scroll' }) },
25
+ label && orientation === 'vertical' && (react_1.default.createElement("div", { style: { paddingBottom: "8px" } },
26
+ react_1.default.createElement(Typo2_1.UI_CAPTION_BOLD_DF, null, label))),
27
+ react_1.default.createElement("div", { style: __assign(__assign({ display: "flex", flexDirection: orientation === "vertical" ? "column" : "row" }, (orientation === 'horizontal' ? { flexWrap: 'wrap' } : {})), { gap: "8px" }) },
28
+ label && orientation === 'horizontal' && (react_1.default.createElement(Typo2_1.UI_CAPTION_BOLD_DF, null, label)),
29
+ data.map(function (d, index) {
30
+ return (react_1.default.createElement("div", { key: index, style: { display: "flex", alignItems: "center", gap: "6px" } },
31
+ react_1.default.createElement(LegendTooltipGlyph_1.LegendTooltipGlyph, { color: d.color }),
32
+ react_1.default.createElement(Typo2_1.UI_CAPTION_DF, null, d.text)));
33
+ }))));
34
+ };
35
+ exports.Legend = Legend;
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ interface LegendTooltipGlyphProps {
3
+ color: string;
4
+ size?: number;
5
+ }
6
+ export declare const LegendTooltipGlyph: React.FC<LegendTooltipGlyphProps>;
7
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LegendTooltipGlyph = void 0;
7
+ var react_1 = __importDefault(require("react"));
8
+ var LegendTooltipGlyph = function (_a) {
9
+ var color = _a.color, _b = _a.size, size = _b === void 0 ? 10 : _b;
10
+ return (react_1.default.createElement("div", { style: {
11
+ width: size + 'px',
12
+ height: size + 'px',
13
+ borderRadius: "50%",
14
+ backgroundColor: color,
15
+ flexShrink: 0
16
+ } }));
17
+ };
18
+ exports.LegendTooltipGlyph = LegendTooltipGlyph;
@@ -18,6 +18,7 @@ export interface BarChartProps {
18
18
  [key: string]: string;
19
19
  };
20
20
  tooltipLabelsPath: string | string[];
21
+ breakdownCategoryName?: string;
21
22
  labelPath: string;
22
23
  onClick?: (name: string) => void;
23
24
  valueSuffix?: string;
@@ -26,6 +27,7 @@ export interface BarChartProps {
26
27
  breakdownDisplayType?: BreakdownDisplayType;
27
28
  colorIdx?: number;
28
29
  summarizeAfterIdx?: number;
30
+ style?: React.CSSProperties;
29
31
  }
30
32
  export declare const BarChart: React.FC<BarChartProps>;
31
33
  export {};
@@ -51,10 +51,11 @@ exports.BarChart = exports.useTrackMousePosition = void 0;
51
51
  var react_1 = __importStar(require("react"));
52
52
  var recharts_1 = require("recharts");
53
53
  var CustomizedLabel_1 = require("./comps/CustomizedLabel");
54
- var colors_1 = require("../../../themes/colors");
55
54
  var CustomTooltip_1 = __importDefault(require("./comps/CustomTooltip"));
56
55
  var usePrepareData_1 = require("../utils/usePrepareData");
57
56
  var _base_barchart_ui_configs_1 = require("./_base_barchart_ui_configs");
57
+ var Legend_1 = require("./comps/Legend");
58
+ var __1 = require("../../../..");
58
59
  var useTrackMousePosition = function () {
59
60
  var _a = (0, react_1.useState)({
60
61
  x: 0,
@@ -73,23 +74,39 @@ var useTrackMousePosition = function () {
73
74
  return ({ mousePosition: mousePosition });
74
75
  };
75
76
  exports.useTrackMousePosition = useTrackMousePosition;
76
- // CHART_OFFSET_TOP is the y shift on top of the entire chart, because otherwise the chart starts with bar 1 at 0,0 coordinates
77
+ // CHART_OFFSET_TOP & CHART_OFFSET_TOP_BREAKDOWN is the y shift on top of the entire chart, because otherwise the chart starts with bar 1 at 0,0 coordinates
77
78
  var CHART_OFFSET_TOP = _base_barchart_ui_configs_1._base_barchart_ui_configs.labelToBarGap +
78
79
  _base_barchart_ui_configs_1._base_barchart_ui_configs.labelHeight +
79
80
  (_base_barchart_ui_configs_1._base_barchart_ui_configs.labelToNextBarGap / 2 - 2); //this minus 2 is just to correct the extra white space that the labelHeight takes on top of the text
81
+ var CHART_OFFSET_TOP_BREAKDOWN = _base_barchart_ui_configs_1._base_barchart_ui_configs.labelToBarGap +
82
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.labelHeight +
83
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenTwoLabels +
84
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.labelHeight + //twice because the text and the percent are on separate lines
85
+ (_base_barchart_ui_configs_1._base_barchart_ui_configs.labelToNextBarGap / 2 - 2); //this minus 2 is just to correct the extra white space that the labelHeight takes on top of the text
80
86
  var TOT_HEIGHT_SINGLE_BAR_SECTION = _base_barchart_ui_configs_1._base_barchart_ui_configs.barHeight +
81
87
  _base_barchart_ui_configs_1._base_barchart_ui_configs.labelToBarGap +
82
88
  _base_barchart_ui_configs_1._base_barchart_ui_configs.labelHeight +
83
89
  _base_barchart_ui_configs_1._base_barchart_ui_configs.labelToNextBarGap;
90
+ var TOT_HEIGHT_STACKED_BAR_SECTION = _base_barchart_ui_configs_1._base_barchart_ui_configs.barHeight +
91
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.labelToBarGap +
92
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.labelHeight +
93
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenTwoLabels +
94
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.labelHeight +
95
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.labelToNextBarGap;
84
96
  var CALC_SINGLE_BAR_SECTION_Y_POS = function (index) {
85
97
  return (TOT_HEIGHT_SINGLE_BAR_SECTION + _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarSections) * index;
86
98
  };
99
+ var CALC_STACKED_BAR_SECTION_Y_POS = function (index) {
100
+ return (TOT_HEIGHT_STACKED_BAR_SECTION + _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarSections) * index;
101
+ };
87
102
  var CALC_TOTAL_HEIGHT_GROUPED_BAR_SECTION = function (noOfBarsInGroup) {
88
103
  var totalHeightOfAllBars = noOfBarsInGroup * _base_barchart_ui_configs_1._base_barchart_ui_configs.barHeight +
89
104
  (noOfBarsInGroup - 1) * _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarsInGroup;
90
105
  return (totalHeightOfAllBars +
91
106
  _base_barchart_ui_configs_1._base_barchart_ui_configs.labelToBarGap +
92
107
  _base_barchart_ui_configs_1._base_barchart_ui_configs.labelHeight +
108
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenTwoLabels +
109
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.labelHeight + //twice because the text and the percent are on separate lines
93
110
  _base_barchart_ui_configs_1._base_barchart_ui_configs.labelToNextBarGap);
94
111
  };
95
112
  var CALC_GROUPED_BAR_SECTION_Y_POS = function (index, barIndex, noOfBarsInGroup) {
@@ -100,15 +117,19 @@ var CALC_GROUPED_BAR_SECTION_Y_POS = function (index, barIndex, noOfBarsInGroup)
100
117
  barIndex * (_base_barchart_ui_configs_1._base_barchart_ui_configs.barHeight + _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarsInGroup));
101
118
  };
102
119
  var CALC_TOTAL_HEIGHT_OF_CHART = function (_a) {
103
- var isBreakdown = _a.isBreakdown, breakdownDisplayType = _a.breakdownDisplayType, data = _a.data;
120
+ var isBreakdown = _a.isBreakdown, breakdownDisplayType = _a.breakdownDisplayType, data = _a.data, showSumOfBreakdownValues = _a.showSumOfBreakdownValues;
104
121
  return isBreakdown && breakdownDisplayType === "grouped"
105
122
  ? CALC_TOTAL_HEIGHT_GROUPED_BAR_SECTION(data[0].length) *
106
123
  data.length +
107
124
  _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarSections * (data.length - 1) +
108
125
  _base_barchart_ui_configs_1._base_barchart_ui_configs.hoverRectStrokeWidth * 2
109
- : TOT_HEIGHT_SINGLE_BAR_SECTION * data.length +
110
- _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarSections * (data.length - 1) +
111
- _base_barchart_ui_configs_1._base_barchart_ui_configs.hoverRectStrokeWidth * 2;
126
+ : isBreakdown && breakdownDisplayType === 'stacked' && !showSumOfBreakdownValues
127
+ ? (TOT_HEIGHT_STACKED_BAR_SECTION * data.length) +
128
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarSections * (data.length - 1) +
129
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.hoverRectStrokeWidth * 2
130
+ : TOT_HEIGHT_SINGLE_BAR_SECTION * data.length +
131
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarSections * (data.length - 1) +
132
+ _base_barchart_ui_configs_1._base_barchart_ui_configs.hoverRectStrokeWidth * 2;
112
133
  };
113
134
  var _debug_controls = {
114
135
  mouseEventDetectorOpacity: 0, //only increase this for debugging. nothing else.
@@ -139,110 +160,155 @@ var barConfigs = {
139
160
  },
140
161
  };
141
162
  var renderBar = function (_a) {
142
- var _b = _a.stackIndex, stackIndex = _b === void 0 ? 0 : _b, dataToRender = _a.data, isBreakdownToRender = _a.isBreakdown, breakdownDisplayTypeToRender = _a.breakdownDisplayType, showSumOfBreakdownValues = _a.showSumOfBreakdownValues,
143
- //
144
- colorIdx = _a.colorIdx, showPercent = _a.showPercent, showCount = _a.showCount, activeBar = _a.activeBar, setActiveBar = _a.setActiveBar, onClick = _a.onClick;
145
- var activeConfig = isBreakdownToRender
163
+ var _b = _a.stackIndex, stackIndex = _b === void 0 ? 0 : _b, data = _a.data, isBreakdown = _a.isBreakdown, breakdownDisplayType = _a.breakdownDisplayType, showSumOfBreakdownValues = _a.showSumOfBreakdownValues, showPercent = _a.showPercent, showCount = _a.showCount, activeBar = _a.activeBar, setActiveBar = _a.setActiveBar, onClick = _a.onClick;
164
+ var activeConfig = isBreakdown
146
165
  ? barConfigs.isBreakdown
147
166
  : barConfigs.isNotBreakdown;
148
- var totalStacks = isBreakdownToRender
149
- ? dataToRender[0].length
167
+ var totalStacks = isBreakdown
168
+ ? data[0].length
150
169
  : 1;
151
- var currentStackId = activeConfig.getStackId(stackIndex, breakdownDisplayTypeToRender);
152
- return (react_1.default.createElement(recharts_1.Bar, { key: "stack-".concat(stackIndex), radius: activeConfig.getBarRadius(stackIndex, breakdownDisplayTypeToRender, totalStacks), dataKey: activeConfig.getDataKey(stackIndex), stackId: currentStackId },
153
- (!isBreakdownToRender || stackIndex === 0) && (react_1.default.createElement(recharts_1.LabelList, { dataKey: isBreakdownToRender ? function (dataPoint) { return dataPoint; } : "labels", offset: 0, position: "bottom", content: function (props) { return (react_1.default.createElement(CustomizedLabel_1.CustomizedLabel, __assign({ CALC_SINGLE_BAR_SECTION_Y_POS: CALC_SINGLE_BAR_SECTION_Y_POS, TOT_HEIGHT_SINGLE_BAR_SECTION: TOT_HEIGHT_SINGLE_BAR_SECTION, TOT_HEIGHT_GROUPED_BAR_SECTION: isBreakdownToRender &&
154
- breakdownDisplayTypeToRender === "grouped"
155
- ? CALC_TOTAL_HEIGHT_GROUPED_BAR_SECTION(dataToRender[0].length)
156
- : undefined,
157
- breakdownDisplayType: breakdownDisplayTypeToRender,
158
- y: props.y,
170
+ var currentStackId = activeConfig.getStackId(stackIndex, breakdownDisplayType);
171
+ return (react_1.default.createElement(recharts_1.Bar, { key: "stack-".concat(stackIndex), radius: activeConfig.getBarRadius(stackIndex, breakdownDisplayType, totalStacks), dataKey: activeConfig.getDataKey(stackIndex), stackId: currentStackId },
172
+ (!isBreakdown || stackIndex === 0) && (react_1.default.createElement(recharts_1.LabelList, { dataKey: isBreakdown ? function (dataPoint) { return dataPoint; } : "labels", offset: 0, position: "bottom", content: function (props) { return (react_1.default.createElement(CustomizedLabel_1.CustomizedLabel, __assign({ CALC_SINGLE_BAR_SECTION_Y_POS: CALC_SINGLE_BAR_SECTION_Y_POS, CALC_STACKED_BAR_SECTION_Y_POS: CALC_STACKED_BAR_SECTION_Y_POS, TOT_HEIGHT_SINGLE_BAR_SECTION: TOT_HEIGHT_SINGLE_BAR_SECTION, TOT_HEIGHT_STACKED_BAR_SECTION: TOT_HEIGHT_STACKED_BAR_SECTION, TOT_HEIGHT_GROUPED_BAR_SECTION: isBreakdown &&
173
+ breakdownDisplayType === "grouped"
174
+ ? CALC_TOTAL_HEIGHT_GROUPED_BAR_SECTION(data[0].length)
175
+ : undefined, breakdownDisplayType: breakdownDisplayType, y: props.y,
159
176
  width: props.width,
160
177
  height: props.height,
161
- value: isBreakdownToRender
162
- ? dataToRender[props.index].map(function (item, idx) { return (__assign(__assign({}, item.labels), { color: colors_1.dataVizColorsText[(colorIdx + idx) % colors_1.dataVizColorsText.length] })); })
178
+ value: isBreakdown
179
+ ? data[props.index].map(function (item, idx) { return (__assign({}, item.labels)); })
163
180
  : props.value, showPercent: showPercent, showCount: showCount, showSumOfBreakdownValues: showSumOfBreakdownValues, opacity: 1, activeBar: activeBar, _base_barchart_ui_configs: _base_barchart_ui_configs_1._base_barchart_ui_configs, _debug_controls: _debug_controls }, (onClick
164
181
  ? {
165
182
  onMouseOver: function (e, value) {
166
- setActiveBar(isBreakdownToRender
167
- ? dataToRender[props.index][0].labels.name
183
+ setActiveBar(isBreakdown
184
+ ? data[props.index][0].labels.name
168
185
  : value.name);
169
186
  },
170
- onMouseOut: function () { return setActiveBar(undefined); },
187
+ onMouseOut: function () {
188
+ setActiveBar(undefined);
189
+ },
171
190
  onMouseDown: function (e, value) {
172
- var name = isBreakdownToRender
173
- ? dataToRender[props.index][0].labels.name
191
+ var name = isBreakdown
192
+ ? data[props.index][0].labels.name
174
193
  : value.name;
175
194
  setActiveBar(name);
176
195
  onClick(name);
177
196
  },
178
197
  }
179
198
  : {})))); } })),
180
- dataToRender.map(function (d, index) { return (react_1.default.createElement(recharts_1.Cell, { y: !isBreakdownToRender || breakdownDisplayTypeToRender === "stacked"
181
- ? CALC_SINGLE_BAR_SECTION_Y_POS(index) + CHART_OFFSET_TOP
182
- : CALC_GROUPED_BAR_SECTION_Y_POS(index, stackIndex, dataToRender[0].length) + CHART_OFFSET_TOP, key: "cell-".concat(index, "-").concat(stackIndex), opacity: 1, height: _base_barchart_ui_configs_1._base_barchart_ui_configs.barHeight, fill: activeConfig.getCellFill(colorIdx, stackIndex, colors_1.dataVizColors) })); })));
199
+ data.map(function (d, index) {
200
+ /**
201
+ * note this this map works differently for breakdown & not breakdown
202
+ * for not breakdown - this map renders each of the inidividual bars.
203
+ * for breakdown - this map renders each of the individual bar groups
204
+ */
205
+ return (react_1.default.createElement(recharts_1.Cell, { y: (!isBreakdown || showSumOfBreakdownValues) // this is confusing, but showSumOfBreakdownValues is only used to render the 'compressed' other bar in normal bar charts. hence it has to have properties like a normal, non breakdown bar chart
206
+ ? CALC_SINGLE_BAR_SECTION_Y_POS(index) + CHART_OFFSET_TOP
207
+ : (breakdownDisplayType === "stacked" && !showSumOfBreakdownValues) //show summ happens in the summarized bar, were we dont want the double label approach
208
+ ? CALC_STACKED_BAR_SECTION_Y_POS(index) + CHART_OFFSET_TOP_BREAKDOWN
209
+ : breakdownDisplayType === "grouped" &&
210
+ CALC_GROUPED_BAR_SECTION_Y_POS(index, stackIndex, data[0].length) + CHART_OFFSET_TOP_BREAKDOWN, key: "cell-".concat(index, "-").concat(stackIndex), opacity: 1, height: _base_barchart_ui_configs_1._base_barchart_ui_configs.barHeight, fill: !isBreakdown
211
+ ? d.labels.barColor
212
+ : d[stackIndex].labels.barColor }));
213
+ })));
214
+ };
215
+ var useDecideLegendOrientation = function (options) {
216
+ if (options === void 0) { options = {}; }
217
+ var _a = options.widthThreshold, widthThreshold = _a === void 0 ? 600 : _a;
218
+ var vizWrapperRef = (0, react_1.useRef)(null);
219
+ var _b = (0, react_1.useState)('horizontal'), orientation = _b[0], setOrientation = _b[1];
220
+ (0, react_1.useEffect)(function () {
221
+ var element = vizWrapperRef.current;
222
+ if (!element)
223
+ return;
224
+ var resizeObserver = new ResizeObserver(function (entries) {
225
+ for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
226
+ var entry = entries_1[_i];
227
+ var width = entry.contentRect.width;
228
+ // If width is >= threshold, use horizontal, otherwise vertical
229
+ var newOrientation = width >= widthThreshold ? 'vertical' : 'horizontal';
230
+ setOrientation(newOrientation);
231
+ }
232
+ });
233
+ resizeObserver.observe(element);
234
+ // Set initial orientation
235
+ var initialWidth = element.getBoundingClientRect().width;
236
+ setOrientation(initialWidth >= widthThreshold ? 'vertical' : 'horizontal');
237
+ // Cleanup
238
+ return function () {
239
+ resizeObserver.disconnect();
240
+ };
241
+ }, [widthThreshold]);
242
+ return {
243
+ vizWrapperRef: vizWrapperRef,
244
+ orientation: orientation
245
+ };
183
246
  };
184
247
  var BarChartRenderer = function (_a) {
185
- var data = _a.data, isBreakdown = _a.isBreakdown, breakdownDisplayType = _a.breakdownDisplayType, showSumOfBreakdownValues = _a.showSumOfBreakdownValues, colorIdx = _a.colorIdx, showPercent = _a.showPercent, showCount = _a.showCount, activeBar = _a.activeBar, setActiveBar = _a.setActiveBar, onClick = _a.onClick,
248
+ var data = _a.data, isBreakdown = _a.isBreakdown, breakdownDisplayType = _a.breakdownDisplayType, showSumOfBreakdownValues = _a.showSumOfBreakdownValues, showPercent = _a.showPercent, showCount = _a.showCount, activeBar = _a.activeBar, setActiveBar = _a.setActiveBar, onClick = _a.onClick,
186
249
  //
187
- mousePosition = _a.mousePosition, dataMaxValue = _a.dataMaxValue, containerWidth = _a.containerWidth;
188
- return (
189
- // <ResponsiveContainer width="100%" height="100%">
190
- react_1.default.createElement(recharts_1.BarChart, { width: containerWidth, height: CALC_TOTAL_HEIGHT_OF_CHART({
250
+ mousePosition = _a.mousePosition, dataMaxValue = _a.dataMaxValue, breakdownCategoryName = _a.breakdownCategoryName;
251
+ return (react_1.default.createElement(recharts_1.ResponsiveContainer, { width: "100%", height: CALC_TOTAL_HEIGHT_OF_CHART({
191
252
  isBreakdown: isBreakdown,
192
253
  breakdownDisplayType: breakdownDisplayType,
254
+ showSumOfBreakdownValues: showSumOfBreakdownValues,
193
255
  data: data
194
- }), data: data, layout: "vertical", margin: {
195
- top: 0,
196
- right: _base_barchart_ui_configs_1._base_barchart_ui_configs.marginRight,
197
- left: _base_barchart_ui_configs_1._base_barchart_ui_configs.marginLeft,
198
- bottom: 0,
199
- } },
200
- react_1.default.createElement(recharts_1.XAxis, { hide: true, type: "number", domain: [0, dataMaxValue] }),
201
- react_1.default.createElement(recharts_1.YAxis, { hide: true, type: "category" }),
202
- isBreakdown && (react_1.default.createElement(recharts_1.Tooltip, { content: function (props) {
203
- var _a;
204
- return (react_1.default.createElement(CustomTooltip_1.default, __assign({}, props, { mousePosition: mousePosition, showPercent: showPercent,
205
- // god knows why the dataindex gets stored against props.label.
206
- // this is some internal recharts thing for tooltips specifically.
207
- // we dont do this.
208
- value: (_a = data[props.label]) === null || _a === void 0 ? void 0 : _a.map(function (item, idx) { return (__assign(__assign({}, item.labels), { color: colors_1.dataVizColors[(colorIdx + idx) % colors_1.dataVizColors.length] })); }) })));
209
- }, cursor: false, allowEscapeViewBox: { x: true, y: true } })),
210
- isBreakdown
211
- ? data[0].map(function (_, stackIndex) {
212
- return renderBar({
213
- stackIndex: stackIndex,
256
+ }) },
257
+ react_1.default.createElement(recharts_1.BarChart, { data: data, layout: "vertical", margin: {
258
+ top: 0,
259
+ right: _base_barchart_ui_configs_1._base_barchart_ui_configs.marginRight,
260
+ left: _base_barchart_ui_configs_1._base_barchart_ui_configs.marginLeft,
261
+ bottom: 0,
262
+ } },
263
+ react_1.default.createElement(recharts_1.XAxis, { hide: true, type: "number", domain: [0, dataMaxValue] }),
264
+ react_1.default.createElement(recharts_1.YAxis, { hide: true, type: "category" }),
265
+ isBreakdown && (react_1.default.createElement(recharts_1.Tooltip, { content: function (props) {
266
+ var _a;
267
+ return (react_1.default.createElement(CustomTooltip_1.default, __assign({}, props, { breakdownCategoryName: breakdownCategoryName, activeBar: activeBar, mousePosition: mousePosition, showPercent: showPercent,
268
+ // god knows why the dataindex gets stored against props.label.
269
+ // this is some internal recharts thing for tooltips specifically.
270
+ // we dont do this.
271
+ value: (_a = data[props.label]) === null || _a === void 0 ? void 0 : _a.map(function (item, idx) { return (__assign({}, item.labels)); }) })));
272
+ }, cursor: false, allowEscapeViewBox: { x: true, y: true } })),
273
+ isBreakdown
274
+ ? data[0].map(function (_, stackIndex) {
275
+ //note that this map renders the individual bars within a breakdown group
276
+ return renderBar({
277
+ stackIndex: stackIndex,
278
+ data: data,
279
+ isBreakdown: isBreakdown,
280
+ breakdownDisplayType: breakdownDisplayType,
281
+ showSumOfBreakdownValues: showSumOfBreakdownValues,
282
+ showPercent: showPercent,
283
+ showCount: showCount,
284
+ activeBar: activeBar,
285
+ setActiveBar: setActiveBar,
286
+ onClick: onClick,
287
+ });
288
+ })
289
+ : renderBar({
290
+ stackIndex: undefined,
214
291
  data: data,
215
292
  isBreakdown: isBreakdown,
216
293
  breakdownDisplayType: breakdownDisplayType,
217
294
  showSumOfBreakdownValues: showSumOfBreakdownValues,
218
- colorIdx: colorIdx,
219
295
  showPercent: showPercent,
220
296
  showCount: showCount,
221
297
  activeBar: activeBar,
222
298
  setActiveBar: setActiveBar,
223
299
  onClick: onClick,
224
- });
225
- })
226
- : renderBar({
227
- stackIndex: undefined,
228
- data: data,
229
- isBreakdown: isBreakdown,
230
- breakdownDisplayType: breakdownDisplayType,
231
- showSumOfBreakdownValues: showSumOfBreakdownValues,
232
- colorIdx: colorIdx,
233
- showPercent: showPercent,
234
- showCount: showCount,
235
- activeBar: activeBar,
236
- setActiveBar: setActiveBar,
237
- onClick: onClick,
238
- }))
239
- // </ResponsiveContainer>
240
- );
300
+ }))));
301
+ };
302
+ var FadeGradientWhenScroll = function (_a) {
303
+ var _b = _a.style, style = _b === void 0 ? {} : _b;
304
+ return (react_1.default.createElement("div", { style: __assign({ width: '100%', height: '40px', position: 'sticky', left: 0, bottom: 0, background: "linear-gradient(to top, ".concat(__1.colors2.white, ", hsla(0, 0%, 100%, 0))") }, style) }));
241
305
  };
242
306
  var BarChart = function (_a) {
243
- var _data = _a.data, valuePath = _a.valuePath, tooltipLabelsMapping = _a.tooltipLabelsMapping, tooltipLabelsPath = _a.tooltipLabelsPath, _b = _a.labelPath, labelPath = _b === void 0 ? "name" : _b, onClick = _a.onClick, _c = _a.breakdownDisplayType, breakdownDisplayType = _c === void 0 ? "grouped" : _c, _d = _a.showCount, showCount = _d === void 0 ? true : _d, _e = _a.showPercent, showPercent = _e === void 0 ? true : _e, _f = _a.colorIdx, colorIdx = _f === void 0 ? 0 : _f, _g = _a.summarizeAfterIdx, summarizeAfterIdx = _g === void 0 ? 5 : _g;
307
+ var _data = _a.data, valuePath = _a.valuePath, _b = _a.style, style = _b === void 0 ? {} : _b, tooltipLabelsMapping = _a.tooltipLabelsMapping, tooltipLabelsPath = _a.tooltipLabelsPath, breakdownCategoryName = _a.breakdownCategoryName, // basically, if lets say tagCat1 is broken down by tagCat2. then tagCat2's display would be this property
308
+ _c = _a.labelPath, // basically, if lets say tagCat1 is broken down by tagCat2. then tagCat2's display would be this property
309
+ labelPath = _c === void 0 ? "name" : _c, onClick = _a.onClick, _d = _a.breakdownDisplayType, breakdownDisplayType = _d === void 0 ? "grouped" : _d, _e = _a.showCount, showCount = _e === void 0 ? true : _e, _f = _a.showPercent, showPercent = _f === void 0 ? true : _f, _g = _a.colorIdx, colorIdx = _g === void 0 ? 0 : _g, _h = _a.summarizeAfterIdx, summarizeAfterIdx = _h === void 0 ? undefined : _h;
244
310
  var isBreakdown = Array.isArray(valuePath);
245
- var _h = (0, usePrepareData_1.usePrepareData)({
311
+ var _j = (0, usePrepareData_1.usePrepareData)({
246
312
  _data: _data,
247
313
  labelPath: labelPath,
248
314
  valuePath: valuePath,
@@ -251,44 +317,29 @@ var BarChart = function (_a) {
251
317
  isBreakdown: isBreakdown,
252
318
  showPercent: showPercent,
253
319
  summarizeAfterIdx: summarizeAfterIdx,
254
- }), data = _h.data, dataMaxValue = _h.dataMaxValue, dataToSummarize = _h.dataToSummarize;
255
- var _j = (0, react_1.useState)(undefined), activeBar = _j[0], setActiveBar = _j[1];
320
+ colorIdx: colorIdx
321
+ }), data = _j.data, dataMaxValue = _j.dataMaxValue, dataToSummarize = _j.dataToSummarize;
322
+ var _k = useDecideLegendOrientation({
323
+ widthThreshold: 500
324
+ }), vizWrapperRef = _k.vizWrapperRef, orientation = _k.orientation;
325
+ var _l = (0, react_1.useState)(undefined), activeBar = _l[0], setActiveBar = _l[1];
256
326
  var mousePosition = (0, exports.useTrackMousePosition)().mousePosition;
257
327
  // menu options for grouped and stacked
258
328
  if (data.length === 0)
259
329
  return react_1.default.createElement("div", null, "No data available");
260
- // At the top of your component
261
- var _k = (0, react_1.useState)(undefined), containerWidth = _k[0], setContainerWidth = _k[1];
262
- // Use a ref and useEffect to measure parent width
263
- var containerRef = (0, react_1.useRef)(null);
264
- (0, react_1.useEffect)(function () {
265
- var updateWidth = function () {
266
- if (containerRef.current) {
267
- setContainerWidth(containerRef.current.getBoundingClientRect().width);
268
- }
269
- };
270
- updateWidth();
271
- window.addEventListener('resize', updateWidth);
272
- return function () { return window.removeEventListener('resize', updateWidth); };
273
- }, []);
274
- return (react_1.default.createElement("div", { style: {
275
- height: "".concat(CALC_TOTAL_HEIGHT_OF_CHART({
276
- isBreakdown: isBreakdown,
277
- breakdownDisplayType: breakdownDisplayType,
278
- data: data
279
- }) + (isBreakdown ? 0 : CALC_TOTAL_HEIGHT_OF_CHART({
280
- isBreakdown: true,
281
- breakdownDisplayType: 'stacked',
282
- data: dataToSummarize
283
- })), "px"),
284
- width: "100%",
285
- background: _debug_controls.chartWrapperBgColor,
286
- } },
287
- react_1.default.createElement("div", { ref: containerRef, style: { width: '100%', height: '100%' } },
288
- react_1.default.createElement(BarChartRenderer, { containerWidth: containerWidth, data: data, isBreakdown: isBreakdown, breakdownDisplayType: breakdownDisplayType, showSumOfBreakdownValues: false, colorIdx: colorIdx, showPercent: showPercent, showCount: showCount, activeBar: activeBar, setActiveBar: setActiveBar, onClick: onClick, mousePosition: mousePosition, dataMaxValue: dataMaxValue }),
289
- dataToSummarize && (react_1.default.createElement(BarChartRenderer, { containerWidth: containerWidth, data: dataToSummarize,
330
+ return (react_1.default.createElement("div", { ref: vizWrapperRef, style: __assign(__assign({}, style), { width: "100%", background: _debug_controls.chartWrapperBgColor, display: 'flex', gap: '8px', flexDirection: orientation === 'vertical' ? 'row' : 'column', position: 'relative', overflow: 'scroll' }) },
331
+ react_1.default.createElement("div", { style: { flexGrow: 1, position: 'relative' } },
332
+ react_1.default.createElement(BarChartRenderer, { data: data, dataToSummarize: dataToSummarize, isBreakdown: isBreakdown, breakdownDisplayType: breakdownDisplayType, showSumOfBreakdownValues: false, showPercent: showPercent, showCount: showCount, activeBar: activeBar, setActiveBar: setActiveBar, onClick: onClick, mousePosition: mousePosition, dataMaxValue: dataMaxValue, breakdownCategoryName: breakdownCategoryName }),
333
+ dataToSummarize && (react_1.default.createElement(BarChartRenderer, { data: dataToSummarize,
290
334
  isBreakdown: true,
291
335
  breakdownDisplayType: "stacked",
292
- showSumOfBreakdownValues: true, colorIdx: colorIdx, showPercent: showPercent, showCount: showCount, activeBar: activeBar, setActiveBar: setActiveBar, onClick: onClick, mousePosition: mousePosition, dataMaxValue: dataMaxValue })))));
336
+ showSumOfBreakdownValues: true, showPercent: showPercent, showCount: showCount, activeBar: activeBar, setActiveBar: setActiveBar, onClick: onClick, mousePosition: mousePosition, dataMaxValue: dataMaxValue, breakdownCategoryName: breakdownCategoryName })),
337
+ orientation === 'vertical' && react_1.default.createElement(FadeGradientWhenScroll, null)),
338
+ isBreakdown && react_1.default.createElement("div", { style: __assign({ position: 'sticky' }, (orientation === 'vertical' ? { top: 0 } : { bottom: 0, background: __1.colors2.white })) },
339
+ orientation === 'horizontal' && react_1.default.createElement(FadeGradientWhenScroll, { style: { transform: 'translateY(-100%)', top: 0, bottom: 'unset', position: 'absolute', } }),
340
+ react_1.default.createElement(Legend_1.Legend, { orientation: orientation, label: breakdownCategoryName, data: data[0].map(function (d) { return ({
341
+ text: d.labels.tooltipLabel,
342
+ color: d.labels.barColor
343
+ }); }) }))));
293
344
  };
294
345
  exports.BarChart = BarChart;
@@ -3,7 +3,8 @@ export interface CountVizLabels {
3
3
  count: number;
4
4
  name: string;
5
5
  dataIndex: number;
6
- color: string;
6
+ barColor: string;
7
+ textColor: string;
7
8
  tooltipLabel?: string;
8
9
  }
9
10
  export interface CountVizDatum {
@@ -10,11 +10,12 @@ interface PrepareDataParams {
10
10
  };
11
11
  tooltipLabelsPath: string | string[];
12
12
  summarizeAfterIdx?: number;
13
+ colorIdx?: number;
13
14
  }
14
15
  interface PreparedData {
15
16
  data: CountVizData;
16
17
  dataToSummarize: CountVizData;
17
18
  dataMaxValue: number;
18
19
  }
19
- export declare const usePrepareData: ({ _data, labelPath, valuePath, tooltipLabelsMapping, tooltipLabelsPath, isBreakdown, showPercent, summarizeAfterIdx, }: PrepareDataParams) => PreparedData;
20
+ export declare const usePrepareData: ({ _data, labelPath, valuePath, tooltipLabelsMapping, tooltipLabelsPath, isBreakdown, showPercent, summarizeAfterIdx, colorIdx }: PrepareDataParams) => PreparedData;
20
21
  export {};
@@ -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.195.0",
3
+ "version": "2.195.2",
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
  }