/* 「テーブルメータ」 2004/05/07版 THU madpoet@thu.sakura.ne.jp http://thu.sakura.ne.jp/ */ // テーブルメータクラス function TableMeter() { this.fieldId = arguments[0]; this.id = this.fieldId + '_meter'; this.type = 0; // 0:左→右 1:右→左 2:下→上 3:上→下 this.width = 100; // 横幅(pt) this.height = 12; // 縦幅(pt) this.frameColor = 'black'; // 枠線の色 this.bgColor = 'white'; // 背景色 var meterColorNum = '20,50,100'; // メータ色の区切りの数値 var meterColor = 'red,gold,blue'; // メータ色 var i; for (i = 1; i < arguments.length; i++) { if (i == 1) { this.id += arguments[i]; } else if (i == 2) { this.type = arguments[i]; } else if (i == 3) { this.width = arguments[i]; } else if (i == 4) { this.height = arguments[i]; } else if (i == 5) { this.frameColor = arguments[i]; } else if (i == 6) { this.bgColor = arguments[i]; } else if (i == 7) { meterColorNum = arguments[i] + ''; } else if (i == 8) { meterColor = arguments[i]; } } this.bgId = this.id + 'bg'; this.meterColorNum = meterColorNum.split(','); this.meterColor = meterColor.split(','); for (i = 0; i < this.meterColorNum.length; i++) { this.meterColorNum[i] = this.meterColorNum[i].replace(/ /g, ''); this.meterColorNum[i] -= 0; this.meterColor[i] = this.meterColor[i].replace(/ /g, ''); } } // テーブルメータ:セット TableMeter.prototype.set = function() { var node; if(!(node = document.getElementById(this.fieldId))) { return false; } var nTable, nTbody, nTr, nTd, nTable2, nTbody2, nTr2, nTd2; nTable = document.createElement('table'); nTable.cellSpacing = 0, nTable.cellPadding = 0; nTable.style.border = '1pt solid ' + this.frameColor; nTbody = document.createElement('tbody'); nTr = document.createElement('tr'); nTd = document.createElement('td'); nTd.vAlign = 'top'; nTd.id = this.bgId; nTd.style.width = this.width + 'pt'; nTd.style.height = this.height + 'pt'; if (this.type == 0 || this.type == 3) { nTd.style.backgroundColor = this.bgColor; } nTable2 = document.createElement('table'); nTable2.cellSpacing = 0, nTable2.cellPadding = 0; nTable2.id = this.id; if (this.type < 2) { if (this.type == 0) { nTable2.style.width = '0%'; } else { nTable2.style.backgroundColor = this.bgColor; nTable2.style.width = '100%'; } nTable2.style.height = '100%'; } else { nTable2.style.width = '100%'; if (this.type == 2) { nTable2.style.backgroundColor = this.bgColor; nTable2.style.height = '100%'; } else { nTable2.style.height = '0%'; } } nTbody2 = document.createElement('tbody'); nTr2 = document.createElement('tr'); nTd2 = document.createElement('td'); nTr2.appendChild(nTd2); nTbody2.appendChild(nTr2); nTable2.appendChild(nTbody2); nTd.appendChild(nTable2); nTr.appendChild(nTd); nTbody.appendChild(nTr); nTable.appendChild(nTbody); node.appendChild(nTable); } // テーブルメータ:ビュー TableMeter.prototype.view = function(num) { var node, bgNode; if(!(node = document.getElementById(this.id))) { return false; } if(!(bgNode = document.getElementById(this.bgId))) { return false; } if (num < 0) { num = 0; } else if (num > 100) { num = 100; } var i; for (i = 0; i < this.meterColorNum.length; i++) { if (num <= this.meterColorNum[i]) { if (this.type == 1 || this.type == 2) { bgNode.style.backgroundColor = this.meterColor[i]; } else { node.style.backgroundColor = this.meterColor[i]; } break; } } if (num == 0) { if (this.type == 1 || this.type == 2) { bgNode.style.backgroundColor = this.bgColor; } else { node.style.backgroundColor = this.bgColor; } } else if (num == 100) { if (this.type == 1 || this.type == 2) { node.style.backgroundColor = this.meterColor[this.meterColor.length-1]; } else { bgNode.style.backgroundColor = this.meterColor[this.meterColor.length-1]; } } else { if (this.type == 1 || this.type == 2) { node.style.backgroundColor = this.bgColor; } else { bgNode.style.backgroundColor = this.bgColor; } } if (this.type < 2) { if (this.type == 1) { num = 100 - num;} node.style.width = num + '%'; } else { if (this.type == 2) { num = 100 - num;} node.style.height = num + '%'; } } // テーブルメータ:クリア TableMeter.prototype.clear = function() { var node; if(!(node = document.getElementById(this.fieldId))) { return false; } while(true) { if(node.childNodes[0] != null) { node.removeChild(node.childNodes[0]); } else { break; } } }