@backstage-community/plugin-opencost 0.2.10 → 0.2.11
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/CHANGELOG.md +6 -0
- package/dist/components/AllocationChart/RangeChart.esm.js +150 -0
- package/dist/components/AllocationChart/RangeChart.esm.js.map +1 -0
- package/dist/components/AllocationChart/SummaryChart.esm.js +89 -0
- package/dist/components/AllocationChart/SummaryChart.esm.js.map +1 -0
- package/dist/components/AllocationChart/index.esm.js +84 -0
- package/dist/components/AllocationChart/index.esm.js.map +1 -0
- package/dist/components/AllocationReport.esm.js +153 -0
- package/dist/components/AllocationReport.esm.js.map +1 -0
- package/dist/components/Controls/Download.esm.js +79 -0
- package/dist/components/Controls/Download.esm.js.map +1 -0
- package/dist/components/Controls/Edit.esm.js +71 -0
- package/dist/components/Controls/Edit.esm.js.map +1 -0
- package/dist/components/Controls/index.esm.js +42 -0
- package/dist/components/Controls/index.esm.js.map +1 -0
- package/dist/components/OpenCostPage/OpenCostPage.esm.js +17 -0
- package/dist/components/OpenCostPage/OpenCostPage.esm.js.map +1 -0
- package/dist/components/OpenCostPage/index.esm.js +2 -0
- package/dist/components/OpenCostPage/index.esm.js.map +1 -0
- package/dist/components/OpenCostReport/OpenCostReport.esm.js +223 -0
- package/dist/components/OpenCostReport/OpenCostReport.esm.js.map +1 -0
- package/dist/components/Page.esm.js +24 -0
- package/dist/components/Page.esm.js.map +1 -0
- package/dist/components/SelectWindow.esm.js +179 -0
- package/dist/components/SelectWindow.esm.js.map +1 -0
- package/dist/components/Subtitle.esm.js +34 -0
- package/dist/components/Subtitle.esm.js.map +1 -0
- package/dist/components/Warnings.esm.js +22 -0
- package/dist/components/Warnings.esm.js.map +1 -0
- package/dist/constants/colors.esm.js +37 -0
- package/dist/constants/colors.esm.js.map +1 -0
- package/dist/constants/currencyCodes.esm.js +183 -0
- package/dist/constants/currencyCodes.esm.js.map +1 -0
- package/dist/index.esm.js +1 -21
- package/dist/index.esm.js.map +1 -1
- package/dist/plugin.esm.js +19 -0
- package/dist/plugin.esm.js.map +1 -0
- package/dist/routes.esm.js +8 -0
- package/dist/routes.esm.js.map +1 -0
- package/dist/services/allocation.esm.js +21 -0
- package/dist/services/allocation.esm.js.map +1 -0
- package/dist/util.esm.js +229 -0
- package/dist/util.esm.js.map +1 -0
- package/package.json +10 -6
- package/dist/esm/index-BQC8_PDN.esm.js +0 -1536
- package/dist/esm/index-BQC8_PDN.esm.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ResponsiveContainer, BarChart, CartesianGrid, XAxis, YAxis, Tooltip, Bar } from 'recharts';
|
|
3
|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
4
|
+
import { reverse } from 'lodash';
|
|
5
|
+
import { greyscale, primary, browns } from '../../constants/colors.esm.js';
|
|
6
|
+
import { toCurrency } from '../../util.esm.js';
|
|
7
|
+
|
|
8
|
+
const useStyles = makeStyles({
|
|
9
|
+
tooltip: {
|
|
10
|
+
borderRadius: 2,
|
|
11
|
+
background: "rgba(255, 255, 255, 0.95)",
|
|
12
|
+
padding: 12
|
|
13
|
+
},
|
|
14
|
+
tooltipLineItem: {
|
|
15
|
+
fontSize: "1rem",
|
|
16
|
+
margin: 0,
|
|
17
|
+
marginBottom: 4,
|
|
18
|
+
padding: 0
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
function toBarLabels(allocationRange) {
|
|
22
|
+
const keyToFill = {};
|
|
23
|
+
let p = 0;
|
|
24
|
+
let g = 0;
|
|
25
|
+
let b = 0;
|
|
26
|
+
for (const { idle } of allocationRange) {
|
|
27
|
+
for (const allocation of idle) {
|
|
28
|
+
const key = allocation.name;
|
|
29
|
+
if (keyToFill[key] === void 0) {
|
|
30
|
+
keyToFill[key] = greyscale[g];
|
|
31
|
+
g = (g + 1) % greyscale.length;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const { top } of allocationRange) {
|
|
36
|
+
for (const allocation of top) {
|
|
37
|
+
const key = allocation.name;
|
|
38
|
+
if (keyToFill[key] === void 0) {
|
|
39
|
+
if (key === "__unallocated__") {
|
|
40
|
+
keyToFill[key] = "#212121";
|
|
41
|
+
} else {
|
|
42
|
+
keyToFill[key] = primary[p];
|
|
43
|
+
p = (p + 1) % primary.length;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
for (const { other } of allocationRange) {
|
|
49
|
+
for (const allocation of other) {
|
|
50
|
+
const key = allocation.name;
|
|
51
|
+
if (keyToFill[key] === void 0) {
|
|
52
|
+
keyToFill[key] = browns[b];
|
|
53
|
+
b = (b + 1) % browns.length;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const labels = [];
|
|
58
|
+
for (const key in keyToFill) {
|
|
59
|
+
if (Object.hasOwn(keyToFill, key)) {
|
|
60
|
+
labels.push({
|
|
61
|
+
dataKey: key,
|
|
62
|
+
fill: keyToFill[key]
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return reverse(labels);
|
|
67
|
+
}
|
|
68
|
+
function toBar(datum) {
|
|
69
|
+
const { top, other, idle } = datum;
|
|
70
|
+
const bar = {};
|
|
71
|
+
for (const key in top) {
|
|
72
|
+
if (Object.hasOwn(top, key)) {
|
|
73
|
+
const allocation = top[key];
|
|
74
|
+
const start = new Date(allocation.start);
|
|
75
|
+
bar.start = `${start.getUTCFullYear()}-${start.getUTCMonth() + 1}-${start.getUTCDate()}`;
|
|
76
|
+
bar[allocation.name] = allocation.totalCost;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const key in other) {
|
|
80
|
+
if (Object.hasOwn(other, key)) {
|
|
81
|
+
const allocation = other[key];
|
|
82
|
+
const start = new Date(allocation.start);
|
|
83
|
+
bar.start = `${start.getUTCFullYear()}-${start.getUTCMonth() + 1}-${start.getUTCDate()}`;
|
|
84
|
+
bar[allocation.name] = allocation.totalCost;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const key in idle) {
|
|
88
|
+
if (Object.hasOwn(idle, key)) {
|
|
89
|
+
const allocation = idle[key];
|
|
90
|
+
const start = new Date(allocation.start);
|
|
91
|
+
bar.start = `${start.getUTCFullYear()}-${start.getUTCMonth() + 1}-${start.getUTCDate()}`;
|
|
92
|
+
bar[allocation.name] = allocation.totalCost;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return bar;
|
|
96
|
+
}
|
|
97
|
+
const RangeChart = ({ data, currency, height }) => {
|
|
98
|
+
const classes = useStyles();
|
|
99
|
+
const barData = data.map(toBar);
|
|
100
|
+
const barLabels = toBarLabels(data);
|
|
101
|
+
const CustomTooltip = (params) => {
|
|
102
|
+
const { active, payload } = params;
|
|
103
|
+
if (!payload || payload.length === 0) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const total = payload.reduce((sum, item) => sum + item.value, 0);
|
|
107
|
+
if (active) {
|
|
108
|
+
return /* @__PURE__ */ React.createElement("div", { className: classes.tooltip }, /* @__PURE__ */ React.createElement(
|
|
109
|
+
"p",
|
|
110
|
+
{
|
|
111
|
+
className: classes.tooltipLineItem,
|
|
112
|
+
style: { color: "#000000" }
|
|
113
|
+
},
|
|
114
|
+
`Total: ${toCurrency(total, currency)}`
|
|
115
|
+
), reverse(payload).map((item, i) => /* @__PURE__ */ React.createElement(
|
|
116
|
+
"p",
|
|
117
|
+
{
|
|
118
|
+
key: i,
|
|
119
|
+
className: classes.tooltipLineItem,
|
|
120
|
+
style: { color: item.fill }
|
|
121
|
+
},
|
|
122
|
+
`${item.name}: ${toCurrency(item.value, currency)}`
|
|
123
|
+
)));
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
};
|
|
127
|
+
return /* @__PURE__ */ React.createElement(ResponsiveContainer, { width: "100%", height }, /* @__PURE__ */ React.createElement(
|
|
128
|
+
BarChart,
|
|
129
|
+
{
|
|
130
|
+
data: barData,
|
|
131
|
+
margin: { top: 30, right: 30, left: 30, bottom: 12 }
|
|
132
|
+
},
|
|
133
|
+
/* @__PURE__ */ React.createElement(CartesianGrid, { strokeDasharray: "3 3" }),
|
|
134
|
+
/* @__PURE__ */ React.createElement(XAxis, { dataKey: "start" }),
|
|
135
|
+
/* @__PURE__ */ React.createElement(YAxis, null),
|
|
136
|
+
/* @__PURE__ */ React.createElement(Tooltip, { content: /* @__PURE__ */ React.createElement(CustomTooltip, null) }),
|
|
137
|
+
barLabels.map((barLabel, i) => /* @__PURE__ */ React.createElement(
|
|
138
|
+
Bar,
|
|
139
|
+
{
|
|
140
|
+
key: i,
|
|
141
|
+
dataKey: barLabel.dataKey,
|
|
142
|
+
stackId: "a",
|
|
143
|
+
fill: barLabel.fill
|
|
144
|
+
}
|
|
145
|
+
))
|
|
146
|
+
));
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export { RangeChart as default };
|
|
150
|
+
//# sourceMappingURL=RangeChart.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RangeChart.esm.js","sources":["../../../src/components/AllocationChart/RangeChart.jsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\nimport {\n BarChart,\n Bar,\n XAxis,\n YAxis,\n CartesianGrid,\n Tooltip,\n ResponsiveContainer,\n} from 'recharts';\nimport { makeStyles } from '@material-ui/core/styles';\nimport { reverse } from 'lodash';\nimport { primary, greyscale, browns } from '../../constants/colors';\nimport { toCurrency } from '../../util';\n\nconst useStyles = makeStyles({\n tooltip: {\n borderRadius: 2,\n background: 'rgba(255, 255, 255, 0.95)',\n padding: 12,\n },\n tooltipLineItem: {\n fontSize: '1rem',\n margin: 0,\n marginBottom: 4,\n padding: 0,\n },\n});\n\nfunction toBarLabels(allocationRange) {\n const keyToFill = {};\n let p = 0;\n let g = 0;\n let b = 0;\n\n for (const { idle } of allocationRange) {\n for (const allocation of idle) {\n const key = allocation.name;\n if (keyToFill[key] === undefined) {\n // idle allocations are assigned grey\n keyToFill[key] = greyscale[g];\n g = (g + 1) % greyscale.length;\n }\n }\n }\n\n for (const { top } of allocationRange) {\n for (const allocation of top) {\n const key = allocation.name;\n if (keyToFill[key] === undefined) {\n if (key === '__unallocated__') {\n // unallocated gets black (clean up)\n keyToFill[key] = '#212121';\n } else {\n // non-idle allocations get the next available color\n keyToFill[key] = primary[p];\n p = (p + 1) % primary.length;\n }\n }\n }\n }\n\n for (const { other } of allocationRange) {\n for (const allocation of other) {\n const key = allocation.name;\n if (keyToFill[key] === undefined) {\n // idle allocations are assigned grey\n keyToFill[key] = browns[b];\n b = (b + 1) % browns.length;\n }\n }\n }\n\n const labels = [];\n for (const key in keyToFill) {\n if (Object.hasOwn(keyToFill, key)) {\n labels.push({\n dataKey: key,\n fill: keyToFill[key],\n });\n }\n }\n\n return reverse(labels);\n}\n\nfunction toBar(datum) {\n const { top, other, idle } = datum;\n const bar = {};\n\n for (const key in top) {\n if (Object.hasOwn(top, key)) {\n const allocation = top[key];\n const start = new Date(allocation.start);\n bar.start = `${start.getUTCFullYear()}-${\n start.getUTCMonth() + 1\n }-${start.getUTCDate()}`;\n bar[allocation.name] = allocation.totalCost;\n }\n }\n\n for (const key in other) {\n if (Object.hasOwn(other, key)) {\n const allocation = other[key];\n const start = new Date(allocation.start);\n bar.start = `${start.getUTCFullYear()}-${\n start.getUTCMonth() + 1\n }-${start.getUTCDate()}`;\n bar[allocation.name] = allocation.totalCost;\n }\n }\n\n for (const key in idle) {\n if (Object.hasOwn(idle, key)) {\n const allocation = idle[key];\n const start = new Date(allocation.start);\n bar.start = `${start.getUTCFullYear()}-${\n start.getUTCMonth() + 1\n }-${start.getUTCDate()}`;\n bar[allocation.name] = allocation.totalCost;\n }\n }\n\n return bar;\n}\n\nconst RangeChart = ({ data, currency, height }) => {\n const classes = useStyles();\n\n const barData = data.map(toBar);\n const barLabels = toBarLabels(data);\n\n const CustomTooltip = params => {\n const { active, payload } = params;\n\n if (!payload || payload.length === 0) {\n return null;\n }\n\n const total = payload.reduce((sum, item) => sum + item.value, 0.0);\n if (active) {\n /* eslint react/forbid-elements: [0, { allow: [\"warning\"] }] */\n return (\n <div className={classes.tooltip}>\n <p\n className={classes.tooltipLineItem}\n style={{ color: '#000000' }}\n >{`Total: ${toCurrency(total, currency)}`}</p>\n {reverse(payload).map((item, i) => (\n <p\n key={i}\n className={classes.tooltipLineItem}\n style={{ color: item.fill }}\n >{`${item.name}: ${toCurrency(item.value, currency)}`}</p>\n ))}\n </div>\n );\n }\n\n return null;\n };\n\n return (\n <ResponsiveContainer width=\"100%\" height={height}>\n <BarChart\n data={barData}\n margin={{ top: 30, right: 30, left: 30, bottom: 12 }}\n >\n <CartesianGrid strokeDasharray=\"3 3\" />\n <XAxis dataKey=\"start\" />\n <YAxis />\n <Tooltip content={<CustomTooltip />} />\n {barLabels.map((barLabel, i) => (\n <Bar\n key={i}\n dataKey={barLabel.dataKey}\n stackId=\"a\"\n fill={barLabel.fill}\n />\n ))}\n </BarChart>\n </ResponsiveContainer>\n );\n};\n\nexport default RangeChart;\n"],"names":[],"mappings":";;;;;;;AA8BA,MAAM,YAAY,UAAW,CAAA;AAAA,EAC3B,OAAS,EAAA;AAAA,IACP,YAAc,EAAA,CAAA;AAAA,IACd,UAAY,EAAA,2BAAA;AAAA,IACZ,OAAS,EAAA,EAAA;AAAA,GACX;AAAA,EACA,eAAiB,EAAA;AAAA,IACf,QAAU,EAAA,MA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AA;AAEJ;;;;"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ResponsiveContainer, PieChart, Pie, Cell } from 'recharts';
|
|
3
|
+
import { primary, browns, greyscale } from '../../constants/colors.esm.js';
|
|
4
|
+
import { toCurrency } from '../../util.esm.js';
|
|
5
|
+
|
|
6
|
+
function toPieData(top, other, idle) {
|
|
7
|
+
const slices = [];
|
|
8
|
+
for (const i in top) {
|
|
9
|
+
if (Object.hasOwn(top, i)) {
|
|
10
|
+
const allocation = top[i];
|
|
11
|
+
const fill = allocation.name === "__unallocated__" ? "#212121" : primary[i % primary.length];
|
|
12
|
+
slices.push({
|
|
13
|
+
name: allocation.name,
|
|
14
|
+
value: allocation.totalCost,
|
|
15
|
+
fill
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
for (const i in other) {
|
|
20
|
+
if (Object.hasOwn(other, i)) {
|
|
21
|
+
const allocation = other[i];
|
|
22
|
+
const fill = browns[i % browns.length];
|
|
23
|
+
slices.push({
|
|
24
|
+
name: allocation.name,
|
|
25
|
+
value: allocation.totalCost,
|
|
26
|
+
fill
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
for (const i in idle) {
|
|
31
|
+
if (Object.hasOwn(idle, i)) {
|
|
32
|
+
const allocation = idle[i];
|
|
33
|
+
const fill = greyscale[i % greyscale.length];
|
|
34
|
+
slices.push({
|
|
35
|
+
name: allocation.name,
|
|
36
|
+
value: allocation.totalCost,
|
|
37
|
+
fill
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return slices;
|
|
42
|
+
}
|
|
43
|
+
const SummaryChart = ({ top, other, idle, currency, height }) => {
|
|
44
|
+
const pieData = toPieData(top, other, idle);
|
|
45
|
+
const renderLabel = (params) => {
|
|
46
|
+
const { cx, cy, midAngle, outerRadius, percent, name, fill, value } = params;
|
|
47
|
+
const RADIAN = Math.PI / 180;
|
|
48
|
+
const radius = outerRadius * 1.1;
|
|
49
|
+
let x = cx + radius * Math.cos(-midAngle * RADIAN);
|
|
50
|
+
x += x > cx ? 2 : -2;
|
|
51
|
+
const y = cy + radius * Math.sin(-midAngle * RADIAN);
|
|
52
|
+
if (percent < 0.02) {
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
return /* @__PURE__ */ React.createElement(
|
|
56
|
+
"text",
|
|
57
|
+
{
|
|
58
|
+
x,
|
|
59
|
+
y,
|
|
60
|
+
fill,
|
|
61
|
+
textAnchor: x > cx ? "start" : "end",
|
|
62
|
+
dominantBaseline: "central"
|
|
63
|
+
},
|
|
64
|
+
`${name}: ${toCurrency(value, currency)} (${(percent * 100).toFixed(
|
|
65
|
+
1
|
|
66
|
+
)}%)`
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
return /* @__PURE__ */ React.createElement(ResponsiveContainer, { width: "100%", height }, /* @__PURE__ */ React.createElement(PieChart, null, /* @__PURE__ */ React.createElement(
|
|
70
|
+
Pie,
|
|
71
|
+
{
|
|
72
|
+
data: pieData,
|
|
73
|
+
dataKey: "value",
|
|
74
|
+
nameKey: "name",
|
|
75
|
+
label: renderLabel,
|
|
76
|
+
labelLine: true,
|
|
77
|
+
animationDuration: 400,
|
|
78
|
+
cy: "90%",
|
|
79
|
+
outerRadius: "140%",
|
|
80
|
+
innerRadius: "60%",
|
|
81
|
+
startAngle: 180,
|
|
82
|
+
endAngle: 0
|
|
83
|
+
},
|
|
84
|
+
pieData.map((datum, i) => /* @__PURE__ */ React.createElement(Cell, { key: i, fill: datum.fill }))
|
|
85
|
+
)));
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export { SummaryChart as default };
|
|
89
|
+
//# sourceMappingURL=SummaryChart.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SummaryChart.esm.js","sources":["../../../src/components/AllocationChart/SummaryChart.jsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\nimport { ResponsiveContainer, PieChart, Pie, Cell } from 'recharts';\nimport { primary, greyscale, browns } from '../../constants/colors';\nimport { toCurrency } from '../../util';\n\nfunction toPieData(top, other, idle) {\n const slices = [];\n\n for (const i in top) {\n if (Object.hasOwn(top, i)) {\n const allocation = top[i];\n const fill =\n allocation.name === '__unallocated__'\n ? '#212121'\n : primary[i % primary.length];\n\n slices.push({\n name: allocation.name,\n value: allocation.totalCost,\n fill: fill,\n });\n }\n }\n\n for (const i in other) {\n if (Object.hasOwn(other, i)) {\n const allocation = other[i];\n const fill = browns[i % browns.length];\n slices.push({\n name: allocation.name,\n value: allocation.totalCost,\n fill: fill,\n });\n }\n }\n\n for (const i in idle) {\n if (Object.hasOwn(idle, i)) {\n const allocation = idle[i];\n const fill = greyscale[i % greyscale.length];\n slices.push({\n name: allocation.name,\n value: allocation.totalCost,\n fill: fill,\n });\n }\n }\n\n return slices;\n}\n\nconst SummaryChart = ({ top, other, idle, currency, height }) => {\n const pieData = toPieData(top, other, idle);\n\n const renderLabel = params => {\n const { cx, cy, midAngle, outerRadius, percent, name, fill, value } =\n params;\n\n const RADIAN = Math.PI / 180;\n const radius = outerRadius * 1.1;\n let x = cx + radius * Math.cos(-midAngle * RADIAN);\n x += x > cx ? 2 : -2;\n const y = cy + radius * Math.sin(-midAngle * RADIAN);\n // y -= Math.min(Math.abs(2 / Math.cos(-midAngle * RADIAN)), 8)\n\n if (percent < 0.02) {\n return undefined;\n }\n\n return (\n <text\n x={x}\n y={y}\n fill={fill}\n textAnchor={x > cx ? 'start' : 'end'}\n dominantBaseline=\"central\"\n >\n {`${name}: ${toCurrency(value, currency)} (${(percent * 100).toFixed(\n 1,\n )}%)`}\n </text>\n );\n };\n\n return (\n <ResponsiveContainer width=\"100%\" height={height}>\n <PieChart>\n <Pie\n data={pieData}\n dataKey=\"value\"\n nameKey=\"name\"\n label={renderLabel}\n labelLine\n // niko: if tooltips error, try disabling animation\n // isAnimationActive={false}\n animationDuration={400}\n cy=\"90%\"\n outerRadius=\"140%\"\n innerRadius=\"60%\"\n startAngle={180}\n endAngle={0}\n >\n {pieData.map((datum, i) => (\n <Cell key={i} fill={datum.fill} />\n ))}\n </Pie>\n </PieChart>\n </ResponsiveContainer>\n );\n};\n\nexport default SummaryChart;\n"],"names":[],"mappings":";;;;;AAoBA,SAAS,SAAA,CAAU,GAAK,EAAA,KAAA,EAAO,IAAM,EAAA;AACnC,EAAA,MAAM,SAAS,EAAC,CAAA;AAEhB,EAAA,KAAA,MAAW,KAAK,GAAK,EAAA;AACnB,IAAA,IAAI,MAAO,CAAA,MAAA,CAAO,GAAK,EAAA,CAAC,CAAG,EAAA;AACzB,MAAM,MAAA,UAAA,GAAa,IAAI,CAAC,CAAA,CAAA;AACxB,MAAM,MAAA,IAAA,GACJ,WAAW,IAAS,KAAA,iBAAA,GAChB,YACA,OAAQ,CAAA,CAAA,GAAI,QAAQ,MAAM,CAAA,CAAA;AAEhC,MAAA,MAAA,CAAO,IAAK,CAAA;AAAA,QACV,MAAM,UAAW,CAAA,IAAA;AAAA,QACjB,OAAO,UAAW,CAAA,SAAA;AAAA,QAClB,IAAA;AAAA,OACD,CAAA,CAAA;AAAA,KACH;AAAA,GACF;AAEA,EAAA,KAAA,MAAW,KAAK,KAAO,EAAA;AACrB,IAAA,IAAI,MAAO,CAAA,MAAA,CAAO,KAAO,EAAA,CAAC,CAAG,EAAA;AAC3B,MAAM,MAAA,UAAA,GAAa,MAAM,CAAC,CAAA,CAAA;AAC1B,MAAA,MAAM,IAAO,GAAA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AAA,CAAI,CAAC,KAAA,EAAO,CACnB,qBAAA,KAAA,CAAA,aAAA,CAAC,IAAK,EAAA,EAAA,GAAA,EAAK,CAAG,EAAA,IAAA,EAAM,KAAM,CAAA,IAAA,EAAM,CACjC,CAAA;AAAA,GAEL,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { isArray, map, reverse, sortBy, filter, reduce } from 'lodash';
|
|
3
|
+
import Typography from '@material-ui/core/Typography';
|
|
4
|
+
import RangeChart from './RangeChart.esm.js';
|
|
5
|
+
import SummaryChart from './SummaryChart.esm.js';
|
|
6
|
+
|
|
7
|
+
function agg(allocationSet, name) {
|
|
8
|
+
if (allocationSet.length === 0) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return reduce(
|
|
12
|
+
allocationSet,
|
|
13
|
+
(agg2, cur) => ({
|
|
14
|
+
name: agg2.name,
|
|
15
|
+
aggregatedBy: cur.aggregatedBy,
|
|
16
|
+
properties: agg2.properties,
|
|
17
|
+
start: cur.start,
|
|
18
|
+
end: cur.end,
|
|
19
|
+
cpuCost: agg2.cpuCost + cur.cpuCost,
|
|
20
|
+
gpuCost: agg2.gpuCost + cur.gpuCost,
|
|
21
|
+
ramCost: agg2.ramCost + cur.ramCost,
|
|
22
|
+
pvCost: agg2.pvCost + cur.pvCost,
|
|
23
|
+
totalCost: agg2.totalCost + cur.totalCost,
|
|
24
|
+
count: agg2.count + 1
|
|
25
|
+
}),
|
|
26
|
+
{
|
|
27
|
+
name,
|
|
28
|
+
properties: null,
|
|
29
|
+
cpuCost: 0,
|
|
30
|
+
gpuCost: 0,
|
|
31
|
+
ramCost: 0,
|
|
32
|
+
pvCost: 0,
|
|
33
|
+
totalCost: 0,
|
|
34
|
+
count: 0
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
function isIdle(allocation) {
|
|
39
|
+
return allocation.name.indexOf("__idle__") >= 0;
|
|
40
|
+
}
|
|
41
|
+
function top(n, by) {
|
|
42
|
+
return (allocations) => {
|
|
43
|
+
if (isArray(allocations[0])) {
|
|
44
|
+
return map(allocations, top(n, by));
|
|
45
|
+
}
|
|
46
|
+
const sorted = reverse(sortBy(allocations, by));
|
|
47
|
+
const active = filter(sorted, (a) => !isIdle(a));
|
|
48
|
+
const idle = filter(sorted, (a) => isIdle(a));
|
|
49
|
+
const topn = active.slice(0, n);
|
|
50
|
+
const other = [];
|
|
51
|
+
if (active.length > n) {
|
|
52
|
+
other.push(agg(active.slice(n), "other"));
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
top: topn,
|
|
56
|
+
other,
|
|
57
|
+
idle
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const AllocationChart = ({ allocationRange, currency, n, height }) => {
|
|
62
|
+
if (allocationRange.length === 0) {
|
|
63
|
+
return /* @__PURE__ */ React.createElement(Typography, { variant: "body2" }, "No data");
|
|
64
|
+
}
|
|
65
|
+
if (allocationRange.length === 1) {
|
|
66
|
+
const datum = top(n, (alloc) => alloc.totalCost)(allocationRange[0]);
|
|
67
|
+
return /* @__PURE__ */ React.createElement(
|
|
68
|
+
SummaryChart,
|
|
69
|
+
{
|
|
70
|
+
top: datum.top,
|
|
71
|
+
other: datum.other,
|
|
72
|
+
idle: datum.idle,
|
|
73
|
+
currency,
|
|
74
|
+
height
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
const data = top(n, (alloc) => alloc.totalCost)(allocationRange);
|
|
79
|
+
return /* @__PURE__ */ React.createElement(RangeChart, { data, currency, height });
|
|
80
|
+
};
|
|
81
|
+
var AllocationChart$1 = React.memo(AllocationChart);
|
|
82
|
+
|
|
83
|
+
export { AllocationChart$1 as default };
|
|
84
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../../src/components/AllocationChart/index.jsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\nimport { isArray, filter, map, reduce, reverse, sortBy } from 'lodash';\n\nimport Typography from '@material-ui/core/Typography';\n\nimport RangeChart from './RangeChart';\nimport SummaryChart from './SummaryChart';\n\n// TODO niko/etl\n/* eslint @typescript-eslint/no-shadow: [\"error\", { \"allow\": [\"agg\"] }]*/\nfunction agg(allocationSet, name) {\n if (allocationSet.length === 0) {\n return null;\n }\n\n return reduce(\n allocationSet,\n (agg, cur) => ({\n name: agg.name,\n aggregatedBy: cur.aggregatedBy,\n properties: agg.properties,\n start: cur.start,\n end: cur.end,\n cpuCost: agg.cpuCost + cur.cpuCost,\n gpuCost: agg.gpuCost + cur.gpuCost,\n ramCost: agg.ramCost + cur.ramCost,\n pvCost: agg.pvCost + cur.pvCost,\n totalCost: agg.totalCost + cur.totalCost,\n count: agg.count + 1,\n }),\n {\n name: name,\n properties: null,\n cpuCost: 0.0,\n gpuCost: 0.0,\n ramCost: 0.0,\n pvCost: 0.0,\n totalCost: 0.0,\n count: 0,\n },\n );\n}\n\nfunction isIdle(allocation) {\n return allocation.name.indexOf('__idle__') >= 0;\n}\n\nfunction top(n, by) {\n return allocations => {\n if (isArray(allocations[0])) {\n return map(allocations, top(n, by));\n }\n\n const sorted = reverse(sortBy(allocations, by));\n const active = filter(sorted, a => !isIdle(a));\n const idle = filter(sorted, a => isIdle(a));\n const topn = active.slice(0, n);\n const other = [];\n if (active.length > n) {\n other.push(agg(active.slice(n), 'other'));\n }\n\n return {\n top: topn,\n other: other,\n idle: idle,\n };\n };\n}\n\nconst AllocationChart = ({ allocationRange, currency, n, height }) => {\n if (allocationRange.length === 0) {\n return <Typography variant=\"body2\">No data</Typography>;\n }\n\n if (allocationRange.length === 1) {\n const datum = top(n, alloc => alloc.totalCost)(allocationRange[0]);\n return (\n <SummaryChart\n top={datum.top}\n other={datum.other}\n idle={datum.idle}\n currency={currency}\n height={height}\n />\n );\n }\n\n const data = top(n, alloc => alloc.totalCost)(allocationRange);\n return <RangeChart data={data} currency={currency} height={height} />;\n};\n\nexport default React.memo(AllocationChart);\n"],"names":["agg"],"mappings":";;;;;;AAyBA,SAAS,GAAA,CAAI,eAAe,IAAM,EAAA;AAChC,EAAI,IAAA,aAAA,CAAc,WAAW,CAAG,EAAA;AAC9B,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA,MAAA;AAAA,IACL,aAAA;AAAA,IACA,CAACA,MAAK,GAAS,MAAA;AAAA,MACb,MAAMA,IAAI,CAAA,IAAA;AAAA,MACV,cAAc,GAAI,CAAA,YAAA;AAAA,MAClB,YAAYA,IAAI,CAAA,UAAA;AAAA,MAChB,OAAO,GAAI,CAAA,KAAA;AAAA,MACX,KAAK,GAAI,CAAA,GAAA;AAAA,MACT,OAAA,EAASA,IAAI,CAAA,OAAA,GAAU,GAAI,CAAA,OAAA;AAAA,MAC3B,OAAA,EAASA,IAAI,CAAA,OAAA,GAAU,GAAI,CAAA,OAAA;AAAA,MAC3B,OAAA,EAASA,IAAI,CAAA,OAAA,GAAU,GAAI,CAAA,OAAA;AAAA,MAC3B,MAAA,EAAQA,IAAI,CAAA,MAAA,GAAS,GAAI,CAAA,MAAA;AAAA,MACzB,SAAA,EAAWA,IAAI,CAAA,SAAA,GAAY,GAAI,CAAA,SAAA;AAAA,MAC/B,KAAA,EAAOA,KAAI,KAAQ,GAAA,CAAA;AAAA,KACrB,CAAA;AAAA,IACA;AAAA,MACE,IAAA;AAAA,MACA,UAAY,EAAA,IAA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,KAAA;AAAA,MACA,IAAA;AAAA,KACF,CAAA;AAAA,GACF,CAAA;AACF,CAAA;AAEA,MAAM,kBAAkB,CAAC,EAAE,iBAAiB,QAAU,EAAA,CAAA,EAAG,QAAa,KAAA;AACpE,EAAI,IAAA,eAAA,CAAgB,WAAW,CAAG,EAAA;AAChC,IAAA,uBAAQ,KAAA,CAAA,aAAA,CAAA,UAAA,EAAA,EAAW,OAAQ,EAAA,OAAA,EAAA,EAAQ,SAAO,CAAA,CAAA;AAAA,GAC5C;AAEA,EAAI,IAAA,eAAA,CAAgB,WAAW,CAAG,EAAA;AAChC,IAAM,MAAA,KAAA,GAAQ,IAAI,CAAG,EAAA,CAAA,KAAA,KAAS,MAAM,SAAS,CAAA,CAAE,eAAgB,CAAA,CAAC,CAAC,CAAA,CAAA;AACjE,IACE,uBAAA,KAAA,CAAA,aAAA;AAAA,MAAC,YAAA;AAAA,MAAA;AAAA,QACC,KAAK,KAAM,CAAA,GAAA;AAAA,QACX,OAAO,KAAM,CAAA,KAAA;AAAA,QACb,MAAM,KAAM,CAAA,IAAA;AAAA,QACZ,QAAA;AAAA,QACA,MAAA;AAAA,OAAA;AAAA,KACF,CAAA;AAAA,GAEJ;AAEA,EAAA,MAAM,OAAO,GAAI,CAAA,CAAA,EAAG,WAAS,KAAM,CAAA,SAAS,EAAE,eAAe,CAAA,CAAA;AAC7D,EAAA,uBAAQ,KAAA,CAAA,aAAA,CAAA,UAAA,EAAA,EAAW,IAAY,EAAA,QAAA,EAAoB,MAAgB,EAAA,CAAA,CAAA;AACrE,CAAA,CAAA;AAEA,wBAAe,KAAA,CAAM,KAAK,eAAe,CAAA;;;;"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import { round, get } from 'lodash';
|
|
3
|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
4
|
+
import Table from '@material-ui/core/Table';
|
|
5
|
+
import TableBody from '@material-ui/core/TableBody';
|
|
6
|
+
import TableCell from '@material-ui/core/TableCell';
|
|
7
|
+
import TableContainer from '@material-ui/core/TableContainer';
|
|
8
|
+
import TableHead from '@material-ui/core/TableHead';
|
|
9
|
+
import TablePagination from '@material-ui/core/TablePagination';
|
|
10
|
+
import TableRow from '@material-ui/core/TableRow';
|
|
11
|
+
import TableSortLabel from '@material-ui/core/TableSortLabel';
|
|
12
|
+
import Typography from '@material-ui/core/Typography';
|
|
13
|
+
import AllocationChart from './AllocationChart/index.esm.js';
|
|
14
|
+
import { toCurrency } from '../util.esm.js';
|
|
15
|
+
|
|
16
|
+
const useStyles = makeStyles({
|
|
17
|
+
noResults: {
|
|
18
|
+
padding: 24
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
function descendingComparator(a, b, orderBy) {
|
|
22
|
+
if (get(b, orderBy) < get(a, orderBy)) {
|
|
23
|
+
return -1;
|
|
24
|
+
}
|
|
25
|
+
if (get(b, orderBy) > get(a, orderBy)) {
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
function getComparator(order, orderBy) {
|
|
31
|
+
return order === "desc" ? (a, b) => descendingComparator(a, b, orderBy) : (a, b) => -descendingComparator(a, b, orderBy);
|
|
32
|
+
}
|
|
33
|
+
function stableSort(array, comparator) {
|
|
34
|
+
const stabilizedThis = array.map((el, index) => [el, index]);
|
|
35
|
+
stabilizedThis.sort((a, b) => {
|
|
36
|
+
const order = comparator(a[0], b[0]);
|
|
37
|
+
if (order !== 0) return order;
|
|
38
|
+
return a[1] - b[1];
|
|
39
|
+
});
|
|
40
|
+
return stabilizedThis.map((el) => el[0]);
|
|
41
|
+
}
|
|
42
|
+
const headCells = [
|
|
43
|
+
{ id: "name", numeric: false, label: "Name", width: "auto" },
|
|
44
|
+
{ id: "cpuCost", numeric: true, label: "CPU", width: 100 },
|
|
45
|
+
{ id: "ramCost", numeric: true, label: "RAM", width: 100 },
|
|
46
|
+
{ id: "pvCost", numeric: true, label: "PV", width: 100 },
|
|
47
|
+
{ id: "totalEfficiency", numeric: true, label: "Efficiency", width: 130 },
|
|
48
|
+
{ id: "totalCost", numeric: true, label: "Total cost", width: 130 }
|
|
49
|
+
];
|
|
50
|
+
const AllocationReport = ({
|
|
51
|
+
allocationData,
|
|
52
|
+
cumulativeData,
|
|
53
|
+
totalData,
|
|
54
|
+
currency
|
|
55
|
+
}) => {
|
|
56
|
+
const classes = useStyles();
|
|
57
|
+
if (allocationData.length === 0) {
|
|
58
|
+
return /* @__PURE__ */ React.createElement(Typography, { variant: "body2", className: classes.noResults }, "No results");
|
|
59
|
+
}
|
|
60
|
+
const [order, setOrder] = React.useState("desc");
|
|
61
|
+
const [orderBy, setOrderBy] = React.useState("totalCost");
|
|
62
|
+
const [page, setPage] = useState(0);
|
|
63
|
+
const [rowsPerPage, setRowsPerPage] = useState(25);
|
|
64
|
+
const numData = cumulativeData.length;
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
setPage(0);
|
|
67
|
+
}, [numData]);
|
|
68
|
+
const lastPage = Math.floor(numData / rowsPerPage);
|
|
69
|
+
const handleChangePage = (event, newPage) => setPage(newPage);
|
|
70
|
+
const handleChangeRowsPerPage = (event) => {
|
|
71
|
+
setRowsPerPage(parseInt(event.target.value, 10));
|
|
72
|
+
setPage(0);
|
|
73
|
+
};
|
|
74
|
+
const handleRequestSort = (event, property) => {
|
|
75
|
+
const isDesc = orderBy === property && order === "desc";
|
|
76
|
+
setOrder(isDesc ? "asc" : "desc");
|
|
77
|
+
setOrderBy(property);
|
|
78
|
+
};
|
|
79
|
+
const createSortHandler = (property) => (event) => handleRequestSort(event, property);
|
|
80
|
+
const orderedRows = stableSort(cumulativeData, getComparator(order, orderBy));
|
|
81
|
+
const pageRows = orderedRows.slice(
|
|
82
|
+
page * rowsPerPage,
|
|
83
|
+
page * rowsPerPage + rowsPerPage
|
|
84
|
+
);
|
|
85
|
+
return /* @__PURE__ */ React.createElement("div", { id: "report" }, /* @__PURE__ */ React.createElement(
|
|
86
|
+
AllocationChart,
|
|
87
|
+
{
|
|
88
|
+
allocationRange: allocationData,
|
|
89
|
+
currency,
|
|
90
|
+
n: 10,
|
|
91
|
+
height: 300
|
|
92
|
+
}
|
|
93
|
+
), /* @__PURE__ */ React.createElement(TableContainer, null, /* @__PURE__ */ React.createElement(Table, null, /* @__PURE__ */ React.createElement(TableHead, null, /* @__PURE__ */ React.createElement(TableRow, null, headCells.map((cell) => /* @__PURE__ */ React.createElement(
|
|
94
|
+
TableCell,
|
|
95
|
+
{
|
|
96
|
+
key: cell.id,
|
|
97
|
+
colSpan: cell.colspan,
|
|
98
|
+
align: cell.numeric ? "right" : "left",
|
|
99
|
+
sortDirection: orderBy === cell.id ? order : false,
|
|
100
|
+
style: { width: cell.width }
|
|
101
|
+
},
|
|
102
|
+
/* @__PURE__ */ React.createElement(
|
|
103
|
+
TableSortLabel,
|
|
104
|
+
{
|
|
105
|
+
active: orderBy === cell.id,
|
|
106
|
+
direction: orderBy === cell.id ? order : "asc",
|
|
107
|
+
onClick: createSortHandler(cell.id)
|
|
108
|
+
},
|
|
109
|
+
cell.label
|
|
110
|
+
)
|
|
111
|
+
)))), /* @__PURE__ */ React.createElement(TableBody, null, /* @__PURE__ */ React.createElement(TableRow, null, headCells.map((cell) => {
|
|
112
|
+
return /* @__PURE__ */ React.createElement(
|
|
113
|
+
TableCell,
|
|
114
|
+
{
|
|
115
|
+
key: cell.id,
|
|
116
|
+
colSpan: cell.colspan,
|
|
117
|
+
align: cell.numeric ? "right" : "left",
|
|
118
|
+
style: { fontWeight: 500 }
|
|
119
|
+
},
|
|
120
|
+
cell.numeric ? cell.label === "Efficiency" ? totalData.totalEfficiency === 1 && totalData.cpuReqCoreHrs === 0 && totalData.ramReqByteHrs === 0 ? "Inf%" : `${round(totalData.totalEfficiency * 100, 1)}%` : toCurrency(totalData[cell.id], currency) : totalData[cell.id]
|
|
121
|
+
);
|
|
122
|
+
})), pageRows.map((row, key) => {
|
|
123
|
+
if (row.name === "__unmounted__") {
|
|
124
|
+
row.name = "Unmounted PVs";
|
|
125
|
+
}
|
|
126
|
+
const isIdle = row.name.indexOf("__idle__") >= 0;
|
|
127
|
+
const isUnallocated = row.name.indexOf("__unallocated__") >= 0;
|
|
128
|
+
const isUnmounted = row.name.indexOf("Unmounted PVs") >= 0;
|
|
129
|
+
let efficiency = round(row.totalEfficiency * 100, 1);
|
|
130
|
+
if (row.totalEfficiency === 1 && row.cpuReqCoreHrs === 0 && row.ramReqByteHrs === 0) {
|
|
131
|
+
efficiency = "Inf";
|
|
132
|
+
}
|
|
133
|
+
if (isIdle || isUnallocated || isUnmounted) {
|
|
134
|
+
return /* @__PURE__ */ React.createElement(TableRow, { key }, /* @__PURE__ */ React.createElement(TableCell, { align: "left" }, row.name), /* @__PURE__ */ React.createElement(TableCell, { align: "right" }, toCurrency(row.cpuCost, currency)), /* @__PURE__ */ React.createElement(TableCell, { align: "right" }, toCurrency(row.ramCost, currency)), /* @__PURE__ */ React.createElement(TableCell, { align: "right" }, toCurrency(row.pvCost, currency)), isIdle ? /* @__PURE__ */ React.createElement(TableCell, { align: "right" }, "\u2014") : /* @__PURE__ */ React.createElement(TableCell, { align: "right" }, efficiency, "%"), /* @__PURE__ */ React.createElement(TableCell, { align: "right" }, toCurrency(row.totalCost, currency)));
|
|
135
|
+
}
|
|
136
|
+
return /* @__PURE__ */ React.createElement(TableRow, { key }, /* @__PURE__ */ React.createElement(TableCell, { align: "left" }, row.name), /* @__PURE__ */ React.createElement(TableCell, { align: "right" }, toCurrency(row.cpuCost, currency)), /* @__PURE__ */ React.createElement(TableCell, { align: "right" }, toCurrency(row.ramCost, currency)), /* @__PURE__ */ React.createElement(TableCell, { align: "right" }, toCurrency(row.pvCost, currency)), /* @__PURE__ */ React.createElement(TableCell, { align: "right" }, efficiency, "%"), /* @__PURE__ */ React.createElement(TableCell, { align: "right" }, toCurrency(row.totalCost, currency)));
|
|
137
|
+
})))), /* @__PURE__ */ React.createElement(
|
|
138
|
+
TablePagination,
|
|
139
|
+
{
|
|
140
|
+
component: "div",
|
|
141
|
+
count: numData,
|
|
142
|
+
rowsPerPage,
|
|
143
|
+
rowsPerPageOptions: [10, 25, 50],
|
|
144
|
+
page: Math.min(page, lastPage),
|
|
145
|
+
onChangePage: handleChangePage,
|
|
146
|
+
onChangeRowsPerPage: handleChangeRowsPerPage
|
|
147
|
+
}
|
|
148
|
+
));
|
|
149
|
+
};
|
|
150
|
+
var AllocationReport$1 = React.memo(AllocationReport);
|
|
151
|
+
|
|
152
|
+
export { AllocationReport$1 as default };
|
|
153
|
+
//# sourceMappingURL=AllocationReport.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AllocationReport.esm.js","sources":["../../src/components/AllocationReport.jsx"],"sourcesContent":["/* not changing the working code at this point */\n/* eslint no-nested-ternary: 0 */\n/* eslint react-hooks/rules-of-hooks: 0 */\n\n/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useEffect, useState } from 'react';\nimport { get, round } from 'lodash';\nimport { makeStyles } from '@material-ui/core/styles';\nimport Table from '@material-ui/core/Table';\nimport TableBody from '@material-ui/core/TableBody';\nimport TableCell from '@material-ui/core/TableCell';\nimport TableContainer from '@material-ui/core/TableContainer';\nimport TableHead from '@material-ui/core/TableHead';\nimport TablePagination from '@material-ui/core/TablePagination';\nimport TableRow from '@material-ui/core/TableRow';\nimport TableSortLabel from '@material-ui/core/TableSortLabel';\nimport Typography from '@material-ui/core/Typography';\nimport AllocationChart from './AllocationChart';\nimport { toCurrency } from '../util';\n\nconst useStyles = makeStyles({\n noResults: {\n padding: 24,\n },\n});\n\nfunction descendingComparator(a, b, orderBy) {\n if (get(b, orderBy) < get(a, orderBy)) {\n return -1;\n }\n if (get(b, orderBy) > get(a, orderBy)) {\n return 1;\n }\n return 0;\n}\n\nfunction getComparator(order, orderBy) {\n return order === 'desc'\n ? (a, b) => descendingComparator(a, b, orderBy)\n : (a, b) => -descendingComparator(a, b, orderBy);\n}\n\nfunction stableSort(array, comparator) {\n const stabilizedThis = array.map((el, index) => [el, index]);\n stabilizedThis.sort((a, b) => {\n const order = comparator(a[0], b[0]);\n if (order !== 0) return order;\n return a[1] - b[1];\n });\n return stabilizedThis.map(el => el[0]);\n}\n\nconst headCells = [\n { id: 'name', numeric: false, label: 'Name', width: 'auto' },\n { id: 'cpuCost', numeric: true, label: 'CPU', width: 100 },\n { id: 'ramCost', numeric: true, label: 'RAM', width: 100 },\n { id: 'pvCost', numeric: true, label: 'PV', width: 100 },\n { id: 'totalEfficiency', numeric: true, label: 'Efficiency', width: 130 },\n { id: 'totalCost', numeric: true, label: 'Total cost', width: 130 },\n];\n\nconst AllocationReport = ({\n allocationData,\n cumulativeData,\n totalData,\n currency,\n}) => {\n const classes = useStyles();\n\n if (allocationData.length === 0) {\n return (\n <Typography variant=\"body2\" className={classes.noResults}>\n No results\n </Typography>\n );\n }\n\n const [order, setOrder] = React.useState('desc');\n const [orderBy, setOrderBy] = React.useState('totalCost');\n const [page, setPage] = useState(0);\n const [rowsPerPage, setRowsPerPage] = useState(25);\n const numData = cumulativeData.length;\n\n useEffect(() => {\n setPage(0);\n }, [numData]);\n\n const lastPage = Math.floor(numData / rowsPerPage);\n\n const handleChangePage = (event, newPage) => setPage(newPage);\n\n const handleChangeRowsPerPage = event => {\n setRowsPerPage(parseInt(event.target.value, 10));\n setPage(0);\n };\n\n const handleRequestSort = (event, property) => {\n const isDesc = orderBy === property && order === 'desc';\n setOrder(isDesc ? 'asc' : 'desc');\n setOrderBy(property);\n };\n\n const createSortHandler = property => event =>\n handleRequestSort(event, property);\n\n const orderedRows = stableSort(cumulativeData, getComparator(order, orderBy));\n const pageRows = orderedRows.slice(\n page * rowsPerPage,\n page * rowsPerPage + rowsPerPage,\n );\n\n return (\n <div id=\"report\">\n <AllocationChart\n allocationRange={allocationData}\n currency={currency}\n n={10}\n height={300}\n />\n <TableContainer>\n <Table>\n <TableHead>\n <TableRow>\n {headCells.map(cell => (\n <TableCell\n key={cell.id}\n colSpan={cell.colspan}\n align={cell.numeric ? 'right' : 'left'}\n sortDirection={orderBy === cell.id ? order : false}\n style={{ width: cell.width }}\n >\n <TableSortLabel\n active={orderBy === cell.id}\n direction={orderBy === cell.id ? order : 'asc'}\n onClick={createSortHandler(cell.id)}\n >\n {cell.label}\n </TableSortLabel>\n </TableCell>\n ))}\n </TableRow>\n </TableHead>\n <TableBody>\n <TableRow>\n {headCells.map(cell => {\n return (\n <TableCell\n key={cell.id}\n colSpan={cell.colspan}\n align={cell.numeric ? 'right' : 'left'}\n style={{ fontWeight: 500 }}\n >\n {cell.numeric\n ? cell.label === 'Efficiency'\n ? totalData.totalEfficiency === 1.0 &&\n totalData.cpuReqCoreHrs === 0 &&\n totalData.ramReqByteHrs === 0\n ? 'Inf%'\n : `${round(totalData.totalEfficiency * 100, 1)}%`\n : toCurrency(totalData[cell.id], currency)\n : totalData[cell.id]}\n </TableCell>\n );\n })}\n </TableRow>\n {pageRows.map((row, key) => {\n if (row.name === '__unmounted__') {\n row.name = 'Unmounted PVs';\n }\n\n const isIdle = row.name.indexOf('__idle__') >= 0;\n const isUnallocated = row.name.indexOf('__unallocated__') >= 0;\n const isUnmounted = row.name.indexOf('Unmounted PVs') >= 0;\n\n // Replace \"efficiency\" with Inf if there is usage w/o request\n let efficiency = round(row.totalEfficiency * 100, 1);\n if (\n row.totalEfficiency === 1.0 &&\n row.cpuReqCoreHrs === 0 &&\n row.ramReqByteHrs === 0\n ) {\n efficiency = 'Inf';\n }\n\n // Do not allow drill-down for idle and unallocated rows\n if (isIdle || isUnallocated || isUnmounted) {\n return (\n <TableRow key={key}>\n <TableCell align=\"left\">{row.name}</TableCell>\n <TableCell align=\"right\">\n {toCurrency(row.cpuCost, currency)}\n </TableCell>\n <TableCell align=\"right\">\n {toCurrency(row.ramCost, currency)}\n </TableCell>\n <TableCell align=\"right\">\n {toCurrency(row.pvCost, currency)}\n </TableCell>\n {isIdle ? (\n <TableCell align=\"right\">—</TableCell>\n ) : (\n <TableCell align=\"right\">{efficiency}%</TableCell>\n )}\n <TableCell align=\"right\">\n {toCurrency(row.totalCost, currency)}\n </TableCell>\n </TableRow>\n );\n }\n\n return (\n <TableRow key={key}>\n <TableCell align=\"left\">{row.name}</TableCell>\n <TableCell align=\"right\">\n {toCurrency(row.cpuCost, currency)}\n </TableCell>\n <TableCell align=\"right\">\n {toCurrency(row.ramCost, currency)}\n </TableCell>\n <TableCell align=\"right\">\n {toCurrency(row.pvCost, currency)}\n </TableCell>\n <TableCell align=\"right\">{efficiency}%</TableCell>\n <TableCell align=\"right\">\n {toCurrency(row.totalCost, currency)}\n </TableCell>\n </TableRow>\n );\n })}\n </TableBody>\n </Table>\n </TableContainer>\n <TablePagination\n component=\"div\"\n count={numData}\n rowsPerPage={rowsPerPage}\n rowsPerPageOptions={[10, 25, 50]}\n page={Math.min(page, lastPage)}\n onChangePage={handleChangePage}\n onChangeRowsPerPage={handleChangeRowsPerPage}\n />\n </div>\n );\n};\n\nexport default React.memo(AllocationReport);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAmCA,MAAM,YAAY,UAAW,CAAA;AAAA,EAC3B,SAAW,EAAA;AAAA,IACT,OAAS,EAAA,EAAA;AAAA,GACX;AACF,CAAC,CAAA,CAAA;AAED,SAAS,oBAAA,CAAqB,CAAG,EAAA,CAAA,EAAG,OAAS,EAAA;AAC3C,EAAA,IAAI,IAAI,CAAG,EAAA,OAAO,IAAI,GAAI,CAAA,CAAA,EAAG,OAAO,CAAG,EAAA;AACrC,IAAO,OAAA,CAAA,CAAA,CA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M,WACd,UAAW,CAAA,GAAA,CAAI,OAAS,EAAA,QAAQ,CACnC,CAAA,kBACC,KAAA,CAAA,aAAA,CAAA,SAAA,EAAA,EAAU,KAAM,EAAA,OAAA,EAAA,EACd,UAAW,CAAA,GAAA,CAAI,OAAS,EAAA,QAAQ,CACnC,CACA,kBAAA,KAAA,CAAA,aAAA,CAAC,SAAU,EAAA,EAAA,KAAA,EAAM,OACd,EAAA,EAAA,UAAA,CAAW,GAAI,CAAA,MAAA,EAAQ,QAAQ,CAClC,CACA,kBAAA,KAAA,CAAA,aAAA,CAAC,SAAU,EAAA,EAAA,KAAA,EAAM,WAAS,UAAW,EAAA,GAAC,CACtC,kBAAA,KAAA,CAAA,aAAA,CAAC,SAAU,EAAA,EAAA,KAAA,EAAM,OACd,EAAA,EAAA,UAAA,CAAW,GAAI,CAAA,SAAA,EAAW,QAAQ,CACrC,CACF,CAAA,CAAA;AAAA,GAEH,CACH,CACF,CACF,CACA,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,eAAA;AAAA,IAAA;AAAA,MACC,SAAU,EAAA,KAAA;AAAA,MACV,KAAO,EAAA,OAAA;AAAA,MACP,WAAA;AAAA,MACA,kBAAoB,EAAA,CAAC,EAAI,EAAA,EAAA,EAAI,EAAE,CAAA;AAAA,MAC/B,IAAM,EAAA,IAAA,CAAK,GAAI,CAAA,IAAA,EAAM,QAAQ,CAAA;AAAA,MAC7B,YAAc,EAAA,gBAAA;AAAA,MACd,mBAAqB,EAAA,uBAAA;AAAA,KAAA;AAAA,GAEzB,CAAA,CAAA;AAEJ,CAAA,CAAA;AAEA,yBAAe,KAAA,CAAM,KAAK,gBAAgB,CAAA;;;;"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { reverse, sortBy, forEach, round, get } from 'lodash';
|
|
3
|
+
import ExportIcon from '@material-ui/icons/GetApp';
|
|
4
|
+
import IconButton from '@material-ui/core/IconButton';
|
|
5
|
+
import Tooltip from '@material-ui/core/Tooltip';
|
|
6
|
+
|
|
7
|
+
const columns = [
|
|
8
|
+
{
|
|
9
|
+
head: "Name",
|
|
10
|
+
prop: "name",
|
|
11
|
+
currency: false
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
head: "CPU",
|
|
15
|
+
prop: "cpuCost",
|
|
16
|
+
currency: true
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
head: "GPU",
|
|
20
|
+
prop: "gpuCost",
|
|
21
|
+
currency: true
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
head: "RAM",
|
|
25
|
+
prop: "ramCost",
|
|
26
|
+
currency: true
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
head: "PV",
|
|
30
|
+
prop: "pvCost",
|
|
31
|
+
currency: true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
head: "Network",
|
|
35
|
+
prop: "networkCost",
|
|
36
|
+
currency: true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
head: "Shared",
|
|
40
|
+
prop: "sharedCost",
|
|
41
|
+
currency: true
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
head: "Total",
|
|
45
|
+
prop: "totalCost",
|
|
46
|
+
currency: true
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
const toCSVLine = (datum) => {
|
|
50
|
+
const cols = [];
|
|
51
|
+
forEach(columns, (c) => {
|
|
52
|
+
if (c.currency) {
|
|
53
|
+
cols.push(round(get(datum, c.prop, 0), 2));
|
|
54
|
+
} else {
|
|
55
|
+
cols.push(`"${get(datum, c.prop, "")}"`);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return cols.join(",");
|
|
59
|
+
};
|
|
60
|
+
const DownloadControl = ({ cumulativeData, title }) => {
|
|
61
|
+
function downloadReport() {
|
|
62
|
+
const head = columns.map((c) => c.head).join(",");
|
|
63
|
+
const body = reverse(sortBy(cumulativeData, "totalCost")).map(toCSVLine).join("\r\n");
|
|
64
|
+
const csv = `${head}\r
|
|
65
|
+
${body}`;
|
|
66
|
+
const a = document.createElement("a");
|
|
67
|
+
a.href = URL.createObjectURL(new Blob([csv], { type: "text/csv" }));
|
|
68
|
+
const filename = title.toLocaleLowerCase("en-US").replace(/\s/gi, "-");
|
|
69
|
+
a.setAttribute("download", `${filename}-${Date.now()}.csv`);
|
|
70
|
+
document.body.appendChild(a);
|
|
71
|
+
a.click();
|
|
72
|
+
document.body.removeChild(a);
|
|
73
|
+
}
|
|
74
|
+
return /* @__PURE__ */ React.createElement(Tooltip, { title: "Download CSV" }, /* @__PURE__ */ React.createElement(IconButton, { onClick: downloadReport }, /* @__PURE__ */ React.createElement(ExportIcon, null)));
|
|
75
|
+
};
|
|
76
|
+
var DownloadControl$1 = React.memo(DownloadControl);
|
|
77
|
+
|
|
78
|
+
export { DownloadControl$1 as default };
|
|
79
|
+
//# sourceMappingURL=Download.esm.js.map
|