@widergy/utilitygo-smart-bill-web 1.10.1 → 1.13.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/components/BarChart/index.js +1 -1
  3. package/dist/components/BillCalculation/components/Glossary/index.js +133 -0
  4. package/dist/components/BillCalculation/components/Glossary/styles.module.scss +53 -0
  5. package/dist/components/BillCalculation/index.js +22 -4
  6. package/dist/components/BillCalculation/styles.module.scss +2 -1
  7. package/dist/components/BillCalculation/utils.js +16 -2
  8. package/dist/components/BillSummary/components/BilledConcepts/index.js +1 -1
  9. package/dist/components/BillSummary/components/BilledConcepts/utils.js +2 -2
  10. package/dist/components/BillSummary/index.js +1 -1
  11. package/dist/components/ConsumptionComparison/index.js +1 -1
  12. package/dist/components/ConsumptionEnergyDetails/components/ConsumptionEnergyComparison/index.js +1 -1
  13. package/dist/components/ConsumptionEnergyDetails/components/EnergyTotalConsumption/index.js +1 -1
  14. package/dist/components/ConsumptionEnergyDetails/index.js +1 -1
  15. package/dist/components/ConsumptionIncluded/components/TimelineRow/components/Card/index.js +1 -1
  16. package/dist/components/ConsumptionIncluded/components/TimelineRow/index.js +1 -1
  17. package/dist/components/ConsumptionIncluded/index.js +1 -1
  18. package/dist/components/ConsumptionPeriod/components/HistoryGraph/index.js +1 -1
  19. package/dist/components/MainBillData/components/BillAlert/index.js +1 -1
  20. package/dist/components/MainBillData/components/BillBody/index.js +1 -1
  21. package/dist/components/Period/index.js +1 -1
  22. package/dist/components/PowerProgresBar/index.js +1 -1
  23. package/dist/components/RateAndCategory/index.js +1 -1
  24. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Indicator/index.js +8 -11
  25. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Indicator/styles.module.scss +1 -4
  26. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Indicator/utils.js +4 -49
  27. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Legend/index.js +50 -0
  28. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Legend/styles.module.scss +34 -0
  29. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Stages/index.js +65 -0
  30. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Stages/styles.module.scss +88 -0
  31. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/constants.js +6 -37
  32. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/index.js +21 -6
  33. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/styles.module.scss +4 -1
  34. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/utils.js +68 -31
  35. package/dist/components/RatesDefinition/components/CategoryByConsumption/constants.js +42 -0
  36. package/dist/components/RatesDefinition/components/CategoryByConsumption/index.js +4 -13
  37. package/dist/components/RatesDefinition/components/CategoryByConsumption/utils.js +16 -0
  38. package/dist/components/SmartBillProvider/index.js +3 -3
  39. package/dist/components/WithContextApi/index.js +2 -2
  40. package/dist/index.js +1 -1
  41. package/dist/shared/constants/aliases.js +9 -4
  42. package/dist/shared/types/componentsTypes.js +2 -2
  43. package/dist/shared/types/rateStagesTypes.js +1 -1
  44. package/dist/shared/types/smartBillTypes.js +2 -2
  45. package/dist/shared/utils/context.js +1 -1
  46. package/dist/utils/hooks.js +5 -76
  47. package/package.json +2 -1
  48. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Bars/components/Stage/components/LimitsLine/index.js +0 -23
  49. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Bars/components/Stage/components/LimitsLine/styles.module.scss +0 -15
  50. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Bars/components/Stage/components/SubStage/index.js +0 -63
  51. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Bars/components/Stage/components/SubStage/styles.module.scss +0 -5
  52. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Bars/components/Stage/components/SubStage/utils.js +0 -14
  53. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Bars/components/Stage/index.js +0 -68
  54. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Bars/components/Stage/styles.module.scss +0 -32
  55. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Bars/index.js +0 -59
  56. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/Bars/styles.module.scss +0 -3
  57. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/LegendItem/index.js +0 -80
  58. package/dist/components/RatesDefinition/components/CategoryByConsumption/components/RateStagesGraph/components/LegendItem/styles.module.scss +0 -57
@@ -3,35 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getIndicatorPosition = void 0;
6
+ exports.getLabelOffset = void 0;
7
7
 
8
- var _constants = require("../../constants");
8
+ var _constants = require("../../../../constants");
9
9
 
