drweb-luxus-mit-tabellen/beispiele/jsc-plugins/jsbarchart2.js

/* -*- javascript -*- 
     Date          : Wed Sep 26 06:32:54 2007
     Created By    : Dr. Detlef Groth, Caputh, Germany
     Created       : Wed Sep 26 06:32:54 2007
     Last Modified : <071113.1651>
     */
// START CODE
if (!String.prototype.repeat) {
    String.prototype.repeat = function(l){
	return new Array(l+1).join(this);
    };
}

function JSBarChart2 (element) {
    var pre = document.getElementsByTagName("pre")[0];
    var cnt = pre.innerHTML;
    var table = document.createElement("table");
    table.className = "chart";
    var tbody = document.createElement("tbody");
    var lines = cnt.split(/\|\|/);
    var max = 0 ;
    var maxIdx = 0 ;
    var minIdx = 0 ;
    var min = 1000 ;
    for (var x = 0 ; x < lines.length; x++) { 
        var tr = document.createElement("tr");
        var cols = lines[x].split(/\|/);
        for (var y = 0 ; y < cols.length;y++) {
            var td = document.createElement("td");
            if (y == 1) {
                var code = document.createElement("code");
                code.className = "middle";
                var i = parseInt(cols[y]);
                if (i>max) {
                    maxIdx = x;
                    max = i ;
                }
                if (i < min) {
                    minIdx = x;
                    min = i ;
                }
                var text = ".".repeat(i);
                code.appendChild(document.createTextNode(text));
                td.appendChild(code);
                
            } else {
                td.appendChild(document.createTextNode(cols[y]));
            }
            tr.appendChild(td);
        } 
        tbody.appendChild(tr);
    }
    table.appendChild(tbody);
    var codes = table.getElementsByTagName("code");
    codes.item(minIdx).className = "min";
    codes.item(maxIdx).className = "max";
    pre.parentNode.insertBefore(table,pre);
    pre.style.display = "none";
}
// END CODE

Generated by GNU enscript 1.6.3.