function gla_chart_all(data, chartopts, {
cwidth = 1200,
cheight = 500,
title = "",
sub = "",
subheads = ["", ""],
link = "",
text = "",
dv = "",
includetitles = true,
horiz = false,
multichart = "none"
} = {}) {
console.log(`MULTI: ${multichart}`)
let self = this;
let asvg
let eld = document.getElementById(dv)
if(eld != undefined) {
cwidth = eld.offsetWidth;
cheight = eld.offsetHeight - 200;
}
asvg = d3.create("svg")
.attr("width", cwidth)
.attr("height", cheight)
.attr("viewBox", [0, 0, cwidth, cheight])
.attr("style", "max-width: 100%; height: auto; height: intrinsic;");
if(includetitles) {
asvg.append("text")
.text(title)
.attr("name", `maintitle`)
.attr("alignment-baseline", "hanging")
.style("font-size", "28pt")
.style("font-family", "Arial")
.style("color", "#333333")
.attr("x", 0)
.attr("y", 0);
let ht = get_bbox(asvg, "maintitle")
asvg.append("text")
.text(sub)
.attr("name", "subtitle")
.attr("alignment-baseline", "hanging")
.style("font-size", "18pt")
.style("font-family", "Arial")
.style("color", "#999999")
.attr("x", 0)
.attr("y", ht.height);
asvg.append("text")
.html(link)
.attr("name", "link")
.attr("alignment-baseline", "ideographic")
.style("font-size", "14pt")
.style("font-family", "Arial")
.style("color", "#999999")
.attr("x", 0)
.attr("y", cheight);
let st = get_bbox(asvg, "subtitle")
let lk = get_bbox(asvg, "link")
//let cht = cheight - (ht.height + st.height + 5);
chartopts["mTop"] = ht.height + st.height
chartopts["cheight"] = cheight - lk.height
} else { // end if include titles
chartopts["mTop"] = 30
chartopts["cheight"] = cheight
}
if(multichart == "none") {
let chart = (chartopts.horiz ? new gla_chart_h(data, asvg, chartopts) : new gla_chart(data, asvg, chartopts))
} else if (multichart == "sbs_horiz_bar") {
chartopts.cwidth = chartopts.cwidth / 2
/// This is like a stacked data chart.
/// Get keys from first data item.
let dats = split_data_stack(data)
// Build colour palette
chartopts.forcecols = {}
chartopts.forcecols[dats.dkeys[1]] = dats.cols[0]
chartopts.forcecols[dats.dkeys[2]] = dats.cols[1]
// build first chart
let lchart = new gla_chart_h(dats.d1, asvg, chartopts)
let copts2 = chartopts
copts2.nolabels = true // charts share the y axis on the first chart, to remove on right chart
copts2.chart_id = 2
let rchart = new gla_chart_h(dats.d2, asvg, copts2)
rchart.shiftChart(lchart.ywidth[1], 0) // shift chart to right hand side
} else if (multichart == "vsplit_line") {
// group data into two distinct data sets
let dats = split_data_vertical(data)
chartopts.cheight = chartopts.cheight / 2
// let cgrps = d3.group(data, d => d.chart);
// get keys
// Build colour palette
chartopts.forcecols = {}
chartopts.forcecols[dats.dkeys[1]] = dats.cols[0]
chartopts.forcecols[dats.dkeys[2]] = dats.cols[1]
//console.log(dats)
// let tchart = new gla_chart(dats.d1, asvg, chartopts)
chartopts.forcecols[dats.dkeys[1]] = dats.cols[1]
chartopts.nolabels = true
let tchart = new gla_chart(dats.d1, asvg, chartopts)
chartopts.nolabels = false
chartopts.forceMarginRight = tchart.marginRight
let bchart = new gla_chart(dats.d2, asvg, chartopts)
bchart.setSharedRange(tchart.getSharedRange())
bchart.shiftChart(0, cheight / 2)
//
} else if(multichart == "lines_horiz") {
console.log("LINES HORIZ!! *************************")
const halfchart = cwidth / 2
asvg.append("text")
.text(subheads[0])
.attr("name", "subtitle_l")
//.attr("alignment-baseline", "hanging")
.style("font-size", "18pt")
.style("font-family", "Arial")
.style("fill", "#999999")
.attr("x", 0)
.attr("y", 20);
let subl = get_bbox(asvg, "subtitle_l")
chartopts.mTop = subl.height + 20
console.log(`SUBH HEIGHT: ${subl.height}`)
asvg.append("text")
.text(subheads[1])
.attr("name", "subtitle_r")
//.style("alignment-baseline", "hanging") // Does not work for the PDF/SVG versions!
.style("font-size", "18pt")
.style("font-family", "Arial")
.style("fill", "#999999")
.attr("x", halfchart)
.attr("y", 20);
let subr = get_bbox(asvg, "subtitle_r")
console.log(`MTOP: ${chartopts.mTop}`)
chartopts.mTop += (subr.height > subl.height ? subr.height : 0)
let dats = split_data_simple(data)
// chartopts.forceYDomain = get_padded_range(d3.extent(data, d => d.y), 0.25, "line")
chartopts.cwidth = halfchart
let lchart = new gla_chart(dats.d1, asvg, chartopts)
//chartopts.nolabels = true
chartopts.chart_id = 2;
//chartopts.nolabels = true
//chartopts.leglab = "none";
console.log(`DOMAIN FROM LCHART: ${lchart.yDomain}`)
let rchart = new gla_chart(dats.d2, asvg, chartopts)
rchart.shiftChart(halfchart, 0)
} else if(multichart == "lines_vertical") {
const halfchart = cheight / 2
asvg.append("text")
.text(subheads[0])
.attr("name", "subtitle_l")
//.attr("alignment-baseline", "hanging")
.style("font-size", "14pt")
.style("font-family", "Arial")
.style("fill", "#999999")
.attr("x", 0)
.attr("y", 40);
let subl = get_bbox(asvg, "subtitle_l")
chartopts.mTop += subl.height
console.log(`SUBH HEIGHT: ${subl.height}`)
asvg.append("text")
.text(subheads[1])
.attr("name", "subtitle_r")
//.attr("alignment-baseline", "hanging")
.style("font-size", "14pt")
.style("font-family", "Arial")
.style("fill", "#999999")
.attr("x", 0)
.attr("y", 40 + halfchart);
let subr = get_bbox(asvg, "subtitle_r")
chartopts.mTop += (subr.height > subl.height ? subr.height : 0)
let dats = split_data_simple(data)
chartopts.cheight = halfchart
chartopts.chart_id = 1;
console.log("CHART 1 (top)")
let rchart = new gla_chart(dats.d1, asvg, chartopts)
chartopts.chart_id = 2;
chartopts.nolabels = true;
console.log("CHART 2 (bottom)")
let lchart = new gla_chart(dats.d2, asvg, chartopts)
rchart.shiftChart(0, halfchart)
/*rchart.setSharedRange(lchart.getSharedRange())*/
}
// }
// let chart = (chartopts.horiz ? new gla_chart_h(data, asvg, chartopts) : new gla_chart(data, asvg, chartopts))
self.draw = function() {
return asvg.node();
}
}