function chart_table()

in static/plugins/charts_table.js [1:61]


function chart_table(title, headers, dict) {
    // Generates a striped table with optional headers and rows corresponding to the provided key/value dictionary.
    // If a key has no corresponding value (is null), the row is treated as a sub-header.
    const table_div = document.createElement('div');
    table_div.style.width = "500px";
    table_div.style.height = "380px";
    table_div.style.margin = "4px";
    table_div.style.padding = "6px";
    table_div.style.overflow = "hidden";
    table_div.className = "card";
    table_div.style.display = "inline-block";

    if (title) {
        const titletxt = document.createElement('h4');
        titletxt.innerText = title;
        titletxt.className = 'text-center';
        table_div.appendChild(titletxt);
    }

    const table = document.createElement('table');
    table.className = 'table';
    table_div.appendChild(table);

    if (headers) {
        const table_header = document.createElement('thead');
        const tr = document.createElement('tr');
        for (const col of headers) {
            const th = document.createElement('th');
            th.innerText = col;
            tr.appendChild(th);
        }
        table_header.appendChild(tr);
        table.appendChild(table_header);
    }

    if (dict) {
        const table_body = document.createElement('tbody');
        for (const [key, value] of Object.entries(dict)) {
            const tr = document.createElement('tr');
            const td_key = document.createElement('td');
            td_key.innerText = key + ":";
            td_key.style.fontWeight = 'bold';
            tr.appendChild(td_key);
            if (value === null) { // If value is null, this row is treated as a sub-header
                td_key.colSpan = 2;
                td_key.style.textAlign = 'center';
                td_key.style.fontVariant = 'small-caps';
            } else {
                const td_value = document.createElement('td');
                td_value.innerText = value;
                tr.appendChild(td_value);
            }
            table_body.appendChild(tr);
        }
        table.appendChild(table_body);
    }



    return table_div
}