10
- var _utils = require("../../utils");
11
-
12
- var getStageWidth = function getStageWidth(totalStages, isDesktop) {
13
- var barsMargin = isDesktop ? _constants.BARS_MARGIN_DESKTOP : _constants.BARS_MARGIN_MOBILE;
14
- var stageMargin = isDesktop ? _constants.STAGE_MARGIN_DESKTOP : _constants.STAGE_MARGIN_MOBILE;
15
- return "(100% - 2 * ".concat(barsMargin, " - ").concat(totalStages - 1, " * ").concat(stageMargin, ") / ").concat(totalStages);
16
- };
17
-
18
- var stagePosition = function stagePosition(value, rateStages, isDesktop) {
19
- var stageMargin = isDesktop ? _constants.STAGE_MARGIN_DESKTOP : _constants.STAGE_MARGIN_MOBILE;
20
- var exceededStages = rateStages.filter(function (stage) {
21
- return stage.range[_constants.MAX_VALUE] !== _constants.INFINITE && stage.range[_constants.MAX_VALUE] < value;
22
- }).length;
23
- var totalStages = rateStages.length;
24
- var marginsCorrection = "".concat(exceededStages, " * ").concat(stageMargin);
25
- return "".concat(getStageWidth(totalStages, isDesktop), " * ").concat(exceededStages, " + ").concat(marginsCorrection);
26
- };
27
-
28
- var subStagePosition = function subStagePosition(value, rateStages, isDesktop) {
29
- var totalStages = rateStages.length;
30
- var currentStage = (0, _utils.getCurrentStage)(value, rateStages);
31
- var currentStageRangeWidth = (0, _utils.getStageRangeWidth)(currentStage);
32
- var deltaFromStageInit = value - currentStage.range[_constants.MIN_VALUE] <= currentStageRangeWidth ? value - currentStage.range[_constants.MIN_VALUE] : currentStageRangeWidth;
33
- return "".concat(getStageWidth(totalStages, isDesktop), " * ").concat(deltaFromStageInit, " / ").concat(currentStageRangeWidth);
34
- };
10
+ var _utils = require("../../../../utils");
35
11
 
