From dc728b91f073c48550e57984b2f434aecc1f2095 Mon Sep 17 00:00:00 2001 From: NATAN Date: Sun, 19 Jan 2025 14:48:19 -0300 Subject: [PATCH] add character table --- app.js | 12 ++++++++++-- style.css | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 5d9e9cc..a9e8ff1 100644 --- a/app.js +++ b/app.js @@ -22,8 +22,16 @@ compressButton.addEventListener('click', () => { compressedResult.innerHTML = `

Tamanho após compressão: ${compressedSizeInBits} bits

Texto convertido: ${huffmanResult.encodedText}

+ `; + let tableHTML = ''; + for (const char in huffmanResult.huffmanCodes) { + tableHTML += ``; + } + tableHTML += '
CaractereCódigo
${char}${huffmanResult.huffmanCodes[char]}
'; + + compressedResult.innerHTML += tableHTML; openHuffmanTreeInNewTab(huffmanResult.huffmanTree); }); @@ -78,7 +86,7 @@ function generateHuffmanCodes(tree, prefix = '', codes = {}) { } function encodeText(text, huffmanCodes) { - return text.split('').map(char => huffmanCodes[char]).join(''); + return text.split('').map(char => huffmanCodes[char]).join(' '); } function calculateCompressedSize(huffmanResult) { @@ -167,4 +175,4 @@ function generateTreeHTML(node) { } return html; -} +} \ No newline at end of file diff --git a/style.css b/style.css index 0d0e981..c608bc7 100644 --- a/style.css +++ b/style.css @@ -58,6 +58,23 @@ button:hover { background-color: #0056b3; } +table { + border-collapse: collapse; + margin: 10px 0; + width: 100%; + font-weight: 500; +} +table th, +table td { + border: 1px solid #ccc; + padding: 8px; + text-align: left; +} +table th { + background-color: #f2f2f2; + font-weight: 500; +} + #compressedResult { margin-top: 20px; font-size: 18px;