chart_a= {
const svg= d3.create("svg")
.attr("viewBox", ([0, 0, width , height +50]));
const svg_a= d3.create("svg").attr("viewBox", ([0, 0, width + 200, height + 200]))
const grouping_a= svg_a.append("g")
grouping_a.append("path").join("path")
.attr("transform", `translate( ${margin.left}, ${margin.height })`)
.attr("d", path(land))
.attr("fill", "#E8E8E8")
.attr("stroke", "#000")
.attr("stroke-width", 0.25);
grouping_a.append("path")
.join("path")
.attr("d", path(borders))
.attr("fill", "none")
.attr("stroke", "black")
.attr("stroke-width", 0.15);
grouping_a.append("path")
.join("path")
.attr("d", path(graticule))
.attr("stroke", "#ccc")
.attr("fill", "none")
.attr("stroke-width", 0.75)
const grouping= svg.append("g");
grouping.append("path")
.join("path")
.attr("transform", `translate(${ margin.left }, ${ margin.height})`)
.attr("d", path(land))
//.attr("fill", "lightgray")
.attr("fill", "#E8E8E8")
.attr("stroke", "#000")
.attr("stroke-width", 0.25);
// BORDERS
grouping.append("path")
.join("path")
.attr("d", path(borders))
.attr("fill", "none")
.attr("stroke", "black")
.attr("stroke-width", 0.15);
// LININGS
grouping.append("path")
.join("path")
.attr("d", path(graticule))
.attr("stroke", "#ccc")
.attr("fill", "none")
.attr("stroke-width", 0.75);
////// XCO2 scatter plot
svg.selectAll("circle")
.data(select_data_a.slice(0, maxNum))
// .data(select_data.slice(0, 12))
.join('circle')
.attr('cx', d => projection([ d.x, d.y])[0])
.attr('cy', d => projection([ d.x, d.y])[1])
.attr('fill', d=> colorXco2( d.mean_xco2_anomaly))
.attr('r', 0.35)
//////////////////////////////////////////
/// BRUSH
// function brush_func(){
// }
// const brush= d3.brush().on("start brush", brush_func)
////////////////////////////////////////////////////////////
/// Scatter plot or BAR graph to represent the data on side
const bar= svg.append("g")
.attr("transform", `translate(${ width / 1.5}, ${ 10})`)
const x= d3.scaleLinear()
.domain([0, d3.max( select_data_a, d=> d.Index)])
.range([0, 300])
// append the x-axis
bar.append("g")
.attr("transform", `translate(${ 0 }, ${ height/ 2})`)
.call(d3.axisBottom(x))
const y= d3.scaleLinear()
// .domain([0, d3.max(select_data_a, d => d.mean_xco2_anomaly)])
.domain([-6, 6])
.range([200, 0])
bar.append("g")
// .attr("transform", `translate( ${width /2}, ${ 100})`)
.call(d3.axisLeft(y))
//////////////////////////////////
//////////////////////////////////
//Scatterr plot
bar.selectAll("circle")
.data(select_data_a.slice(0, maxNum))
//.data(select_data_a)
.join("circle")
.attr("cx", d => x(d['Index']))
.attr("cy", d => y(d["mean_xco2_anomaly"]))
.attr("r", 1.25)
.attr('fill', d=> colorXco2( d.mean_xco2_anomaly))
// .attr("transform", d=> `translate( ${x(d["Index"])}, ${y(d["mean_xco2_anomaly"])}`)
// .attr("r", 1.25)
// .attr("cx", d => x(d.Index))
// .attr("cy", d => y(d.mean_xco2_anomaly))
// .attr("r", 1.25);
// BARS
// bar.selectAll(".series")
// .data(xco2_2015)
// .selectAll(".bar")
// .data(d=> d)
// .attr("x", d=> d["Index"])
// .attr("y", d => d["monthly"])
// //////////////////////////////////////////////////////////
////////////////////
// COLOR BAR
// Create a color bar gradient
const colorBar = svg.append("g")
.attr("transform", `translate( ${20}, ${ height - 50})`);
// Calculate the width of each color segment
var segmentWidth = 40;
var segmentHeight = 20;
var segments = 18;
var segmentColors = [];
for (var i = -6; i <= 6; i++) {
segmentColors.push(colorScale(i));
}
// Draw the color segments
colorBar.selectAll("rect")
.data(segmentColors)
.enter()
.append("rect")
.attr("x", function(d, i) {
return i * segmentWidth;
})
.attr("y", 0)
.attr("width", segmentWidth)
.attr("height", segmentHeight)
.attr("fill", function(d) {
return d;
});
// Add text labels to the color bar
colorBar.selectAll("text")
.data(segmentColors)
.enter()
.append("text")
.attr("x", function(d, i) {
return i * segmentWidth;
})
.attr("y", segmentHeight + 15)
.text(function(d, i) {
var value = i - 6;
return value;
})
return svg.node();
}