You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Jacob Christophersen <ja...@gmail.com> on 2010/04/06 12:54:55 UTC

Pan and Zooms being clipped.

Hi,

I've been experimenting with Batik as a possible option for a project I need
to do.

I need to implement a pan/zoom style similar to google maps.

I'm struggling with the issue that when ever I try to pan or zoom out, the
parts of the SVG that were not visible before the interactor started, are
not shown again until I release the mouse.

I've done a bit of searching around, and the consensus seems to be to set
the overflow property of the SVG root element to visible, but that doesn't
seem to have changed anything.

I've made an example (pasted below), where a rectangle is created with x,y =
(-10,-10). The top left of the rectangle is clipped at first, and while
panning and zooming it remains clipped until I release the mouse.
(Panning/Zooming using Shift + left/right mouse button).

Thanks,

Jacob

Example:

import javax.swing.JFrame;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.swing.JSVGCanvas;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Application extends JFrame {
    private JSVGCanvas canvas;

    public Application(){
        setSize(400, 400);
        initComponents();
    }

    private void initComponents(){
        canvas = new JSVGCanvas();
        canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        canvas.setSize(400,400);
        getContentPane().add(canvas);
        canvas.setDocument(createSVG());
    }

    private Document createSVG(){
        DOMImplementation impl =
SVGDOMImplementation.getDOMImplementation();
        final String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
        final Document doc = impl.createDocument(svgNS, "svg", null);

        Element svgRoot = doc.getDocumentElement();
        svgRoot.setAttributeNS(null, "overflow", "visible");
        svgRoot.setAttributeNS(null, "width", "400");
        svgRoot.setAttributeNS(null, "height", "400");

        Element rectangle = doc.createElementNS(svgNS, "rect");
        rectangle.setAttributeNS(null, "x", "-10");
        rectangle.setAttributeNS(null, "y", "-10");
        rectangle.setAttributeNS(null, "width", "200");
        rectangle.setAttributeNS(null, "height", "200");
        rectangle.setAttribute("style", "fill:red");

        svgRoot.appendChild(rectangle);
        return doc;
    }

    public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Application().setVisible(true);
            }
        });
    }
}

Re: Pan and Zooms being clipped.

Posted by th...@kodak.com.
Hi Jacob,

> > Jacob Christophersen <ja...@gmail.com> wrote on 
04/06/2010 06:54:55 AM:
> >
> > > I'm struggling with the issue that when ever I try to pan or zoom
> > > out, the parts of the SVG that were not visible before the
> > > interactor started, are not shown again until I release the mouse.

>  Thomas DeWeese wrote:

> >   Correct, there is no simple way to avoid this.  In order to have
> > good performance the interactors simply scale/translate/rotate the
> > previous offscreen buffer.

Jacob Christophersen <ja...@gmail.com> wrote on 04/06/2010 
07:47:49 AM:

> So would I be able to, for example, set the viewBox = "100 100 200
> 200", that I could then move the viewBox to other areas smoothly
> within the 400 x 400 root element?

    I don't think so.  The problem has nothing to do with viewBox
(zooming and panning the canvas do not effect the viewBox) it has to
do with the size of the offscreen buffer in the canvas.  It might be
possible to make the offscreen buffer in the canvas larger but that
get's really inefficient really quickly, and would slow down all
drawing operations.

> And if that is possible, would I just override the
> AbstractPanInteractor methods to manipulate the viewBox?

    Yes, you can create your own version of the Interactors, and in
your version you can manipulate the viewBox, or _much_ better simply 
update the rendering transform on the canvas (setRenderingTransform) 
however due to my previous statement:

> > For most SVG documents the time to render
> > them from scratch is far too long to update the screen smoothly during
> > pan/zoom operations.

     I don't think you will get 'smooth' updates, although that
depends on the SVG document and the computer in question.


Re: Pan and Zooms being clipped.

Posted by Jacob Christophersen <ja...@gmail.com>.
On 6 April 2010 21:23, <th...@kodak.com> wrote:
>
> Hi Jacob,
>
> Jacob Christophersen <ja...@gmail.com> wrote on 04/06/2010 06:54:55 AM:
>
> > I need to implement a pan/zoom style similar to google maps.
> >
> > I'm struggling with the issue that when ever I try to pan or zoom
> > out, the parts of the SVG that were not visible before the
> > interactor started, are not shown again until I release the mouse.
>
>   Correct, there is no simple way to avoid this.  In order to have
> good performance the interactors simply scale/translate/rotate the
> previous offscreen buffer.  For most SVG documents the time to render
> them from scratch is far too long to update the screen smoothly during
> pan/zoom operations.
>
>    Ideally in the background we would be updating as best we could
> and refreshing the offscreen image as we are able, but doing that
> is really quite complex, and you can quickly end up just thrashing
> the processor.
>
> > I've done a bit of searching around, and the consensus seems to be
> > to set the overflow property of the SVG root element to visible, but
> > that doesn't seem to have changed anything.
>
>     The overflow is needed if you are panning to areas that used to
> be outside of the viewBox.  In this case you are still within the
> viewBox, but we just don't have a rendered version of the areas.
>
Thanks for the prompt response.

So would I be able to, for example, set the viewBox = "100 100 200
200", that I could then move the viewBox to other areas smoothly
within the 400 x 400 root element?

And if that is possible, would I just override the
AbstractPanInteractor methods to manipulate the viewBox?

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Pan and Zooms being clipped.

Posted by th...@kodak.com.
Hi Jacob,

Jacob Christophersen <ja...@gmail.com> wrote on 04/06/2010 
06:54:55 AM:

> I need to implement a pan/zoom style similar to google maps.
> 
> I'm struggling with the issue that when ever I try to pan or zoom 
> out, the parts of the SVG that were not visible before the 
> interactor started, are not shown again until I release the mouse.

   Correct, there is no simple way to avoid this.  In order to have
good performance the interactors simply scale/translate/rotate the
previous offscreen buffer.  For most SVG documents the time to render
them from scratch is far too long to update the screen smoothly during
pan/zoom operations.

   Ideally in the background we would be updating as best we could
and refreshing the offscreen image as we are able, but doing that
is really quite complex, and you can quickly end up just thrashing
the processor.

> I've done a bit of searching around, and the consensus seems to be 
> to set the overflow property of the SVG root element to visible, but
> that doesn't seem to have changed anything.

    The overflow is needed if you are panning to areas that used to
be outside of the viewBox.  In this case you are still within the 
viewBox, but we just don't have a rendered version of the areas.