How to use the d3-zoom.zoomTransform function in d3-zoom

To help you get started, we’ve selected a few d3-zoom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vasturiano / force-graph / src / force-graph.js View on Github external
const tooltipContent = obj ? accessorFn(state[`${obj.type.toLowerCase()}Label`])(obj.d) || '' : '';
          toolTipElem.style.visibility = tooltipContent ? 'visible' : 'hidden';
          toolTipElem.innerHTML = tooltipContent;

          state.hoverObj = obj;
        }

        refreshShadowCanvas();
      }

      // Wipe canvas
      clearCanvas(ctx, state.width, state.height);

      // Frame cycle
      const t = d3ZoomTransform(state.canvas);
      state.forceGraph.globalScale(t.k).tickFrame();

      TWEEN.update(); // update canvas animation tweens

      state.animationFrameRequestId = requestAnimationFrame(animate);
    })();
  },
github vasturiano / force-graph / src / force-graph.js View on Github external
// Element size
      canvas.style.width = `${state.width}px`;
      canvas.style.height = `${state.height}px`;

      // Memory size (scaled to avoid blurriness)
      canvas.width = state.width * pxScale;
      canvas.height = state.height * pxScale;

      // Normalize coordinate system to use css pixels (on init only)
      if (!curWidth && !curHeight) {
        canvas.getContext('2d').scale(pxScale, pxScale);
      }
    });

    // Relative center panning based on 0,0
    const k = d3ZoomTransform(state.canvas).k;
    state.zoom.translateBy(state.zoom.__baseElem,
      (state.width - curWidth) / 2 / k,
      (state.height - curHeight) / 2 / k
    );
  }
}
github naver / billboard.js / src / api / api.zoom.js View on Github external
unzoom() {
		const $$ = this.internal;
		const config = $$.config;

		if ($$.zoomScale) {
			config.subchart_show ?
				$$.brush.getSelection().call($$.brush.move, null) :
				$$.zoom.updateTransformScale(d3ZoomIdentity);

			$$.updateZoom(true);
			$$.zoom.resetBtn && $$.zoom.resetBtn.style("display", "none");

			// reset transform
			const eventRects = $$.main.select(`.${CLASS.eventRects}`);

			if (d3ZoomTransform(eventRects.node()) !== d3ZoomIdentity) {
				$$.zoom.transform(eventRects, d3ZoomIdentity);
			}

			$$.redraw({
				withTransition: true,
				withY: config.zoom_rescale
			});
		}
	}
});
github CyberReboot / CRviz / src / features / visualization / d3-viz / setup-zoom.js View on Github external
const setupZoom = ({
  zoomRoot,
  transformRoot,
  nodes,
  showNodes,
  width,
  height,
  packedData
}) => {

  const state = {
    zoomTo: null,
    zoomToTransform: null,
    // Find the current zoom transform if any
    transform: zoomTransform(zoomRoot.node())
  };

  const zoomBehavior = zoom();

  zoomBehavior.on("zoom", () => {
    const event = d3Event;
    state.transform = event.transform;
    zoomToTransform(event.transform)
  });

  zoomRoot.call(zoomBehavior);

  // Amount of space to leave around a node when zoomed into that node
  // (as a fraction of the node diameter)
  const viewPadding = 0.25;
github jaegertracing / jaeger-ui / packages / plexus / src / DirectedGraph / DirectedGraph.tsx View on Github external
_onZoomed = () => {
    const root = this.rootRef.current;
    if (!root) {
      return;
    }
    const zoomTransform = getTransform(root);
    this.setState({ zoomTransform });
  };
github magjac / d3-graphviz / src / zoom.js View on Github external
if (svg.size() == 0) {
        return this;
    }
    this._zoomSelection = svg;
    var zoomBehavior = zoom()
        .scaleExtent(this._options.zoomScaleExtent)
        .translateExtent(this._options.zoomTranslateExtent)
        .interpolate(interpolate)
        .on("zoom", zoomed);
    this._zoomBehavior = zoomBehavior;
    var g = d3.select(svg.node().querySelector("g"));
    svg.call(zoomBehavior);
    if (!this._active) {
        translateZoomBehaviorTransform.call(this, g);
    }
    this._originalTransform = zoomTransform(svg.node());

    return this;
};
github UXAspects / UXAspects / src / components / organization-chart / organization-chart.component.ts View on Github external
private getCameraPosition(): ZoomTransform {
        return zoomTransform(this._nodesContainer.node());
    }
github magjac / d3-graphviz / src / render.js View on Github external
return function(t) {
                                                node.setAttribute("transform", interpolateTransformSvg(zoomTransform(graphvizInstance._zoomSelection.node()).toString(), getTranslatedZoomTransform.call(graphvizInstance, element).toString())(t));
                                            };
                                        });
github wikimedia / analytics-wikistats2 / src / components / detail / chart / MapChart / MapChart.vue View on Github external
configureZoom (svg, g) {
            svg = svg || d3.select('.map.canvas');
            g = g || svg.select('g.map.group');

            const c = this.constants;
            const t = zoom.zoomTransform(g).translate(c.xi, c.yi).scale(c.scale);

            const zoomBehavior = zoom.zoom()
                .scaleExtent([c.scale-0.2, 8])
                .translateExtent([[c.x0, c.y0],[c.x1, c.y1]])
                .on('zoom', () => {
                    g.attr('transform', d3.event.transform);
                });
            svg.call(zoomBehavior).on('wheel', function () { d3.event.preventDefault(); });
            svg.call(zoomBehavior.transform, t);
        },
    }

d3-zoom

Pan and zoom SVG, HTML or Canvas using mouse or touch input.

ISC
Latest version published 3 years ago

Package Health Score

74 / 100
Full package analysis