36
12
  var relativePorcentageValue = function relativePorcentageValue(value, rateStages) {
37
13
  var globalLastSubRate = rateStages.at(-1).sub_rate_stages.at(-1).range;
@@ -50,25 +26,4 @@ var getLabelOffset = function getLabelOffset(value, rateStages) {
50
26
  return isLastRate ? "calc(-".concat(baseOffset, " + ").concat(_constants.INDICATOR_LABEL_LAST_OFFSET, ")") : isFirstRate ? "calc(-".concat(baseOffset, " - ").concat(_constants.INDICATOR_LABEL_FIRST_OFFSET, ")") : _constants.INDICATOR_LABEL_DEFAULT_OFFSET;
51
27
  };
52
28
 
53
- var subStagePositionRounded = function subStagePositionRounded(value, rateStages) {
54
- var roundedVal = Math.round(value);
55
- var currentStage = (0, _utils.getCurrentStage)(value, rateStages);
56
-
57
- var findRange = function findRange(_ref) {
58
- var range = _ref.range;
59
- return roundedVal >= range[0] && (!range[1] || roundedVal <= range[1]);
60
- };
61
-
62
- var currentSubstageIndex = currentStage.sub_rate_stages.findIndex(findRange);
63
- var stageWidth = getStageWidth(rateStages.length, false);
64
- return "".concat(stageWidth, " * ").concat((currentSubstageIndex + 0.5) / currentStage.sub_rate_stages.length);
65
- };
66
-
67
- var getIndicatorPosition = function getIndicatorPosition(value, rateStages, isDesktop) {
68
- return {
69
- containerLeft: "calc(".concat(isDesktop ? _constants.INITIAL_INDICATOR_POSITION_DESKTOP : _constants.INITIAL_INDICATOR_POSITION_MOBILE, " + ").concat(stagePosition(value, rateStages, isDesktop), " + ").concat(isDesktop ? subStagePosition(value, rateStages, isDesktop) : subStagePositionRounded(value, rateStages), ")"),
70
- labelOffset: getLabelOffset(value, rateStages)
71
- };
72
- };
73
-
74
- exports.getIndicatorPosition = getIndicatorPosition;
29
+ exports.getLabelOffset = getLabelOffset;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _propTypes = require("prop-types");
11
+
12
+ var _WithContextApi = _interopRequireDefault(require("../../../../../../../WithContextApi"));
13
+
14
+ var _smartBillTypes = require("../../../../../../../../shared/types/smartBillTypes");
15
+
16
+ var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ var Legend = function Legend(_ref) {
21
+ var stagesFormattedData = _ref.stagesFormattedData,
22
+ contextApiInfo = _ref.contextApiInfo;
23
+ var Label = contextApiInfo.Label,
24
+ config = contextApiInfo.config;
25
+ var texts = config.texts;
26
+ return /*#__PURE__*/_react.default.createElement("div", {
27
+ className: _stylesModule.default.legendContainer
28
+ }, stagesFormattedData.map(function (stage) {
29
+ return stage.sub_rate_stages.map(function (substage) {
30
+ return /*#__PURE__*/_react.default.createElement("div", {
31
+ className: _stylesModule.default.legendLine
32
+ }, /*#__PURE__*/_react.default.createElement("div", {
33
+ className: _stylesModule.default.leftLabels
34
+ }, /*#__PURE__*/_react.default.createElement(Label, {
35
+ className: _stylesModule.default.name
36
+ }, substage.name), /*#__PURE__*/_react.default.createElement(Label, null, substage.i === 0 ? texts.ratesDefinition.consumptionUpToDesktop : texts.ratesDefinition.consumptionMoreThanDesktop)), /*#__PURE__*/_react.default.createElement(Label, {
37
+ className: _stylesModule.default.legendValue
38
+ }, substage.legend));
39
+ });
40
+ }));
41
+ };
42
+
43
+ Legend.propTypes = {
44
+ contextApiInfo: _smartBillTypes.contextApiInfoTypes,
45
+ stagesFormattedData: (0, _propTypes.arrayOf)(_propTypes.any)
46
+ };
47
+
48
+ var _default = (0, _WithContextApi.default)()(Legend);
49
+
50
+ exports.default = _default;
@@ -0,0 +1,34 @@
1
+ @import '../../../../../../../../scss/variables/_colorsExport.scss';
2
+ @import '../../../../../../../../scss/variables/_mediaQueries';
3
+
4
+ .legendContainer {
5
+ display: flex;
6
+ flex-direction: column;
7
+ border-top: 1px solid $borders-gray;
8
+
9
+ :last-child {
10
+ margin-bottom: 0;
11
+ }
12
+ }
13
+
14
+ .legendLine {
15
+ display: flex;
16
+ justify-content: space-between;
17
+ margin-bottom: 16px;
18
+ }
19
+
20
+ .leftLabels {
21
+ display: flex;
22
+
23
+ :first-child {
24
+ margin-right: 4px;
25
+ }
26
+ }
27
+
28
+ .name {
29
+ font-weight: 500;
30
+ }
31
+
32
+ .legendValue {
33
+ font-weight: 500;
34
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _propTypes = require("prop-types");
11
+
12
+ var _WithContextApi = _interopRequireDefault(require("../../../../../../../WithContextApi"));
13
+
14
+ var _smartBillTypes = require("../../../../../../../../shared/types/smartBillTypes");
15
+
16
+ var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ var Stages = function Stages(_ref) {
21
+ var stagesFormattedData = _ref.stagesFormattedData,
22
+ contextApiInfo = _ref.contextApiInfo;
23
+ var Label = contextApiInfo.Label;
24
+
25
+ var toFinalWidth = function toFinalWidth(val) {
26
+ return {
27
+ width: "".concat(val * 100, "%")
28
+ };
29
+ };
30
+
31
+ return /*#__PURE__*/_react.default.createElement("div", {
32
+ className: _stylesModule.default.stagesContainer
33
+ }, stagesFormattedData.map(function (stage) {
34
+ return /*#__PURE__*/_react.default.createElement("div", {
35
+ className: _stylesModule.default.stage,
36
+ style: toFinalWidth(stage.width, 0.2)
37
+ }, /*#__PURE__*/_react.default.createElement(Label, {
38
+ className: _stylesModule.default.group
39
+ }, stage.group), /*#__PURE__*/_react.default.createElement("div", {
40
+ className: _stylesModule.default.substagesContainer
41
+ }, stage.sub_rate_stages.map(function (substage) {
42
+ return /*#__PURE__*/_react.default.createElement("div", {
43
+ className: _stylesModule.default.substage,
44
+ style: toFinalWidth(substage.width)
45
+ }, substage.label && /*#__PURE__*/_react.default.createElement(Label, {
46
+ withoutMarkdown: true,
47
+ className: _stylesModule.default.substageValue
48
+ }, substage.label), /*#__PURE__*/_react.default.createElement("div", {
49
+ className: _stylesModule.default.substageName,
50
+ style: {
51
+ backgroundColor: substage.color
52
+ }
53
+ }, /*#__PURE__*/_react.default.createElement(Label, null, substage.name)));
54
+ })));
55
+ }));
56
+ };
57
+
58
+ Stages.propTypes = {
59
+ contextApiInfo: _smartBillTypes.contextApiInfoTypes,
60
+ stagesFormattedData: (0, _propTypes.arrayOf)(_propTypes.any)
61
+ };
62
+
63
+ var _default = (0, _WithContextApi.default)()(Stages);
64
+
65
+ exports.default = _default;
@@ -0,0 +1,88 @@
1
+ @import '../../../../../../../../scss/variables/_colorsExport.scss';
2
+ @import '../../../../../../../../scss/variables/_mediaQueries';
3
+
4
+ $substage-spacing: 4px;
5
+ $substage-spacing-responsive: 2px;
6
+
7
+ .stage {
8
+ padding-right: $substage-spacing;
9
+
10
+ @media #{$tablet-mobile} {
11
+ padding-right: $substage-spacing-responsive;
12
+ }
13
+ }
14
+
15
+ .group {
16
+ background-color: $light-gray;
17
+ font-weight: 500;
18
+ margin-bottom: 8px;
19
+ padding: 8px;
20
+ text-align: center;
21
+ white-space: nowrap;
22
+
23
+ @media #{$mobile} {
24
+ font-size: 12px;
25
+ }
26
+
27
+ @media #{$desktop} {
28
+ margin-bottom: 0;
29
+ }
30
+ }
31
+
32
+ .stagesContainer {
33
+ display: flex;
34
+ flex-direction: row;
35
+ padding-bottom: 32px;
36
+
37
+ > :last-child {
38
+ padding-right: 0;
39
+ }
40
+
41
+ @media #{$mobile} {
42
+ padding-bottom: 16px !important;
43
+ }
44
+ }
45
+
46
+ .substagesContainer {
47
+ align-items: flex-end;
48
+ display: flex;
49
+
50
+ :last-child {
51
+ margin-right: 0;
52
+ }
53
+ }
54
+
55
+ .substage {
56
+ margin-right: $substage-spacing;
57
+
58
+ @media #{$tablet-mobile} {
59
+ margin-right: $substage-spacing-responsive;
60
+ }
61
+ }
62
+
63
+ .substageValue {
64
+ color: $gray;
65
+ display: flex;
66
+ font-family: 'Swiss';
67
+ font-size: 13px;
68
+ font-weight: 500;
69
+ justify-content: center;
70
+ padding: 12px 0;
71
+ text-align: center;
72
+ width: 100%;
73
+ }
74
+
75
+ .substageName {
76
+ align-items: center;
77
+ display: flex;
78
+ height: 32px;
79
+ justify-content: center;
80
+
81
+ :first-child {
82
+ font-weight: 500;
83
+
84
+ @media #{$mobile} {
85
+ font-size: 13px;
86
+ }
87
+ }
88
+ }
@@ -3,40 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.SUB_STAGE_MARGIN_MOBILE = exports.SUB_STAGE_MARGIN_DESKTOP = exports.STAGE_MARGIN_MOBILE = exports.STAGE_MARGIN_DESKTOP = exports.MIN_VALUE = exports.MAX_VALUE = exports.MAX_RANGE_LIMIT = exports.LAST_SUB_STAGE_MARGIN = exports.LAST_STAGE_MARGIN = exports.INITIAL_INDICATOR_POSITION_MOBILE = exports.INITIAL_INDICATOR_POSITION_DESKTOP = exports.INFINITE = exports.INDICATOR_LABEL_LAST_OFFSET = exports.INDICATOR_LABEL_FIRST_OFFSET = exports.INDICATOR_LABEL_DEFAULT_OFFSET = exports.DEFAULT_INFINITE_SUB_STAGE_RANGE_WIDTH = exports.BARS_MARGIN_MOBILE = exports.BARS_MARGIN_DESKTOP = void 0;
7
- var INFINITE = null;
8
- exports.INFINITE = INFINITE;
9
- var MAX_VALUE = 1;
10
- exports.MAX_VALUE = MAX_VALUE;
11
- var MIN_VALUE = 0;
12
- exports.MIN_VALUE = MIN_VALUE;
13
- var MAX_RANGE_LIMIT = 9999999;
14
- exports.MAX_RANGE_LIMIT = MAX_RANGE_LIMIT;
15
- var DEFAULT_INFINITE_SUB_STAGE_RANGE_WIDTH = 200;
16
- exports.DEFAULT_INFINITE_SUB_STAGE_RANGE_WIDTH = DEFAULT_INFINITE_SUB_STAGE_RANGE_WIDTH;
17
- var INITIAL_INDICATOR_POSITION_DESKTOP = '-4px';
18
- exports.INITIAL_INDICATOR_POSITION_DESKTOP = INITIAL_INDICATOR_POSITION_DESKTOP;
19
- var INITIAL_INDICATOR_POSITION_MOBILE = '-4px';
20
- exports.INITIAL_INDICATOR_POSITION_MOBILE = INITIAL_INDICATOR_POSITION_MOBILE;
21
- var BARS_MARGIN_DESKTOP = '0px';
22
- exports.BARS_MARGIN_DESKTOP = BARS_MARGIN_DESKTOP;
23
- var BARS_MARGIN_MOBILE = '0px';
24
- exports.BARS_MARGIN_MOBILE = BARS_MARGIN_MOBILE;
25
- var LAST_STAGE_MARGIN = '0px';
26
- exports.LAST_STAGE_MARGIN = LAST_STAGE_MARGIN;
27
- var STAGE_MARGIN_DESKTOP = '4px';
28
- exports.STAGE_MARGIN_DESKTOP = STAGE_MARGIN_DESKTOP;
29
- var STAGE_MARGIN_MOBILE = '2px';
30
- exports.STAGE_MARGIN_MOBILE = STAGE_MARGIN_MOBILE;
31
- var SUB_STAGE_MARGIN_DESKTOP = '4px';
32
- exports.SUB_STAGE_MARGIN_DESKTOP = SUB_STAGE_MARGIN_DESKTOP;
33
- var SUB_STAGE_MARGIN_MOBILE = '2px';
34
- exports.SUB_STAGE_MARGIN_MOBILE = SUB_STAGE_MARGIN_MOBILE;
35
- var LAST_SUB_STAGE_MARGIN = '0px';
36
- exports.LAST_SUB_STAGE_MARGIN = LAST_SUB_STAGE_MARGIN;
37
- var INDICATOR_LABEL_FIRST_OFFSET = '0px';
38
- exports.INDICATOR_LABEL_FIRST_OFFSET = INDICATOR_LABEL_FIRST_OFFSET;
39
- var INDICATOR_LABEL_LAST_OFFSET = '16px';
40
- exports.INDICATOR_LABEL_LAST_OFFSET = INDICATOR_LABEL_LAST_OFFSET;
41
- var INDICATOR_LABEL_DEFAULT_OFFSET = '-48px';
42
- exports.INDICATOR_LABEL_DEFAULT_OFFSET = INDICATOR_LABEL_DEFAULT_OFFSET;
6
+ exports.MIN_STAGE_WIDTH = exports.DEFAULT_LAST_INFINITE_RANGE = void 0;
7
+ var DEFAULT_LAST_INFINITE_RANGE = 200; // kWh
8
+
9
+ exports.DEFAULT_LAST_INFINITE_RANGE = DEFAULT_LAST_INFINITE_RANGE;
10
+ var MIN_STAGE_WIDTH = 0.2;
11
+ exports.MIN_STAGE_WIDTH = MIN_STAGE_WIDTH;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -17,12 +17,16 @@ var _rateStagesTypes = require("../../../../../../shared/types/rateStagesTypes")
17
17
 
