function gla_chart_all(data, chartopts, {
cwidth = 1000,
cheight = 500,
title = "",
sub = "",
link = "",
text = "",
dv = "",
subheads = ["", ""],
includetitles = true,
horiz = false,
multichart = "none",
header_size = "21pt",
sub_size = "15pt"
} = {}) {
console.log(`HORIZ: ${horiz} | TITLE: ${includetitles}`)
let self = this;
let asvg
let chart
function get_svg() {
return asvg
}
self.alterdims = function(w, h) {
if(w > 0){
cwidth = w;
chartopts.cwidth = w;
chart = new gla_chart(data, asvg, chartopts)
}
if(h > 0) cheight = h
}
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) {
let ttl = asvg.append("text")
.text(title)
.attr("name", `maintitle`)
.classed("title", true)
//.attr("alignment-baseline", "hanging")
.style("font-size", header_size)
.style("font-family", "Arial")
.style("fill", "#2a3135")
.attr("x", 0)
.attr("y", 0);
let ht = get_bbox(asvg, "maintitle")
ttl.attr("y", ht.height) // Title needs to be moved down to fit into the chart
let subttl = asvg.append("text")
.text(sub)
.attr("name", "subtitle")
.classed("title", true)
//.attr("alignment-baseline", "hanging")
.style("font-size", sub_size)
.style("font-family", "Arial")
.style("fill", "#515a5e")
.attr("x", 0)
.attr("y", (ht.height)*2); // It's height * 2, so that it fits under the title
// wrap_text(subttl, cwidth - 30, 15, `subttl`, asvg, "hanging") // wrap to 200?
asvg.append("text")
.html(link)
.attr("name", "link")
.classed("title", true)
.attr("alignment-baseline", "ideographic")
.style("font-size", "13pt")
.style("font-family", "Arial")
.style("fill", "#AAAAAA")
.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 + 23
chartopts["cheight"] = cheight - lk.height - 12
} else { // end if include titles
console.log("NOT INCLUDING TITLES")
chartopts["mTop"] = 30
chartopts["cheight"] = cheight
}
if(multichart == "none") {
const regex = new RegExp('^E09')
if(regex.test(data[0].xd)) {
let chart = new boroughMap(data, asvg, {
width: chartopts.cwidth,
height: chartopts.cheight,
g_code: "xd",
valname: "y",
mTop: chartopts.mTop
})
} else {
chart = (chartopts.horiz ? new gla_chart_h(data, asvg, chartopts) : new gla_chart(data, asvg, chartopts))
}
let dg = asvg.append("g")
.classed("dialog", true)
/*let db = new dialog(data, asvg, {
cwidth: cwidth,
cheight: cheight,
marginTop: chartopts["mTop"],
chart: chart
}, dg)*/
} 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
console.log(dats)
// 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]
// let tchart = new gla_chart(dats.d1, asvg, chartopts)
chartopts.forcecols[dats.dkeys[1]] = dats.cols[1]
//chartopts.nolabels = true
console.log("DOING FIRST CHART")
let tchart = new gla_chart(dats.d1, asvg, chartopts)
chartopts.nolabels = false
chartopts.forceMarginRight = tchart.marginRight
chartopts.chart_id = 2
console.log("DOING OTHER CHART")
let bchart = new gla_chart(dats.d2, asvg, chartopts)
console.log("DONE CHARTS")
console.log(tchart.getSharedRange())
let rr = tchart.getSharedRange()
if(!isNaN(rr[0])) {
bchart.setSharedRange(tchart.getSharedRange())
}
bchart.shiftChart(0, cheight / 2)
} else if (multichart == "vsplit_line_3") {
// group data into two distinct data sets
let dats = split_data_vertical(data)
chartopts.cheight = chartopts.cheight / 3
// 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]
// 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") {
let ttls_ht = 20 + chartopts.mTop
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", ttls_ht);
let subl = get_bbox(asvg, "subtitle_l")
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", ttls_ht);
let subr = get_bbox(asvg, "subtitle_r")
chartopts.mTop = (subr.height > subl.height ? chartopts.mTop + subr.height : chartopts.mTop + subl.height)
let dats = split_data_simple(data)
// chartopts.forceYDomain = get_padded_range(d3.extent(data, d => d.y), 0.25, "line")
let shared_y = false
chartopts.cwidth = halfchart
let dd1 = d3.extent(dats.d1, d => d.y)
let dd2 = d3.extent(dats.d2, d => d.y)
if(dd1[0] >= (dd2[0] * 0.9) && dd1[1] <= (dd2[1] * 1.1)) {
let yext = d3.extent(data, d => d.y)
let range = yext[1] - yext[0]
let rangepad = range * .25
let ymm = (yext[0] >= 0 && yext[0] - range < 0 ? 0 : yext[0] - rangepad)
chartopts.forceYDomain = [ymm, yext[1] + rangepad]
shared_y = true
}
let lchart = new gla_chart(dats.d1, asvg, chartopts)
//chartopts.nolabels = true
chartopts.chart_id = 2;
chartopts.nolabels = shared_y;
//chartopts.leglab = "none";
let rchart = new gla_chart(dats.d2, asvg, chartopts)
rchart.shiftChart(halfchart, 0)
} else if(multichart == "lines_v_multi") {
//let dats = split_data_vertical(data)
let dats = split_data_simple(data)
let halfheight = (chartopts.cheight-30) / 2
chartopts.cheight = halfheight //(chartopts.cheight-30) / 2
const halfchart = cwidth / 2
console.log(dats)
let ttls_ht = 20 + chartopts.mTop
// const halfchart = cwidth / 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", 20)
.attr("y", ttls_ht + 40);
let subl = get_bbox(asvg, "subtitle_l")
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", "14pt")
.style("font-family", "Arial")
.style("fill", "#999999")
.attr("x", 20)
.attr("y", ttls_ht + halfheight);
let subr = get_bbox(asvg, "subtitle_r")
// 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]*/
// let tchart = new gla_chart(dats.d1, asvg, chartopts)
//chartopts.forcecols[dats.dkeys[1]] = dats.cols[1]
//
console.log("DOING FIRST CHART")
chartopts.leglab = "legend"
//chartopts.xFontsize = "0pt"
let tchart = new gla_chart(dats.d1, asvg, chartopts)
// chartopts.nolabels = true
chartopts.leglab = "NONE"
chartopts.forceMarginRight = tchart.marginRight
chartopts.chart_id = 2
//chartopts.xFontsize = "12pt"
console.log("DOING OTHER CHART")
let bchart = new gla_chart(dats.d2, asvg, chartopts)
console.log("DONE CHARTS")
console.log(tchart.getSharedRange())
let rr = tchart.getSharedRange()
if(!isNaN(rr[0])) {
bchart.setSharedRange(tchart.getSharedRange())
}
bchart.shiftChart(0, halfheight + 30)
}
// let chart = (chartopts.horiz ? new gla_chart_h(data, asvg, chartopts) : new gla_chart(data, asvg, chartopts))
self.draw = function() {
console.log("DRAWING")
return asvg.node();
}
}