function data_control(data,{
yvlkp = [],
xtype = "date",
convert_b = true,
parseTimeString = "%Y-%m-%d",
is_stack = false
} = {}) {
let self = this;
self.data = []
const parseTime = d3.timeParse(parseTimeString);
self.ext = []
self.datacols;
let dtid = 0;
if(xtype == "date") {
data = data.slice().sort((a, b) => d3.ascending(a.xd, b.xd))
}
let last_xd = data[0].xd
let allmax = 0
data.forEach((d) => {
if(d.xd > last_xd) {
last_xd = d.xd
dtid += 1
}
d.dtid = dtid
let temp = JSON.parse(JSON.stringify(d)) ;
if(is_stack) {
let ctgs = Object.keys(temp)
let a = ctgs.shift()
let b = ctgs.pop()
self.datacols = ctgs
let rowmax = 0;
self.datacols.forEach((ctg) => {
temp[ctg] = +temp[ctg]
rowmax += temp[ctg]
})
allmax = (allmax > rowmax ? allmax : rowmax)
} else {
temp.b = (convert_b === true ? yvlkp[(+temp.b-1)] : temp.b);
if(temp.y == null) temp.y = NaN
temp.y = +temp.y
}
if(xtype == "date" | xtype == "quarter"){
temp.xd = parseTime(temp.xd);
}
self.data.push(temp)
})
self.y_ext = d3.extent(this.data, d => d.y)
self.ext = [0, allmax]
self.sort_by_var = function(v, border) {
console.log(v)
console.log(border)
if(v != "") {
self.data.sort(function(x, y){
return d3.ascending(x[v], y[v]);
})
} else {
self.data.forEach((d) => {
d.order = border.indexOf(d.b)
})
self.data.sort(function(x, y){
return d3.ascending(x.order, y.order) || d3.ascending(x.y, y.y);
})
console.log(self.data)
}
console.log("SORTING")
}
}