18
18
  var _deviceSizes = require("../../../../../../constants/deviceSizes");
19
19
 
20
- var _Bars = _interopRequireDefault(require("./components/Bars"));
20
+ var _Stages = _interopRequireDefault(require("./components/Stages"));
21
21
 
22
22
  var _Indicator = _interopRequireDefault(require("./components/Indicator"));
23
23
 
24
24
  var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
25
25
 
26
+ var _utils = require("./utils");
27
+
28
+ var _Legend = _interopRequireDefault(require("./components/Legend"));
29
+
26
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
31
 
28
32
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -44,7 +48,8 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
44
48
  var RateStagesGraph = function RateStagesGraph(_ref) {
45
49
  var value = _ref.value,
46
50
  unit = _ref.unit,
47
- rateStages = _ref.rateStages;
51
+ rateStages = _ref.rateStages,
52
+ getStageColor = _ref.getStageColor;
48
53
 
49
54
  var _useState = (0, _react.useState)((0, _browser.isDesktop)(_deviceSizes.TabletBreakpoint)),
50
55
  _useState2 = _slicedToArray(_useState, 2),
@@ -62,22 +67,32 @@ var RateStagesGraph = function RateStagesGraph(_ref) {
62
67
  return window.removeEventListener(_browser.RESIZE_EVENT, handleResizeScreen);
63
68
  };
64
69
  }, []);
70
+
71
+ var _useMemo = (0, _react.useMemo)(function () {
72
+ return (0, _utils.getStagesFormattedData)(value, rateStages, getStageColor, isDesktopSize);
73
+ }, [isDesktopSize, value, rateStages, getStageColor]),
74
+ stagesFormattedData = _useMemo.stagesFormattedData,
75
+ indicatorPosition = _useMemo.indicatorPosition;
76
+
65
77
  return /*#__PURE__*/_react.default.createElement("div", {
66
78
  className: _stylesModule.default.container
67
- }, /*#__PURE__*/_react.default.createElement(_Bars.default, {
68
- rateStages: rateStages,
69
- isDesktop: isDesktopSize
79
+ }, /*#__PURE__*/_react.default.createElement(_Stages.default, {
80
+ stagesFormattedData: stagesFormattedData
70
81
  }), /*#__PURE__*/_react.default.createElement(_Indicator.default, {
82
+ indicatorPosition: indicatorPosition,
71
83
  value: value,
72
84
  unit: unit,
73
85
  rateStages: rateStages,
74
86
  isDesktop: isDesktopSize
87
+ }), !isDesktopSize && /*#__PURE__*/_react.default.createElement(_Legend.default, {
88
+ stagesFormattedData: stagesFormattedData
75
89
  }));
76
90
  };
77
91
 
78
92
  RateStagesGraph.propTypes = {
79
93
  value: _propTypes.number,
80
94
  unit: _propTypes.string,
95
+ getStageColor: _propTypes.func,
81
96
  rateStages: _rateStagesTypes.rateStagesTypes
82
97
  };
83
98
  var _default = RateStagesGraph;
@@ -6,7 +6,10 @@
6
6
  display: flex;
7
7
  flex-flow: column;
8
8
  width: 100%;
9
- padding: $default-container-padding;
9
+
10
+ > * {
11
+ padding: $default-container-padding;
12
+ }
10
13
 
11
14
  @media #{$tablet-mobile} {
12
15
  width: 100%;
@@ -3,47 +3,84 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getSubStageRangeWidth = exports.getStageRangeWidth = exports.getCurrentStage = void 0;
6
+ exports.getStagesFormattedData = void 0;
7
+
8
+ var _lodash = _interopRequireDefault(require("lodash"));
7
9
 
8
10
  var _constants = require("./constants");
9
11
 
10
- var normalizeRange = function normalizeRange(range) {
11
- return range.map(function (val) {
12
- return typeof val === 'string' ? parseInt(val, 10) : val;
13
- });
14
- };
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
13
 
16
- var isInfinite = function isInfinite(range) {
17
- return range[_constants.MAX_VALUE] === _constants.INFINITE || range[_constants.MAX_VALUE] >= _constants.MAX_RANGE_LIMIT;
18
- };
14
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
15
 
20
- var getCurrentStage = function getCurrentStage(value, rateStages) {
21
- return rateStages.find(function (stage) {
22
- return stage.range[_constants.MIN_VALUE] <= value && (value <= stage.range[_constants.MAX_VALUE] || stage.range[_constants.MAX_VALUE] === _constants.INFINITE);
23
- });
24
- };
16
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
17
 
26
- exports.getCurrentStage = getCurrentStage;
18
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
19
 
28
- var getSubStageRangeWidth = function getSubStageRangeWidth(subStage) {
29
- var range = subStage.range;
30
- range = normalizeRange(range);
31
- return isInfinite(range) || !range[_constants.MAX_VALUE] ? _constants.DEFAULT_INFINITE_SUB_STAGE_RANGE_WIDTH : range[_constants.MAX_VALUE] - range[_constants.MIN_VALUE];
32
- };
20
+ var getResponsiveStageWidth = function getResponsiveStageWidth(rateStages, stage, totalSubStages) {
21
+ var totalWidth = 1; // if we have only one rate, then return max width.
22
+
23
+ if (rateStages.length === 1) {
24
+ return totalWidth;
25
+ } // We sort the stages based in sub stages in cases that former stages are larger than later ones.
33
26
 
34
- exports.getSubStageRangeWidth = getSubStageRangeWidth;
35
27
 
36
- var getStageRangeWidth = function getStageRangeWidth(stage) {
37
- var range = stage.range;
38
- range = normalizeRange(range);
28
+ var sortedRateStages = _lodash.default.sortBy(rateStages, function (_stage) {
29
+ return _stage.sub_rate_stages.length;
30
+ }); // Iterate over the sorted array until finished.
39
31
 
40
- if (isInfinite(range) || !range[_constants.MAX_VALUE]) {
41
- return stage.sub_rate_stages.reduce(function (totalWidth, subStage) {
42
- return totalWidth + getSubStageRangeWidth(subStage);
43
- }, 0);
44
- }
45
32
 
46
- return range[_constants.MAX_VALUE] - range[_constants.MIN_VALUE];
33
+ for (var index = 0; index < sortedRateStages.length; index += 1) {
34
+ // If we reached our stage then we break, we need to know the space former ones ocuppy and not the laters.
35
+ if (sortedRateStages[index].group === stage.group) {
36
+ break;
37
+ }
38
+
39
+ var currentSubStages = sortedRateStages[index].sub_rate_stages.length; // Maximum a stage can ocuppy (since minimum is MIN_STAGE_WIDTH), is MIN_STAGE_WIDTH times the other stages.
40
+
41
+ var width = Math.min(Math.max(currentSubStages / totalSubStages, _constants.MIN_STAGE_WIDTH), _constants.MIN_STAGE_WIDTH * rateStages.length);
42
+ totalWidth -= width;
43
+ } // Final width will be the minimum value between the calculated width and the total width left.
44
+
45
+
46
+ return Math.min(Math.max(stage.sub_rate_stages.length / totalSubStages, _constants.MIN_STAGE_WIDTH), totalWidth);
47
+ };
48
+
49
+ var getStagesFormattedData = function getStagesFormattedData(value, rateStages, getStageColor, isDesktop) {
50
+ var totalSubstagesCount = rateStages.reduce(function (count, stage) {
51
+ return count += stage.sub_rate_stages.length;
52
+ }, 0);
53
+ var i = -1;
54
+ var stagesFormattedData = rateStages.map(function (stage) {
55
+ return _objectSpread(_objectSpread({}, stage), {}, {
56
+ width: isDesktop ? stage.sub_rate_stages.length / totalSubstagesCount : getResponsiveStageWidth(rateStages, stage, totalSubstagesCount),
57
+ sub_rate_stages: stage.sub_rate_stages.map(function (substage) {
58
+ i += 1;
59
+ var labelValue = "".concat(substage.range[i === 0 ? 1 : 0], " ").concat(stage.unit);
60
+ return _objectSpread(_objectSpread({}, substage), {}, {
61
+ i: i,
62
+ width: 1 / stage.sub_rate_stages.length,
63
+ color: substage.color || getStageColor && getStageColor(i, totalSubstagesCount),
64
+ label: isDesktop && "".concat(i === 0 ? '< ' : i === 1 ? '> ' : '').concat(labelValue),
65
+ legend: !isDesktop && labelValue
66
+ });
67
+ })
68
+ });
69
+ });
70
+ var indicatorPosition = 0;
71
+ stagesFormattedData.find(function (stage) {
72
+ return stage.sub_rate_stages.find(function (substage) {
73
+ var isCurrentStage = substage.range[1] >= value;
74
+ var currentWidth = substage.width * stage.width;
75
+ var currentDeltaWidth = value - substage.range[0];
76
+ if (!isCurrentStage && substage.i === totalSubstagesCount - 1) indicatorPosition += Math.min(currentDeltaWidth / _constants.DEFAULT_LAST_INFINITE_RANGE * currentWidth, currentWidth);else if (!isCurrentStage) indicatorPosition += currentWidth;else indicatorPosition += currentDeltaWidth / (substage.range[1] - substage.range[0]) * currentWidth;
77
+ return isCurrentStage;
78
+ });
79
+ });
80
+ return {
81
+ stagesFormattedData: stagesFormattedData,
82
+ indicatorPosition: indicatorPosition
83
+ };
47
84
  };
48
85
 
49
- exports.getStageRangeWidth = getStageRangeWidth;
86
+ exports.getStagesFormattedData = getStagesFormattedData;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.THIGT_RANGE_BREAKPOINT_RATIO = exports.SUB_STAGE_MARGIN_MOBILE = exports.SUB_STAGE_MARGIN_DESKTOP = exports.STAGE_MARGIN_MOBILE = exports.STAGE_MARGIN_DESKTOP = exports.MIN_VALUE = exports.MAX_VALUE = exports.MAX_RANGE_LIMIT = exports.LAST_SUB_STAGE_MARGIN = exports.LAST_STAGE_MARGIN = exports.INITIAL_INDICATOR_POSITION = exports.INFINITE = exports.INDICATOR_LABEL_LAST_OFFSET = exports.INDICATOR_LABEL_FIRST_OFFSET = exports.INDICATOR_LABEL_DEFAULT_OFFSET = exports.DEFAULT_INFINITE_SUB_STAGE_RANGE_WIDTH = exports.BARS_MARGIN_MOBILE = exports.BARS_MARGIN_DESKTOP = void 0;
7
+ var INFINITE = null;
8
+ exports.INFINITE = INFINITE;
9
+ var MAX_VALUE = 1;
10
+ exports.MAX_VALUE = MAX_VALUE;
11
+ var MIN_VALUE = 0;
12
+ exports.MIN_VALUE = MIN_VALUE;
13
+ var MAX_RANGE_LIMIT = 9999999;
14
+ exports.MAX_RANGE_LIMIT = MAX_RANGE_LIMIT;
15
+ var DEFAULT_INFINITE_SUB_STAGE_RANGE_WIDTH = 200;
16
+ exports.DEFAULT_INFINITE_SUB_STAGE_RANGE_WIDTH = DEFAULT_INFINITE_SUB_STAGE_RANGE_WIDTH;
17
+ var INITIAL_INDICATOR_POSITION = '-6px';
18
+ exports.INITIAL_INDICATOR_POSITION = INITIAL_INDICATOR_POSITION;
19
+ var BARS_MARGIN_DESKTOP = '0px';
20
+ exports.BARS_MARGIN_DESKTOP = BARS_MARGIN_DESKTOP;
21
+ var BARS_MARGIN_MOBILE = '0px';
22
+ exports.BARS_MARGIN_MOBILE = BARS_MARGIN_MOBILE;
23
+ var LAST_STAGE_MARGIN = '0px';
24
+ exports.LAST_STAGE_MARGIN = LAST_STAGE_MARGIN;
25
+ var STAGE_MARGIN_DESKTOP = '4px';
26
+ exports.STAGE_MARGIN_DESKTOP = STAGE_MARGIN_DESKTOP;
27
+ var STAGE_MARGIN_MOBILE = '2px';
28
+ exports.STAGE_MARGIN_MOBILE = STAGE_MARGIN_MOBILE;
29
+ var SUB_STAGE_MARGIN_DESKTOP = '4px';
30
+ exports.SUB_STAGE_MARGIN_DESKTOP = SUB_STAGE_MARGIN_DESKTOP;
31
+ var SUB_STAGE_MARGIN_MOBILE = '2px';
32
+ exports.SUB_STAGE_MARGIN_MOBILE = SUB_STAGE_MARGIN_MOBILE;
33
+ var LAST_SUB_STAGE_MARGIN = '0px';
34
+ exports.LAST_SUB_STAGE_MARGIN = LAST_SUB_STAGE_MARGIN;
35
+ var INDICATOR_LABEL_FIRST_OFFSET = '0px';
36
+ exports.INDICATOR_LABEL_FIRST_OFFSET = INDICATOR_LABEL_FIRST_OFFSET;
37
+ var INDICATOR_LABEL_LAST_OFFSET = '-8px';
38
+ exports.INDICATOR_LABEL_LAST_OFFSET = INDICATOR_LABEL_LAST_OFFSET;
39
+ var INDICATOR_LABEL_DEFAULT_OFFSET = '-48px';
40
+ exports.INDICATOR_LABEL_DEFAULT_OFFSET = INDICATOR_LABEL_DEFAULT_OFFSET;
41
+ var THIGT_RANGE_BREAKPOINT_RATIO = 0.1;
42
+ exports.THIGT_RANGE_BREAKPOINT_RATIO = THIGT_RANGE_BREAKPOINT_RATIO;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -27,8 +27,6 @@ var _Category = _interopRequireDefault(require("./components/Category"));
27
27
 
28
28
  var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
29
29
 
30
- var _LegendItem = _interopRequireDefault(require("./components/RateStagesGraph/components/LegendItem"));
31
-
32
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
31
 
34
32
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -55,7 +53,8 @@ var CategoryByConsumption = function CategoryByConsumption(_ref) {
55
53
  var config = contextApiInfo.config,
56
54
  Label = contextApiInfo.Label;
57
55
  var rateStages = config.rateStages,
58
- texts = config.texts;
56
+ texts = config.texts,
57
+ getStageColor = config.getStageColor;
59
58
 
60
59
  var _useState = (0, _react.useState)((0, _browser.isDesktop)(_deviceSizes.TabletBreakpoint)),
61
60
  _useState2 = _slicedToArray(_useState, 2),
@@ -88,18 +87,10 @@ var CategoryByConsumption = function CategoryByConsumption(_ref) {
88
87
  category: category,
89
88
  wrap: true
90
89
  }), (valueCorrected === 0 || valueCorrected) && /*#__PURE__*/_react.default.createElement(_RateStagesGraph.default, {
90
+ getStageColor: getStageColor,
91
91
  value: valueCorrected,
92
92
  unit: unit,
93
93
  rateStages: rateStages
94
- })), !isDesktopSize && /*#__PURE__*/_react.default.createElement("div", {
95
- className: _stylesModule.default.ratesLegend
96
- }, rateStages.map(function (rateStage, index) {
97
- return /*#__PURE__*/_react.default.createElement(_LegendItem.default, {
98
- legendNumber: index + 1,
99
- showNumber: true,
100
- stagesLength: rateStages.length,
101
- stage: rateStage
102
- });
103
94
  })));
104
95
  };
105
96
 
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getCurrentStage = void 0;
7
+
8
+ var _constants = require("./constants");
9
+
10
+ var getCurrentStage = function getCurrentStage(value, rateStages) {
11
+ return rateStages.find(function (stage) {
12
+ return stage.range[_constants.MIN_VALUE] <= value && (value <= stage.range[_constants.MAX_VALUE] || stage.range[_constants.MAX_VALUE] === _constants.INFINITE);
13
+ });
14
+ };
15
+
16
+ exports.getCurrentStage = getCurrentStage;