@aclymatepackages/modules 1.0.14 → 1.0.16

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.
@@ -349,7 +349,7 @@ const EmissionsChart = _ref13 => {
349
349
  startDate,
350
350
  convertCarbonUnits,
351
351
  displayUnitLabel,
352
- scopes
352
+ branding
353
353
  } = _ref13;
354
354
  const {
355
355
  chartLabelsArray,
@@ -358,7 +358,7 @@ const EmissionsChart = _ref13 => {
358
358
  subcategoriesArray,
359
359
  period,
360
360
  groupedEmissions
361
- } = (0, _chartHelpers.buildEmissionGroupData)(emissions, graphPeriod, startDate, scopes);
361
+ } = (0, _chartHelpers.buildEmissionGroupData)(emissions, graphPeriod, startDate, branding);
362
362
  const isDataProjected = findIsDataProjected(latestEmissionDate);
363
363
  const isFirstPeriodEstimated = findIsFirstPeriodEstimated(chartLabelsArray, graphPeriod);
364
364
  const buildProjectionObj = viewMode === "subcategories" ? buildSubcategoriesProjectionObj : buildScopesProjectionObj;
@@ -64,10 +64,10 @@ const EmissionsPieChart = _ref2 => {
64
64
  dataArray: emissions,
65
65
  viewMode = "subcategories",
66
66
  pieChartRef,
67
- scopes
67
+ branding
68
68
  } = _ref2;
69
69
  const subcategoriesArray = (0, _subcategories.buildSubcategoriesArray)(emissions);
70
- const scopesArray = scopes || (0, _subcategories.buildScopesArray)();
70
+ const scopesArray = (0, _subcategories.buildScopesWithColors)(branding);
71
71
  const emissionsSum = (0, _otherHelpers.sumTonsCo2e)(emissions);
72
72
  const formatChartPieSlices = () => {
73
73
  const filterFunction = subcategory => emission => {
@@ -7,7 +7,6 @@ exports.default = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _material = require("@mui/material");
9
9
  var _atoms = require("@aclymatepackages/atoms");
10
- var _formatters = require("@aclymatepackages/formatters");
11
10
  var _otherHelpers = require("@aclymatepackages/other-helpers");
12
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
12
  const EmissionsSummarySentence = _ref => {
@@ -31,6 +30,9 @@ const EmissionsSummarySentence = _ref => {
31
30
  item: true
32
31
  }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
33
32
  variant: "body2"
34
- }, label, ": ", (0, _formatters.formatDecimal)((0, _otherHelpers.sumTonsCo2e)(emissions)), " tons CO2e")));
33
+ }, (0, _otherHelpers.buildEmissionsSummarySentence)({
34
+ label,
35
+ emissions
36
+ }))));
35
37
  };
36
38
  var _default = exports.default = EmissionsSummarySentence;
@@ -12,19 +12,21 @@ require("core-js/modules/es.regexp.to-string.js");
12
12
  require("core-js/modules/es.array.sort.js");
13
13
  var _react = _interopRequireDefault(require("react"));
14
14
  var _material = require("@mui/material");
15
- var _modules = require("@aclymatepackages/modules");
16
15
  var _otherHelpers = require("@aclymatepackages/other-helpers");
17
16
  var _emissionsCalcs = require("@aclymatepackages/emissions-calcs");
18
17
  var _converters = require("@aclymatepackages/converters");
19
18
  var _themes = _interopRequireDefault(require("@aclymatepackages/themes"));
20
19
  var _subcategories = require("@aclymatepackages/subcategories");
21
- var _EmissionsSummarySentence = _interopRequireDefault(require("./EmissionsSummarySentence"));
22
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
21
  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; }
24
22
  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; }
25
23
  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; }
26
24
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
27
25
  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
+
28
30
  const adjustHexColorHue = function adjustHexColorHue(hexColor) {
29
31
  let hueChange = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 20;
30
32
  const rgbaColor = (0, _converters.hexToRgba)(hexColor);
@@ -147,55 +149,66 @@ const adjustHexColorHue = function adjustHexColorHue(hexColor) {
147
149
  };
148
150
  return hslToHex(adjustedHue);
149
151
  };
