oolib 2.54.0 → 2.54.2

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.
@@ -0,0 +1 @@
1
+ export function BarChart(props: any): any;
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.BarChart = void 0;
30
+ var react_1 = __importStar(require("react"));
31
+ var d3Modules_1 = __importDefault(require("../../../../d3Modules"));
32
+ var utils_1 = require("../../utils");
33
+ var testJSON_1 = require("../../../../utils/testJSON");
34
+ var getVal_1 = require("../../../../utils/getterSetterDeleter/getVal");
35
+ var themes_1 = require("../../../../themes");
36
+ var styled_components_1 = require("styled-components");
37
+ var utilsOolib_1 = require("../../../../utilsOolib");
38
+ var BarChart = function (props) {
39
+ var config = {
40
+ width: 550,
41
+ height: 100,
42
+ margin: { top: 50, right: 50, bottom: 50, left: 100 },
43
+ };
44
+ var theme = (0, styled_components_1.useTheme)();
45
+ var width = props.width || config.width;
46
+ var height = props.height || config.height;
47
+ var marginProp = (0, testJSON_1.testJSON)(props.margin)
48
+ ? JSON.parse(props.margin)
49
+ : undefined;
50
+ var margin = marginProp
51
+ ? {
52
+ top: marginProp.top || config.margin.top,
53
+ bottom: marginProp.bottom || config.margin.bottom,
54
+ left: marginProp.left || config.margin.left,
55
+ right: marginProp.right || config.margin.right,
56
+ }
57
+ : config.margin;
58
+ var data = props.data, id = props.id, className = props.className, numValuePath = props.numValuePath, categoryValuePath = props.categoryValuePath, _a = props.categoryAxis, categoryAxis = _a === void 0 ? 'y' : _a, _b = props.barWidth, barWidth = _b === void 0 ? 20 : _b, numberAxisLabel = props.numberAxisLabel, _c = props.highlight
59
+ /**
60
+ * can be 'max' or 'min' or undefined. if undefined,
61
+ * all bars will be painted the same color. if defined,
62
+ * only the max/min will be painted a color.
63
+ * rest of bars will be grey
64
+ */
65
+ , highlight = _c === void 0 ? 'max' : _c
66
+ /**
67
+ * can be 'max' or 'min' or undefined. if undefined,
68
+ * all bars will be painted the same color. if defined,
69
+ * only the max/min will be painted a color.
70
+ * rest of bars will be grey
71
+ */
72
+ ;
73
+ var wrapperId = "OKE_PiChart".concat(id ? "_" + id : "");
74
+ var wrapperClass = "OKE-PiChart ".concat(className || "");
75
+ (0, react_1.useEffect)(function () { return drawChart(data); }, [data]);
76
+ var drawChart = function (data) {
77
+ // console.log({DATA : data})
78
+ //first clear the div
79
+ d3Modules_1.default.select("#" + wrapperId + ">svg").remove();
80
+ //then draw
81
+ var svg = (0, utils_1.genResponsiveSvgCanvas)({
82
+ width: width,
83
+ height: height,
84
+ wrapperId: wrapperId,
85
+ margin: margin,
86
+ translate: "".concat(margin.left, ",").concat(margin.right)
87
+ });
88
+ // X axis
89
+ var categoryAxisGenerator = d3Modules_1.default
90
+ .scaleBand()
91
+ // .range([0, width]) alt
92
+ .range([0, height])
93
+ .domain(data.map(function (d) {
94
+ return (0, getVal_1.getVal)(d, categoryValuePath);
95
+ }))
96
+ .padding(0.2);
97
+ var categoryAxis = svg
98
+ .append("g")
99
+ //.attr("transform", "translate(0," + height + ")") //alt
100
+ .attr("transform", "translate(0, 0)")
101
+ //.call(d3.axisBottom(categoryAxis)) //alt
102
+ .call(d3Modules_1.default.axisLeft(categoryAxisGenerator));
103
+ categoryAxis.selectAll("text")
104
+ // .attr("transform", "translate(-5,0)")
105
+ .style("text-anchor", "end")
106
+ .attr("color", themes_1.colors.greyColor100);
107
+ categoryAxis.select('.domain').remove();
108
+ categoryAxis.selectAll('.tick line').remove();
109
+ // Add Y axis
110
+ var numbersAxisGenerator = d3Modules_1.default
111
+ .scaleLinear()
112
+ .domain([0, (0, utils_1.getMax)({ data: data, valuePath: numValuePath })])
113
+ // .range([height, 0]) // alt
114
+ .range([0, width]);
115
+ var numberAxisG = svg.append("g");
116
+ var numberAxis = numberAxisG
117
+ //.attr("transform", "translate(0, 0)") alt
118
+ .attr("transform", "translate(0," + height + ")") //alt
119
+ //.call(d3.axisLeft(numbersAxis)); //alt
120
+ .call(d3Modules_1.default.axisBottom(numbersAxisGenerator));
121
+ numberAxis.select('.domain').attr('stroke', themes_1.colors.greyColor40);
122
+ numberAxis.selectAll('.tick text').attr('color', themes_1.colors.greyColor70);
123
+ numberAxis.selectAll('.tick line').attr('stroke', themes_1.colors.greyColor40);
124
+ if (numberAxisLabel) {
125
+ svg.append('text')
126
+ .text(numberAxisLabel)
127
+ .attr("x", 0)
128
+ .attr("y", height + 35)
129
+ .attr('fill', themes_1.colors.greyColor100);
130
+ }
131
+ // Bars
132
+ svg
133
+ .selectAll("mybar")
134
+ .data(data)
135
+ .enter()
136
+ .append("rect")
137
+ // .attr("x", function (d) {
138
+ // return categoryAxis(getVal(d, categoryValuePath)) + 10;
139
+ // }) //alt
140
+ .attr("y", function (d) {
141
+ return categoryAxisGenerator((0, getVal_1.getVal)(d, categoryValuePath)) + (categoryAxisGenerator.bandwidth() / 2) - (barWidth / 2);
142
+ })
143
+ // .attr("y", function (d) {
144
+ // return numbersAxis(getVal(d, numValuePath));
145
+ // }) //alt
146
+ .attr("x", 0)
147
+ //.attr("width", barWidth) //alt
148
+ .attr("height", barWidth)
149
+ // .attr("height", function (d) {
150
+ // return height - numbersAxis(getVal(d, numValuePath));
151
+ // }) //alt
152
+ .attr("width", function (d) {
153
+ return numbersAxisGenerator((0, getVal_1.getVal)(d, numValuePath));
154
+ })
155
+ .attr('rx', 5)
156
+ .attr("transform", 'translateX(50%)')
157
+ .attr("fill", function (d) {
158
+ return !highlight
159
+ ? (0, utilsOolib_1.getPrimaryColor40)(theme === null || theme === void 0 ? void 0 : theme.colors)
160
+ : highlight === 'max'
161
+ ? (0, utils_1.getMax)({ data: data, valuePath: numValuePath }) === (0, getVal_1.getVal)(d, numValuePath)
162
+ ? (0, utilsOolib_1.getPrimaryColor40)(theme === null || theme === void 0 ? void 0 : theme.colors)
163
+ : themes_1.colors.greyColor15
164
+ : (0, utils_1.getMin)({ data: data, valuePath: numValuePath }) === (0, getVal_1.getVal)(d, numValuePath)
165
+ ? (0, utilsOolib_1.getPrimaryColor40)(theme === null || theme === void 0 ? void 0 : theme.colors)
166
+ : themes_1.colors.greyColor15;
167
+ });
168
+ //Bar Number Labels
169
+ svg
170
+ .selectAll("barnumlabels")
171
+ .data(data)
172
+ .enter()
173
+ .append("text")
174
+ .text(function (d) { return (0, getVal_1.getVal)(d, numValuePath); })
175
+ .attr("y", function (d) {
176
+ return categoryAxisGenerator((0, getVal_1.getVal)(d, categoryValuePath)) + (categoryAxisGenerator.bandwidth() / 2) + 4;
177
+ })
178
+ .attr("x", function (d) {
179
+ return numbersAxisGenerator((0, getVal_1.getVal)(d, numValuePath)) + 5;
180
+ });
181
+ };
182
+ return react_1.default.createElement("div", { id: wrapperId, className: wrapperClass });
183
+ };
184
+ exports.BarChart = BarChart;
@@ -0,0 +1,24 @@
1
+ export function genResponsiveSvgCanvas({ margin, width, height, wrapperId, translate }: {
2
+ margin: any;
3
+ width: any;
4
+ height: any;
5
+ wrapperId: any;
6
+ translate: any;
7
+ }): any;
8
+ export function getMinMax({ data, valuePath }: {
9
+ data: any;
10
+ valuePath: any;
11
+ }): number[];
12
+ export function getMax({ data, valuePath }: {
13
+ data: any;
14
+ valuePath: any;
15
+ }): number;
16
+ export function getMin({ data, valuePath }: {
17
+ data: any;
18
+ valuePath: any;
19
+ }): number;
20
+ export function calcSvgElemScaleFactor({ setWidth, actualWidth, setValueToScale, }: {
21
+ setWidth: any;
22
+ actualWidth: any;
23
+ setValueToScale: any;
24
+ }): number;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.calcSvgElemScaleFactor = exports.getMin = exports.getMax = exports.getMinMax = exports.genResponsiveSvgCanvas = void 0;
7
+ var d3Modules_1 = __importDefault(require("../../../d3Modules"));
8
+ var getVal_1 = require("../../../utils/getterSetterDeleter/getVal");
9
+ var genResponsiveSvgCanvas = function (_a) {
10
+ var margin = _a.margin, width = _a.width, height = _a.height, wrapperId = _a.wrapperId, translate = _a.translate;
11
+ return d3Modules_1.default
12
+ .select("#" + wrapperId)
13
+ .append("svg")
14
+ // Responsive SVG needs these 2 attributes and no width and height attr.
15
+ .attr("preserveAspectRatio", "xMinYMin meet")
16
+ .attr("viewBox", "0 0 ".concat(width + margin.left + margin.right, " ").concat(height + margin.top + margin.bottom))
17
+ .append("g")
18
+ .classed("vizCanvas", true)
19
+ .attr("transform", "translate(".concat(translate || "".concat(width / 2, ",").concat(height / 2), ")"))
20
+ .attr("font-family", "'noto_sans', 'noto_sans_devanagari', 'noto_sans_gu','noto_sans_te', 'noto_sans_kn', 'noto_sans_or', sans-serif");
21
+ };
22
+ exports.genResponsiveSvgCanvas = genResponsiveSvgCanvas;
23
+ var getOnlyNumbersAry = function (_a) {
24
+ var data = _a.data, valuePath = _a.valuePath;
25
+ return data.map(function (d) { return parseInt((0, getVal_1.getVal)(d, valuePath)); });
26
+ };
27
+ var getMinMax = function (_a) {
28
+ var data = _a.data, valuePath = _a.valuePath;
29
+ var onlyNumbers = getOnlyNumbersAry({ data: data, valuePath: valuePath });
30
+ return [Math.min.apply(Math, onlyNumbers), Math.max.apply(Math, onlyNumbers)];
31
+ };
32
+ exports.getMinMax = getMinMax;
33
+ var getMax = function (_a) {
34
+ var data = _a.data, valuePath = _a.valuePath;
35
+ var onlyNumbers = getOnlyNumbersAry({ data: data, valuePath: valuePath });
36
+ return Math.max.apply(Math, onlyNumbers);
37
+ };
38
+ exports.getMax = getMax;
39
+ var getMin = function (_a) {
40
+ var data = _a.data, valuePath = _a.valuePath;
41
+ var onlyNumbers = getOnlyNumbersAry({ data: data, valuePath: valuePath });
42
+ return Math.min.apply(Math, onlyNumbers);
43
+ };
44
+ exports.getMin = getMin;
45
+ var calcSvgElemScaleFactor = function (_a) {
46
+ var setWidth = _a.setWidth, actualWidth = _a.actualWidth, setValueToScale = _a.setValueToScale;
47
+ var scaleFactor = actualWidth / setWidth;
48
+ return setValueToScale * (1 / scaleFactor);
49
+ };
50
+ exports.calcSvgElemScaleFactor = calcSvgElemScaleFactor;
@@ -0,0 +1,29 @@
1
+ declare namespace _default {
2
+ export { line };
3
+ export { area };
4
+ export { scaleLinear };
5
+ export { scaleTime };
6
+ export { scaleBand };
7
+ export { select };
8
+ export { selectAll };
9
+ export { format };
10
+ export { pie };
11
+ export { arc };
12
+ export { curveMonotoneX };
13
+ export { timeParse };
14
+ export { extent };
15
+ export { min };
16
+ export { max };
17
+ export { bisector };
18
+ export { mouse };
19
+ export { axisBottom };
20
+ export { axisLeft };
21
+ export { axisRight };
22
+ export { axisTop };
23
+ export { geoMercator };
24
+ export { geoPath };
25
+ export { transition };
26
+ export { scaleOrdinal };
27
+ export { entries };
28
+ }
29
+ export default _default;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var d3_shape_1 = require("d3-shape");
4
+ var d3_scale_1 = require("d3-scale");
5
+ var d3_axis_1 = require("d3-axis");
6
+ var d3_time_format_1 = require("d3-time-format");
7
+ /**
8
+ * @note
9
+ * mouse is deprecated d3 6 onnwards. read : https://observablehq.com/@d3/d3v6-migration-guide#pointer
10
+ */
11
+ var d3_collection_1 = require("d3-collection");
12
+ var d3_selection_1 = require("d3-selection");
13
+ var d3_transition_1 = require("d3-transition");
14
+ var d3_array_1 = require("d3-array");
15
+ var d3_format_1 = require("d3-format");
16
+ var d3_geo_1 = require("d3-geo");
17
+ exports.default = {
18
+ line: d3_shape_1.line,
19
+ area: d3_shape_1.area,
20
+ scaleLinear: d3_scale_1.scaleLinear,
21
+ scaleTime: d3_scale_1.scaleTime,
22
+ scaleBand: d3_scale_1.scaleBand,
23
+ select: d3_selection_1.select,
24
+ selectAll: d3_selection_1.selectAll,
25
+ format: d3_format_1.format,
26
+ pie: d3_shape_1.pie,
27
+ arc: d3_shape_1.arc,
28
+ curveMonotoneX: d3_shape_1.curveMonotoneX,
29
+ timeParse: d3_time_format_1.timeParse,
30
+ extent: d3_array_1.extent,
31
+ min: d3_array_1.min,
32
+ max: d3_array_1.max,
33
+ bisector: d3_array_1.bisector,
34
+ mouse: d3_selection_1.mouse,
35
+ get event() { return d3_selection_1.event; },
36
+ axisBottom: d3_axis_1.axisBottom,
37
+ axisLeft: d3_axis_1.axisLeft,
38
+ axisRight: d3_axis_1.axisRight,
39
+ axisTop: d3_axis_1.axisTop,
40
+ geoMercator: d3_geo_1.geoMercator,
41
+ geoPath: d3_geo_1.geoPath,
42
+ transition: d3_transition_1.transition,
43
+ scaleOrdinal: d3_scale_1.scaleOrdinal,
44
+ entries: d3_collection_1.entries
45
+ };
package/dist/index.d.ts CHANGED
@@ -35,5 +35,6 @@ export { HomeCover } from "./components/HomeCover";
35
35
  export { PageScrollIndicator } from "./components/PageScrollIndicator";
