@aclymatepackages/modules 1.0.16 → 1.0.18
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.
- package/dist/components/CustomTooltipDisplayRow.js +11 -13
- package/dist/components/EmissionsChart.js +37 -219
- package/dist/components/EmissionsCustomTooltip.js +4 -17
- package/dist/components/EmissionsPieChart.js +11 -13
- package/package.json +4 -8
- package/src/components/CustomTooltipDisplayRow.js +11 -7
- package/src/components/EmissionsChart.js +7 -276
- package/src/components/EmissionsCustomTooltip.js +6 -25
- package/src/components/EmissionsPieChart.js +11 -7
|
@@ -6,17 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _material = require("@mui/material");
|
|
9
|
+
var _atoms = require("@aclymatepackages/atoms");
|
|
9
10
|
var _formatters = require("@aclymatepackages/formatters");
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
12
|
const CustomTooltipDisplayRow = _ref => {
|
|
12
13
|
let {
|
|
13
14
|
category,
|
|
14
|
-
Icon,
|
|
15
|
-
icon,
|
|
16
15
|
customAvatar,
|
|
17
16
|
color,
|
|
18
17
|
name,
|
|
19
|
-
subtitle
|
|
18
|
+
subtitle,
|
|
19
|
+
viewMode,
|
|
20
|
+
subcategory,
|
|
21
|
+
scope
|
|
20
22
|
} = _ref;
|
|
21
23
|
return /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
22
24
|
item: true,
|
|
@@ -26,16 +28,12 @@ const CustomTooltipDisplayRow = _ref => {
|
|
|
26
28
|
alignItems: "center"
|
|
27
29
|
}, /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
28
30
|
item: true
|
|
29
|
-
}, customAvatar || /*#__PURE__*/_react.default.createElement(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
style: {
|
|
36
|
-
color: "inherit"
|
|
37
|
-
}
|
|
38
|
-
}))), /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
31
|
+
}, customAvatar || /*#__PURE__*/_react.default.createElement(_atoms.CategoriesAvatar, {
|
|
32
|
+
viewMode: viewMode,
|
|
33
|
+
color: color,
|
|
34
|
+
subcategory: subcategory,
|
|
35
|
+
scope: scope
|
|
36
|
+
})), /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
39
37
|
item: true,
|
|
40
38
|
container: true,
|
|
41
39
|
direction: "column",
|
|
@@ -15,8 +15,6 @@ var _dayOfYear = _interopRequireDefault(require("dayjs/plugin/dayOfYear"));
|
|
|
15
15
|
var _recharts = require("recharts");
|
|
16
16
|
var _material = require("@mui/material");
|
|
17
17
|
var _formatters = require("@aclymatepackages/formatters");
|
|
18
|
-
var _dateHelpers = require("@aclymatepackages/date-helpers");
|
|
19
|
-
var _constants = require("@aclymatepackages/constants");
|
|
20
18
|
var _otherHelpers = require("@aclymatepackages/other-helpers");
|
|
21
19
|
var _EmissionsCustomTooltip = _interopRequireDefault(require("./EmissionsCustomTooltip"));
|
|
22
20
|
var _useChartWarningLabels = _interopRequireDefault(require("./useChartWarningLabels"));
|
|
@@ -34,164 +32,20 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
34
32
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
35
33
|
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); }
|
|
36
34
|
_dayjs.default.extend(_dayOfYear.default);
|
|
37
|
-
const DAYS_IN_QUARTER = _constants.DAYS_PER_YEAR / 4;
|
|
38
35
|
const findObjectValuesSum = object => Object.values(object).reduce((sum, value) => sum + value, 0);
|
|
39
|
-
const
|
|
40
|
-
if (period === "quarter") {
|
|
41
|
-
return (0, _dateHelpers.findQuarterDate)(label);
|
|
42
|
-
}
|
|
43
|
-
if (period === "year") {
|
|
44
|
-
return (0, _dateHelpers.findYearFirstDate)(label);
|
|
45
|
-
}
|
|
46
|
-
return (0, _dayjs.default)(label, "MM-YY");
|
|
47
|
-
};
|
|
48
|
-
const isDateFirstDateOfPeriod = (date, period) => {
|
|
49
|
-
if (period === "quarter") {
|
|
50
|
-
const quarterFirstDate = (0, _dateHelpers.findQuarterDate)(date);
|
|
51
|
-
return (0, _dayjs.default)(date).isSame(quarterFirstDate, "day");
|
|
52
|
-
}
|
|
53
|
-
if (period === "year") {
|
|
54
|
-
const yearFirstDate = (0, _dateHelpers.findYearFirstDate)(date);
|
|
55
|
-
return (0, _dayjs.default)(date).isSame(yearFirstDate, "day");
|
|
56
|
-
}
|
|
57
|
-
return (0, _dayjs.default)(date).date() === 1;
|
|
58
|
-
};
|
|
59
|
-
const findIsEstimatedFirstDateLabel = _ref => {
|
|
36
|
+
const buildGroupedChartData = _ref => {
|
|
60
37
|
let {
|
|
61
|
-
startDate,
|
|
62
|
-
earliestEmissionDate,
|
|
63
|
-
label,
|
|
64
|
-
period
|
|
65
|
-
} = _ref;
|
|
66
|
-
const labelDate = findLabelDate(period, label);
|
|
67
|
-
const labelStartDateDifference = (0, _dateHelpers.findInclusiveDateDifference)(labelDate, startDate, period);
|
|
68
|
-
const labelDateIsFirstOfPeriod = isDateFirstDateOfPeriod(earliestEmissionDate, period);
|
|
69
|
-
return labelStartDateDifference === 1 && !labelDateIsFirstOfPeriod;
|
|
70
|
-
};
|
|
71
|
-
const findIsFirstPeriodEstimated = (chartLabelsArray, period) => !chartLabelsArray.reduce((acc, label) => acc && !findIsEstimatedFirstDateLabel({
|
|
72
|
-
label,
|
|
73
|
-
period
|
|
74
|
-
}), true);
|
|
75
|
-
const findIsDataProjected = latestEmissionDate => {
|
|
76
|
-
if (!(0, _dayjs.default)(latestEmissionDate).isSame((0, _dayjs.default)(), "month")) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
return (0, _dayjs.default)(latestEmissionDate).date() !== (0, _dayjs.default)().daysInMonth();
|
|
80
|
-
};
|
|
81
|
-
const findProjectedSubcategoryValueFromEmissions = _ref2 => {
|
|
82
|
-
let {
|
|
83
|
-
emissions,
|
|
84
|
-
projectionMultiplier
|
|
85
|
-
} = _ref2;
|
|
86
|
-
return subcategory => {
|
|
87
|
-
const recurringSubcategoryEmissionsSum = (0, _chartHelpers.sumEmissionsTonsBySubcategory)(emissions, subcategory);
|
|
88
|
-
return projectionMultiplier * recurringSubcategoryEmissionsSum;
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
const buildSubcategoriesProjectionObj = (emissions, projectionMultiplier) => {
|
|
92
|
-
const findProjectedSubcategoryValue = findProjectedSubcategoryValueFromEmissions({
|
|
93
|
-
emissions,
|
|
94
|
-
projectionMultiplier
|
|
95
|
-
});
|
|
96
|
-
return {
|
|
97
|
-
"commuting-auto_projected": findProjectedSubcategoryValue("commuting-auto"),
|
|
98
|
-
"home-office_projected": findProjectedSubcategoryValue("home-office"),
|
|
99
|
-
utilities_projected: findProjectedSubcategoryValue("utilities")
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
const buildScopesProjectionObj = (emissions, projectionMultiplier) => {
|
|
103
|
-
const findProjectedSubcategoryValue = findProjectedSubcategoryValueFromEmissions({
|
|
104
|
-
emissions,
|
|
105
|
-
projectionMultiplier
|
|
106
|
-
});
|
|
107
|
-
const projectedCommutingEmissionsTons = findProjectedSubcategoryValue("commuting-auto");
|
|
108
|
-
const projectedHomeOfficeEmissionsTons = findProjectedSubcategoryValue("homeOffice");
|
|
109
|
-
const projectedElectricityEmissionsTons = findProjectedSubcategoryValue("electricity");
|
|
110
|
-
const projectedGasEmissionsTons = findProjectedSubcategoryValue("gas");
|
|
111
|
-
return {
|
|
112
|
-
scope1_projected: projectedGasEmissionsTons,
|
|
113
|
-
scope2_projected: projectedElectricityEmissionsTons,
|
|
114
|
-
scope3_projected: projectedHomeOfficeEmissionsTons + projectedCommutingEmissionsTons
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
const buildGroupedChartData = _ref3 => {
|
|
118
|
-
let {
|
|
119
|
-
startDate = "",
|
|
120
|
-
period,
|
|
121
|
-
isDataProjected,
|
|
122
|
-
isFirstPeriodEstimated,
|
|
123
38
|
groupedEmissions,
|
|
124
|
-
buildProjectionObj,
|
|
125
39
|
buildRealDataObj,
|
|
126
|
-
|
|
127
|
-
} =
|
|
128
|
-
const findPeriodPosition = idx => {
|
|
129
|
-
if (!idx) {
|
|
130
|
-
return "first";
|
|
131
|
-
}
|
|
132
|
-
if (idx === groupedEmissions.length - 1) {
|
|
133
|
-
return "last";
|
|
134
|
-
}
|
|
135
|
-
return "middle";
|
|
136
|
-
};
|
|
137
|
-
const forwardProjectionPeriodFraction = period => {
|
|
138
|
-
if (period === "month") {
|
|
139
|
-
const daysInMonth = (0, _dayjs.default)().daysInMonth();
|
|
140
|
-
return (0, _dayjs.default)().date() / daysInMonth;
|
|
141
|
-
}
|
|
142
|
-
if (period === "quarter") {
|
|
143
|
-
const firstDayInQuarter = (0, _dateHelpers.findQuarterDate)((0, _dayjs.default)());
|
|
144
|
-
const currentDaysIntoQuarter = (0, _dayjs.default)().diff(firstDayInQuarter, "day");
|
|
145
|
-
return currentDaysIntoQuarter / DAYS_IN_QUARTER;
|
|
146
|
-
}
|
|
147
|
-
const currentDaysIntoYear = (0, _dayjs.default)().dayOfYear();
|
|
148
|
-
return currentDaysIntoYear / _constants.DAYS_PER_YEAR;
|
|
149
|
-
};
|
|
150
|
-
const backwardsProjectionPeriodFraction = period => {
|
|
151
|
-
const formattedStartDate = (0, _dayjs.default)(startDate);
|
|
152
|
-
if (period === "month") {
|
|
153
|
-
const daysInMonth = formattedStartDate.daysInMonth();
|
|
154
|
-
const daysFromEndOfMonth = daysInMonth - formattedStartDate.date();
|
|
155
|
-
return daysFromEndOfMonth / daysInMonth;
|
|
156
|
-
}
|
|
157
|
-
if (period === "quarter") {
|
|
158
|
-
const lastDateInQuarter = (0, _dateHelpers.findQuarterDate)(startDate, false);
|
|
159
|
-
const daysFromEndOfQuarter = Math.abs(formattedStartDate.diff(lastDateInQuarter, "day")) + 1;
|
|
160
|
-
return daysFromEndOfQuarter / DAYS_IN_QUARTER;
|
|
161
|
-
}
|
|
162
|
-
const daysFromEndOfYear = Math.abs(formattedStartDate.diff((0, _dayjs.default)(new Date(formattedStartDate.year(), 12, 31)), "day"));
|
|
163
|
-
return daysFromEndOfYear / _constants.DAYS_PER_YEAR;
|
|
164
|
-
};
|
|
165
|
-
const findPeriodProjectionMultiplier = _ref4 => {
|
|
166
|
-
let {
|
|
167
|
-
period,
|
|
168
|
-
position
|
|
169
|
-
} = _ref4;
|
|
170
|
-
if (!showProjection || position === "middle" || position === "first" && !isFirstPeriodEstimated || position === "last" && !isDataProjected) {
|
|
171
|
-
return 0;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
//TODO: -UPDATE: this projection function doesn't take into account closed offices or terminated employee, so we probably need to rethink it
|
|
175
|
-
const projectionFraction = position === "first" ? backwardsProjectionPeriodFraction(period) : forwardProjectionPeriodFraction(period);
|
|
176
|
-
return 1 / projectionFraction - 1;
|
|
177
|
-
};
|
|
40
|
+
viewMode
|
|
41
|
+
} = _ref;
|
|
178
42
|
return groupedEmissions.map((emissionsArray, idx) => {
|
|
179
|
-
const position = findPeriodPosition(idx, groupedEmissions);
|
|
180
|
-
const projectionMultiplier = findPeriodProjectionMultiplier({
|
|
181
|
-
startDate,
|
|
182
|
-
position,
|
|
183
|
-
period,
|
|
184
|
-
isDataProjected,
|
|
185
|
-
isFirstPeriodEstimated
|
|
186
|
-
});
|
|
187
|
-
const projectedCategoriesObj = buildProjectionObj(emissionsArray, projectionMultiplier);
|
|
188
43
|
const subcategoriesObj = buildRealDataObj(emissionsArray, _subcategories.allSubcategoriesWithOther);
|
|
189
|
-
const chartCategoriesObj = _objectSpread(_objectSpread({}, projectedCategoriesObj), subcategoriesObj);
|
|
190
44
|
const buildWarningObj = () => {
|
|
191
|
-
const singleEmissionWarning = emissionsArray.find(
|
|
45
|
+
const singleEmissionWarning = emissionsArray.find(_ref2 => {
|
|
192
46
|
let {
|
|
193
47
|
warning
|
|
194
|
-
} =
|
|
48
|
+
} = _ref2;
|
|
195
49
|
return !!warning;
|
|
196
50
|
});
|
|
197
51
|
if (!singleEmissionWarning) {
|
|
@@ -202,27 +56,27 @@ const buildGroupedChartData = _ref3 => {
|
|
|
202
56
|
} = singleEmissionWarning;
|
|
203
57
|
return warning;
|
|
204
58
|
};
|
|
205
|
-
return _objectSpread(_objectSpread({},
|
|
59
|
+
return _objectSpread(_objectSpread({}, subcategoriesObj), {}, {
|
|
206
60
|
warning: buildWarningObj(),
|
|
207
61
|
id: "emissions-chart-group-".concat(idx),
|
|
208
62
|
emissionsSumTons: (0, _otherHelpers.sumTonsCo2e)(emissionsArray),
|
|
209
|
-
totalEmissionsSumTons: findObjectValuesSum(
|
|
210
|
-
|
|
63
|
+
totalEmissionsSumTons: findObjectValuesSum(subcategoriesObj),
|
|
64
|
+
viewMode
|
|
211
65
|
});
|
|
212
66
|
});
|
|
213
67
|
};
|
|
214
68
|
const addTrendlineToChartData = chartData => {
|
|
215
69
|
const averageX = (chartData.length - 1) / 2;
|
|
216
|
-
const averageY = chartData.reduce((sum,
|
|
70
|
+
const averageY = chartData.reduce((sum, _ref3) => {
|
|
217
71
|
let {
|
|
218
72
|
totalEmissionsSumTons
|
|
219
|
-
} =
|
|
73
|
+
} = _ref3;
|
|
220
74
|
return Number(sum) + Number(totalEmissionsSumTons);
|
|
221
75
|
}, 0) / chartData.length;
|
|
222
|
-
const trendLineCalcData = chartData.map((
|
|
76
|
+
const trendLineCalcData = chartData.map((_ref4, idx) => {
|
|
223
77
|
let {
|
|
224
78
|
totalEmissionsSumTons
|
|
225
|
-
} =
|
|
79
|
+
} = _ref4;
|
|
226
80
|
const xDifferenceFromMean = idx - averageX;
|
|
227
81
|
const yDifferenceFromMean = totalEmissionsSumTons - averageY;
|
|
228
82
|
const xDifferenceSquared = xDifferenceFromMean * xDifferenceFromMean;
|
|
@@ -232,32 +86,32 @@ const addTrendlineToChartData = chartData => {
|
|
|
232
86
|
xyDifferenceFromMean
|
|
233
87
|
};
|
|
234
88
|
});
|
|
235
|
-
const xDifferenceSquaredSum = trendLineCalcData.reduce((sum,
|
|
89
|
+
const xDifferenceSquaredSum = trendLineCalcData.reduce((sum, _ref5) => {
|
|
236
90
|
let {
|
|
237
91
|
xDifferenceSquared
|
|
238
|
-
} =
|
|
92
|
+
} = _ref5;
|
|
239
93
|
return sum + xDifferenceSquared;
|
|
240
94
|
}, 0);
|
|
241
|
-
const xyDifferenceFromMeanSum = trendLineCalcData.reduce((sum,
|
|
95
|
+
const xyDifferenceFromMeanSum = trendLineCalcData.reduce((sum, _ref6) => {
|
|
242
96
|
let {
|
|
243
97
|
xyDifferenceFromMean
|
|
244
|
-
} =
|
|
98
|
+
} = _ref6;
|
|
245
99
|
return sum + xyDifferenceFromMean;
|
|
246
100
|
}, 0);
|
|
247
101
|
const trendlineSlope = xyDifferenceFromMeanSum / xDifferenceSquaredSum;
|
|
248
102
|
const trendlineIntercept = averageY - trendlineSlope * averageX;
|
|
249
103
|
const findTrendlineValue = x => trendlineSlope * x + trendlineIntercept;
|
|
250
|
-
return chartData.map((
|
|
104
|
+
return chartData.map((_ref7, idx) => {
|
|
251
105
|
let {
|
|
252
106
|
totalEmissionsSumTons
|
|
253
|
-
} =
|
|
254
|
-
otherProps = _objectWithoutProperties(
|
|
107
|
+
} = _ref7,
|
|
108
|
+
otherProps = _objectWithoutProperties(_ref7, _excluded);
|
|
255
109
|
return _objectSpread(_objectSpread({}, otherProps), {}, {
|
|
256
110
|
trendline: findTrendlineValue(idx)
|
|
257
111
|
});
|
|
258
112
|
});
|
|
259
113
|
};
|
|
260
|
-
const LabeledEmissionsChart =
|
|
114
|
+
const LabeledEmissionsChart = _ref8 => {
|
|
261
115
|
var _data$, _data;
|
|
262
116
|
let {
|
|
263
117
|
data,
|
|
@@ -267,7 +121,7 @@ const LabeledEmissionsChart = _ref11 => {
|
|
|
267
121
|
chartArray,
|
|
268
122
|
aspect = 3,
|
|
269
123
|
showTooltip = true
|
|
270
|
-
} =
|
|
124
|
+
} = _ref8;
|
|
271
125
|
const {
|
|
272
126
|
palette
|
|
273
127
|
} = (0, _material.useTheme)();
|
|
@@ -307,12 +161,12 @@ const LabeledEmissionsChart = _ref11 => {
|
|
|
307
161
|
categoriesArray: chartArray,
|
|
308
162
|
displayUnitLabel: displayUnitLabel
|
|
309
163
|
})
|
|
310
|
-
}), chartArray.map(
|
|
164
|
+
}), chartArray.map(_ref9 => {
|
|
311
165
|
let {
|
|
312
166
|
subcategory,
|
|
313
167
|
color
|
|
314
|
-
} =
|
|
315
|
-
otherProps = _objectWithoutProperties(
|
|
168
|
+
} = _ref9,
|
|
169
|
+
otherProps = _objectWithoutProperties(_ref9, _excluded2);
|
|
316
170
|
return /*#__PURE__*/_react.default.createElement(ChartElement, _extends({
|
|
317
171
|
key: "emissions-chart-element-".concat(subcategory),
|
|
318
172
|
type: "monotone",
|
|
@@ -332,7 +186,7 @@ const LabeledEmissionsChart = _ref11 => {
|
|
|
332
186
|
strokeDasharray: "5 5"
|
|
333
187
|
}))), warningLabels);
|
|
334
188
|
};
|
|
335
|
-
const EmissionsChart =
|
|
189
|
+
const EmissionsChart = _ref10 => {
|
|
336
190
|
let {
|
|
337
191
|
dataArray: emissions,
|
|
338
192
|
type,
|
|
@@ -340,7 +194,6 @@ const EmissionsChart = _ref13 => {
|
|
|
340
194
|
graphPeriod,
|
|
341
195
|
chartRef,
|
|
342
196
|
showTrendline,
|
|
343
|
-
showProjection,
|
|
344
197
|
displayUnit,
|
|
345
198
|
unitConverter,
|
|
346
199
|
aspect,
|
|
@@ -350,73 +203,54 @@ const EmissionsChart = _ref13 => {
|
|
|
350
203
|
convertCarbonUnits,
|
|
351
204
|
displayUnitLabel,
|
|
352
205
|
branding
|
|
353
|
-
} =
|
|
206
|
+
} = _ref10;
|
|
354
207
|
const {
|
|
355
208
|
chartLabelsArray,
|
|
356
|
-
latestEmissionDate,
|
|
357
209
|
scopesArray,
|
|
358
210
|
subcategoriesArray,
|
|
359
|
-
period,
|
|
360
211
|
groupedEmissions
|
|
361
212
|
} = (0, _chartHelpers.buildEmissionGroupData)(emissions, graphPeriod, startDate, branding);
|
|
362
|
-
const isDataProjected = findIsDataProjected(latestEmissionDate);
|
|
363
|
-
const isFirstPeriodEstimated = findIsFirstPeriodEstimated(chartLabelsArray, graphPeriod);
|
|
364
|
-
const buildProjectionObj = viewMode === "subcategories" ? buildSubcategoriesProjectionObj : buildScopesProjectionObj;
|
|
365
213
|
const buildRealDataObj = viewMode === "subcategories" ? _chartHelpers.buildSubcategoriesDataObj : _chartHelpers.buildScopesRealDataObj;
|
|
366
214
|
const buildChartData = () => {
|
|
367
215
|
const preliminaryChartData = buildGroupedChartData({
|
|
368
|
-
startDate,
|
|
369
|
-
period,
|
|
370
|
-
isDataProjected,
|
|
371
|
-
isFirstPeriodEstimated,
|
|
372
216
|
groupedEmissions,
|
|
373
|
-
buildProjectionObj,
|
|
374
217
|
buildRealDataObj,
|
|
375
|
-
|
|
376
|
-
});
|
|
377
|
-
const formattedLabels = chartLabelsArray.map((label, idx) => {
|
|
378
|
-
if (idx === chartLabelsArray.length - 1 && isDataProjected) {
|
|
379
|
-
return "".concat(label, "*");
|
|
380
|
-
}
|
|
381
|
-
if (idx || !isFirstPeriodEstimated) {
|
|
382
|
-
return label;
|
|
383
|
-
}
|
|
384
|
-
return "".concat(label, "**");
|
|
218
|
+
viewMode
|
|
385
219
|
});
|
|
386
|
-
const convertChartDataObject = (chartDataObj, converter) => Object.fromEntries(Object.entries(chartDataObj).map(
|
|
387
|
-
let [key, value] =
|
|
220
|
+
const convertChartDataObject = (chartDataObj, converter) => Object.fromEntries(Object.entries(chartDataObj).map(_ref11 => {
|
|
221
|
+
let [key, value] = _ref11;
|
|
388
222
|
if (typeof value !== "number") {
|
|
389
223
|
return [key, value];
|
|
390
224
|
}
|
|
391
225
|
return [key, converter(value)];
|
|
392
226
|
}));
|
|
393
227
|
const labelChartData = chartData => chartData.map((data, idx) => _objectSpread(_objectSpread({}, data), {}, {
|
|
394
|
-
label:
|
|
228
|
+
label: chartLabelsArray[idx]
|
|
395
229
|
}));
|
|
396
230
|
if (isPercentageChart) {
|
|
397
231
|
const percentageConvertedChartData = preliminaryChartData.map(chartDataObj => {
|
|
398
|
-
const objectSubcategoryProperties = Object.keys(chartDataObj).filter(key => _subcategories.subcategories.find(
|
|
232
|
+
const objectSubcategoryProperties = Object.keys(chartDataObj).filter(key => _subcategories.subcategories.find(_ref12 => {
|
|
399
233
|
let {
|
|
400
234
|
subcategory
|
|
401
|
-
} =
|
|
235
|
+
} = _ref12;
|
|
402
236
|
return subcategory === key;
|
|
403
237
|
}));
|
|
404
238
|
const objectSubcategoryValues = objectSubcategoryProperties.map(subcategory => ({
|
|
405
239
|
key: subcategory,
|
|
406
240
|
value: chartDataObj[subcategory]
|
|
407
241
|
}));
|
|
408
|
-
const periodEmissionsSum = objectSubcategoryValues.reduce((sum,
|
|
242
|
+
const periodEmissionsSum = objectSubcategoryValues.reduce((sum, _ref13) => {
|
|
409
243
|
let {
|
|
410
244
|
value
|
|
411
|
-
} =
|
|
245
|
+
} = _ref13;
|
|
412
246
|
return value + sum;
|
|
413
247
|
}, 0);
|
|
414
248
|
const percentageConverter = value => value / periodEmissionsSum * 100;
|
|
415
|
-
const newObject = Object.fromEntries(objectSubcategoryValues.map(
|
|
249
|
+
const newObject = Object.fromEntries(objectSubcategoryValues.map(_ref14 => {
|
|
416
250
|
let {
|
|
417
251
|
key,
|
|
418
252
|
value
|
|
419
|
-
} =
|
|
253
|
+
} = _ref14;
|
|
420
254
|
return [key, value];
|
|
421
255
|
}));
|
|
422
256
|
return convertChartDataObject(newObject, percentageConverter);
|
|
@@ -445,22 +279,6 @@ const EmissionsChart = _ref13 => {
|
|
|
445
279
|
chartArray: chartArray,
|
|
446
280
|
aspect: aspect,
|
|
447
281
|
showTooltip: showTooltip
|
|
448
|
-
}))
|
|
449
|
-
item: true,
|
|
450
|
-
container: true,
|
|
451
|
-
justifyContent: "flex-end"
|
|
452
|
-
}, /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
453
|
-
item: true
|
|
454
|
-
}, isDataProjected && showProjection && /*#__PURE__*/_react.default.createElement(_material.Typography, {
|
|
455
|
-
variant: "caption",
|
|
456
|
-
color: "textSecondary",
|
|
457
|
-
display: "block",
|
|
458
|
-
align: "right"
|
|
459
|
-
}, "*Data in the most recent period is projected since this period isn't complete yet."), isFirstPeriodEstimated && showProjection && /*#__PURE__*/_react.default.createElement(_material.Typography, {
|
|
460
|
-
variant: "caption",
|
|
461
|
-
color: "textSecondary",
|
|
462
|
-
display: "block",
|
|
463
|
-
align: "right"
|
|
464
|
-
}, "**Data in the first period is estimated since your start date is in the middle of this period."))));
|
|
282
|
+
})));
|
|
465
283
|
};
|
|
466
284
|
var _default = exports.default = EmissionsChart;
|
|
@@ -82,13 +82,7 @@ const EmissionsCustomTooltip = _ref2 => {
|
|
|
82
82
|
dataArray = [],
|
|
83
83
|
displayUnitLabel
|
|
84
84
|
} = _ref2;
|
|
85
|
-
const buildSubtitle = (realCarbonVolume,
|
|
86
|
-
const baseSubtitle = "".concat((0, _formatters.formatDecimal)(realCarbonVolume), " ").concat(displayUnitLabel, " CO2");
|
|
87
|
-
if (!projectedCarbonVolume) {
|
|
88
|
-
return baseSubtitle;
|
|
89
|
-
}
|
|
90
|
-
return "".concat(baseSubtitle, " (").concat((0, _formatters.formatDecimal)(projectedCarbonVolume), " projected)");
|
|
91
|
-
};
|
|
85
|
+
const buildSubtitle = realCarbonVolume => "".concat((0, _formatters.formatDecimal)(realCarbonVolume), " ").concat(displayUnitLabel, " CO2");
|
|
92
86
|
const columnDetails = payload === null || payload === void 0 || (_payload$ = payload[0]) === null || _payload$ === void 0 ? void 0 : _payload$.payload;
|
|
93
87
|
const _ref3 = columnDetails || {},
|
|
94
88
|
{
|
|
@@ -119,14 +113,11 @@ const EmissionsCustomTooltip = _ref2 => {
|
|
|
119
113
|
return subcategory;
|
|
120
114
|
}))];
|
|
121
115
|
const subcategoryDisplayArray = uniqueSubcategories.map(subcategory => {
|
|
122
|
-
var _filteredFormattedGra
|
|
123
|
-
const realValue = (_filteredFormattedGra = filteredFormattedGraphValuesArray.find(graphValue => graphValue.subcategory === subcategory
|
|
124
|
-
const projectedValue = (_filteredFormattedGra2 = filteredFormattedGraphValuesArray.find(graphValue => graphValue.subcategory === subcategory && !!graphValue.projected)) === null || _filteredFormattedGra2 === void 0 ? void 0 : _filteredFormattedGra2.value;
|
|
116
|
+
var _filteredFormattedGra;
|
|
117
|
+
const realValue = (_filteredFormattedGra = filteredFormattedGraphValuesArray.find(graphValue => graphValue.subcategory === subcategory)) === null || _filteredFormattedGra === void 0 ? void 0 : _filteredFormattedGra.value;
|
|
125
118
|
return {
|
|
126
119
|
subcategory,
|
|
127
|
-
realValue
|
|
128
|
-
projectedValue,
|
|
129
|
-
subtitle: buildSubtitle(realValue, projectedValue)
|
|
120
|
+
subtitle: buildSubtitle(realValue)
|
|
130
121
|
};
|
|
131
122
|
});
|
|
132
123
|
const displayArrayWithIcons = subcategoryDisplayArray.map(_ref7 => {
|
|
@@ -135,15 +126,11 @@ const EmissionsCustomTooltip = _ref2 => {
|
|
|
135
126
|
} = _ref7,
|
|
136
127
|
otherProps = _objectWithoutProperties(_ref7, _excluded2);
|
|
137
128
|
const {
|
|
138
|
-
Icon,
|
|
139
129
|
color,
|
|
140
|
-
icon,
|
|
141
130
|
name
|
|
142
131
|
} = categoriesArray.find(categoryObj => categoryObj.subcategory === subcategory) || {};
|
|
143
132
|
return _objectSpread({
|
|
144
133
|
subcategory,
|
|
145
|
-
Icon,
|
|
146
|
-
icon,
|
|
147
134
|
color,
|
|
148
135
|
name
|
|
149
136
|
}, otherProps);
|
|
@@ -30,9 +30,10 @@ const PieChartCustomTooltip = _ref => {
|
|
|
30
30
|
const {
|
|
31
31
|
name,
|
|
32
32
|
emissionPercentage,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
scope,
|
|
34
|
+
subcategory,
|
|
35
|
+
viewMode,
|
|
36
|
+
color
|
|
36
37
|
} = payload;
|
|
37
38
|
return /*#__PURE__*/_react.default.createElement(_atoms.DefaultPaper, null, /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
38
39
|
container: true,
|
|
@@ -40,16 +41,12 @@ const PieChartCustomTooltip = _ref => {
|
|
|
40
41
|
alignItems: "center"
|
|
41
42
|
}, /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
42
43
|
item: true
|
|
43
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
style: {
|
|
50
|
-
color: "inherit"
|
|
51
|
-
}
|
|
52
|
-
}))), /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
44
|
+
}, /*#__PURE__*/_react.default.createElement(_atoms.CategoriesAvatar, {
|
|
45
|
+
scope: scope,
|
|
46
|
+
subcategory: subcategory,
|
|
47
|
+
viewMode: viewMode,
|
|
48
|
+
color: color
|
|
49
|
+
})), /*#__PURE__*/_react.default.createElement(_material.Grid, {
|
|
53
50
|
item: true
|
|
54
51
|
}, /*#__PURE__*/_react.default.createElement(_material.Typography, {
|
|
55
52
|
variant: "subtitle1",
|
|
@@ -92,6 +89,7 @@ const EmissionsPieChart = _ref2 => {
|
|
|
92
89
|
const emissionsWithThisCategory = emissions.filter(filterFunction(subcategory));
|
|
93
90
|
const categoryEmissionsSum = (0, _otherHelpers.sumTonsCo2e)(emissionsWithThisCategory);
|
|
94
91
|
return _objectSpread(_objectSpread({}, subcategoryObj), {}, {
|
|
92
|
+
viewMode,
|
|
95
93
|
emissionPercentage: categoryEmissionsSum / emissionsSum * 100
|
|
96
94
|
});
|
|
97
95
|
});
|
package/package.json
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aclymatepackages/modules",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "Aclymate modules",
|
|
5
5
|
"author": "William Loopesko",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@aclymatepackages/array-immutability-helpers": "^1.0.0",
|
|
9
|
-
"@aclymatepackages/atoms": "^1.0.
|
|
10
|
-
"@aclymatepackages/chart-helpers": "^1.0.
|
|
11
|
-
"@aclymatepackages/constants": "^1.0.0",
|
|
9
|
+
"@aclymatepackages/atoms": "^1.0.14",
|
|
10
|
+
"@aclymatepackages/chart-helpers": "^1.0.10",
|
|
12
11
|
"@aclymatepackages/converters": "^1.0.0",
|
|
13
|
-
"@aclymatepackages/date-helpers": "^1.0.0",
|
|
14
12
|
"@aclymatepackages/emissions-calcs": "^1.1.1",
|
|
15
13
|
"@aclymatepackages/fetch-aclymate-api": "^1.0.0",
|
|
16
14
|
"@aclymatepackages/formatters": "^1.0.0",
|
|
17
15
|
"@aclymatepackages/lists": "^1.0.0",
|
|
18
16
|
"@aclymatepackages/multi-part-form": "1.0.1",
|
|
19
|
-
"@aclymatepackages/other-helpers": "^1.0.
|
|
17
|
+
"@aclymatepackages/other-helpers": "^1.0.3",
|
|
20
18
|
"@aclymatepackages/reg-exp": "^1.0.0",
|
|
21
19
|
"@aclymatepackages/themes": "^1.0.0",
|
|
22
20
|
"@babel/preset-react": "^7.16.7",
|
|
23
21
|
"@emotion/react": "^11.11.1",
|
|
24
22
|
"@emotion/styled": "^11.11.0",
|
|
25
23
|
"@fortawesome/react-fontawesome": "^0.1.18",
|
|
26
|
-
"@mui/icons-material": "^5.11.16",
|
|
27
24
|
"@mui/lab": "^5.0.0-alpha.134",
|
|
28
25
|
"@mui/material": "^5.13.6",
|
|
29
26
|
"@stripe/react-stripe-js": "^2.1.0",
|
|
@@ -32,7 +29,6 @@
|
|
|
32
29
|
"dayjs": "^1.11.7",
|
|
33
30
|
"npm": "^8.19.4",
|
|
34
31
|
"peopledatalabs": "^5.0.4",
|
|
35
|
-
"react-cookie": "^6.1.0",
|
|
36
32
|
"react-countup": "^4.4.0",
|
|
37
33
|
"recharts": "^2.10.4",
|
|
38
34
|
"typewriter-effect": "^2.18.2"
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
|
-
import { Grid, Typography
|
|
3
|
+
import { Grid, Typography } from "@mui/material";
|
|
4
4
|
|
|
5
|
+
import { CategoriesAvatar } from "@aclymatepackages/atoms";
|
|
5
6
|
import { ucFirstLetters } from "@aclymatepackages/formatters";
|
|
6
7
|
|
|
7
8
|
const CustomTooltipDisplayRow = ({
|
|
8
9
|
category,
|
|
9
|
-
Icon,
|
|
10
|
-
icon,
|
|
11
10
|
customAvatar,
|
|
12
11
|
color,
|
|
13
12
|
name,
|
|
14
13
|
subtitle,
|
|
14
|
+
viewMode,
|
|
15
|
+
subcategory,
|
|
16
|
+
scope,
|
|
15
17
|
}) => (
|
|
16
18
|
<Grid item container spacing={1} wrap="nowrap" alignItems="center">
|
|
17
19
|
<Grid item>
|
|
18
20
|
{customAvatar || (
|
|
19
|
-
<
|
|
20
|
-
{
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
<CategoriesAvatar
|
|
22
|
+
viewMode={viewMode}
|
|
23
|
+
color={color}
|
|
24
|
+
subcategory={subcategory}
|
|
25
|
+
scope={scope}
|
|
26
|
+
/>
|
|
23
27
|
)}
|
|
24
28
|
</Grid>
|
|
25
29
|
<Grid item container direction="column" wrap="nowrap">
|
|
@@ -14,15 +14,9 @@ import {
|
|
|
14
14
|
Tooltip as ChartTooltip,
|
|
15
15
|
} from "recharts";
|
|
16
16
|
|
|
17
|
-
import { Grid,
|
|
17
|
+
import { Grid, Box, useTheme } from "@mui/material";
|
|
18
18
|
|
|
19
19
|
import { formatDecimal } from "@aclymatepackages/formatters";
|
|
20
|
-
import {
|
|
21
|
-
findInclusiveDateDifference,
|
|
22
|
-
findYearFirstDate,
|
|
23
|
-
findQuarterDate,
|
|
24
|
-
} from "@aclymatepackages/date-helpers";
|
|
25
|
-
import { DAYS_PER_YEAR } from "@aclymatepackages/constants";
|
|
26
20
|
import { sumTonsCo2e } from "@aclymatepackages/other-helpers";
|
|
27
21
|
|
|
28
22
|
import EmissionsCustomTooltip from "./EmissionsCustomTooltip";
|
|
@@ -31,7 +25,6 @@ import useChartWarningLabels from "./useChartWarningLabels";
|
|
|
31
25
|
import {
|
|
32
26
|
buildScopesRealDataObj,
|
|
33
27
|
buildSubcategoriesDataObj,
|
|
34
|
-
sumEmissionsTonsBySubcategory,
|
|
35
28
|
buildEmissionGroupData,
|
|
36
29
|
} from "@aclymatepackages/chart-helpers";
|
|
37
30
|
import {
|
|
@@ -41,223 +34,20 @@ import {
|
|
|
41
34
|
|
|
42
35
|
dayjs.extend(dayOfYear);
|
|
43
36
|
|
|
44
|
-
const DAYS_IN_QUARTER = DAYS_PER_YEAR / 4;
|
|
45
|
-
|
|
46
37
|
const findObjectValuesSum = (object) =>
|
|
47
38
|
Object.values(object).reduce((sum, value) => sum + value, 0);
|
|
48
39
|
|
|
49
|
-
const findLabelDate = (period, label) => {
|
|
50
|
-
if (period === "quarter") {
|
|
51
|
-
return findQuarterDate(label);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (period === "year") {
|
|
55
|
-
return findYearFirstDate(label);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return dayjs(label, "MM-YY");
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const isDateFirstDateOfPeriod = (date, period) => {
|
|
62
|
-
if (period === "quarter") {
|
|
63
|
-
const quarterFirstDate = findQuarterDate(date);
|
|
64
|
-
return dayjs(date).isSame(quarterFirstDate, "day");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (period === "year") {
|
|
68
|
-
const yearFirstDate = findYearFirstDate(date);
|
|
69
|
-
return dayjs(date).isSame(yearFirstDate, "day");
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return dayjs(date).date() === 1;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const findIsEstimatedFirstDateLabel = ({
|
|
76
|
-
startDate,
|
|
77
|
-
earliestEmissionDate,
|
|
78
|
-
label,
|
|
79
|
-
period,
|
|
80
|
-
}) => {
|
|
81
|
-
const labelDate = findLabelDate(period, label);
|
|
82
|
-
const labelStartDateDifference = findInclusiveDateDifference(
|
|
83
|
-
labelDate,
|
|
84
|
-
startDate,
|
|
85
|
-
period
|
|
86
|
-
);
|
|
87
|
-
const labelDateIsFirstOfPeriod = isDateFirstDateOfPeriod(
|
|
88
|
-
earliestEmissionDate,
|
|
89
|
-
period
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
return labelStartDateDifference === 1 && !labelDateIsFirstOfPeriod;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const findIsFirstPeriodEstimated = (chartLabelsArray, period) =>
|
|
96
|
-
!chartLabelsArray.reduce(
|
|
97
|
-
(acc, label) => acc && !findIsEstimatedFirstDateLabel({ label, period }),
|
|
98
|
-
true
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
const findIsDataProjected = (latestEmissionDate) => {
|
|
102
|
-
if (!dayjs(latestEmissionDate).isSame(dayjs(), "month")) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
return dayjs(latestEmissionDate).date() !== dayjs().daysInMonth();
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const findProjectedSubcategoryValueFromEmissions =
|
|
109
|
-
({ emissions, projectionMultiplier }) =>
|
|
110
|
-
(subcategory) => {
|
|
111
|
-
const recurringSubcategoryEmissionsSum = sumEmissionsTonsBySubcategory(
|
|
112
|
-
emissions,
|
|
113
|
-
subcategory
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
return projectionMultiplier * recurringSubcategoryEmissionsSum;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const buildSubcategoriesProjectionObj = (emissions, projectionMultiplier) => {
|
|
120
|
-
const findProjectedSubcategoryValue =
|
|
121
|
-
findProjectedSubcategoryValueFromEmissions({
|
|
122
|
-
emissions,
|
|
123
|
-
projectionMultiplier,
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
"commuting-auto_projected": findProjectedSubcategoryValue("commuting-auto"),
|
|
128
|
-
"home-office_projected": findProjectedSubcategoryValue("home-office"),
|
|
129
|
-
utilities_projected: findProjectedSubcategoryValue("utilities"),
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const buildScopesProjectionObj = (emissions, projectionMultiplier) => {
|
|
134
|
-
const findProjectedSubcategoryValue =
|
|
135
|
-
findProjectedSubcategoryValueFromEmissions({
|
|
136
|
-
emissions,
|
|
137
|
-
projectionMultiplier,
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
const projectedCommutingEmissionsTons =
|
|
141
|
-
findProjectedSubcategoryValue("commuting-auto");
|
|
142
|
-
const projectedHomeOfficeEmissionsTons =
|
|
143
|
-
findProjectedSubcategoryValue("homeOffice");
|
|
144
|
-
const projectedElectricityEmissionsTons =
|
|
145
|
-
findProjectedSubcategoryValue("electricity");
|
|
146
|
-
const projectedGasEmissionsTons = findProjectedSubcategoryValue("gas");
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
scope1_projected: projectedGasEmissionsTons,
|
|
150
|
-
scope2_projected: projectedElectricityEmissionsTons,
|
|
151
|
-
scope3_projected:
|
|
152
|
-
projectedHomeOfficeEmissionsTons + projectedCommutingEmissionsTons,
|
|
153
|
-
};
|
|
154
|
-
};
|
|
155
|
-
|
|
156
40
|
const buildGroupedChartData = ({
|
|
157
|
-
startDate = "",
|
|
158
|
-
period,
|
|
159
|
-
isDataProjected,
|
|
160
|
-
isFirstPeriodEstimated,
|
|
161
41
|
groupedEmissions,
|
|
162
|
-
buildProjectionObj,
|
|
163
42
|
buildRealDataObj,
|
|
164
|
-
|
|
43
|
+
viewMode,
|
|
165
44
|
}) => {
|
|
166
|
-
const findPeriodPosition = (idx) => {
|
|
167
|
-
if (!idx) {
|
|
168
|
-
return "first";
|
|
169
|
-
}
|
|
170
|
-
if (idx === groupedEmissions.length - 1) {
|
|
171
|
-
return "last";
|
|
172
|
-
}
|
|
173
|
-
return "middle";
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const forwardProjectionPeriodFraction = (period) => {
|
|
177
|
-
if (period === "month") {
|
|
178
|
-
const daysInMonth = dayjs().daysInMonth();
|
|
179
|
-
return dayjs().date() / daysInMonth;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (period === "quarter") {
|
|
183
|
-
const firstDayInQuarter = findQuarterDate(dayjs());
|
|
184
|
-
const currentDaysIntoQuarter = dayjs().diff(firstDayInQuarter, "day");
|
|
185
|
-
return currentDaysIntoQuarter / DAYS_IN_QUARTER;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const currentDaysIntoYear = dayjs().dayOfYear();
|
|
189
|
-
return currentDaysIntoYear / DAYS_PER_YEAR;
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const backwardsProjectionPeriodFraction = (period) => {
|
|
193
|
-
const formattedStartDate = dayjs(startDate);
|
|
194
|
-
if (period === "month") {
|
|
195
|
-
const daysInMonth = formattedStartDate.daysInMonth();
|
|
196
|
-
const daysFromEndOfMonth = daysInMonth - formattedStartDate.date();
|
|
197
|
-
return daysFromEndOfMonth / daysInMonth;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (period === "quarter") {
|
|
201
|
-
const lastDateInQuarter = findQuarterDate(startDate, false);
|
|
202
|
-
const daysFromEndOfQuarter =
|
|
203
|
-
Math.abs(formattedStartDate.diff(lastDateInQuarter, "day")) + 1;
|
|
204
|
-
return daysFromEndOfQuarter / DAYS_IN_QUARTER;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const daysFromEndOfYear = Math.abs(
|
|
208
|
-
formattedStartDate.diff(
|
|
209
|
-
dayjs(new Date(formattedStartDate.year(), 12, 31)),
|
|
210
|
-
"day"
|
|
211
|
-
)
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
return daysFromEndOfYear / DAYS_PER_YEAR;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const findPeriodProjectionMultiplier = ({ period, position }) => {
|
|
218
|
-
if (
|
|
219
|
-
!showProjection ||
|
|
220
|
-
position === "middle" ||
|
|
221
|
-
(position === "first" && !isFirstPeriodEstimated) ||
|
|
222
|
-
(position === "last" && !isDataProjected)
|
|
223
|
-
) {
|
|
224
|
-
return 0;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
//TODO: -UPDATE: this projection function doesn't take into account closed offices or terminated employee, so we probably need to rethink it
|
|
228
|
-
const projectionFraction =
|
|
229
|
-
position === "first"
|
|
230
|
-
? backwardsProjectionPeriodFraction(period)
|
|
231
|
-
: forwardProjectionPeriodFraction(period);
|
|
232
|
-
|
|
233
|
-
return 1 / projectionFraction - 1;
|
|
234
|
-
};
|
|
235
|
-
|
|
236
45
|
return groupedEmissions.map((emissionsArray, idx) => {
|
|
237
|
-
const position = findPeriodPosition(idx, groupedEmissions);
|
|
238
|
-
const projectionMultiplier = findPeriodProjectionMultiplier({
|
|
239
|
-
startDate,
|
|
240
|
-
position,
|
|
241
|
-
period,
|
|
242
|
-
isDataProjected,
|
|
243
|
-
isFirstPeriodEstimated,
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
const projectedCategoriesObj = buildProjectionObj(
|
|
247
|
-
emissionsArray,
|
|
248
|
-
projectionMultiplier
|
|
249
|
-
);
|
|
250
|
-
|
|
251
46
|
const subcategoriesObj = buildRealDataObj(
|
|
252
47
|
emissionsArray,
|
|
253
48
|
allSubcategoriesWithOther
|
|
254
49
|
);
|
|
255
50
|
|
|
256
|
-
const chartCategoriesObj = {
|
|
257
|
-
...projectedCategoriesObj,
|
|
258
|
-
...subcategoriesObj,
|
|
259
|
-
};
|
|
260
|
-
|
|
261
51
|
const buildWarningObj = () => {
|
|
262
52
|
const singleEmissionWarning = emissionsArray.find(
|
|
263
53
|
({ warning }) => !!warning
|
|
@@ -272,12 +62,12 @@ const buildGroupedChartData = ({
|
|
|
272
62
|
};
|
|
273
63
|
|
|
274
64
|
return {
|
|
275
|
-
...
|
|
65
|
+
...subcategoriesObj,
|
|
276
66
|
warning: buildWarningObj(),
|
|
277
67
|
id: `emissions-chart-group-${idx}`,
|
|
278
68
|
emissionsSumTons: sumTonsCo2e(emissionsArray),
|
|
279
|
-
totalEmissionsSumTons: findObjectValuesSum(
|
|
280
|
-
|
|
69
|
+
totalEmissionsSumTons: findObjectValuesSum(subcategoriesObj),
|
|
70
|
+
viewMode,
|
|
281
71
|
};
|
|
282
72
|
});
|
|
283
73
|
};
|
|
@@ -403,7 +193,6 @@ const EmissionsChart = ({
|
|
|
403
193
|
graphPeriod,
|
|
404
194
|
chartRef,
|
|
405
195
|
showTrendline,
|
|
406
|
-
showProjection,
|
|
407
196
|
displayUnit,
|
|
408
197
|
unitConverter,
|
|
409
198
|
aspect,
|
|
@@ -416,24 +205,11 @@ const EmissionsChart = ({
|
|
|
416
205
|
}) => {
|
|
417
206
|
const {
|
|
418
207
|
chartLabelsArray,
|
|
419
|
-
latestEmissionDate,
|
|
420
208
|
scopesArray,
|
|
421
209
|
subcategoriesArray,
|
|
422
|
-
period,
|
|
423
210
|
groupedEmissions,
|
|
424
211
|
} = buildEmissionGroupData(emissions, graphPeriod, startDate, branding);
|
|
425
212
|
|
|
426
|
-
const isDataProjected = findIsDataProjected(latestEmissionDate);
|
|
427
|
-
const isFirstPeriodEstimated = findIsFirstPeriodEstimated(
|
|
428
|
-
chartLabelsArray,
|
|
429
|
-
graphPeriod
|
|
430
|
-
);
|
|
431
|
-
|
|
432
|
-
const buildProjectionObj =
|
|
433
|
-
viewMode === "subcategories"
|
|
434
|
-
? buildSubcategoriesProjectionObj
|
|
435
|
-
: buildScopesProjectionObj;
|
|
436
|
-
|
|
437
213
|
const buildRealDataObj =
|
|
438
214
|
viewMode === "subcategories"
|
|
439
215
|
? buildSubcategoriesDataObj
|
|
@@ -441,26 +217,9 @@ const EmissionsChart = ({
|
|
|
441
217
|
|
|
442
218
|
const buildChartData = () => {
|
|
443
219
|
const preliminaryChartData = buildGroupedChartData({
|
|
444
|
-
startDate,
|
|
445
|
-
period,
|
|
446
|
-
isDataProjected,
|
|
447
|
-
isFirstPeriodEstimated,
|
|
448
220
|
groupedEmissions,
|
|
449
|
-
buildProjectionObj,
|
|
450
221
|
buildRealDataObj,
|
|
451
|
-
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
const formattedLabels = chartLabelsArray.map((label, idx) => {
|
|
455
|
-
if (idx === chartLabelsArray.length - 1 && isDataProjected) {
|
|
456
|
-
return `${label}*`;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
if (idx || !isFirstPeriodEstimated) {
|
|
460
|
-
return label;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
return `${label}**`;
|
|
222
|
+
viewMode,
|
|
464
223
|
});
|
|
465
224
|
|
|
466
225
|
const convertChartDataObject = (chartDataObj, converter) =>
|
|
@@ -476,7 +235,7 @@ const EmissionsChart = ({
|
|
|
476
235
|
const labelChartData = (chartData) =>
|
|
477
236
|
chartData.map((data, idx) => ({
|
|
478
237
|
...data,
|
|
479
|
-
label:
|
|
238
|
+
label: chartLabelsArray[idx],
|
|
480
239
|
}));
|
|
481
240
|
|
|
482
241
|
if (isPercentageChart) {
|
|
@@ -545,34 +304,6 @@ const EmissionsChart = ({
|
|
|
545
304
|
showTooltip={showTooltip}
|
|
546
305
|
/>
|
|
547
306
|
</Grid>
|
|
548
|
-
{(isDataProjected || isFirstPeriodEstimated) && (
|
|
549
|
-
<Grid item container justifyContent="flex-end">
|
|
550
|
-
<Grid item>
|
|
551
|
-
{isDataProjected && showProjection && (
|
|
552
|
-
<Typography
|
|
553
|
-
variant="caption"
|
|
554
|
-
color="textSecondary"
|
|
555
|
-
display="block"
|
|
556
|
-
align="right"
|
|
557
|
-
>
|
|
558
|
-
*Data in the most recent period is projected since this period
|
|
559
|
-
isn't complete yet.
|
|
560
|
-
</Typography>
|
|
561
|
-
)}
|
|
562
|
-
{isFirstPeriodEstimated && showProjection && (
|
|
563
|
-
<Typography
|
|
564
|
-
variant="caption"
|
|
565
|
-
color="textSecondary"
|
|
566
|
-
display="block"
|
|
567
|
-
align="right"
|
|
568
|
-
>
|
|
569
|
-
**Data in the first period is estimated since your start date is
|
|
570
|
-
in the middle of this period.
|
|
571
|
-
</Typography>
|
|
572
|
-
)}
|
|
573
|
-
</Grid>
|
|
574
|
-
</Grid>
|
|
575
|
-
)}
|
|
576
307
|
</Grid>
|
|
577
308
|
);
|
|
578
309
|
};
|
|
@@ -50,19 +50,8 @@ const EmissionsCustomTooltip = ({
|
|
|
50
50
|
dataArray = [],
|
|
51
51
|
displayUnitLabel,
|
|
52
52
|
}) => {
|
|
53
|
-
const buildSubtitle = (realCarbonVolume
|
|
54
|
-
|
|
55
|
-
realCarbonVolume
|
|
56
|
-
)} ${displayUnitLabel} CO2`;
|
|
57
|
-
|
|
58
|
-
if (!projectedCarbonVolume) {
|
|
59
|
-
return baseSubtitle;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return `${baseSubtitle} (${formatDecimal(
|
|
63
|
-
projectedCarbonVolume
|
|
64
|
-
)} projected)`;
|
|
65
|
-
};
|
|
53
|
+
const buildSubtitle = (realCarbonVolume) =>
|
|
54
|
+
`${formatDecimal(realCarbonVolume)} ${displayUnitLabel} CO2`;
|
|
66
55
|
|
|
67
56
|
const columnDetails = payload?.[0]?.payload;
|
|
68
57
|
const {
|
|
@@ -90,30 +79,22 @@ const EmissionsCustomTooltip = ({
|
|
|
90
79
|
|
|
91
80
|
const subcategoryDisplayArray = uniqueSubcategories.map((subcategory) => {
|
|
92
81
|
const realValue = filteredFormattedGraphValuesArray.find(
|
|
93
|
-
(graphValue) =>
|
|
94
|
-
graphValue.subcategory === subcategory && !graphValue.projected
|
|
95
|
-
)?.value;
|
|
96
|
-
|
|
97
|
-
const projectedValue = filteredFormattedGraphValuesArray.find(
|
|
98
|
-
(graphValue) =>
|
|
99
|
-
graphValue.subcategory === subcategory && !!graphValue.projected
|
|
82
|
+
(graphValue) => graphValue.subcategory === subcategory
|
|
100
83
|
)?.value;
|
|
101
84
|
|
|
102
85
|
return {
|
|
103
86
|
subcategory,
|
|
104
|
-
realValue,
|
|
105
|
-
projectedValue,
|
|
106
|
-
subtitle: buildSubtitle(realValue, projectedValue),
|
|
87
|
+
subtitle: buildSubtitle(realValue),
|
|
107
88
|
};
|
|
108
89
|
});
|
|
109
90
|
|
|
110
91
|
const displayArrayWithIcons = subcategoryDisplayArray
|
|
111
92
|
.map(({ subcategory, ...otherProps }) => {
|
|
112
|
-
const {
|
|
93
|
+
const { color, name } =
|
|
113
94
|
categoriesArray.find(
|
|
114
95
|
(categoryObj) => categoryObj.subcategory === subcategory
|
|
115
96
|
) || {};
|
|
116
|
-
return { subcategory,
|
|
97
|
+
return { subcategory, color, name, ...otherProps };
|
|
117
98
|
})
|
|
118
99
|
.filter(({ color }) => color);
|
|
119
100
|
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
Cell,
|
|
9
9
|
} from "recharts";
|
|
10
10
|
|
|
11
|
-
import { Typography, Grid
|
|
11
|
+
import { Typography, Grid } from "@mui/material";
|
|
12
12
|
|
|
13
|
-
import { DefaultPaper } from "@aclymatepackages/atoms";
|
|
13
|
+
import { DefaultPaper, CategoriesAvatar } from "@aclymatepackages/atoms";
|
|
14
14
|
import { formatDecimal } from "@aclymatepackages/formatters";
|
|
15
15
|
import { sumTonsCo2e } from "@aclymatepackages/other-helpers";
|
|
16
16
|
import {
|
|
@@ -21,16 +21,19 @@ import {
|
|
|
21
21
|
const PieChartCustomTooltip = ({ payload: passedPayload }) => {
|
|
22
22
|
const [payloadObj] = passedPayload;
|
|
23
23
|
const { payload = {} } = payloadObj || [{}];
|
|
24
|
-
const { name, emissionPercentage,
|
|
24
|
+
const { name, emissionPercentage, scope, subcategory, viewMode, color } =
|
|
25
|
+
payload;
|
|
25
26
|
|
|
26
27
|
return (
|
|
27
28
|
<DefaultPaper>
|
|
28
29
|
<Grid container spacing={2} alignItems="center">
|
|
29
30
|
<Grid item>
|
|
30
|
-
<
|
|
31
|
-
{
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
<CategoriesAvatar
|
|
32
|
+
scope={scope}
|
|
33
|
+
subcategory={subcategory}
|
|
34
|
+
viewMode={viewMode}
|
|
35
|
+
color={color}
|
|
36
|
+
/>
|
|
34
37
|
</Grid>
|
|
35
38
|
<Grid item>
|
|
36
39
|
<Typography variant="subtitle1" color="textPrimary">
|
|
@@ -84,6 +87,7 @@ const EmissionsPieChart = ({
|
|
|
84
87
|
|
|
85
88
|
return {
|
|
86
89
|
...subcategoryObj,
|
|
90
|
+
viewMode,
|
|
87
91
|
emissionPercentage: (categoryEmissionsSum / emissionsSum) * 100,
|
|
88
92
|
};
|
|
89
93
|
});
|