src/chart/index.js
// Zoom extent to fit svg on the screen
Zoom extent to fit svg on the screen
Zoom extent to fit svg on the screen
function scaleToFit() {
    const latestConfig = loadConfig()
      const {
        nodeLeftX,
        nodeRightX,
        nodeWidth,
        nodeY,
        margin,
        elemHeight,
        elemWidth,
      } = latestConfig
      const centerPoint = elemWidth / 2 - nodeWidth / 2 - margin.left / 2
      const svgWidth = nodeLeftX + nodeRightX
      const svgHeight = nodeY + nodeHeight * 2 + 48
      let scaleX = elemWidth / svgWidth - 0.03
      let scaleY = elemHeight / svgHeight - 0.06
      const chooseScale = scaleX < scaleY ? scaleX : scaleY
      let scale =
        svgWidth > elemWidth || svgHeight > elemHeight ? chooseScale : 1
      let translateX = nodeLeftX * scale + nodeWidth / 2
      if (svgWidth > elemWidth || svgHeight > elemHeight) {
        if (scaleX < scaleY) {
          interpolateZoom([translateX, 48], scale)
        } else if (scaleX > scaleY) {
          interpolateZoom([centerPoint, 48], scale)
        }
      } else {
        interpolateZoom([centerPoint, 48], scale)
      }
  }
function scaleToFit ( ) { const latestConfig = loadConfig ( ) const { nodeLeftX , nodeRightX , nodeWidth , nodeY , margin , elemHeight , elemWidth , } = latestConfig const centerPoint = elemWidth / 2 - nodeWidth / 2 - margin . left / 2 const svgWidth = nodeLeftX + nodeRightX const svgHeight = nodeY + nodeHeight * 2 + 48 let scaleX = elemWidth / svgWidth - 0.03 let scaleY = elemHeight / svgHeight - 0.06 const chooseScale = scaleX < scaleY ? scaleX : scaleY let scale = svgWidth > elemWidth || svgHeight > elemHeight ? chooseScale : 1 let translateX = nodeLeftX * scale + nodeWidth / 2 if ( svgWidth > elemWidth || svgHeight > elemHeight ) { if ( scaleX < scaleY ) { interpolateZoom ( [ translateX , 48 ] , scale ) } else if ( scaleX > scaleY ) { interpolateZoom ( [ centerPoint , 48 ] , scale ) } } else { interpolateZoom ( [ centerPoint , 48 ] , scale ) } }
Zoom extent to fit svg on the screen
Zoom extent to fit svg on the screen
//If width is more than height //If height is more than width