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.
@@ -1,10 +1,9 @@
1
1
  import React from "react";
2
- export declare const PercentBarChart: ({ data: _data, valuePath, display, onBarClick, colors }: {
2
+ export declare const PercentBarChart: ({ data: _data, title, valuePath, id, onClick, colors }: {
3
3
  data: any;
4
4
  valuePath: string;
5
- display: string;
6
- onBarClick?: (name: string) => void;
7
- colors?: {
8
- [key: string]: string;
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.display, display = _d === void 0 ? "name" : _d, onBarClick = _a.onBarClick, _e = _a.colors, colors = _e === void 0 ? {
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[display], color: Object.values(colors)[i % Object.values(colors).length] })); });
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, display, valuePath]);
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: display }),
97
- react_1.default.createElement(recharts_1.Bar, { style: { cursor: "pointer" }, dataKey: "value", unit: "%", onMouseOver: function (args) { return setActiveBar(args[display]); }, onMouseOut: function () { return setActiveBar(undefined); }, onMouseDown: function (args) {
98
- setActiveBar(args[display]);
99
- onBarClick(args[display]);
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: display, position: "top", content: function (props) {
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[display]),
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[display]),
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[display]), key: "cell-".concat(index), height: 30, fill: entry.color })); }))))));
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", display: "name", onBarClick: handleBarClick })));
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oolib",
3
- "version": "2.114.0",
3
+ "version": "2.115.0",
4
4
  "description": " OKE Component Library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",