Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


D3js Template

07 Aug 2022 »
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://d3js.org/d3.v7.min.js"></script>
  <title>Document</title>
  <style>
    body {
      width:100%;
      height:100%;
      overflow:hidden;
    }
  </style>
</head>
<body>

  <script>
    width = document.body.scrollWidth
    height = document.body.scrollHeight
    var svg = d3.select('body').append('svg')
                  .attr('width', `${width}px`)
                  .attr('height', `${height}px`)
    var g = svg.append('g')
    var zoom = d3.zoom().on('zoom', zoomed)
    function zoomed(event) {
      g.attr('transform', event.transform)
    }
    svg.call(zoom)
    // svg.call(zoom.transform, d3.zoomIdentity.translate(20, 11).scale(0.1249))




    g.append('rect')
          .attr('width', '500px')
          .attr('height', '500px')
          .attr('fill', 'red')
  </script>
</body>
</html>