Esempio n. 1
0
  private void updateScale(double oldScale, double newScale, SVGElement svg, int cx, int cy) {

    double zoomFactor = newScale / oldScale;
    // (x in new coord system - x in old coord system)/x coordinate
    SVGGElement g = m_svgViewPort.cast();

    if (cx == 0) {
      cx = (int) (Math.ceil(svg.getOffsetWidth() / 2.0) - 1);
    }

    if (cy == 0) {
      cy = (int) (Math.ceil(svg.getOffsetHeight() / 2.0) - 1);
    }

    SVGPoint p = svg.createSVGPoint();
    p.setX(cx);
    p.setY(cy);
    p = p.matrixTransform(g.getCTM().inverse());

    SVGMatrix m =
        svg.createSVGMatrix()
            .translate(p.getX(), p.getY())
            .scale(zoomFactor)
            .translate(-p.getX(), -p.getY());
    SVGMatrix ctm = g.getCTM().multiply(m);

    consoleLog("zoomFactor: " + zoomFactor + " oldScale: " + oldScale + " newScale:" + newScale);
    D3.d3()
        .select(m_svgViewPort)
        .transition()
        .duration(1000)
        .attr("transform", matrixTransform(ctm));
  }
Esempio n. 2
0
    public PanObject(Element draggableElement, Element containerElement) {
      super(draggableElement, containerElement);

      SVGGElement g = draggableElement.cast();
      m_stateTf = g.getCTM().inverse();

      m_stateOrigin = getEventPoint(D3.getEvent()).matrixTransform(m_stateTf);
    }