oolib 2.125.2 → 2.125.3
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/PercentBarChart/index.d.ts +2 -1
- package/dist/components/PercentBarChart/index.js +29 -23
- package/dist/stories/PercentBarChart.stories.js +4 -4
- package/dist/utils/_EXPORTS/index.d.ts +2 -0
- package/dist/utils/_EXPORTS/index.js +5 -1
- package/dist/utils/getPercentage.d.ts +1 -0
- package/dist/utils/getPercentage.js +7 -0
- package/dist/utils/getTotalCount.d.ts +4 -0
- package/dist/utils/getTotalCount.js +15 -0
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
export declare const PercentBarChart: ({ data: _data, title, valuePath, labelPath, onClick, colors, }: {
|
|
2
|
+
export declare const PercentBarChart: ({ data: _data, title, valuePath, labelPath, onClick, colors, valueSuffix, }: {
|
|
3
3
|
data: any;
|
|
4
4
|
valuePath: string;
|
|
5
5
|
labelPath: string;
|
|
6
6
|
title?: string;
|
|
7
7
|
onClick?: (name: string) => void;
|
|
8
8
|
colors?: string[];
|
|
9
|
+
valueSuffix?: string;
|
|
9
10
|
}) => React.JSX.Element;
|
|
@@ -46,8 +46,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
46
46
|
exports.PercentBarChart = void 0;
|
|
47
47
|
var react_1 = __importStar(require("react"));
|
|
48
48
|
var recharts_1 = require("recharts");
|
|
49
|
+
var _EXPORTS_1 = require("../../utils/_EXPORTS");
|
|
49
50
|
var Typo_1 = require("../Typo");
|
|
50
|
-
var
|
|
51
|
+
var getTotalCount_1 = require("../../utils/getTotalCount");
|
|
51
52
|
var chartColors = [
|
|
52
53
|
"rgb(120, 86, 255)",
|
|
53
54
|
"rgb(255, 117, 86)",
|
|
@@ -74,50 +75,55 @@ var renderCustomizedValue = function (_a) {
|
|
|
74
75
|
return (react_1.default.createElement("text", { opacity: opacity, fontSize: 14, fontWeight: "600", x: width + xOffset, y: y + height / 2 + yOffset, fill: "black", textAnchor: "start", dominantBaseline: "middle", className: "SANS_2" }, "".concat(value).concat(suffix || "")));
|
|
75
76
|
};
|
|
76
77
|
var _dataSample = [
|
|
77
|
-
{ name: "
|
|
78
|
-
{ name: "
|
|
79
|
-
{ name: "
|
|
80
|
-
{ name: "
|
|
78
|
+
{ name: "Great food", value: 72.3, Type: 0 },
|
|
79
|
+
{ name: "Great Ambience", value: 10.1, Type: 1 },
|
|
80
|
+
{ name: "Great Music", value: 9.87, Type: 2 },
|
|
81
|
+
{ name: "Great Cocktails", value: 5.63, Type: 3 },
|
|
81
82
|
];
|
|
83
|
+
var configs = {
|
|
84
|
+
barHeight: 24,
|
|
85
|
+
barGap: 32,
|
|
86
|
+
};
|
|
82
87
|
var PercentBarChart = function (_a) {
|
|
83
|
-
var _b = _a.data, _data = _b === void 0 ? _dataSample : _b, title = _a.title, _c = _a.valuePath, valuePath = _c === void 0 ? "value" : _c, _d = _a.labelPath, labelPath = _d === void 0 ? "name" : _d, onClick = _a.onClick, _e = _a.colors, colors = _e === void 0 ? chartColors : _e;
|
|
88
|
+
var _b = _a.data, _data = _b === void 0 ? _dataSample : _b, title = _a.title, _c = _a.valuePath, valuePath = _c === void 0 ? "value" : _c, _d = _a.labelPath, labelPath = _d === void 0 ? "name" : _d, onClick = _a.onClick, _e = _a.colors, colors = _e === void 0 ? chartColors : _e, _f = _a.valueSuffix, valueSuffix = _f === void 0 ? "%" : _f;
|
|
89
|
+
var totalCount = (0, getTotalCount_1.getTotalCount)({ data: _data, countPath: valuePath });
|
|
84
90
|
var data = (0, react_1.useMemo)(function () {
|
|
85
91
|
var finalData = __spreadArray([], _data, true);
|
|
86
|
-
finalData = finalData.map(function (d, i) { return (__assign(__assign({}, d), { value: d
|
|
92
|
+
finalData = finalData.map(function (d, i) { return (__assign(__assign({}, d), { value: (0, _EXPORTS_1.getPercentage)((0, _EXPORTS_1.getVal)(d, valuePath), totalCount), name: (0, _EXPORTS_1.getVal)(d, labelPath), color: colors[i % colors.length] })); });
|
|
87
93
|
finalData.sort(function (a, b) {
|
|
88
94
|
return Number(b.value || 0) - Number(a.value || 0);
|
|
89
95
|
});
|
|
90
96
|
return finalData;
|
|
91
97
|
}, [_data, labelPath, valuePath]);
|
|
92
|
-
var
|
|
98
|
+
var _g = (0, react_1.useState)(undefined), activeBar = _g[0], setActiveBar = _g[1];
|
|
93
99
|
var changeBarOpacityFn = function (name) {
|
|
94
100
|
return activeBar && activeBar !== name ? 0.4 : 1;
|
|
95
101
|
};
|
|
96
|
-
return (react_1.default.createElement("div",
|
|
97
|
-
title && (react_1.default.createElement(Typo_1.SANS_4_5, { style: {
|
|
102
|
+
return (react_1.default.createElement("div", null,
|
|
103
|
+
title && (react_1.default.createElement(Typo_1.SANS_4_5, { style: { paddingBottom: "2rem" }, semibold: true }, title)),
|
|
98
104
|
react_1.default.createElement("div", { style: {
|
|
99
|
-
height: "".concat(
|
|
105
|
+
height: "".concat((configs.barHeight + configs.barGap) * data.length, "px"),
|
|
100
106
|
width: "100%",
|
|
101
|
-
padding: "2rem",
|
|
102
|
-
paddingTop: 0,
|
|
103
107
|
} },
|
|
104
108
|
react_1.default.createElement(recharts_1.ResponsiveContainer, { width: "100%", height: "100%" },
|
|
105
109
|
react_1.default.createElement(recharts_1.BarChart, { width: 500, height: 500, barCategoryGap: 20, data: data, layout: "vertical", margin: {
|
|
106
|
-
top:
|
|
110
|
+
top: 0,
|
|
107
111
|
right: 60,
|
|
108
112
|
left: 0,
|
|
109
113
|
bottom: 0,
|
|
110
114
|
} },
|
|
111
115
|
react_1.default.createElement(recharts_1.XAxis, { hide: true, type: "number" }),
|
|
112
116
|
react_1.default.createElement(recharts_1.YAxis, { hide: true, type: "category", width: 250, dataKey: labelPath }),
|
|
113
|
-
react_1.default.createElement(recharts_1.Bar, __assign({ radius: [2, 4, 4, 2], style: onClick ? { cursor: "pointer" } : {}, dataKey: "value"
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
react_1.default.createElement(recharts_1.Bar, __assign({ radius: [2, 4, 4, 2], style: onClick ? { cursor: "pointer" } : {}, dataKey: "value" }, (onClick
|
|
118
|
+
? {
|
|
119
|
+
onMouseOver: function (args) { return setActiveBar(args[labelPath]); },
|
|
120
|
+
onMouseOut: function () { return setActiveBar(undefined); },
|
|
121
|
+
onMouseDown: function (args) {
|
|
122
|
+
setActiveBar(args[labelPath]);
|
|
123
|
+
onClick(args[labelPath]);
|
|
124
|
+
},
|
|
119
125
|
}
|
|
120
|
-
|
|
126
|
+
: {})),
|
|
121
127
|
react_1.default.createElement(recharts_1.LabelList, { dataKey: labelPath, position: "top", content: function (props) {
|
|
122
128
|
return renderCustomizedLabel({
|
|
123
129
|
y: props.y,
|
|
@@ -131,10 +137,10 @@ var PercentBarChart = function (_a) {
|
|
|
131
137
|
width: props.width,
|
|
132
138
|
height: props.height,
|
|
133
139
|
value: props.value,
|
|
134
|
-
suffix:
|
|
140
|
+
suffix: valueSuffix,
|
|
135
141
|
opacity: changeBarOpacityFn(props[labelPath]),
|
|
136
142
|
});
|
|
137
143
|
} }),
|
|
138
|
-
data.map(function (entry, index) { return (react_1.default.createElement(recharts_1.Cell, { opacity: changeBarOpacityFn(entry[labelPath]), key: "cell-".concat(index), height:
|
|
144
|
+
data.map(function (entry, index) { return (react_1.default.createElement(recharts_1.Cell, { opacity: changeBarOpacityFn(entry[labelPath]), key: "cell-".concat(index), height: configs.barHeight, fill: entry.color })); })))))));
|
|
139
145
|
};
|
|
140
146
|
exports.PercentBarChart = PercentBarChart;
|
|
@@ -10,10 +10,10 @@ exports.default = {
|
|
|
10
10
|
title: "Components/PercentBarChart",
|
|
11
11
|
};
|
|
12
12
|
var data = [
|
|
13
|
-
{ name:
|
|
14
|
-
{ name:
|
|
15
|
-
{ name:
|
|
16
|
-
{ name:
|
|
13
|
+
{ name: "Great food", value: 72.3, Type: 0 },
|
|
14
|
+
{ name: "Great Ambience", value: 10.1, Type: 1 },
|
|
15
|
+
{ name: "Great Music", value: 9.87, Type: 2 },
|
|
16
|
+
{ name: "Great Cocktails", value: 5.63, Type: 3 },
|
|
17
17
|
];
|
|
18
18
|
var PercentBarChart_ = function (args) {
|
|
19
19
|
var handleBarClick = function (name) {
|
|
@@ -21,3 +21,5 @@ export { getDaysDiff } from "../momentjs/getDaysDiff";
|
|
|
21
21
|
export { stitchLink } from "../stitchLink";
|
|
22
22
|
export { decideLinkCompAndTarget } from "../../components/cards/utils/decideLinkCompAndTarget";
|
|
23
23
|
export { isExternalUrl } from "../../components/cards/utils/isExternalUrl";
|
|
24
|
+
export { getPercentage } from "../getPercentage";
|
|
25
|
+
export { getTotalCount } from "../getTotalCount";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isExternalUrl = exports.decideLinkCompAndTarget = exports.stitchLink = exports.getDaysDiff = exports.useContainerQuery = exports.useScreenWidth = exports.testJSON = exports.useHandleClickOutside = exports.usePopOutOfOverflowHiddenParent = exports.useScroll = exports.isStringMatch = exports.sortData = exports.makeArrayFromLength = exports.toArray = exports.formatCamelCaseToSentenceCase = exports.formatTextToCamelCase = exports.injectHttps = exports.getBlockLabelProps = exports.getKeyCode = exports.getText = exports.deleteVal = exports.setVal = exports.getVal = void 0;
|
|
3
|
+
exports.getTotalCount = exports.getPercentage = exports.isExternalUrl = exports.decideLinkCompAndTarget = exports.stitchLink = exports.getDaysDiff = exports.useContainerQuery = exports.useScreenWidth = exports.testJSON = exports.useHandleClickOutside = exports.usePopOutOfOverflowHiddenParent = exports.useScroll = exports.isStringMatch = exports.sortData = exports.makeArrayFromLength = exports.toArray = exports.formatCamelCaseToSentenceCase = exports.formatTextToCamelCase = exports.injectHttps = exports.getBlockLabelProps = exports.getKeyCode = exports.getText = exports.deleteVal = exports.setVal = exports.getVal = void 0;
|
|
4
4
|
//the holy setter, getter & deleter
|
|
5
5
|
var getVal_1 = require("../getterSetterDeleter/getVal");
|
|
6
6
|
Object.defineProperty(exports, "getVal", { enumerable: true, get: function () { return getVal_1.getVal; } });
|
|
@@ -52,3 +52,7 @@ var decideLinkCompAndTarget_1 = require("../../components/cards/utils/decideLink
|
|
|
52
52
|
Object.defineProperty(exports, "decideLinkCompAndTarget", { enumerable: true, get: function () { return decideLinkCompAndTarget_1.decideLinkCompAndTarget; } });
|
|
53
53
|
var isExternalUrl_1 = require("../../components/cards/utils/isExternalUrl");
|
|
54
54
|
Object.defineProperty(exports, "isExternalUrl", { enumerable: true, get: function () { return isExternalUrl_1.isExternalUrl; } });
|
|
55
|
+
var getPercentage_1 = require("../getPercentage");
|
|
56
|
+
Object.defineProperty(exports, "getPercentage", { enumerable: true, get: function () { return getPercentage_1.getPercentage; } });
|
|
57
|
+
var getTotalCount_1 = require("../getTotalCount");
|
|
58
|
+
Object.defineProperty(exports, "getTotalCount", { enumerable: true, get: function () { return getTotalCount_1.getTotalCount; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPercentage: (d1: number, d2: number) => number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTotalCount = void 0;
|
|
4
|
+
var _EXPORTS_1 = require("./_EXPORTS");
|
|
5
|
+
var getTotalCount = function (_a) {
|
|
6
|
+
var data = _a.data, countPath = _a.countPath;
|
|
7
|
+
var total = 0;
|
|
8
|
+
for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
|
|
9
|
+
var d = data_1[_i];
|
|
10
|
+
var count = (0, _EXPORTS_1.getVal)(d, countPath);
|
|
11
|
+
total += count;
|
|
12
|
+
}
|
|
13
|
+
return total;
|
|
14
|
+
};
|
|
15
|
+
exports.getTotalCount = getTotalCount;
|