From e64e04edddb733c4d60e93970659a8f23007d0a2 Mon Sep 17 00:00:00 2001 From: Ajay Rao Date: Sat, 7 Nov 2020 20:39:11 -0500 Subject: [PATCH] added legend in bottom right corner --- index.html | 8 +-- js/Stacked_Bar_Chart.js | 125 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 121 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index d6f6479..d3e3b63 100644 --- a/index.html +++ b/index.html @@ -60,13 +60,6 @@

Visualization

- - A - B - - - - @@ -109,5 +102,6 @@

Acknowledgments

+ diff --git a/js/Stacked_Bar_Chart.js b/js/Stacked_Bar_Chart.js index 4531c1f..296de05 100644 --- a/js/Stacked_Bar_Chart.js +++ b/js/Stacked_Bar_Chart.js @@ -1,7 +1,122 @@ -// Immediately Invoked Function Expression to limit access to our -// variables and prevent -((() => { +// Stacked Bar Chart Data +let margin = { + top: 35, + left: 120 , + right: 30, + bottom: 50 +}, +width = 500 - margin.left - margin.right, +height = 500 - margin.top - margin.bottom; - console.log('Hello, world!'); +let svg_stack_bar = d3.select('#vis-svg-1') + .append('svg') + .attr('preserveAspectRatio', 'xMidYMid meet') // this will scale your visualization according to the size of the page. + .attr('width', '100%') // this is now required by Chrome to ensure the SVG shows up at all + .style('background-color', 'white') // change the background color to white -})()); \ No newline at end of file +// Legend Data +const legend_width = 150 +const legend_height = 200 +const legend_x = 10 +const legend_y = 740 +const y_incr = 20 +const x_incr = 10 + +// legend outlined box +svg_stack_bar.append("rect") + .attr("x",legend_x) + .attr("y",legend_y) + .attr("width",legend_width) + .attr("height", legend_height) + .style("fill", "white") + .style("stroke", 'black'); + +// legend title +svg_stack_bar.append("text") + .attr("x", ((legend_x + legend_width)/2)) + .attr("y", (legend_y + x_incr)) + .text("Regeneration Type") + .style("font-size", "10px") + .style('text-anchor', 'middle') + .attr('text-decoration', 'underline') + .attr("alignment-baseline","middle") + +// legend: none regeneration SHAPE +svg_stack_bar.append("circle") + .attr("cx",(legend_x + y_incr)) + .attr("cy",(legend_y + (2*y_incr))) + .attr("r", 6) + .style("fill", "purple") + .style("stroke", 'black'); + +// legend: none regeneration TEXT +svg_stack_bar.append("text") + .attr("x", (legend_x + y_incr + x_incr)) + .attr("y", (legend_y + (2*y_incr))) + .text("None") + .style("font-size", "10px") + .attr("alignment-baseline","middle") + +// legend: not to ring regeneration SHAPE +svg_stack_bar.append("circle") + .attr("cx",(legend_x + y_incr)) + .attr("cy",(legend_y + (2*y_incr) + y_incr)) + .attr("r", 6) + .style("fill", "blue") + .style("stroke", 'black'); + +// legend: not to ring regeneration TEXT +svg_stack_bar.append("text") + .attr("x", (legend_x + y_incr + x_incr)) + .attr("y", (legend_y + (2*y_incr) + y_incr)) + .text("Not to Ring") + .style("font-size", "10px") + .attr("alignment-baseline","middle") + +// legend: to ring regeneration SHAPE +svg_stack_bar.append("circle") +.attr("cx",(legend_x + y_incr)) +.attr("cy",(legend_y + (2*y_incr) + y_incr + y_incr)) +.attr("r", 6) +.style("fill", "green") +.style("stroke", 'black'); + +// legend: to ring regeneration TEXT +svg_stack_bar.append("text") +.attr("x", (legend_x + y_incr + x_incr)) +.attr("y", (legend_y + (2*y_incr) + y_incr + y_incr)) +.text("To Ring") +.style("font-size", "10px") +.attr("alignment-baseline","middle") + +// legend: along ring regeneration SHAPE +svg_stack_bar.append("circle") + .attr("cx",(legend_x + y_incr)) + .attr("cy",(legend_y + (2*y_incr) + y_incr + y_incr + y_incr)) + .attr("r", 6) + .style("fill", "yellow") + .style("stroke", 'black'); + +// legend: along ring regeneration TEXT +svg_stack_bar.append("text") + .attr("x", (legend_x + y_incr + x_incr)) + .attr("y", (legend_y + (2*y_incr) + y_incr + y_incr + y_incr)) + .text("Along Ring") + .style("font-size", "10px") + .attr("alignment-baseline","middle") + +// legend: full length regeneration SHAPE +svg_stack_bar.append("circle") + .attr("cx",(legend_x + y_incr)) + .attr("cy",(legend_y + (2*y_incr) + y_incr + y_incr + y_incr + y_incr)) + .attr("r", 6) + .style("fill", "red") + .style("stroke", 'black'); + +// legend: full length regeneration TEXT +svg_stack_bar.append("text") + .attr("x", (legend_x + y_incr + x_incr)) + .attr("y", (legend_y + (2*y_incr) + y_incr + y_incr + y_incr + y_incr)) + .text("Not to Ring") + .style("font-size", "10px") + .attr("alignment-baseline","middle") \ No newline at end of file