first commit
This commit is contained in:
97
js/Object_.js
Normal file
97
js/Object_.js
Normal file
@@ -0,0 +1,97 @@
|
||||
/* Object 데이터 시각화 */
|
||||
|
||||
function ObjTo(JSON) {
|
||||
this.Obj = JSON;
|
||||
this.tabletarget = ""
|
||||
this.tableoption
|
||||
}
|
||||
|
||||
ObjTo.prototype.setTabletarget = function(attr){
|
||||
this.tabletarget = createnode('TABLE', '', attr)
|
||||
}
|
||||
|
||||
|
||||
ObjTo.prototype.getTabletarget = function(){
|
||||
return this.tabletarget
|
||||
}
|
||||
|
||||
ObjTo.prototype.setTableoption = function(option){
|
||||
this.tableoption = option
|
||||
}
|
||||
|
||||
|
||||
ObjTo.prototype.getTableoption = function(){
|
||||
return this.tableoption
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @date 2020-02-25
|
||||
* @param {Object} attr
|
||||
* @param {Object} option = { "row" or "col" [1] key를 행으로 가져갈 지 , 열로 가져갈지 }
|
||||
* object key가 열 이름, object[key]의 배열이 각 요소, => 추후에 Object[key] -> Object형으로
|
||||
* 작성하여 { "자식td":[], "자식td":[] } 를 rowspan묶을 수 있게 작업.
|
||||
*
|
||||
*/
|
||||
ObjTo.prototype.MakeTable = function (attr, option) {
|
||||
var TR = [],
|
||||
Obj = this.Obj; // this
|
||||
|
||||
if(!option) option = "col";
|
||||
|
||||
this.setTableoption(option)
|
||||
this.setTabletarget(attr);
|
||||
|
||||
TR[0] = createnode("TR", "");
|
||||
Object.keys(Obj).forEach(function (element, index) {
|
||||
var o,
|
||||
t;
|
||||
Obj[element].forEach(function (value, id) {
|
||||
option === "col" ? o = id + 1 : o = index;
|
||||
option === "col" ? t = 0 : t = index
|
||||
|
||||
if(!TR[o]) TR[o] = createnode("TR", "")
|
||||
if (!id) TR[t].appendChild(createnode("TD", element))
|
||||
TR[o].appendChild(createnode("TD", String(value)))
|
||||
})
|
||||
})
|
||||
appendChild_m(this.getTabletarget(), TR)
|
||||
}
|
||||
|
||||
ObjTo.prototype.setColSame = function () {
|
||||
var length = Object.keys(this.Obj).length;
|
||||
var ratio = 100 / length;
|
||||
var Colgroup = createnode("COLGROUP","")
|
||||
appendChild_m(Colgroup,createnode_m("col",fillArray("",length)),{"width":ratio.toFixed(0)+"%"})
|
||||
this.getTabletarget().insertAdjacentElement("afterbegin",Colgroup)
|
||||
}
|
||||
|
||||
//3.TableSum
|
||||
ObjTo.prototype.TableSum = function(){
|
||||
var TR = [],
|
||||
Obj = this.Obj,
|
||||
option = this.getTableoption();
|
||||
tableTarget = this.getTabletarget();
|
||||
|
||||
if(option ==="col"){
|
||||
TR.push(createnode("TD","합계"))
|
||||
} else {
|
||||
$(tableTarget).find("tr:first").append(createnode("TD","합계",{"style":"background-color:aliceblue"}))
|
||||
}
|
||||
|
||||
Object.keys(Obj).forEach(function(key,id){
|
||||
var total = 0
|
||||
if(checkType(Obj[key],"number")) {
|
||||
Obj[key].forEach(function(element){total+=parseInt(element);});
|
||||
if(option === "col"){
|
||||
TR.push(createnode("TD",String(total)))
|
||||
} else {
|
||||
$(tableTarget).find("tr:eq("+id+")").append(createnode("TD",String(total),{"style":"background-color:aliceblue"}))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if(option ==="col") appendChild_m(this.getTabletarget(), TR,{"style":"background-color:aliceblue"})
|
||||
}
|
||||
Reference in New Issue
Block a user