150
- const ReportSummaryBlock = _ref => {
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 => {
151
204
  let {
152
205
  emissions,
153
206
  interval,
154
207
  branding
155
- } = _ref;
156
- const buildScopesArrayWithColors = () => {
157
- const colorizeScopesArray = (scopesArray, colorsArray) => scopesArray.map((scopeObj, idx) => _objectSpread(_objectSpread({}, scopeObj), {}, {
158
- color: colorsArray[idx]
159
- }));
160
- const scopesArray = [1, 2, 3].map(scope => {
161
- const scopeEmissions = (0, _emissionsCalcs.filterEmissionsByScope)(emissions, scope);
162
- const totalTonsCo2e = (0, _otherHelpers.sumTonsCo2e)(scopeEmissions);
163
- return {
164
- scope,
165
- subcategory: "scope".concat(scope),
166
- name: "Scope ".concat(scope),
167
- emissions: scopeEmissions,
168
- totalTonsCo2e,
169
- icon: /*#__PURE__*/_react.default.createElement(_material.Typography, {
170
- variant: "h6"
171
- }, scope)
172
- };
173
- });
174
- if (!branding) {
175
- const colorsArray = _subcategories.scopesList.map(_ref2 => {
176
- var _mainTheme$palette$co;
177
- let {
178
- color
179
- } = _ref2;
180
- return (_mainTheme$palette$co = _themes.default.palette[color]) === null || _mainTheme$palette$co === void 0 ? void 0 : _mainTheme$palette$co.main;
181
- });
182
- return colorizeScopesArray(scopesArray, colorsArray);
183
- }
184
- const {
185
- primaryColor,
186
- secondaryColor
187
- } = branding;
188
- if (!primaryColor || !secondaryColor) {
189
- return scopesArray;
190
- }
191
- const sortedScopes = scopesArray.sort((a, b) => b.totalTonsCo2e - a.totalTonsCo2e);
192
- const adjustedPrimaryColor = adjustHexColorHue(primaryColor);
193
- const colorsArray = [primaryColor, secondaryColor, adjustedPrimaryColor];
194
- return colorizeScopesArray(sortedScopes, colorsArray).sort((a, b) => a.scope - b.scope);
195
- };
208
+ } = _ref2;
196
209
  const scopesWithColors = buildScopesArrayWithColors();
197
210
  const chartScopes = branding ? scopesWithColors : null;
198
- return /*#__PURE__*/_react.default.createElement(_modules.ReportGraphContentLayout, {
211
+ return /*#__PURE__*/_react.default.createElement(ReportGraphContentLayout, {
199
212
  scopes: chartScopes,
200
213
  contentTitle: (0, _otherHelpers.buildEmissionsSummarySentence)({
201
214
  label: "Total Emissions",
@@ -203,7 +216,7 @@ const ReportSummaryBlock = _ref => {
203
216
  }),
204
217
  interval: interval,
205
218
  emissions: emissions,
206
- contentRows: [/*#__PURE__*/_react.default.createElement(_modules.EmissionsPieChart, {
219
+ contentRows: [/*#__PURE__*/_react.default.createElement(EmissionsPieChart, {
207
220
  dataArray: emissions,
208
221
  viewMode: "scopes",
209
222
  scopes: chartScopes
@@ -215,7 +228,7 @@ const ReportSummaryBlock = _ref => {
215
228
  emissions,
216
229
  color
217
230
  } = _ref3;
218
- return /*#__PURE__*/_react.default.createElement(_EmissionsSummarySentence.default, {
231
+ return /*#__PURE__*/_react.default.createElement(EmissionsSummarySentence, {
219
232
  key: "summary-sentence-".concat(idx),
220
233
  label: "Total Scope ".concat(scope),
221
234
  emissions: emissions,
package/dist/index.js CHANGED
@@ -51,6 +51,12 @@ Object.defineProperty(exports, "EmissionsReductionGraph", {
51
51
  return _EmissionsReductionGraph.default;
52
52
  }
53
53
  });
54
+ Object.defineProperty(exports, "EmissionsSummarySentence", {
55
+ enumerable: true,
56
+ get: function get() {
57
+ return _EmissionsSummarySentence.default;
58
+ }
59
+ });
54
60
  Object.defineProperty(exports, "EmissionsSummaryTable", {
55
61
  enumerable: true,
56
62
  get: function get() {
@@ -136,4 +142,5 @@ var _useChartWarningLabels = _interopRequireDefault(require("./components/useCha
136
142
  var _EmissionsSummaryTable = _interopRequireDefault(require("./components/EmissionsSummaryTable"));
137
143
  var _ReportSummaryBlock = _interopRequireDefault(require("./components/ReportSummaryBlock"));
138
144
  var _ReportGraphContentLayout = _interopRequireDefault(require("./components/ReportGraphContentLayout"));
145
+ var _EmissionsSummarySentence = _interopRequireDefault(require("./components/EmissionsSummarySentence"));
139
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.14",
3
+ "version": "1.0.16",
4
4
  "description": "Aclymate modules",
5
5
  "author": "William Loopesko",
6
6
  "main": "dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "@aclymatepackages/formatters": "^1.0.0",
17
17
  "@aclymatepackages/lists": "^1.0.0",
18
18
  "@aclymatepackages/multi-part-form": "1.0.1",
19
- "@aclymatepackages/other-helpers": "^1.0.0",
19
+ "@aclymatepackages/other-helpers": "^1.0.2",
20
20
  "@aclymatepackages/reg-exp": "^1.0.0",
21
21
  "@aclymatepackages/themes": "^1.0.0",
22
22
  "@babel/preset-react": "^7.16.7",
@@ -412,7 +412,7 @@ const EmissionsChart = ({
412
412
  startDate,
413
413
  convertCarbonUnits,
414
414
  displayUnitLabel,
415
- scopes,
415
+ branding,
416
416
  }) => {
417
417
  const {
418
418
  chartLabelsArray,
@@ -421,7 +421,7 @@ const EmissionsChart = ({
421
421
  subcategoriesArray,
422
422
  period,
423
423
  groupedEmissions,
424
- } = buildEmissionGroupData(emissions, graphPeriod, startDate, scopes);
424
+ } = buildEmissionGroupData(emissions, graphPeriod, startDate, branding);
425
425
 
426
426
  const isDataProjected = findIsDataProjected(latestEmissionDate);
427
427
  const isFirstPeriodEstimated = findIsFirstPeriodEstimated(
@@ -15,7 +15,7 @@ import { formatDecimal } from "@aclymatepackages/formatters";
15
15
  import { sumTonsCo2e } from "@aclymatepackages/other-helpers";
16
16
  import {
17
17
  buildSubcategoriesArray,
18
- buildScopesArray,
18
+ buildScopesWithColors,
19
19
  } from "@aclymatepackages/subcategories";
20
20
 
21
21
  const PieChartCustomTooltip = ({ payload: passedPayload }) => {
@@ -49,10 +49,10 @@ const EmissionsPieChart = ({
49
49
  dataArray: emissions,
50
50
  viewMode = "subcategories",
51
51
  pieChartRef,
52
- scopes,
52
+ branding,
53
53
  }) => {
54
54
  const subcategoriesArray = buildSubcategoriesArray(emissions);
55
- const scopesArray = scopes || buildScopesArray();
55
+ const scopesArray = buildScopesWithColors(branding);
56
56
 
57
57
  const emissionsSum = sumTonsCo2e(emissions);
58
58
 
@@ -3,8 +3,7 @@ import React from "react";
3
3
  import { Typography, Grid } from "@mui/material";
4
4
 
5
5
  import { CategoriesAvatar } from "@aclymatepackages/atoms";
6
- import { formatDecimal } from "@aclymatepackages/formatters";
7
- import { sumTonsCo2e } from "@aclymatepackages/other-helpers";
6
+ import { buildEmissionsSummarySentence } from "@aclymatepackages/other-helpers";
8
7
 
9
8
  const EmissionsSummarySentence = ({ label, emissions, color, scope }) => (
10
9
  <Grid container spacing={1} alignItems="center" wrap="nowrap">
@@ -13,7 +12,7 @@ const EmissionsSummarySentence = ({ label, emissions, color, scope }) => (
13
12
  </Grid>
14
13
  <Grid item>
15
14
  <Typography variant="body2">
16
- {label}: {formatDecimal(sumTonsCo2e(emissions))} tons CO2e
15
+ {buildEmissionsSummarySentence({ label, emissions })}
17
16
  </Typography>
18
17
  </Grid>
19
18
  </Grid>
@@ -2,10 +2,6 @@ import React from "react";
2
2
 
3
3
  import { Typography } from "@mui/material";
4
4
 
5
- import {
6
- EmissionsPieChart,
7
- ReportGraphContentLayout,
8
- } from "@aclymatepackages/modules";
9
5
  import {
10
6
  buildEmissionsSummarySentence,
11
7
  sumTonsCo2e,
@@ -15,7 +11,9 @@ import { hexToRgba } from "@aclymatepackages/converters";
15
11
  import mainTheme from "@aclymatepackages/themes";
16
12
  import { scopesList } from "@aclymatepackages/subcategories";
17
13
 
18
- import EmissionsSummarySentence from "./EmissionsSummarySentence";
14
+ // import ReportGraphContentLayout from "./ReportGraphContentLayout";
15
+ // import EmissionsPieChart from "./EmissionsPieChart";
16
+ // import EmissionsSummarySentence from "./EmissionsSummarySentence";
19
17
 
20
18
  const adjustHexColorHue = (hexColor, hueChange = 20) => {
21
19
  const rgbaColor = hexToRgba(hexColor);
@@ -135,51 +133,61 @@ const adjustHexColorHue = (hexColor, hueChange = 20) => {
135
133
  return hslToHex(adjustedHue);
136
134
  };
137
135
 
138
- const ReportSummaryBlock = ({ emissions, interval, branding }) => {
139
- const buildScopesArrayWithColors = () => {
140
- const colorizeScopesArray = (scopesArray, colorsArray) =>
141
- scopesArray.map((scopeObj, idx) => ({
142
- ...scopeObj,
143
- color: colorsArray[idx],
144
- }));
145
-
146
- const scopesArray = [1, 2, 3].map((scope) => {
147
- const scopeEmissions = filterEmissionsByScope(emissions, scope);
148
- const totalTonsCo2e = sumTonsCo2e(scopeEmissions);
149
- return {
150
- scope,
151
- subcategory: `scope${scope}`,
152
- name: `Scope ${scope}`,
153
- emissions: scopeEmissions,
154
- totalTonsCo2e,
155
- icon: <Typography variant="h6">{scope}</Typography>,
156
- };
157
- });
158
-
159
- if (!branding) {
160
- const colorsArray = scopesList.map(
161
- ({ color }) => mainTheme.palette[color]?.main
162
- );
163
-
164
- return colorizeScopesArray(scopesArray, colorsArray);
165
- }
136
+ //Sort emissions by scope
137
+ //Calculate total tons for emissions
166
138
 
167
- const { primaryColor, secondaryColor } = branding;
168
- if (!primaryColor || !secondaryColor) {
169
- return scopesArray;
170
- }
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
171
142
 
172
- const sortedScopes = scopesArray.sort(
173
- (a, b) => b.totalTonsCo2e - a.totalTonsCo2e
174
- );
175
- const adjustedPrimaryColor = adjustHexColorHue(primaryColor);
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) => {
154
+ 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
+ };
164
+ });
176
165
 
177
- const colorsArray = [primaryColor, secondaryColor, adjustedPrimaryColor];
178
- return colorizeScopesArray(sortedScopes, colorsArray).sort(
179
- (a, b) => a.scope - b.scope
166
+ if (!branding) {
167
+ const colorsArray = scopesList.map(
168
+ ({ color }) => mainTheme.palette[color]?.main
180
169
  );
181
- };
182
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 }) => {
183
191
  const scopesWithColors = buildScopesArrayWithColors();
184
192
 
185
193
  const chartScopes = branding ? scopesWithColors : null;
package/src/index.js CHANGED
@@ -17,6 +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
21
 
21
22
  export {
22
23
  FootprintVideo,
@@ -38,4 +39,5 @@ export {
38
39
  EmissionsSummaryTable,
39
40
  ReportSummaryBlock,
40
41
  ReportGraphContentLayout,
42
+ EmissionsSummarySentence,
41
43
  };