Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sadly, the solution posted by Bill did only half the trick: While it does indeed inhibit the panning, it causes the graph to distort if zoom is applied. It is then usually impossible to return to a properly proportioned and positioned graph.</p> <p>In the following version the proportions of the axes are maintained, even if scrolling to the borders. </p> <p>As soon as the scaling hits 100%, the scales' domains are reset to their original position. This guarantees a correct positioning, even if the intermediate steps return illegal parameters for the axes. </p> <p>While not perfect, I hope this script can help somebody until d3 (re)implements this feature.</p> <pre><code># x and y are the scales # xAxis and yAxis are the axes # graph is the graph you want attach the zoom to x0 = x.copy() y0 = y.copy() successfulTranslate = [0, 0] zoomer = d3.behavior.zoom() .scaleExtent([1,2]) onZoom = -&gt; ev = d3.event # contains: .translate[x,y], .scale if ev.scale == 1.0 x.domain x0.domain() y.domain y0.domain() successfulTranslate = [0, 0] else xTrans = x0.range().map( (xVal) -&gt; (xVal-ev.translate[0]) / ev.scale ).map(x0.invert) yTrans = y0.range().map( (yVal) -&gt; (yVal-ev.translate[1]) / ev.scale ).map(y0.invert) xTransOk = xTrans[0] &gt;= x0.domain()[0] and xTrans[1] &lt;= x0.domain()[1] yTransOk = yTrans[0] &gt;= y0.domain()[0] and yTrans[1] &lt;= y0.domain()[1] if xTransOk x.domain xTrans successfulTranslate[0] = ev.translate[0] if yTransOk y.domain yTrans successfulTranslate[1] = ev.translate[1] zoomer.translate successfulTranslate graph.select('g.x.axis').call(xAxis) graph.select('g.y.axis').call(yAxis) drawBars() zoomer.on('zoom', onZoom) # ... graph.call(zoomer) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload