Responsive width with wordcloud2.js (canvas html5 element) -


You can create beautiful and easy wordclouds with you. I do not really have a problem with this script, in fact, with canvas element as usual: I have to do a responsive width (in this matter related to browser-width).

It shows the correct width (100%), but the canvas is extended and the "image" gets distorted. I save "png" if this is the year / basic resolution given by the script

how to fix it

 . & Lt;?! DOCTYPE html public "- / / W3C / DTD XHTML 1.0 Transcription // N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Title & gt; Canvas & lt; / Title & gt; & Lt; Script src = "// code.jquery.com/jquery-1.11.0.min.js"></script> & Lt; Script src = "// code.jquery.com/jquery-migrate-1.2.1.min.js"></script> & Lt; Link href = 'http: //fonts.googleapis.com/css? Family = open + sans' relay = 'stylesheet' type = 'text / css' & gt; & Lt; Script src = "js / wordcloud2.js" & gt; & Lt; / Script & gt; & Lt; Style type = "text / css" & gt; #canvas_cloud {width: 100%; Height: 500px; } & Lt; / Style & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Canvas id = "canvas_cloud" & gt; & Lt; / Canvas & gt; & Lt; Script & gt; Up option = {list: ["pear", "9"], ["grapes", "3"], ["pineapple", "8"], ["apple", "5"]], gridSize: Math.Gual (16 * document.getElementById ('canvas_cloud') offsetWidth / 1024), weightFactor :. Function (size) {return Math.pow (size, 1.9) * document.getElementById ('canvas_cloud') offsetWidth / 1024; }} WordCloud (document.getElementById ('canvas_cloud', option); & lt; / script & gt; & gt; & gt; & lt; / html & gt;  

I got it! Sourround with div > element, which is 100% wide and the ID "Sourrounding_div"

  
gt; canvas id = "canvas_cloud" & gt;

Em>:

  on div = document.getElementById ("sourrounding_div"); Var canvas = document. GetElementById ("canvas_cloud"); can Habit = div.offsetHeight; Canvas.width = div.offsetWidth;  

All this is: -)


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -