javascript - D3 scatterplot with viewbox not fitting to screen on resize -


below scatterplot i've created d3 laptop's standard window size.

enter image description here

issue #1:

when screen small, box doesn't fit screen enter image description here

issue #2: when expand screen, chart becomes larger screen size , falls out-of-screen. example

i start assigning padding relative window size based on looked on normal-sized window

var width = window.innerwidth || document.documentelement.clientwidth || document.body.clientwidth;  var height = window.innerheight || document.documentelement.clientheight || document.body.clientheight;  //constants var w = .85 * width,  h = .70* height,  pad = .0078 * width,  bottom_pad = .1*height  left_pad = .08*width;  

then, create svg so

var dim = "0 0 " + w + " " + h var svg = d3.select("#chart")         .append("svg")         //.attr("preserveaspectratio", "xmaxymax meet")         .attr("viewbox", dim) 

to position various elements within chart, relied on paddings defined above. example,

var xscale = d3.scale.linear().domain([840454400.0, 1483228800.0]).range([left_pad, w-pad])  var yscale= d3.scale.linear()         .domain([0, 85])         .range([h-bottom_pad, pad]); 


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -