oolib 2.188.8 → 2.190.0
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/dist/components/Dropdowns/DropdownMulti/index.js +2 -0
- package/dist/components/Dropdowns/DropdownSingle/index.js +6 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/stories/v2/components/Accordion.stories.js +1 -1
- package/dist/stories/v2/components/BarChart.stories.js +146 -43
- package/dist/stories/v2/components/BarGraphCollection.stories.d.ts +18 -0
- package/dist/stories/v2/components/BarGraphCollection.stories.js +122 -0
- package/dist/stories/v2/components/HeatMapGrid.stories.d.ts +17 -0
- package/dist/stories/v2/components/HeatMapGrid.stories.js +107 -0
- package/dist/v2/components/DataVizAccordion/index.d.ts +1 -1
- package/dist/v2/components/DataVizAccordion/index.js +1 -1
- package/dist/v2/components/Dropdowns/DropdownMulti/index.js +2 -0
- package/dist/v2/components/Dropdowns/DropdownSingle/index.js +6 -1
- package/dist/v2/components/dataviz/BarChart/_base_barchart_ui_configs.d.ts +18 -0
- package/dist/v2/components/dataviz/BarChart/_base_barchart_ui_configs.js +24 -0
- package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/CustomTooltip/index.d.ts +4 -4
- package/dist/v2/components/dataviz/BarChart/comps/CustomTooltip/index.js +161 -0
- package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/CustomizedLabel/index.d.ts +7 -12
- package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/CustomizedLabel/index.js +22 -12
- package/dist/v2/components/{BarChart → dataviz/BarChart}/index.d.ts +12 -14
- package/dist/v2/components/dataviz/BarChart/index.js +276 -0
- package/dist/v2/components/dataviz/BarGraphCollection/index.d.ts +21 -0
- package/dist/v2/components/dataviz/BarGraphCollection/index.js +159 -0
- package/dist/v2/components/dataviz/BarGraphCollection/styled.d.ts +7 -0
- package/dist/v2/components/dataviz/BarGraphCollection/styled.js +22 -0
- package/dist/v2/components/dataviz/BarGraphCollection/utils/useGetDimensions.d.ts +1 -0
- package/dist/v2/components/dataviz/BarGraphCollection/utils/useGetDimensions.js +41 -0
- package/dist/v2/components/dataviz/BarGraphCollection/utils/usePrepareData.d.ts +11 -0
- package/dist/v2/components/dataviz/BarGraphCollection/utils/usePrepareData.js +76 -0
- package/dist/v2/components/dataviz/HeatMapGrid/index.d.ts +21 -0
- package/dist/v2/components/dataviz/HeatMapGrid/index.js +230 -0
- package/dist/v2/components/dataviz/types.d.ts +12 -0
- package/dist/v2/components/dataviz/types.js +2 -0
- package/dist/v2/components/dataviz/utils/usePrepareData.d.ts +20 -0
- package/dist/v2/components/dataviz/utils/usePrepareData.js +116 -0
- package/package.json +1 -1
- package/dist/v2/components/BarChart/comps/CustomTooltip/index.js +0 -50
- package/dist/v2/components/BarChart/index.js +0 -294
- /package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/TruncatedSVGText/index.d.ts +0 -0
- /package/dist/v2/components/{BarChart → dataviz/BarChart}/comps/TruncatedSVGText/index.js +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
3
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
4
|
+
return cooked;
|
|
5
|
+
};
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
40
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
41
|
+
if (ar || !(i in from)) {
|
|
42
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
43
|
+
ar[i] = from[i];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
47
|
+
};
|
|
48
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
49
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
50
|
+
};
|
|
51
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
+
var react_1 = __importStar(require("react"));
|
|
53
|
+
var styled_components_1 = __importDefault(require("styled-components"));
|
|
54
|
+
var __1 = require("../../../../../..");
|
|
55
|
+
var Typo2_1 = require("../../../../Typo2");
|
|
56
|
+
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
|
+
var clampT = _a.clampT;
|
|
58
|
+
return clampT ? (0, __1.clampText)(3) : '';
|
|
59
|
+
});
|
|
60
|
+
var CustomTooltip = function (props) {
|
|
61
|
+
var active = props.active, value = props.value, showPercent = props.showPercent, mousePosition = props.mousePosition;
|
|
62
|
+
var tooltipWrapperRef = (0, react_1.useRef)(null);
|
|
63
|
+
var calcTooltipTop = function (_a) {
|
|
64
|
+
var _b, _c;
|
|
65
|
+
var tooltipWrapperRef = _a.tooltipWrapperRef, mousePosY = _a.mousePosY;
|
|
66
|
+
var windowHeight = window.innerHeight;
|
|
67
|
+
var tooltipWrapperBottom = (_c = (_b = tooltipWrapperRef === null || tooltipWrapperRef === void 0 ? void 0 : tooltipWrapperRef.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect()) === null || _c === void 0 ? void 0 : _c.bottom;
|
|
68
|
+
if (tooltipWrapperBottom && tooltipWrapperBottom > windowHeight) {
|
|
69
|
+
var topNegativeOffset = tooltipWrapperBottom - windowHeight;
|
|
70
|
+
return mousePosY - topNegativeOffset - 5; // plus 5 so that the bottom of the tooltip doesnt touch the bottom of the screen
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return mousePosY;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
// Calculate position - align with the right side of the bars
|
|
77
|
+
var style = {
|
|
78
|
+
position: "fixed",
|
|
79
|
+
left: "".concat((mousePosition === null || mousePosition === void 0 ? void 0 : mousePosition.x) || 0, "px"),
|
|
80
|
+
top: "".concat(calcTooltipTop({ tooltipWrapperRef: tooltipWrapperRef, mousePosY: (mousePosition === null || mousePosition === void 0 ? void 0 : mousePosition.y) || 0 }), "px"),
|
|
81
|
+
transform: "translate(10px, 10px)", // Offset from cursor and center vertically
|
|
82
|
+
backgroundColor: __1.colors2.black,
|
|
83
|
+
color: __1.colors2.white,
|
|
84
|
+
border: "1px solid ".concat(__1.colors2.grey10),
|
|
85
|
+
borderRadius: "6px",
|
|
86
|
+
padding: "8px",
|
|
87
|
+
boxShadow: "0px 4px 10px 0px rgba(0, 0, 0, 0.12)",
|
|
88
|
+
zIndex: 100000,
|
|
89
|
+
width: "max-content",
|
|
90
|
+
maxWidth: "300px",
|
|
91
|
+
maxHeight: "500px",
|
|
92
|
+
overflow: "auto",
|
|
93
|
+
display: "flex",
|
|
94
|
+
flexDirection: "column",
|
|
95
|
+
gap: "1rem",
|
|
96
|
+
// pointerEvents: "none", // Add this to prevent tooltip from interfering with mouse events
|
|
97
|
+
};
|
|
98
|
+
var tooltipLabelLengthRefs = (0, react_1.useRef)([]);
|
|
99
|
+
var _a = (0, react_1.useState)([]), rowHeights = _a[0], setRowHeights = _a[1];
|
|
100
|
+
var _b = (0, react_1.useState)((value === null || value === void 0 ? void 0 : value.map(function (v) { return true; })) || []), tooltipTextClampStates = _b[0], setTooltipTextClampStates = _b[1];
|
|
101
|
+
(0, react_1.useEffect)(function () {
|
|
102
|
+
if (!tooltipTextClampStates) {
|
|
103
|
+
setTooltipTextClampStates(value === null || value === void 0 ? void 0 : value.map(function (v) { return true; }));
|
|
104
|
+
}
|
|
105
|
+
}, [value]);
|
|
106
|
+
(0, react_1.useEffect)(function () {
|
|
107
|
+
// console.log({ tooltipLabelLengthRefs });
|
|
108
|
+
var rowHeightsToSet = tooltipLabelLengthRefs.current.map(function (ref) {
|
|
109
|
+
var _a;
|
|
110
|
+
var heightOfLabelText = (_a = ref === null || ref === void 0 ? void 0 : ref.getBoundingClientRect()) === null || _a === void 0 ? void 0 : _a.height;
|
|
111
|
+
// console.log({heightOfLabelText})
|
|
112
|
+
return heightOfLabelText || null;
|
|
113
|
+
});
|
|
114
|
+
setRowHeights(rowHeightsToSet);
|
|
115
|
+
}, [tooltipTextClampStates.join()]);
|
|
116
|
+
if (!active)
|
|
117
|
+
return null;
|
|
118
|
+
return (react_1.default.createElement(react_1.Fragment, null,
|
|
119
|
+
react_1.default.createElement("div", { ref: tooltipWrapperRef, style: style },
|
|
120
|
+
react_1.default.createElement("div", { style: {
|
|
121
|
+
display: "grid",
|
|
122
|
+
gridTemplateColumns: showPercent ? "auto auto auto" : "auto auto",
|
|
123
|
+
gap: "0.6rem",
|
|
124
|
+
} },
|
|
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" } },
|
|
126
|
+
react_1.default.createElement("div", { style: {
|
|
127
|
+
display: "flex",
|
|
128
|
+
alignItems: "center",
|
|
129
|
+
gap: "0.6rem",
|
|
130
|
+
} },
|
|
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")))); })),
|
|
138
|
+
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
|
+
height: rowHeights[index]
|
|
140
|
+
? rowHeights[index] + "px"
|
|
141
|
+
: "auto",
|
|
142
|
+
} },
|
|
143
|
+
react_1.default.createElement(Typo2_1.UI_CAPTION_DF, { key: index }, entry.count || "0"))); }))),
|
|
144
|
+
react_1.default.createElement("div", { style: {
|
|
145
|
+
paddingLeft: "0.8rem",
|
|
146
|
+
display: "flex",
|
|
147
|
+
flexDirection: "column",
|
|
148
|
+
gap: "1rem",
|
|
149
|
+
} }, value.map(function (entry, index) { return (react_1.default.createElement("div", { onMouseOver: function () { return setTooltipTextClampStates(function (prev) {
|
|
150
|
+
var newState = __spreadArray([], prev, true);
|
|
151
|
+
newState[index] = false;
|
|
152
|
+
return newState;
|
|
153
|
+
}); }, onMouseOut: function () { return setTooltipTextClampStates(function (prev) {
|
|
154
|
+
var newState = __spreadArray([], prev, true);
|
|
155
|
+
newState[index] = true;
|
|
156
|
+
return newState;
|
|
157
|
+
}); }, ref: function (el) { return (tooltipLabelLengthRefs.current[index] = el); } },
|
|
158
|
+
react_1.default.createElement(UI_CAPTION_DF_WITH_LINE_CLAMP, { clampT: tooltipTextClampStates[index], key: index }, entry.tooltipLabel))); }))))));
|
|
159
|
+
};
|
|
160
|
+
exports.default = CustomTooltip;
|
|
161
|
+
var templateObject_1;
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
name: string;
|
|
7
|
-
dataIndex: number;
|
|
8
|
-
color: string;
|
|
9
|
-
tooltipLabel?: string;
|
|
10
|
-
}
|
|
11
|
-
export type CustomizedLabelValue = LabelData | LabelData[];
|
|
2
|
+
import { DebugControls } from "../..";
|
|
3
|
+
import { CountVizLabels } from "../../../types";
|
|
4
|
+
import { BaseBarChartUIConfigs } from "../../_base_barchart_ui_configs";
|
|
5
|
+
export type CustomizedLabelValue = CountVizLabels | CountVizLabels[];
|
|
12
6
|
interface CustomizedLabelProps {
|
|
13
7
|
y?: number | string;
|
|
14
8
|
width?: number | string;
|
|
@@ -19,14 +13,15 @@ interface CustomizedLabelProps {
|
|
|
19
13
|
opacity: number;
|
|
20
14
|
activeBar?: string;
|
|
21
15
|
breakdownDisplayType?: 'grouped' | 'stacked';
|
|
22
|
-
|
|
16
|
+
_base_barchart_ui_configs: BaseBarChartUIConfigs;
|
|
23
17
|
_debug_controls: DebugControls;
|
|
24
18
|
TOT_HEIGHT_SINGLE_BAR_SECTION: number;
|
|
25
19
|
TOT_HEIGHT_GROUPED_BAR_SECTION: number;
|
|
26
20
|
CALC_SINGLE_BAR_SECTION_Y_POS: (index: number) => number;
|
|
21
|
+
showSumOfBreakdownValues?: boolean;
|
|
27
22
|
onMouseOver?: (e: React.MouseEvent<SVGRectElement, MouseEvent>, v: CustomizedLabelValue) => void;
|
|
28
23
|
onMouseOut?: (e: React.MouseEvent<SVGRectElement, MouseEvent>, v: CustomizedLabelValue) => void;
|
|
29
24
|
onMouseDown?: (e: React.MouseEvent<SVGRectElement, MouseEvent>, v: CustomizedLabelValue) => void;
|
|
30
25
|
}
|
|
31
|
-
export declare const CustomizedLabel: ({ y, width, height, value, showPercent, showCount, opacity,
|
|
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;
|
|
32
27
|
export {};
|
|
@@ -35,22 +35,32 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.CustomizedLabel = void 0;
|
|
37
37
|
var react_1 = __importStar(require("react"));
|
|
38
|
-
var themes_1 = require("
|
|
38
|
+
var themes_1 = require("../../../../../themes");
|
|
39
39
|
var TruncatedSVGText_1 = require("../TruncatedSVGText");
|
|
40
40
|
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,
|
|
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;
|
|
42
42
|
if (!value)
|
|
43
43
|
return null;
|
|
44
|
-
var yOffset = -(
|
|
44
|
+
var yOffset = -(_base_barchart_ui_configs.labelToBarGap + (_base_barchart_ui_configs.barHeight / 2));
|
|
45
45
|
var xOffsetRelative = 10;
|
|
46
46
|
var isBreakdown = Array.isArray(value);
|
|
47
47
|
var name = isBreakdown ? value[0].name : value.name;
|
|
48
48
|
var formatValue = function () {
|
|
49
49
|
if (isBreakdown) {
|
|
50
50
|
var values_1 = value;
|
|
51
|
-
|
|
52
|
-
showPercent ?
|
|
53
|
-
|
|
51
|
+
if (showSumOfBreakdownValues) {
|
|
52
|
+
var valueKey_1 = showPercent ? 'percentage' : 'count';
|
|
53
|
+
var suffixFunction = function (value) {
|
|
54
|
+
return showPercent ? value.toFixed(1) + '%' : value;
|
|
55
|
+
};
|
|
56
|
+
var totValue = suffixFunction(values_1.reduce(function (acc, b) { return acc + b[valueKey_1]; }, 0));
|
|
57
|
+
return totValue;
|
|
58
|
+
}
|
|
59
|
+
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" },
|
|
61
|
+
showPercent ? v.percentage.toFixed(1) + '%' : v.count,
|
|
62
|
+
index < values_1.length - 1 && (react_1.default.createElement("tspan", { fill: themes_1.colors.grey80 }, " + ")))); });
|
|
63
|
+
}
|
|
54
64
|
}
|
|
55
65
|
else {
|
|
56
66
|
var singleValue = value;
|
|
@@ -70,14 +80,14 @@ var CustomizedLabel = function (_a) {
|
|
|
70
80
|
var widthRef = (0, react_1.useRef)(null);
|
|
71
81
|
var textContainerRef = (0, react_1.useRef)(null);
|
|
72
82
|
return (react_1.default.createElement("g", null,
|
|
73
|
-
react_1.default.createElement("text", { ref: textContainerRef, opacity: opacity, x:
|
|
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" },
|
|
74
84
|
formatValue(),
|
|
75
85
|
showPercent && !isBreakdown && (react_1.default.createElement("tspan", { className: "UI_BODY_SM", dx: xOffsetRelative, fill: themes_1.colors.grey80 }, getCount())),
|
|
76
86
|
react_1.default.createElement("tspan", { className: "UI_BODY_SM", dx: xOffsetRelative, fill: themes_1.colors.grey80 },
|
|
77
|
-
react_1.default.createElement(TruncatedSVGText_1.TruncatedSVGText, { text: name, textContainerRef: textContainerRef, widthRef: widthRef, widthOffset: -(
|
|
78
|
-
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:
|
|
79
|
-
?
|
|
80
|
-
:
|
|
81
|
-
(activeBar === name ? 1 : 0), stroke: themes_1.colors.grey30, rx: 5, ry: 5, strokeWidth: "".concat(
|
|
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')
|
|
89
|
+
? _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 ||
|
|
91
|
+
(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 })));
|
|
82
92
|
};
|
|
83
93
|
exports.CustomizedLabel = CustomizedLabel;
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
3
|
-
barHeight: number;
|
|
4
|
-
labelToBarGap: number;
|
|
5
|
-
labelHeight: number;
|
|
6
|
-
labelToNextBarGap: number;
|
|
7
|
-
barRadius: number;
|
|
8
|
-
gapBetweenBarSections: number;
|
|
9
|
-
hoverRectStrokeWidth: number;
|
|
10
|
-
marginLeft: number;
|
|
11
|
-
marginRight: number;
|
|
12
|
-
gapBetweenBarsInGroup: number;
|
|
13
|
-
}
|
|
2
|
+
import { CountVizData } from "../types";
|
|
14
3
|
export interface DebugControls {
|
|
15
4
|
mouseEventDetectorOpacity: number;
|
|
16
5
|
chartWrapperBgColor: string;
|
|
17
6
|
}
|
|
7
|
+
export declare const useTrackMousePosition: () => {
|
|
8
|
+
mousePosition: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
type BreakdownDisplayType = "grouped" | "stacked";
|
|
18
14
|
export interface BarChartProps {
|
|
19
|
-
data:
|
|
15
|
+
data: CountVizData;
|
|
20
16
|
valuePath: string | string[];
|
|
21
17
|
tooltipLabelsMapping: {
|
|
22
18
|
[key: string]: string;
|
|
@@ -27,7 +23,9 @@ export interface BarChartProps {
|
|
|
27
23
|
valueSuffix?: string;
|
|
28
24
|
showCount?: boolean;
|
|
29
25
|
showPercent?: boolean;
|
|
30
|
-
breakdownDisplayType?:
|
|
26
|
+
breakdownDisplayType?: BreakdownDisplayType;
|
|
31
27
|
colorIdx?: number;
|
|
28
|
+
summarizeAfterIdx?: number;
|
|
32
29
|
}
|
|
33
30
|
export declare const BarChart: React.FC<BarChartProps>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,276 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
47
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.BarChart = exports.useTrackMousePosition = void 0;
|
|
51
|
+
var react_1 = __importStar(require("react"));
|
|
52
|
+
var recharts_1 = require("recharts");
|
|
53
|
+
var CustomizedLabel_1 = require("./comps/CustomizedLabel");
|
|
54
|
+
var colors_1 = require("../../../themes/colors");
|
|
55
|
+
var CustomTooltip_1 = __importDefault(require("./comps/CustomTooltip"));
|
|
56
|
+
var usePrepareData_1 = require("../utils/usePrepareData");
|
|
57
|
+
var _base_barchart_ui_configs_1 = require("./_base_barchart_ui_configs");
|
|
58
|
+
var useTrackMousePosition = function () {
|
|
59
|
+
var _a = (0, react_1.useState)({
|
|
60
|
+
x: 0,
|
|
61
|
+
y: 0,
|
|
62
|
+
}), mousePosition = _a[0], setMousePosition = _a[1];
|
|
63
|
+
(0, react_1.useEffect)(function () {
|
|
64
|
+
var handleMouseMove = function (e) {
|
|
65
|
+
setMousePosition({ x: e.clientX, y: e.clientY });
|
|
66
|
+
};
|
|
67
|
+
window.addEventListener("mousemove", handleMouseMove);
|
|
68
|
+
// Clean up
|
|
69
|
+
return function () {
|
|
70
|
+
window.removeEventListener("mousemove", handleMouseMove);
|
|
71
|
+
};
|
|
72
|
+
}, []);
|
|
73
|
+
return ({ mousePosition: mousePosition });
|
|
74
|
+
};
|
|
75
|
+
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
|
+
var CHART_OFFSET_TOP = _base_barchart_ui_configs_1._base_barchart_ui_configs.labelToBarGap +
|
|
78
|
+
_base_barchart_ui_configs_1._base_barchart_ui_configs.labelHeight +
|
|
79
|
+
(_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
|
+
var TOT_HEIGHT_SINGLE_BAR_SECTION = _base_barchart_ui_configs_1._base_barchart_ui_configs.barHeight +
|
|
81
|
+
_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.labelToNextBarGap;
|
|
84
|
+
var CALC_SINGLE_BAR_SECTION_Y_POS = function (index) {
|
|
85
|
+
return (TOT_HEIGHT_SINGLE_BAR_SECTION + _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarSections) * index;
|
|
86
|
+
};
|
|
87
|
+
var CALC_TOTAL_HEIGHT_GROUPED_BAR_SECTION = function (noOfBarsInGroup) {
|
|
88
|
+
var totalHeightOfAllBars = noOfBarsInGroup * _base_barchart_ui_configs_1._base_barchart_ui_configs.barHeight +
|
|
89
|
+
(noOfBarsInGroup - 1) * _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarsInGroup;
|
|
90
|
+
return (totalHeightOfAllBars +
|
|
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.labelToNextBarGap);
|
|
94
|
+
};
|
|
95
|
+
var CALC_GROUPED_BAR_SECTION_Y_POS = function (index, barIndex, noOfBarsInGroup) {
|
|
96
|
+
var TOTAL_HEIGHT_GROUPED_BAR_SECTION = CALC_TOTAL_HEIGHT_GROUPED_BAR_SECTION(noOfBarsInGroup);
|
|
97
|
+
var startYPosOfGroup = (TOTAL_HEIGHT_GROUPED_BAR_SECTION + _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarSections) *
|
|
98
|
+
index;
|
|
99
|
+
return (startYPosOfGroup +
|
|
100
|
+
barIndex * (_base_barchart_ui_configs_1._base_barchart_ui_configs.barHeight + _base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarsInGroup));
|
|
101
|
+
};
|
|
102
|
+
var CALC_TOTAL_HEIGHT_OF_CHART = function (_a) {
|
|
103
|
+
var isBreakdown = _a.isBreakdown, breakdownDisplayType = _a.breakdownDisplayType, data = _a.data;
|
|
104
|
+
return isBreakdown && breakdownDisplayType === "grouped"
|
|
105
|
+
? CALC_TOTAL_HEIGHT_GROUPED_BAR_SECTION(data[0].length) *
|
|
106
|
+
data.length +
|
|
107
|
+
_base_barchart_ui_configs_1._base_barchart_ui_configs.gapBetweenBarSections * (data.length - 1) +
|
|
108
|
+
_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;
|
|
112
|
+
};
|
|
113
|
+
var _debug_controls = {
|
|
114
|
+
mouseEventDetectorOpacity: 0, //only increase this for debugging. nothing else.
|
|
115
|
+
chartWrapperBgColor: "", //set this to some color value for debugging
|
|
116
|
+
};
|
|
117
|
+
var barConfigs = {
|
|
118
|
+
isBreakdown: {
|
|
119
|
+
getBarRadius: function (stackIndex, breakdownDisplayType, //replaced breakdownDisplayType
|
|
120
|
+
totalStacks) {
|
|
121
|
+
return breakdownDisplayType === "grouped" //replaced breakdownDisplayType
|
|
122
|
+
? _base_barchart_ui_configs_1._base_barchart_ui_configs.barRadius
|
|
123
|
+
: stackIndex === totalStacks - 1
|
|
124
|
+
? [0, _base_barchart_ui_configs_1._base_barchart_ui_configs.barRadius, _base_barchart_ui_configs_1._base_barchart_ui_configs.barRadius, 0]
|
|
125
|
+
: stackIndex === 0
|
|
126
|
+
? [_base_barchart_ui_configs_1._base_barchart_ui_configs.barRadius, 0, 0, _base_barchart_ui_configs_1._base_barchart_ui_configs.barRadius]
|
|
127
|
+
: 0;
|
|
128
|
+
},
|
|
129
|
+
getDataKey: function (stackIndex) { return "".concat(stackIndex, ".labels.count"); },
|
|
130
|
+
getStackId: function (stackIndex, breakdownDisplayType //replaced breakdownDisplayType
|
|
131
|
+
) { return (breakdownDisplayType === "stacked" ? "stack" : "stack-".concat(stackIndex)); },
|
|
132
|
+
getCellFill: function (colorIdx, stackIndex, dataVizColors) { return dataVizColors[(colorIdx + stackIndex) % dataVizColors.length]; },
|
|
133
|
+
},
|
|
134
|
+
isNotBreakdown: {
|
|
135
|
+
getBarRadius: function () { return _base_barchart_ui_configs_1._base_barchart_ui_configs.barRadius; },
|
|
136
|
+
getDataKey: function () { return "labels.count"; },
|
|
137
|
+
getStackId: function () { return undefined; },
|
|
138
|
+
getCellFill: function (colorIdx, _stackIndex, dataVizColors) { return dataVizColors[colorIdx]; },
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
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
|
|
146
|
+
? barConfigs.isBreakdown
|
|
147
|
+
: barConfigs.isNotBreakdown;
|
|
148
|
+
var totalStacks = isBreakdownToRender
|
|
149
|
+
? dataToRender[0].length
|
|
150
|
+
: 1;
|
|
151
|
+
var currentStackId = activeConfig.getStackId(stackIndex, breakdownDisplayTypeToRender);
|
|
152
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
153
|
+
react_1.default.createElement(recharts_1.Bar, { key: "stack-".concat(stackIndex), radius: activeConfig.getBarRadius(stackIndex, breakdownDisplayTypeToRender, totalStacks), dataKey: activeConfig.getDataKey(stackIndex), stackId: currentStackId },
|
|
154
|
+
(!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 &&
|
|
155
|
+
breakdownDisplayTypeToRender === "grouped"
|
|
156
|
+
? CALC_TOTAL_HEIGHT_GROUPED_BAR_SECTION(dataToRender[0].length)
|
|
157
|
+
: undefined,
|
|
158
|
+
breakdownDisplayType: breakdownDisplayTypeToRender,
|
|
159
|
+
y: props.y,
|
|
160
|
+
width: props.width,
|
|
161
|
+
height: props.height,
|
|
162
|
+
value: isBreakdownToRender
|
|
163
|
+
? dataToRender[props.index].map(function (item, idx) { return (__assign(__assign({}, item.labels), { color: colors_1.dataVizColorsText[(colorIdx + idx) % colors_1.dataVizColorsText.length] })); })
|
|
164
|
+
: 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
|
|
165
|
+
? {
|
|
166
|
+
onMouseOver: function (e, value) {
|
|
167
|
+
setActiveBar(isBreakdownToRender
|
|
168
|
+
? dataToRender[props.index][0].labels.name
|
|
169
|
+
: value.name);
|
|
170
|
+
},
|
|
171
|
+
onMouseOut: function () { return setActiveBar(undefined); },
|
|
172
|
+
onMouseDown: function (e, value) {
|
|
173
|
+
var name = isBreakdownToRender
|
|
174
|
+
? dataToRender[props.index][0].labels.name
|
|
175
|
+
: value.name;
|
|
176
|
+
setActiveBar(name);
|
|
177
|
+
onClick(name);
|
|
178
|
+
},
|
|
179
|
+
}
|
|
180
|
+
: {})))); } })),
|
|
181
|
+
dataToRender.map(function (d, index) { return (react_1.default.createElement(recharts_1.Cell, { y: !isBreakdownToRender || breakdownDisplayTypeToRender === "stacked"
|
|
182
|
+
? CALC_SINGLE_BAR_SECTION_Y_POS(index) + CHART_OFFSET_TOP
|
|
183
|
+
: 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) })); }))));
|
|
184
|
+
};
|
|
185
|
+
var BarChartRenderer = function (_a) {
|
|
186
|
+
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,
|
|
187
|
+
//
|
|
188
|
+
mousePosition = _a.mousePosition, dataMaxValue = _a.dataMaxValue;
|
|
189
|
+
return (react_1.default.createElement(recharts_1.BarChart, { width: 500, height: CALC_TOTAL_HEIGHT_OF_CHART({
|
|
190
|
+
isBreakdown: isBreakdown,
|
|
191
|
+
breakdownDisplayType: breakdownDisplayType,
|
|
192
|
+
data: data
|
|
193
|
+
}), data: data, layout: "vertical", margin: {
|
|
194
|
+
top: 0,
|
|
195
|
+
right: _base_barchart_ui_configs_1._base_barchart_ui_configs.marginRight,
|
|
196
|
+
left: _base_barchart_ui_configs_1._base_barchart_ui_configs.marginLeft,
|
|
197
|
+
bottom: 0,
|
|
198
|
+
} },
|
|
199
|
+
react_1.default.createElement(recharts_1.XAxis, { hide: true, type: "number", domain: [0, dataMaxValue] }),
|
|
200
|
+
react_1.default.createElement(recharts_1.YAxis, { hide: true, type: "category" }),
|
|
201
|
+
isBreakdown && (react_1.default.createElement(recharts_1.Tooltip, { content: function (props) {
|
|
202
|
+
var _a;
|
|
203
|
+
return (react_1.default.createElement(CustomTooltip_1.default, __assign({}, props, { mousePosition: mousePosition, showPercent: showPercent,
|
|
204
|
+
// god knows why the dataindex gets stored against props.label.
|
|
205
|
+
// this is some internal recharts thing for tooltips specifically.
|
|
206
|
+
// we dont do this.
|
|
207
|
+
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] })); }) })));
|
|
208
|
+
}, cursor: false, allowEscapeViewBox: { x: true, y: true } })),
|
|
209
|
+
isBreakdown
|
|
210
|
+
? data[0].map(function (_, stackIndex) {
|
|
211
|
+
return renderBar({
|
|
212
|
+
stackIndex: stackIndex,
|
|
213
|
+
data: data,
|
|
214
|
+
isBreakdown: isBreakdown,
|
|
215
|
+
breakdownDisplayType: breakdownDisplayType,
|
|
216
|
+
showSumOfBreakdownValues: showSumOfBreakdownValues,
|
|
217
|
+
colorIdx: colorIdx,
|
|
218
|
+
showPercent: showPercent,
|
|
219
|
+
showCount: showCount,
|
|
220
|
+
activeBar: activeBar,
|
|
221
|
+
setActiveBar: setActiveBar,
|
|
222
|
+
onClick: onClick,
|
|
223
|
+
});
|
|
224
|
+
})
|
|
225
|
+
: renderBar({
|
|
226
|
+
stackIndex: undefined,
|
|
227
|
+
data: data,
|
|
228
|
+
isBreakdown: isBreakdown,
|
|
229
|
+
breakdownDisplayType: breakdownDisplayType,
|
|
230
|
+
showSumOfBreakdownValues: showSumOfBreakdownValues,
|
|
231
|
+
colorIdx: colorIdx,
|
|
232
|
+
showPercent: showPercent,
|
|
233
|
+
showCount: showCount,
|
|
234
|
+
activeBar: activeBar,
|
|
235
|
+
setActiveBar: setActiveBar,
|
|
236
|
+
onClick: onClick,
|
|
237
|
+
})));
|
|
238
|
+
};
|
|
239
|
+
var BarChart = function (_a) {
|
|
240
|
+
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;
|
|
241
|
+
var isBreakdown = Array.isArray(valuePath);
|
|
242
|
+
var _h = (0, usePrepareData_1.usePrepareData)({
|
|
243
|
+
_data: _data,
|
|
244
|
+
labelPath: labelPath,
|
|
245
|
+
valuePath: valuePath,
|
|
246
|
+
tooltipLabelsMapping: tooltipLabelsMapping,
|
|
247
|
+
tooltipLabelsPath: tooltipLabelsPath,
|
|
248
|
+
isBreakdown: isBreakdown,
|
|
249
|
+
showPercent: showPercent,
|
|
250
|
+
summarizeAfterIdx: summarizeAfterIdx,
|
|
251
|
+
}), data = _h.data, dataMaxValue = _h.dataMaxValue, dataToSummarize = _h.dataToSummarize;
|
|
252
|
+
var _j = (0, react_1.useState)(undefined), activeBar = _j[0], setActiveBar = _j[1];
|
|
253
|
+
var mousePosition = (0, exports.useTrackMousePosition)().mousePosition;
|
|
254
|
+
// menu options for grouped and stacked
|
|
255
|
+
return (react_1.default.createElement("div", { style: {
|
|
256
|
+
height: "".concat(CALC_TOTAL_HEIGHT_OF_CHART({
|
|
257
|
+
isBreakdown: isBreakdown,
|
|
258
|
+
breakdownDisplayType: breakdownDisplayType,
|
|
259
|
+
data: data
|
|
260
|
+
}) + (isBreakdown ? 0 : CALC_TOTAL_HEIGHT_OF_CHART({
|
|
261
|
+
isBreakdown: true,
|
|
262
|
+
breakdownDisplayType: 'stacked',
|
|
263
|
+
data: dataToSummarize
|
|
264
|
+
})), "px"),
|
|
265
|
+
width: "100%",
|
|
266
|
+
background: _debug_controls.chartWrapperBgColor,
|
|
267
|
+
} },
|
|
268
|
+
react_1.default.createElement(recharts_1.ResponsiveContainer, { width: "100%", height: "100%" },
|
|
269
|
+
react_1.default.createElement("div", null,
|
|
270
|
+
react_1.default.createElement(BarChartRenderer, { data: data, isBreakdown: isBreakdown, breakdownDisplayType: breakdownDisplayType, showSumOfBreakdownValues: false, colorIdx: colorIdx, showPercent: showPercent, showCount: showCount, activeBar: activeBar, setActiveBar: setActiveBar, onClick: onClick, mousePosition: mousePosition, dataMaxValue: dataMaxValue }),
|
|
271
|
+
dataToSummarize && (react_1.default.createElement(BarChartRenderer, { data: dataToSummarize,
|
|
272
|
+
isBreakdown: true,
|
|
273
|
+
breakdownDisplayType: "stacked",
|
|
274
|
+
showSumOfBreakdownValues: true, colorIdx: colorIdx, showPercent: showPercent, showCount: showCount, activeBar: activeBar, setActiveBar: setActiveBar, onClick: onClick, mousePosition: mousePosition, dataMaxValue: dataMaxValue }))))));
|
|
275
|
+
};
|
|
276
|
+
exports.BarChart = BarChart;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const BAR_GRAPH_HEIGHT: 250;
|
|
2
|
+
export const DEFAULT_SINGLE_BAR_WIDTH: 24;
|
|
3
|
+
export const BAR_GAP: 0.3;
|
|
4
|
+
export function BarGraphCollection({ data: originalData, valuePath, labelPath, tooltipLabelsMapping, onClick, showCount, showPercent, groupBy, }: {
|
|
5
|
+
data: any;
|
|
6
|
+
valuePath: any;
|
|
7
|
+
labelPath?: string;
|
|
8
|
+
tooltipLabelsMapping?: {};
|
|
9
|
+
onClick: any;
|
|
10
|
+
showCount?: boolean;
|
|
11
|
+
showPercent?: boolean;
|
|
12
|
+
groupBy: any;
|
|
13
|
+
}): React.JSX.Element;
|
|
14
|
+
export function BarGraph({ tagCategory, index1, showCount, showPercent, onClick }: {
|
|
15
|
+
tagCategory: any;
|
|
16
|
+
index1: any;
|
|
17
|
+
showCount?: boolean;
|
|
18
|
+
showPercent?: boolean;
|
|
19
|
+
onClick: any;
|
|
20
|
+
}): React.JSX.Element;
|
|
21
|
+
import React from "react";
|