简体   繁体   English

将D3 Band缩放集成到D3热图中

[英]To integrate D3 Band zoom in D3 heatmap

Here I want to integrate D3 Band zoom in D3 Heatmap with resettable zoom . 在这里,我想将D3波段缩放功能 与可重置缩放功能集成到D3热图中 The red band appears while dragging, but it didn't zoom. 拖动时出现红色带,但没有缩放。 I think, there some issue in zoom function, but i couldn't track it yet. 我认为,缩放功能存在一些问题,但我还无法跟踪。 Please check out my fiddle . 请检查我的小提琴

Zoom function: 缩放功能:

function zoom() {

    //recalculate domains
  if(zoomArea.x1 > zoomArea.x2) {
      x.domain([zoomArea.x2, zoomArea.x1]);
    } else {
      x.domain([zoomArea.x1, zoomArea.x2]);
    }

    if(zoomArea.y1 > zoomArea.y2) {
      y.domain([zoomArea.y2, zoomArea.y1]);
    } else {
      y.domain([zoomArea.y1, zoomArea.y2]);
    }

    var t = svg.transition().duration(750);
    t.select(".x.axis").call(scale[X]);
    t.select(".y.axis").call(scale[Y]);
}

在此处输入图片说明

Please suggest a method to resolve it. 请提出解决方法。 Thank you in advance. 先感谢您。

Here is a potential canvas-based solution. 这是一个潜在的基于画布的解决方案。

You can modify your zoom function to force a redraw using only a sub rectangle of the image with 您可以修改缩放功能以仅使用图像的子矩形强制重绘

context.drawImage(image,sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);

Then give sx,sy top-left coordinates of your selection rectangle, and sWidth,sHeight width and size of selection rectangle. 然后给出选择矩形的sx,sy左上角坐标,以及选择矩形的sWidth,sHeight宽度和大小。

dx,dy,dWidth,dHeight are constant in your case, 0,0,canvasWidth,canvasSize dx,dy,dWidth,dHeight在您的情况下是常数, 0,0,canvasWidth,canvasSize

You will probably need to modify createImageObj to also use drawImage rather than putImage . 您可能需要修改createImageObj以也使用drawImage而不是putImage I am not familiar with canvas so you need to check this point. 我对canvas不熟悉,因此您需要检查这一点。

Hope this helps. 希望这可以帮助。

For reference, MDN docs on drawImage 供参考,有关drawImage MDN文档

Here is a potential solution. 这是一个潜在的解决方案。

First, ditch the canvas. 首先,抛开画布。

Use the following structure instead : 请改用以下结构:

 <svg> <g id="x axis"> // ... </g> <g id="y axis"> // ... </g> <svg id="imageContainer" viewbox="0 0 heatmapDim[0] heatmapDim[1]"> <image xlink:href="yourHeatmap"/> </svg> </svg> 

The key here is to use the viewBox attribute of the second <svg> (#imageContainer). 此处的关键是使用第二个<svg> (#imageContainer)的viewBox属性。 This will allow you to define a subwindow on your image 这将允许您在图像上定义一个子窗口

And modify your zoom 并修改您的缩放

 function zoom() { //recalculate domains var x0,x1,y0,y1; if(zoomArea.x1 > zoomArea.x2) { x0 = zoomArea.x2; x1 = zoomArea.x1; } else { x0 = zoomArea.x1; x1 = zoomArea.x2; } if(zoomArea.y1 > zoomArea.y2) { y0 = zoomArea.y2 y1 = zoomArea.y1; } else { y0 = zoomArea.y1; y1 = zoomArea.y2; } d3.select("#imageContainer").attr("viewBox",x0 + " " + y0 + " " + x1 + " " + y1); } 

That should do the trick, haven't tested it thought, your fiddle is quite large and that doesn't help. 那应该可以解决问题,还没有测试过,您的小提琴相当大,没有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM