UNPKG

infinity-forge

Version:
108 lines 8.98 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Matriz = Matriz; var jsx_runtime_1 = require("react/jsx-runtime"); var S = __importStar(require("./styles.js")); function Matriz(_a) { var title = _a.title, data = _a.data; var headers = Object.keys(data[0]).filter(function (key) { return key !== "label" && key !== "image"; }); var dataHeaders = headers.filter(function (key) { return key !== "overall"; }); var maxValue = Math.max.apply(Math, data.flatMap(function (row) { return dataHeaders.map(function (header) { return typeof row[header] === 'number' ? row[header] : 0; }); })); return ((0, jsx_runtime_1.jsxs)(S.Matriz, { children: [(0, jsx_runtime_1.jsx)("h3", { className: "font-20-regular", children: title }), (0, jsx_runtime_1.jsxs)("div", { className: "matriz", children: [(0, jsx_runtime_1.jsxs)("table", { children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("th", { style: { width: "30%" } }), headers.map(function (header, index) { return ((0, jsx_runtime_1.jsxs)("th", { children: [header !== "Não sei avaliar" && header !== "Overall" && header !== "image" && index + 1 + " " + "-", " ", header] }, header)); })] }) }), (0, jsx_runtime_1.jsx)("tbody", { children: data.map(function (row, rowIndex) { return ((0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("td", { style: { textAlign: "left" }, children: (0, jsx_runtime_1.jsxs)("div", { className: "label_container", children: [row.image && (0, jsx_runtime_1.jsx)("img", { src: row.image, alt: "" }), (0, jsx_runtime_1.jsxs)("span", { children: [" ", row.label] })] }) }), headers.map(function (key) { var value = typeof row[key] === "number" ? row[key] : 0; var isOverall = key === "Overall"; var percentage = isOverall ? "" : ((value / row.overall) * 100).toFixed(1) + "%"; return ((0, jsx_runtime_1.jsxs)("td", { "data-value": value, style: { backgroundColor: isOverall ? "#ccc" : "rgba(74, 144, 226, ".concat(value / maxValue, ")"), color: isOverall ? "#000" : value / maxValue > 0.5 ? "#fff" : "#000", fontWeight: isOverall ? "bold" : "normal", textAlign: "center", }, children: [(0, jsx_runtime_1.jsx)("div", { children: value }), !isOverall && ((0, jsx_runtime_1.jsx)("div", { style: { fontSize: "0.8em", opacity: 0.7 }, children: percentage }))] }, key)); })] }, rowIndex)); }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "gradient", children: [(0, jsx_runtime_1.jsx)("div", { className: "background" }), (0, jsx_runtime_1.jsxs)("div", { className: "legend", children: [(0, jsx_runtime_1.jsx)("span", { children: "Min" }), (0, jsx_runtime_1.jsx)("span", { children: "Max" })] })] })] }), (0, jsx_runtime_1.jsx)("div", { className: "table-informations", children: (0, jsx_runtime_1.jsxs)("table", { children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("th", { style: { width: "30%" }, children: "Pergunta" }), (0, jsx_runtime_1.jsx)("th", { style: { width: "100px" }, children: "Contagem" }), (0, jsx_runtime_1.jsx)("th", { style: { width: "50%" }, children: "Pontua\u00E7\u00E3o" })] }) }), (0, jsx_runtime_1.jsx)("tbody", { children: data.map(function (row, rowIndex) { var validEntries = Object.entries(row).filter(function (_a) { var key = _a[0]; return key !== "label" && key !== "Não sei avaliar" && key !== "Overall" && key !== "image"; }); var totalCount = validEntries.reduce(function (sum, _a) { var value = _a[1]; return sum + Number(value); }, 0); var weightedSum = validEntries.reduce(function (sum, _a, index) { var value = _a[1]; return sum + Number(value) * (index + 1); }, 0); var score = totalCount > 0 ? (weightedSum / totalCount).toFixed(2) : "N/A"; var scores = data.map(function (row) { var validEntries = Object.entries(row).filter(function (_a) { var key = _a[0]; return key !== "label" && key !== "Não sei avaliar" && key !== "Overall" && key !== "image"; }); var totalCount = validEntries.reduce(function (sum, _a) { var value = _a[1]; return sum + Number(value); }, 0); var weightedSum = validEntries.reduce(function (sum, _a, index) { var value = _a[1]; return sum + Number(value) * (index + 1); }, 0); return totalCount > 0 ? Number((weightedSum / totalCount).toFixed(2)) : 0; }); var maxScore = Math.max.apply(Math, scores); return ((0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsxs)("td", { style: { textAlign: "left" }, children: [" ", row.label] }), (0, jsx_runtime_1.jsx)("td", { children: totalCount }), (0, jsx_runtime_1.jsx)("td", { children: (0, jsx_runtime_1.jsxs)("div", { className: "progress", children: [(0, jsx_runtime_1.jsx)("div", { className: "score-value", children: score }), (0, jsx_runtime_1.jsx)("div", { className: "progress-bar", children: (0, jsx_runtime_1.jsx)("span", { style: { width: "".concat((Number(score) / dataHeaders.length) * 100, "%"), backgroundColor: Number(score) === maxScore ? "#007BFF" : "#555", } }) })] }) })] }, rowIndex)); }) })] }) })] })); } //# sourceMappingURL=index.js.map