oolib 2.114.0 → 2.115.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/PercentBarChart/index.d.ts +5 -6
- package/dist/components/PercentBarChart/index.js +25 -18
- package/dist/stories/{PercentageBarChart.stories.js → PercentBarChart.stories.js} +1 -2
- package/package.json +1 -1
- /package/dist/stories/{PercentageBarChart.stories.d.ts → PercentBarChart.stories.d.ts} +0 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
export declare const PercentBarChart: ({ data: _data, valuePath,
|
|
2
|
+
export declare const PercentBarChart: ({ data: _data, title, valuePath, id, onClick, colors }: {
|
|
3
3
|
data: any;
|
|
4
4
|
valuePath: string;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
5
|
+
title?: string;
|
|
6
|
+
id: string;
|
|
7
|
+
onClick?: (name: string) => void;
|
|
8
|
+
colors?: string[];
|
|
10
9
|
}) => React.JSX.Element;
|
|
@@ -46,6 +46,19 @@ 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 Typo_1 = require("../Typo");
|
|
50
|
+
var chartColors = [
|
|
51
|
+
"#F53D65",
|
|
52
|
+
"#666666",
|
|
53
|
+
"#EBAF4D",
|
|
54
|
+
"#0ACC22",
|
|
55
|
+
"#E60000",
|
|
56
|
+
"#66DAB0",
|
|
57
|
+
"#6A2B99",
|
|
58
|
+
"#ff836d",
|
|
59
|
+
"#b4a8d0",
|
|
60
|
+
"#ff7167",
|
|
61
|
+
];
|
|
49
62
|
var renderCustomizedLabel = function (_a) {
|
|
50
63
|
var y = _a.y, value = _a.value, opacity = _a.opacity;
|
|
51
64
|
var offset = 12;
|
|
@@ -64,27 +77,21 @@ var _dataSample = [
|
|
|
64
77
|
{ name: "AA+", value: 5.63, Type: 3 },
|
|
65
78
|
];
|
|
66
79
|
var PercentBarChart = function (_a) {
|
|
67
|
-
var _b = _a.data, _data = _b === void 0 ? _dataSample : _b, _c = _a.valuePath, valuePath = _c === void 0 ? "value" : _c, _d = _a.
|
|
68
|
-
hoverInvertRed: '#FBC3C3',
|
|
69
|
-
yellow: '#FFCC00',
|
|
70
|
-
green: '#08A84B',
|
|
71
|
-
blue: '#33A4FF'
|
|
72
|
-
} : _e;
|
|
80
|
+
var _b = _a.data, _data = _b === void 0 ? _dataSample : _b, title = _a.title, _c = _a.valuePath, valuePath = _c === void 0 ? "value" : _c, _d = _a.id, id = _d === void 0 ? "name" : _d, onClick = _a.onClick, _e = _a.colors, colors = _e === void 0 ? chartColors : _e;
|
|
73
81
|
var data = (0, react_1.useMemo)(function () {
|
|
74
82
|
var finalData = __spreadArray([], _data, true);
|
|
75
|
-
finalData = finalData.map(function (d, i) { return (__assign(__assign({}, d), { value: d[valuePath], name: d[
|
|
76
|
-
// console.log({ finalData })
|
|
83
|
+
finalData = finalData.map(function (d, i) { return (__assign(__assign({}, d), { value: d[valuePath], name: d[id], color: (colors)[i % (colors).length] })); });
|
|
77
84
|
finalData.sort(function (a, b) {
|
|
78
85
|
return Number(b.value || 0) - Number(a.value || 0);
|
|
79
86
|
});
|
|
80
87
|
return finalData;
|
|
81
|
-
}, [_data,
|
|
88
|
+
}, [_data, id, valuePath]);
|
|
82
89
|
var _f = (0, react_1.useState)(undefined), activeBar = _f[0], setActiveBar = _f[1];
|
|
83
|
-
// console.log({ activeBar });
|
|
84
90
|
var changeBarOpacityFn = function (name) {
|
|
85
91
|
return activeBar && activeBar !== name ? 0.4 : 1;
|
|
86
92
|
};
|
|
87
93
|
return (react_1.default.createElement("div", { style: { height: "".concat(80 * data.length, "px"), width: "100%" } },
|
|
94
|
+
title && react_1.default.createElement(Typo_1.SANS_4_5, null, title),
|
|
88
95
|
react_1.default.createElement(recharts_1.ResponsiveContainer, { width: "100%", height: "100%" },
|
|
89
96
|
react_1.default.createElement(recharts_1.BarChart, { width: 500, height: 500, data: data, layout: "vertical", margin: {
|
|
90
97
|
top: 15,
|
|
@@ -93,16 +100,16 @@ var PercentBarChart = function (_a) {
|
|
|
93
100
|
bottom: 0,
|
|
94
101
|
} },
|
|
95
102
|
react_1.default.createElement(recharts_1.XAxis, { hide: true, type: "number" }),
|
|
96
|
-
react_1.default.createElement(recharts_1.YAxis, { hide: true, type: "category", width: 250, dataKey:
|
|
97
|
-
react_1.default.createElement(recharts_1.Bar, { style: { cursor: "pointer" }, dataKey: "value", unit: "%", onMouseOver: function (args) { return setActiveBar(args[
|
|
98
|
-
setActiveBar(args[
|
|
99
|
-
|
|
103
|
+
react_1.default.createElement(recharts_1.YAxis, { hide: true, type: "category", width: 250, dataKey: id }),
|
|
104
|
+
react_1.default.createElement(recharts_1.Bar, { style: { cursor: "pointer" }, dataKey: "value", unit: "%", onMouseOver: function (args) { return setActiveBar(args[id]); }, onMouseOut: function () { return setActiveBar(undefined); }, onMouseDown: function (args) {
|
|
105
|
+
setActiveBar(args[id]);
|
|
106
|
+
onClick(args[id]);
|
|
100
107
|
} },
|
|
101
|
-
react_1.default.createElement(recharts_1.LabelList, { dataKey:
|
|
108
|
+
react_1.default.createElement(recharts_1.LabelList, { dataKey: id, position: "top", content: function (props) {
|
|
102
109
|
return renderCustomizedLabel({
|
|
103
110
|
y: props.y,
|
|
104
111
|
value: props.value,
|
|
105
|
-
opacity: changeBarOpacityFn(props[
|
|
112
|
+
opacity: changeBarOpacityFn(props[id]),
|
|
106
113
|
});
|
|
107
114
|
} }),
|
|
108
115
|
react_1.default.createElement(recharts_1.LabelList, { dataKey: "value", offset: 0, content: function (props) {
|
|
@@ -112,9 +119,9 @@ var PercentBarChart = function (_a) {
|
|
|
112
119
|
height: props.height,
|
|
113
120
|
value: props.value,
|
|
114
121
|
suffix: "%",
|
|
115
|
-
opacity: changeBarOpacityFn(props[
|
|
122
|
+
opacity: changeBarOpacityFn(props[id]),
|
|
116
123
|
});
|
|
117
124
|
} }),
|
|
118
|
-
data.map(function (entry, index) { return (react_1.default.createElement(recharts_1.Cell, { opacity: changeBarOpacityFn(entry[
|
|
125
|
+
data.map(function (entry, index) { return (react_1.default.createElement(recharts_1.Cell, { opacity: changeBarOpacityFn(entry[id]), key: "cell-".concat(index), height: 30, fill: entry.color })); }))))));
|
|
119
126
|
};
|
|
120
127
|
exports.PercentBarChart = PercentBarChart;
|
|
@@ -9,7 +9,6 @@ var PercentBarChart_1 = require("../components/PercentBarChart");
|
|
|
9
9
|
exports.default = {
|
|
10
10
|
title: "Components/PercentBarChart",
|
|
11
11
|
};
|
|
12
|
-
var uid = 0;
|
|
13
12
|
var data = [
|
|
14
13
|
{ name: 'AAA/A1+', value: 72.3, Type: 0 },
|
|
15
14
|
{ name: 'Cash & Cash Equivalents', value: 10.1, Type: 1 },
|
|
@@ -21,6 +20,6 @@ var PercentBarChart_ = function (args) {
|
|
|
21
20
|
console.log("Bar clicked: ".concat(name));
|
|
22
21
|
};
|
|
23
22
|
return (react_1.default.createElement("div", null,
|
|
24
|
-
react_1.default.createElement(PercentBarChart_1.PercentBarChart, { data: data, valuePath: "value",
|
|
23
|
+
react_1.default.createElement(PercentBarChart_1.PercentBarChart, { data: data, id: "name", valuePath: "value", title: "This is PercentBarChart representing the data", onClick: handleBarClick })));
|
|
25
24
|
};
|
|
26
25
|
exports.PercentBarChart_ = PercentBarChart_;
|
package/package.json
CHANGED
|
File without changes
|