Loading ...
Sorry, an error occurred while loading the content.

RE: [svg-developers] Re: showing full svg content whithout calculating extents

Expand Messages
  • David Dailey
    No, I don’t believe there is any such tag or attribute to set the viewBox so that it will hold all drawn contents of a drawing. I could see the value,
    Message 1 of 4 , Apr 9 4:21 AM
    View Source
    • 0 Attachment
      No, I don’t believe there is any such tag or attribute to set the viewBox so that it will hold all drawn contents of a drawing. I could see the value, though, of what you’re saying: doing it declaratively instead of via script. As it is, I believe you’d have to do as Yannick says: render all content inside a <g> and, upon the load of the svg, measure the <g> with getBBox(). If you’re using D3, then you have access to JavaScript (not all viewers do), so it shouldn’t matter too much (the computational efficiency of getBBox() should work pretty efficiently as a function of the number of drawn objects in the <g>, though I suppose the complexity of the objects would affect this as well)



      Good luck

      David



      From: svg-developers@yahoogroups.com [mailto:svg-developers@yahoogroups.com] On Behalf Of Alireza
      Sent: Friday, April 06, 2012 9:31 AM
      To: svg-developers@yahoogroups.com
      Subject: [svg-developers] Re: showing full svg content whithout calculating extents





      Thanks, I wished I could find a tag or attribute for this but this is also useful.

      Anyhow thanks
      --- In svg-developers@yahoogroups.com <mailto:svg-developers%40yahoogroups.com> , yannick.bochatay@... wrote:
      >
      > Hi,
      > if all your shapes are included in a g element, you can use the getBBox method on this node to get the dimensions.
      > In your example :
      > document.getElementById('G2').getBBox()
      >
      > Yannick
      >
      > ----- Mail original -----
      > De: "Alireza" <ahmadi_rad@...>
      > À: svg-developers@yahoogroups.com <mailto:svg-developers%40yahoogroups.com>
      > Envoyé: Jeudi 5 Avril 2012 10:19:19
      > Objet: [svg-developers] showing full svg content whithout calculating extents
      >
      >
      >
      >
      >
      >
      > Hello
      >
      > I need help for finding extents of an svg drawing. Please take a look at this example:
      >
      > <svg id="SVG1" width="5cm" height="5cm" viewBox="0 -100 200 200">
      > <g id="G2">
      > <line x1="0" y1="0" x2="100" y2="100" stroke="blue"/>
      > <line x1="0" y1="0" x2="0" y2="100" stroke="blue"/>
      > <line x1="0" y1="0" x2="100" y2="0" stroke="blue"/>
      > <line x1="0" y1="0" x2="100" y2="-100" stroke="blue"/>
      > </g>
      > </svg>
      >
      > For this sample it was easy to understand that viewBox="0 -100 200 200" will fit the whole drawing. But in my real world application this will not be so easy to calculate this. And without this viewbox or with incorrect calculations, at least a part of drawing will not be shown which is not desirable.
      >
      > I want to show the whole drawing in svg without getting involved in calculating the extents. Something like zoom extents in aoutocad. could you please help?
      >
      > Thanks
      >





      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.