36
36
  export { default as DatePicker } from "./components/DatePicker";
37
37
  export { default as DateRangePicker } from "./components/DateRangePicker";
38
+ export { BarChart } from "./components/dataViz/comps/BarChart";
38
39
  export { HintsProvider } from "./components/Hints/contextApi";
39
40
  export { LoaderCircle, ProgressBar, LoaderCircle as Loader, LoaderOverlay } from "./components/LoadersAndProgress";
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.HintsProvider = exports.DateRangePicker = exports.DatePicker = exports.PageScrollIndicator = exports.HomeCover = exports.EmptyStates = exports.ModalSmall = exports.ModalLarge = exports.ModalConfirm = exports.SkeletonLoader = exports.Divider = exports.PercentCompletedPie = exports.Accordion = exports.ActionMenu = exports.Tooltip = exports.OKELink = exports.UserRoleBadge = exports.Section = exports.LoaderOverlay = exports.Loader = exports.ProgressBar = exports.LoaderCircle = exports.icons = exports.colors = exports.GlobalStyles = void 0;
20
+ exports.HintsProvider = exports.BarChart = exports.DateRangePicker = exports.DatePicker = exports.PageScrollIndicator = exports.HomeCover = exports.EmptyStates = exports.ModalSmall = exports.ModalLarge = exports.ModalConfirm = exports.SkeletonLoader = exports.Divider = exports.PercentCompletedPie = exports.Accordion = exports.ActionMenu = exports.Tooltip = exports.OKELink = exports.UserRoleBadge = exports.Section = exports.LoaderOverlay = exports.Loader = exports.ProgressBar = exports.LoaderCircle = exports.icons = exports.colors = exports.GlobalStyles = void 0;
21
21
  //css and styling related ( styled-components )
22
22
  var globalStyles_1 = require("./globalStyles");
23
23
  Object.defineProperty(exports, "GlobalStyles", { enumerable: true, get: function () { return globalStyles_1.GlobalStyles; } });
@@ -83,6 +83,8 @@ var DatePicker_1 = require("./components/DatePicker");
83
83
  Object.defineProperty(exports, "DatePicker", { enumerable: true, get: function () { return __importDefault(DatePicker_1).default; } });
84
84
  var DateRangePicker_1 = require("./components/DateRangePicker");
85
85
  Object.defineProperty(exports, "DateRangePicker", { enumerable: true, get: function () { return __importDefault(DateRangePicker_1).default; } });
86
+ var BarChart_1 = require("./components/dataViz/comps/BarChart");
87
+ Object.defineProperty(exports, "BarChart", { enumerable: true, get: function () { return BarChart_1.BarChart; } });
86
88
  //// context
87
89
  var contextApi_1 = require("./components/Hints/contextApi");
88
90
  Object.defineProperty(exports, "HintsProvider", { enumerable: true, get: function () { return contextApi_1.HintsProvider; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oolib",
3
- "version": "2.54.0",
3
+ "version": "2.54.2",
4
4
  "description": " OKE Component Library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",