oolib 2.136.0 → 2.136.1

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.
@@ -5,14 +5,13 @@ type TCustomizedLabeValue = {
5
5
  count: number;
6
6
  name: string;
7
7
  };
8
- export declare const CustomizedLabel: ({ y, width, height, value, showCount, suffix, opacity, _base_configs, onMouseOver, onMouseOut, onMouseDown, }: {
8
+ export declare const CustomizedLabel: ({ y, width, height, value, plotDataPoint, opacity, _base_configs, onMouseOver, onMouseOut, onMouseDown, }: {
9
9
  y?: number | string;
10
10
  width?: number | string;
11
11
  height?: number | string;
12
12
  value?: TCustomizedLabeValue;
13
13
  opacity: number;
14
- suffix?: string;
15
- showCount?: boolean;
14
+ plotDataPoint?: "percentage" | "count";
16
15
  _base_configs: TBaseConfigs;
17
16
  onMouseOver?: (e: React.MouseEvent<SVGRectElement, MouseEvent>, v: TCustomizedLabeValue) => void;
18
17
  onMouseOut?: (e: React.MouseEvent<SVGRectElement, MouseEvent>, v: TCustomizedLabeValue) => void;
@@ -8,7 +8,7 @@ var react_1 = __importDefault(require("react"));
8
8
  var themes_1 = require("../../../../themes");
9
9
  var CustomizedLabel = function (_a) {
10
10
  var y = _a.y, width = _a.width, //i think this is the width and the height of the bar. dont need it just yet..
11
- height = _a.height, value = _a.value, showCount = _a.showCount, suffix = _a.suffix, opacity = _a.opacity, _base_configs = _a._base_configs, onMouseOver = _a.onMouseOver, onMouseOut = _a.onMouseOut, onMouseDown = _a.onMouseDown;
11
+ height = _a.height, value = _a.value, plotDataPoint = _a.plotDataPoint, opacity = _a.opacity, _base_configs = _a._base_configs, onMouseOver = _a.onMouseOver, onMouseOut = _a.onMouseOut, onMouseDown = _a.onMouseDown;
12
12
  var yOffset = -(_base_configs.labelToBarGap + _base_configs.barHeight);
13
13
  var percent = value.percentage;
14
14
  var count = value.count;
@@ -16,8 +16,14 @@ var CustomizedLabel = function (_a) {
16
16
  var percentXOffset = 0;
17
17
  var xOffsetRelative = 10;
18
18
  return (react_1.default.createElement("g", null,
19
- react_1.default.createElement("text", { opacity: opacity, x: percentXOffset, y: y + yOffset, fill: themes_1.colors.greyColor100, textAnchor: "start", dominantBaseline: "middle", className: "UI_BODY_BOLD_SM" }, "".concat(percent).concat(suffix || ""),
20
- react_1.default.createElement("tspan", { className: "UI_BODY_SM", dx: xOffsetRelative, y: y + yOffset, fill: themes_1.colors.greyColor80 }, showCount ? count : ""),
19
+ react_1.default.createElement("text", { opacity: opacity, x: percentXOffset, y: y + yOffset, fill: themes_1.colors.greyColor100, textAnchor: "start", dominantBaseline: "middle", className: "UI_BODY_BOLD_SM" },
20
+ plotDataPoint === "percentage"
21
+ ? percent + "%"
22
+ : plotDataPoint === "count"
23
+ ? count
24
+ : "",
25
+ plotDataPoint === "percentage" && ( // basically no need to show this only if plotDataPoint is count, since in that case, count is already shown above
26
+ react_1.default.createElement("tspan", { className: "UI_BODY_SM", dx: xOffsetRelative, y: y + yOffset, fill: themes_1.colors.greyColor80 }, count)),
21
27
  react_1.default.createElement("tspan", { className: "UI_BODY_SM", dx: xOffsetRelative, y: y + yOffset, fill: themes_1.colors.greyColor80 }, name)),
22
28
  react_1.default.createElement("rect", { 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: percentXOffset, y: y + _base_configs.mouseEventDetectorYOffset, width: width, height: _base_configs.mouseEventDetectorHeight, fill: "red", "fill-opacity": _base_configs.mouseEventDetectorOpacity })));
23
29
  };
@@ -7,7 +7,7 @@ export type TBaseConfigs = {
7
7
  mouseEventDetectorHeight: number;
8
8
  mouseEventDetectorOpacity: number;
9
9
  };
10
- export declare const PercentBarChart: ({ data: _data, title, valuePath, labelPath, onClick, colors, colorIdx, valueSuffix, showCount }: {
10
+ export declare const PercentBarChart: ({ data: _data, title, valuePath, labelPath, onClick, colors, colorIdx, plotDataPoint, }: {
11
11
  data: any;
12
12
  valuePath: string;
13
13
  labelPath: string;
@@ -16,5 +16,7 @@ export declare const PercentBarChart: ({ data: _data, title, valuePath, labelPat
16
16
  colors?: string[];
17
17
  colorIdx?: number;
18
18
  valueSuffix?: string;
19
+ plotDataPoint?: 'percentage' | 'count';
19
20
  showCount?: boolean;
21
+ showPercent?: boolean;
20
22
  }) => React.JSX.Element;
@@ -83,28 +83,23 @@ var PercentBarChart = function (_a) {
83
83
  _c = _a.labelPath, // is relevant only for the initial data setting in useMemo. after that, the actual percentage is always stored against the 'percentage' key, and the count against the 'count' key
84
84
  labelPath = _c === void 0 ? "name" : _c, // same as above for label path
85
85
  onClick = _a.onClick, _d = _a.colors, colors = _d === void 0 ? chartColors : _d, _e = _a.colorIdx, colorIdx = _e === void 0 ? 0 : _e, //if you are rendering a grid of such charts, then maybe you want each of their colors to be different. in that case, increment this idx from the parent component
86
- _f = _a.valueSuffix, //if you are rendering a grid of such charts, then maybe you want each of their colors to be different. in that case, increment this idx from the parent component
87
- valueSuffix = _f === void 0 ? "%" : _f, _g = _a.showCount, showCount = _g === void 0 ? true : _g;
86
+ _f = _a.plotDataPoint, //if you are rendering a grid of such charts, then maybe you want each of their colors to be different. in that case, increment this idx from the parent component
87
+ plotDataPoint = _f === void 0 ? 'percentage' : _f;
88
88
  var totalCount = (0, getTotalCount_1.getTotalCount)({ data: _data, countPath: valuePath });
89
89
  var data = (0, react_1.useMemo)(function () {
90
90
  var finalData = __spreadArray([], _data, true);
91
91
  finalData = finalData.map(function (d, i) {
92
- var percentage = (0, _EXPORTS_1.getPercentage)((0, _EXPORTS_1.getVal)(d, valuePath), totalCount);
93
92
  var count = (0, _EXPORTS_1.getVal)(d, valuePath);
94
93
  return ({
95
- labels: {
96
- percentage: percentage,
97
- count: count,
98
- name: (0, _EXPORTS_1.getVal)(d, labelPath),
99
- },
94
+ labels: __assign(__assign({}, (plotDataPoint === 'percentage' ? { percentage: (0, _EXPORTS_1.getPercentage)((0, _EXPORTS_1.getVal)(d, valuePath), totalCount) } : {})), { count: count, name: (0, _EXPORTS_1.getVal)(d, labelPath) }),
100
95
  });
101
96
  });
102
97
  finalData.sort(function (a, b) {
103
- return Number(b.value || 0) - Number(a.value || 0);
98
+ return Number((0, _EXPORTS_1.getVal)(b, "labels.".concat(plotDataPoint)) || 0) - Number((0, _EXPORTS_1.getVal)(a, "labels.".concat(plotDataPoint)) || 0);
104
99
  });
105
100
  return finalData;
106
101
  }, [_data, labelPath, valuePath]);
107
- var _h = (0, react_1.useState)(undefined), activeBar = _h[0], setActiveBar = _h[1];
102
+ var _g = (0, react_1.useState)(undefined), activeBar = _g[0], setActiveBar = _g[1];
108
103
  var changeBarOpacityFn = function (name) {
109
104
  return activeBar && activeBar !== name ? 0.4 : 1;
110
105
  };
@@ -137,13 +132,12 @@ var PercentBarChart = function (_a) {
137
132
  } },
138
133
  react_1.default.createElement(recharts_1.XAxis, { hide: true, type: "number" }),
139
134
  react_1.default.createElement(recharts_1.YAxis, { hide: true, type: "category" }),
140
- react_1.default.createElement(recharts_1.Bar, { radius: _base_configs.barRadius, style: onClick ? { cursor: "pointer" } : {}, dataKey: "labels.percentage" },
135
+ react_1.default.createElement(recharts_1.Bar, { radius: _base_configs.barRadius, style: onClick ? { cursor: "pointer" } : {}, dataKey: "labels.".concat(plotDataPoint) },
141
136
  react_1.default.createElement(recharts_1.LabelList, { dataKey: "labels", offset: 0, content: function (props) { return react_1.default.createElement(CustomizedLabel_1.CustomizedLabel, __assign({ y: props.y,
142
137
  width: props.width,
143
138
  height: props.height,
144
139
  value: props.value, //here value is the percentage
145
- showCount: showCount, suffix: valueSuffix,
146
- opacity: changeBarOpacityFn(props.value.name), _base_configs: _base_configs }, (onClick
140
+ plotDataPoint: plotDataPoint, opacity: changeBarOpacityFn(props.value.name), _base_configs: _base_configs }, (onClick
147
141
  ? {
148
142
  onMouseOver: function (e, value) { return setActiveBar(value.name); },
149
143
  onMouseOut: function () { return setActiveBar(undefined); },
@@ -10,10 +10,10 @@ exports.default = {
10
10
  title: "Components/PercentBarChart",
11
11
  };
12
12
  var data = [
13
- { display: "Great food", value: 72, },
14
- { display: "Great Ambience", value: 10, },
15
- { display: "Great Music", value: 9, },
16
- { display: "Great Cocktails", value: 5, },
13
+ { display: 'Logged In Once', value: 60 },
14
+ { display: 'Registered Users', value: 100 },
15
+ { display: 'Created Profile', value: 20 },
16
+ { display: 'Wrote at least 1 story', value: 8 }
17
17
  ];
18
18
  var PercentBarChart_ = function (args) {
19
19
  var handleBarClick = function (name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oolib",
3
- "version": "2.136.0",
3
+ "version": "2.136.1",
4
4
  "description": " OKE Component Library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",