From 56b2e2ad38309128c68f3d2988d6f192131dacc9 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Fri, 9 Sep 2022 19:13:48 -0400 Subject: [PATCH] create box --- app.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app.js b/app.js index e0969ac..d77030b 100644 --- a/app.js +++ b/app.js @@ -28,12 +28,20 @@ var dragBehavior = d3.drag() //create a drag behavior .html(worldProjection.invert(d3.mouse(this))[0]) d3.select('table tr:nth-child(2) td:last-child') .html(worldProjection.invert(d3.mouse(this))[1]) + + d3.selectAll('rect').remove(); + d3.select('svg').append('rect') + .attr('x', d3.mouse(this)[0]) + .attr('y', d3.mouse(this)[1]); }) .on('drag', function(){ d3.select('table tr:nth-child(3) td:first-child') .html(worldProjection.invert(d3.mouse(this))[0]) d3.select('table tr:nth-child(3) td:last-child') .html(worldProjection.invert(d3.mouse(this))[1]) + + d3.select('rect').attr('width', d3.mouse(this)[0]-d3.select('rect').attr('x')) + d3.select('rect').attr('height', d3.mouse(this)[1]-d3.select('rect').attr('y')) }) d3.select('svg').call(dragBehavior);