@aclymatepackages/modules 1.0.20 → 1.0.21

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.
@@ -120,7 +120,7 @@ const LabeledEmissionsChart = _ref8 => {
120
120
  displayUnitLabel,
121
121
  chartArray,
122
122
  aspect = 3,
123
- showTooltip = true
123
+ showTooltip
124
124
  } = _ref8;
125
125
  const {
126
126
  palette
@@ -198,7 +198,7 @@ const EmissionsChart = _ref10 => {
198
198
  unitConverter,
199
199
  aspect,
200
200
  isPercentageChart,
201
- showTooltip,
201
+ showTooltip = true,
202
202
  startDate,
203
203
  convertCarbonUnits,
204
204
  displayUnitLabel,
@@ -61,7 +61,8 @@ const EmissionsPieChart = _ref2 => {
61
61
  dataArray: emissions,
62
62
  viewMode = "subcategories",
63
63
  pieChartRef,
64
- branding
64
+ branding,
65
+ showTooltip = true
65
66
  } = _ref2;
66
67
  const subcategoriesArray = (0, _subcategories.buildSubcategoriesArray)(emissions);
67
68
  const scopesArray = (0, _subcategories.buildScopesWithColors)(branding);
@@ -118,7 +119,7 @@ const EmissionsPieChart = _ref2 => {
118
119
  name: name,
119
120
  fill: color
120
121
  });
121
- })), /*#__PURE__*/_react.default.createElement(_recharts.Tooltip, {
122
+ })), showTooltip && /*#__PURE__*/_react.default.createElement(_recharts.Tooltip, {
122
123
  wrapperStyle: {
123
124
  zIndex: 99
124
125
  },
@@ -9,7 +9,7 @@ var _material = require("@mui/material");
9
9
  var _atoms = require("@aclymatepackages/atoms");
10
10
  var _otherHelpers = require("@aclymatepackages/other-helpers");
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- const EmissionsSummarySentence = _ref => {
12
+ const EmissionsScopeSummarySentence = _ref => {
13
13
  let {
14
14
  label,
15
15
  emissions,
@@ -25,7 +25,9 @@ const EmissionsSummarySentence = _ref => {
25
25
  item: true
26
26
  }, /*#__PURE__*/_react.default.createElement(_atoms.CategoriesAvatar, {
27
27
  scope: scope,
28
- color: color
28
+ color: color,
29
+ viewMode: "scopes",
30
+ size: "small"
29
31
  })), /*#__PURE__*/_react.default.createElement(_material.Grid, {
30
32
  item: true
31
33
  }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
@@ -35,4 +37,4 @@ const EmissionsSummarySentence = _ref => {
35
37
  emissions
36
38
  }))));
37
39
  };
38
- var _default = exports.default = EmissionsSummarySentence;
40
+ var _default = exports.default = EmissionsScopeSummarySentence;
@@ -18,7 +18,8 @@ const ReportGraphContentLayout = _ref => {
18
18
  interval = "quarter",
19
19
  isPercentageChart,
20
20
  height,
21
- scopes
21
+ branding,
22
+ showTooltip
22
23
  } = _ref;
23
24
  return /*#__PURE__*/_react.default.createElement(_material.Box, {
24
25
  p: 2,
@@ -53,8 +54,8 @@ const ReportGraphContentLayout = _ref => {
53
54
  unitConverter: tons => tons,
54
55
  aspect: 2,
55
56
  isPercentageChart: isPercentageChart,
56
- showTooltip: false,
57
- scopes: scopes
57
+ showTooltip: showTooltip,
58
+ branding: branding
58
59
  }))));
59
60
  };
60
61
  var _default = exports.default = ReportGraphContentLayout;
@@ -1,234 +1,65 @@
1
1
  "use strict";
2
2
 
3
- require("core-js/modules/es.symbol.description.js");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = void 0;
8
- require("core-js/modules/es.regexp.exec.js");
9
- require("core-js/modules/es.string.match.js");
10
7
  require("core-js/modules/web.dom-collections.iterator.js");
11
- require("core-js/modules/es.regexp.to-string.js");
12
- require("core-js/modules/es.array.sort.js");
8
+ require("core-js/modules/es.symbol.description.js");
13
9
  var _react = _interopRequireDefault(require("react"));
14
10
  var _material = require("@mui/material");
15
11
  var _otherHelpers = require("@aclymatepackages/other-helpers");
16
12
  var _emissionsCalcs = require("@aclymatepackages/emissions-calcs");
17
- var _converters = require("@aclymatepackages/converters");
18
- var _themes = _interopRequireDefault(require("@aclymatepackages/themes"));
19
13
  var _subcategories = require("@aclymatepackages/subcategories");
14
+ var _ReportGraphContentLayout = _interopRequireDefault(require("./ReportGraphContentLayout"));
15
+ var _EmissionsPieChart = _interopRequireDefault(require("./EmissionsPieChart"));
16
+ var _EmissionsSummarySentence = _interopRequireDefault(require("./EmissionsSummarySentence"));
20
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
18
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
19
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
20
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
21
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
25
22
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
26
- // import ReportGraphContentLayout from "./ReportGraphContentLayout";
27
- // import EmissionsPieChart from "./EmissionsPieChart";
28
- // import EmissionsSummarySentence from "./EmissionsSummarySentence";
29
-
30
- const adjustHexColorHue = function adjustHexColorHue(hexColor) {
31
- let hueChange = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 20;
32
- const rgbaColor = (0, _converters.hexToRgba)(hexColor);
33
- const extractColorValueFromString = color => color.match(/\d+/g).map(value => Number(value));
34
-
35
- //This function was assisted by Chat GPT
36
- const rgbaToHslParams = () => {
37
- const [r, g, b] = extractColorValueFromString(rgbaColor);
38
- const rFraction = r / 255;
39
- const gFraction = g / 255;
40
- const bFraction = b / 255;
41
- const fractionsArray = [rFraction, gFraction, bFraction];
42
- const maxValue = Math.max(...fractionsArray);
43
- const minValue = Math.min(...fractionsArray);
44
- const luminance = (maxValue + minValue) / 2;
45
- const maxMinDelta = maxValue - minValue;
46
- const calcSaturationValue = () => {
47
- if (maxValue === minValue) {
48
- return 0;
49
- }
50
- if (luminance > 0.5) {
51
- return maxMinDelta / (2 - maxValue - minValue);
52
- }
53
- return maxMinDelta / (maxValue + minValue);
54
- };
55
- const saturation = calcSaturationValue();
56
- const calcHueValue = () => {
57
- if (maxValue === minValue) {
58
- return 0;
59
- }
60
- if (maxValue === rFraction) {
61
- return (gFraction - bFraction) / maxMinDelta + (gFraction < bFraction ? 6 : 0);
62
- }
63
- if (maxValue === gFraction) {
64
- return (bFraction - rFraction) / maxMinDelta + 2;
65
- }
66
- return (rFraction - gFraction) / maxMinDelta + 4;
67
- };
68
- const hue = Math.round(calcHueValue() * 60) % 360;
69
- return {
70
- hue,
71
- saturation: Math.round(saturation * 100),
72
- luminance: Math.round(luminance * 100)
73
- };
74
- };
75
- const {
76
- hue,
77
- saturation,
78
- luminance
79
- } = rgbaToHslParams();
80
- const adjustHue = () => {
81
- const adjustedHue = hue + hueChange;
82
- if (adjustedHue < 360) {
83
- return adjustedHue;
84
- }
85
- return adjustedHue - 360;
86
- };
87
- const adjustedHue = adjustHue();
88
-
89
- //This functions was assisted by Chat GPT
90
- const hslToHex = hue => {
91
- const saturationFraction = saturation / 100;
92
- const luminanceFraction = luminance / 100;
93
- const chroma = (1 - Math.abs(2 * luminanceFraction - 1)) * saturationFraction;
94
- const chromaScaled = chroma * (1 - Math.abs(hue / 60 % 2 - 1));
95
- const lightnessAdjustment = luminanceFraction - chroma / 2;
96
- const findRgbParts = () => {
97
- if (hue >= 0 && hue < 60) {
98
- return {
99
- rFraction: chroma,
100
- gFraction: chromaScaled,
101
- bFraction: 0
102
- };
103
- }
104
- if (hue >= 60 && hue < 120) {
105
- return {
106
- rFraction: chromaScaled,
107
- gFraction: chroma,
108
- bFraction: 0
109
- };
110
- }
111
- if (hue >= 120 && hue < 180) {
112
- return {
113
- rFraction: 0,
114
- gFraction: chroma,
115
- bFraction: chromaScaled
116
- };
117
- }
118
- if (hue >= 180 && hue < 240) {
119
- return {
120
- rFraction: 0,
121
- gFraction: chromaScaled,
122
- bFraction: chroma
123
- };
124
- }
125
- if (hue >= 240 && hue < 300) {
126
- return {
127
- rFraction: chromaScaled,
128
- gFraction: 0,
129
- bFraction: chroma
130
- };
131
- }
132
- return {
133
- rFraction: chroma,
134
- gFraction: 0,
135
- bFraction: chromaScaled
136
- };
137
- };
138
- const {
139
- rFraction,
140
- gFraction,
141
- bFraction
142
- } = findRgbParts();
143
- const buildFullRgbColors = fraction => Math.round((fraction + lightnessAdjustment) * 255);
144
- const red = buildFullRgbColors(rFraction);
145
- const green = buildFullRgbColors(gFraction);
146
- const blue = buildFullRgbColors(bFraction);
147
- const toHex = color => color.toString(16).padStart(2, "0");
148
- return "#".concat(toHex(red)).concat(toHex(green)).concat(toHex(blue));
149
- };
150
- return hslToHex(adjustedHue);
151
- };
152
-
153
- //Sort emissions by scope
154
- //Calculate total tons for emissions
155
-
156
- //define colors for scopes
157
- //use branding colors OR theme colors
158
- //if branding colors: Primary = scope 1, modifedPrimary = scope 2, secondary = scope 3
159
-
160
- //build projected scope categories/colors
161
- //Build a function to lighten colors for projections
162
-
163
- const buildScopesArrayWithColors = (emissions, branding) => {
164
- const colorizeScopesArray = (scopesArray, colorsArray) => scopesArray.map((scopeObj, idx) => _objectSpread(_objectSpread({}, scopeObj), {}, {
165
- color: colorsArray[idx]
166
- }));
167
- const scopesArray = [1, 2, 3].map(scope => {
168
- const scopeEmissions = (0, _emissionsCalcs.filterEmissionsByScope)(emissions, scope);
169
- const totalTonsCo2e = (0, _otherHelpers.sumTonsCo2e)(scopeEmissions);
170
- return {
171
- scope,
172
- subcategory: "scope".concat(scope),
173
- name: "Scope ".concat(scope),
174
- emissions: scopeEmissions,
175
- totalTonsCo2e,
176
- icon: /*#__PURE__*/_react.default.createElement(_material.Typography, {
177
- variant: "h6"
178
- }, scope)
179
- };
180
- });
181
- if (!branding) {
182
- const colorsArray = _subcategories.scopesList.map(_ref => {
183
- var _mainTheme$palette$co;
184
- let {
185
- color
186
- } = _ref;
187
- return (_mainTheme$palette$co = _themes.default.palette[color]) === null || _mainTheme$palette$co === void 0 ? void 0 : _mainTheme$palette$co.main;
188
- });
189
- return colorizeScopesArray(scopesArray, colorsArray);
190
- }
191
- const {
192
- primaryColor,
193
- secondaryColor
194
- } = branding;
195
- if (!primaryColor || !secondaryColor) {
196
- return scopesArray;
197
- }
198
- const sortedScopes = scopesArray.sort((a, b) => b.totalTonsCo2e - a.totalTonsCo2e);
199
- const adjustedPrimaryColor = adjustHexColorHue(primaryColor);
200
- const colorsArray = [primaryColor, secondaryColor, adjustedPrimaryColor];
201
- return colorizeScopesArray(sortedScopes, colorsArray).sort((a, b) => a.scope - b.scope);
202
- };
203
- const ReportSummaryBlock = _ref2 => {
23
+ const ReportSummaryBlock = _ref => {
204
24
  let {
205
25
  emissions,
206
26
  interval,
207
- branding
208
- } = _ref2;
209
- const scopesWithColors = buildScopesArrayWithColors();
210
- const chartScopes = branding ? scopesWithColors : null;
211
- return /*#__PURE__*/_react.default.createElement(ReportGraphContentLayout, {
212
- scopes: chartScopes,
27
+ branding,
28
+ showTooltip
29
+ } = _ref;
30
+ const scopesWithColors = (0, _subcategories.buildScopesWithColors)(branding);
31
+ const scopesWithEmissions = scopesWithColors.map(scopeObj => {
32
+ const {
33
+ scope
34
+ } = scopeObj;
35
+ const scopeEmissions = (0, _emissionsCalcs.filterEmissionsByScope)(emissions, scope);
36
+ return _objectSpread(_objectSpread({}, scopeObj), {}, {
37
+ emissions: scopeEmissions
38
+ });
39
+ });
40
+ return /*#__PURE__*/_react.default.createElement(_ReportGraphContentLayout.default, {
41
+ showTooltip: showTooltip,
42
+ branding: branding,
213
43
  contentTitle: (0, _otherHelpers.buildEmissionsSummarySentence)({
214
44
  label: "Total Emissions",
215
45
  emissions
216
46
  }),
217
47
  interval: interval,
218
48
  emissions: emissions,
219
- contentRows: [/*#__PURE__*/_react.default.createElement(EmissionsPieChart, {
49
+ contentRows: [/*#__PURE__*/_react.default.createElement(_EmissionsPieChart.default, {
220
50
  dataArray: emissions,
221
51
  viewMode: "scopes",
222
- scopes: chartScopes
52
+ branding: branding,
53
+ showTooltip: showTooltip
223
54
  }), /*#__PURE__*/_react.default.createElement(_material.Typography, {
224
55
  variant: "subtitle1"
225
- }, "Emissions Scope Breakdown"), ...scopesWithColors.map((_ref3, idx) => {
56
+ }, "Emissions Scope Breakdown"), ...scopesWithEmissions.map((_ref2, idx) => {
226
57
  let {
227
58
  scope,
228
59
  emissions,
229
60
  color
230
- } = _ref3;
231
- return /*#__PURE__*/_react.default.createElement(EmissionsSummarySentence, {
61
+ } = _ref2;
62
+ return /*#__PURE__*/_react.default.createElement(_EmissionsSummarySentence.default, {
232
63
  key: "summary-sentence-".concat(idx),
233
64
  label: "Total Scope ".concat(scope),
234
65
  emissions: emissions,
package/dist/index.js CHANGED
@@ -51,10 +51,10 @@ Object.defineProperty(exports, "EmissionsReductionGraph", {
51
51
  return _EmissionsReductionGraph.default;
52
52
  }
53
53
  });
54
- Object.defineProperty(exports, "EmissionsSummarySentence", {
54
+ Object.defineProperty(exports, "EmissionsScopeSummarySentence", {
55
55
  enumerable: true,
56
56
  get: function get() {
57
- return _EmissionsSummarySentence.default;
57
+ return _EmissionsScopeSummarySentence.default;
58
58
  }
59
59
  });
60
60
  Object.defineProperty(exports, "EmissionsSummaryTable", {
@@ -142,5 +142,5 @@ var _useChartWarningLabels = _interopRequireDefault(require("./components/useCha
142
142
  var _EmissionsSummaryTable = _interopRequireDefault(require("./components/EmissionsSummaryTable"));
143
143
  var _ReportSummaryBlock = _interopRequireDefault(require("./components/ReportSummaryBlock"));
144
144
  var _ReportGraphContentLayout = _interopRequireDefault(require("./components/ReportGraphContentLayout"));
145
- var _EmissionsSummarySentence = _interopRequireDefault(require("./components/EmissionsSummarySentence"));
145
+ var _EmissionsScopeSummarySentence = _interopRequireDefault(require("./components/EmissionsScopeSummarySentence"));
146
146
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aclymatepackages/modules",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "Aclymate modules",
5
5
  "author": "William Loopesko",
6
6
  "main": "dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "@aclymatepackages/multi-part-form": "1.0.1",
17
17
  "@aclymatepackages/other-helpers": "^1.0.3",
18
18
  "@aclymatepackages/reg-exp": "^1.0.0",
19
- "@aclymatepackages/subcategories": "^1.0.4",
19
+ "@aclymatepackages/subcategories": "^1.0.5",
20
20
  "@aclymatepackages/themes": "^1.0.0",
21
21
  "@babel/preset-react": "^7.16.7",
22
22
  "@emotion/react": "^11.11.1",
@@ -117,7 +117,7 @@ const LabeledEmissionsChart = ({
117
117
  displayUnitLabel,
118
118
  chartArray,
119
119
  aspect = 3,
120
- showTooltip = true,
120
+ showTooltip,
121
121
  }) => {
122
122
  const { palette } = useTheme();
123
123
 
@@ -197,7 +197,7 @@ const EmissionsChart = ({
197
197
  unitConverter,
198
198
  aspect,
199
199
  isPercentageChart,
200
- showTooltip,
200
+ showTooltip = true,
201
201
  startDate,
202
202
  convertCarbonUnits,
203
203
  displayUnitLabel,
@@ -53,6 +53,7 @@ const EmissionsPieChart = ({
53
53
  viewMode = "subcategories",
54
54
  pieChartRef,
55
55
  branding,
56
+ showTooltip = true,
56
57
  }) => {
57
58
  const subcategoriesArray = buildSubcategoriesArray(emissions);
58
59
  const scopesArray = buildScopesWithColors(branding);
@@ -114,10 +115,12 @@ const EmissionsPieChart = ({
114
115
  />
115
116
  ))}
116
117
  </Pie>
117
- <ChartTooltip
118
- wrapperStyle={{ zIndex: 99 }}
119
- content={<PieChartCustomTooltip />}
120
- />
118
+ {showTooltip && (
119
+ <ChartTooltip
120
+ wrapperStyle={{ zIndex: 99 }}
121
+ content={<PieChartCustomTooltip />}
122
+ />
123
+ )}
121
124
  </PieChart>
122
125
  </ResponsiveContainer>
123
126
  );
@@ -5,10 +5,15 @@ import { Typography, Grid } from "@mui/material";
5
5
  import { CategoriesAvatar } from "@aclymatepackages/atoms";
6
6
  import { buildEmissionsSummarySentence } from "@aclymatepackages/other-helpers";
7
7
 
8
- const EmissionsSummarySentence = ({ label, emissions, color, scope }) => (
8
+ const EmissionsScopeSummarySentence = ({ label, emissions, color, scope }) => (
9
9
  <Grid container spacing={1} alignItems="center" wrap="nowrap">
10
10
  <Grid item>
11
- <CategoriesAvatar scope={scope} color={color} />
11
+ <CategoriesAvatar
12
+ scope={scope}
13
+ color={color}
14
+ viewMode="scopes"
15
+ size="small"
16
+ />
12
17
  </Grid>
13
18
  <Grid item>
14
19
  <Typography variant="body2">
@@ -17,5 +22,4 @@ const EmissionsSummarySentence = ({ label, emissions, color, scope }) => (
17
22
  </Grid>
18
23
  </Grid>
19
24
  );
20
-
21
- export default EmissionsSummarySentence;
25
+ export default EmissionsScopeSummarySentence;
@@ -13,7 +13,8 @@ const ReportGraphContentLayout = ({
13
13
  interval = "quarter",
14
14
  isPercentageChart,
15
15
  height,
16
- scopes,
16
+ branding,
17
+ showTooltip,
17
18
  }) => {
18
19
  return (
19
20
  <Box p={2} style={{ height: height || "auto" }}>
@@ -38,8 +39,8 @@ const ReportGraphContentLayout = ({
38
39
  unitConverter={(tons) => tons}
39
40
  aspect={2}
40
41
  isPercentageChart={isPercentageChart}
41
- showTooltip={false}
42
- scopes={scopes}
42
+ showTooltip={showTooltip}
43
+ branding={branding}
43
44
  />
44
45
  </Grid>
45
46
  </Grid>
@@ -2,199 +2,27 @@ import React from "react";
2
2
 
3
3
  import { Typography } from "@mui/material";
4
4
 
5
- import {
6
- buildEmissionsSummarySentence,
7
- sumTonsCo2e,
8
- } from "@aclymatepackages/other-helpers";
5
+ import { buildEmissionsSummarySentence } from "@aclymatepackages/other-helpers";
9
6
  import { filterEmissionsByScope } from "@aclymatepackages/emissions-calcs";
10
- import { hexToRgba } from "@aclymatepackages/converters";
11
- import mainTheme from "@aclymatepackages/themes";
12
- import { scopesList } from "@aclymatepackages/subcategories";
7
+ import { buildScopesWithColors } from "@aclymatepackages/subcategories";
13
8
 
14
- // import ReportGraphContentLayout from "./ReportGraphContentLayout";
15
- // import EmissionsPieChart from "./EmissionsPieChart";
16
- // import EmissionsSummarySentence from "./EmissionsSummarySentence";
9
+ import ReportGraphContentLayout from "./ReportGraphContentLayout";
10
+ import EmissionsPieChart from "./EmissionsPieChart";
11
+ import EmissionsSummarySentence from "./EmissionsSummarySentence";
17
12
 
18
- const adjustHexColorHue = (hexColor, hueChange = 20) => {
19
- const rgbaColor = hexToRgba(hexColor);
13
+ const ReportSummaryBlock = ({ emissions, interval, branding, showTooltip }) => {
14
+ const scopesWithColors = buildScopesWithColors(branding);
20
15
 
21
- const extractColorValueFromString = (color) =>
22
- color.match(/\d+/g).map((value) => Number(value));
23
-
24
- //This function was assisted by Chat GPT
25
- const rgbaToHslParams = () => {
26
- const [r, g, b] = extractColorValueFromString(rgbaColor);
27
-
28
- const rFraction = r / 255;
29
- const gFraction = g / 255;
30
- const bFraction = b / 255;
31
-
32
- const fractionsArray = [rFraction, gFraction, bFraction];
33
-
34
- const maxValue = Math.max(...fractionsArray);
35
- const minValue = Math.min(...fractionsArray);
36
-
37
- const luminance = (maxValue + minValue) / 2;
38
-
39
- const maxMinDelta = maxValue - minValue;
40
- const calcSaturationValue = () => {
41
- if (maxValue === minValue) {
42
- return 0;
43
- }
44
- if (luminance > 0.5) {
45
- return maxMinDelta / (2 - maxValue - minValue);
46
- }
47
- return maxMinDelta / (maxValue + minValue);
48
- };
49
-
50
- const saturation = calcSaturationValue();
51
-
52
- const calcHueValue = () => {
53
- if (maxValue === minValue) {
54
- return 0;
55
- }
56
-
57
- if (maxValue === rFraction) {
58
- return (
59
- (gFraction - bFraction) / maxMinDelta +
60
- (gFraction < bFraction ? 6 : 0)
61
- );
62
- }
63
-
64
- if (maxValue === gFraction) {
65
- return (bFraction - rFraction) / maxMinDelta + 2;
66
- }
67
-
68
- return (rFraction - gFraction) / maxMinDelta + 4;
69
- };
70
- const hue = Math.round(calcHueValue() * 60) % 360;
71
-
72
- return {
73
- hue,
74
- saturation: Math.round(saturation * 100),
75
- luminance: Math.round(luminance * 100),
76
- };
77
- };
78
-
79
- const { hue, saturation, luminance } = rgbaToHslParams();
80
- const adjustHue = () => {
81
- const adjustedHue = hue + hueChange;
82
- if (adjustedHue < 360) {
83
- return adjustedHue;
84
- }
85
- return adjustedHue - 360;
86
- };
87
-
88
- const adjustedHue = adjustHue();
89
-
90
- //This functions was assisted by Chat GPT
91
- const hslToHex = (hue) => {
92
- const saturationFraction = saturation / 100;
93
- const luminanceFraction = luminance / 100;
94
-
95
- const chroma =
96
- (1 - Math.abs(2 * luminanceFraction - 1)) * saturationFraction;
97
- const chromaScaled = chroma * (1 - Math.abs(((hue / 60) % 2) - 1));
98
- const lightnessAdjustment = luminanceFraction - chroma / 2;
99
-
100
- const findRgbParts = () => {
101
- if (hue >= 0 && hue < 60) {
102
- return { rFraction: chroma, gFraction: chromaScaled, bFraction: 0 };
103
- }
104
- if (hue >= 60 && hue < 120) {
105
- return { rFraction: chromaScaled, gFraction: chroma, bFraction: 0 };
106
- }
107
- if (hue >= 120 && hue < 180) {
108
- return { rFraction: 0, gFraction: chroma, bFraction: chromaScaled };
109
- }
110
- if (hue >= 180 && hue < 240) {
111
- return { rFraction: 0, gFraction: chromaScaled, bFraction: chroma };
112
- }
113
- if (hue >= 240 && hue < 300) {
114
- return { rFraction: chromaScaled, gFraction: 0, bFraction: chroma };
115
- }
116
- return { rFraction: chroma, gFraction: 0, bFraction: chromaScaled };
117
- };
118
-
119
- const { rFraction, gFraction, bFraction } = findRgbParts();
120
-
121
- const buildFullRgbColors = (fraction) =>
122
- Math.round((fraction + lightnessAdjustment) * 255);
123
-
124
- const red = buildFullRgbColors(rFraction);
125
- const green = buildFullRgbColors(gFraction);
126
- const blue = buildFullRgbColors(bFraction);
127
-
128
- const toHex = (color) => color.toString(16).padStart(2, "0");
129
-
130
- return `#${toHex(red)}${toHex(green)}${toHex(blue)}`;
131
- };
132
-
133
- return hslToHex(adjustedHue);
134
- };
135
-
136
- //Sort emissions by scope
137
- //Calculate total tons for emissions
138
-
139
- //define colors for scopes
140
- //use branding colors OR theme colors
141
- //if branding colors: Primary = scope 1, modifedPrimary = scope 2, secondary = scope 3
142
-
143
- //build projected scope categories/colors
144
- //Build a function to lighten colors for projections
145
-
146
- const buildScopesArrayWithColors = (emissions, branding) => {
147
- const colorizeScopesArray = (scopesArray, colorsArray) =>
148
- scopesArray.map((scopeObj, idx) => ({
149
- ...scopeObj,
150
- color: colorsArray[idx],
151
- }));
152
-
153
- const scopesArray = [1, 2, 3].map((scope) => {
16
+ const scopesWithEmissions = scopesWithColors.map((scopeObj) => {
17
+ const { scope } = scopeObj;
154
18
  const scopeEmissions = filterEmissionsByScope(emissions, scope);
155
- const totalTonsCo2e = sumTonsCo2e(scopeEmissions);
156
- return {
157
- scope,
158
- subcategory: `scope${scope}`,
159
- name: `Scope ${scope}`,
160
- emissions: scopeEmissions,
161
- totalTonsCo2e,
162
- icon: <Typography variant="h6">{scope}</Typography>,
163
- };
19
+ return { ...scopeObj, emissions: scopeEmissions };
164
20
  });
165
21
 
166
- if (!branding) {
167
- const colorsArray = scopesList.map(
168
- ({ color }) => mainTheme.palette[color]?.main
169
- );
170
-
171
- return colorizeScopesArray(scopesArray, colorsArray);
172
- }
173
-
174
- const { primaryColor, secondaryColor } = branding;
175
- if (!primaryColor || !secondaryColor) {
176
- return scopesArray;
177
- }
178
-
179
- const sortedScopes = scopesArray.sort(
180
- (a, b) => b.totalTonsCo2e - a.totalTonsCo2e
181
- );
182
- const adjustedPrimaryColor = adjustHexColorHue(primaryColor);
183
-
184
- const colorsArray = [primaryColor, secondaryColor, adjustedPrimaryColor];
185
- return colorizeScopesArray(sortedScopes, colorsArray).sort(
186
- (a, b) => a.scope - b.scope
187
- );
188
- };
189
-
190
- const ReportSummaryBlock = ({ emissions, interval, branding }) => {
191
- const scopesWithColors = buildScopesArrayWithColors();
192
-
193
- const chartScopes = branding ? scopesWithColors : null;
194
-
195
22
  return (
196
23
  <ReportGraphContentLayout
197
- scopes={chartScopes}
24
+ showTooltip={showTooltip}
25
+ branding={branding}
198
26
  contentTitle={buildEmissionsSummarySentence({
199
27
  label: "Total Emissions",
200
28
  emissions,
@@ -205,10 +33,11 @@ const ReportSummaryBlock = ({ emissions, interval, branding }) => {
205
33
  <EmissionsPieChart
206
34
  dataArray={emissions}
207
35
  viewMode="scopes"
208
- scopes={chartScopes}
36
+ branding={branding}
37
+ showTooltip={showTooltip}
209
38
  />,
210
39
  <Typography variant="subtitle1">Emissions Scope Breakdown</Typography>,
211
- ...scopesWithColors.map(({ scope, emissions, color }, idx) => (
40
+ ...scopesWithEmissions.map(({ scope, emissions, color }, idx) => (
212
41
  <EmissionsSummarySentence
213
42
  key={`summary-sentence-${idx}`}
214
43
  label={`Total Scope ${scope}`}
@@ -221,5 +50,4 @@ const ReportSummaryBlock = ({ emissions, interval, branding }) => {
221
50
  />
222
51
  );
223
52
  };
224
-
225
53
  export default ReportSummaryBlock;
package/src/index.js CHANGED
@@ -17,7 +17,7 @@ import useChartWarningLabels from "./components/useChartWarningLabels";
17
17
  import EmissionsSummaryTable from "./components/EmissionsSummaryTable";
18
18
  import ReportSummaryBlock from "./components/ReportSummaryBlock";
19
19
  import ReportGraphContentLayout from "./components/ReportGraphContentLayout";
20
- import EmissionsSummarySentence from "./components/EmissionsSummarySentence";
20
+ import EmissionsScopeSummarySentence from "./components/EmissionsScopeSummarySentence";
21
21
 
22
22
  export {
23
23
  FootprintVideo,
@@ -39,5 +39,5 @@ export {
39
39
  EmissionsSummaryTable,
40
40
  ReportSummaryBlock,
41
41
  ReportGraphContentLayout,
42
- EmissionsSummarySentence,
42
+ EmissionsScopeSummarySentence,
43
43
  };