d3js - need to find the full size of g element - svg

I am using D3JS to create a graph. I would like to retrieve the size of the graph to use elsewhere in my code in javascript. When inspecting the element in firebug and going to the layout tab, it shows the dimensions in pixels which is what I am trying to grab programatically. However, trying to do something like grab the G by typing $('g').height() returns 0. Is there a special way I am supposed to grab the element to get its full rendered height and width?

The SVG way is to call element.getBBox(). That will give you an object with width and height properties.

Related

Using Ellipsis with SVG's TSPAN?

I have a page where we are using SVG to render a sequence diagram. Some of the data represented has the potential to occasionally be very long, so I would like to limit the width of TSPAN elements and provide an ellipsis, while allowing the user to hover over the text and show the full text.
Initially I tried to use CSS in conjunction with the text-overflow property by setting the value to "ellipsis" which is the exact behavior I am looking for, but it doesn't have that functionality available (big bummer) is there any other way to limit the length of text and allow the full text to be shown on an action such as hover?
Create the tspan with the ellipsis text and then have a <title> element with the complete text e.g.
<tspan>Really really...<title>Really really long text</title></tspan>

How to implement panning like google maps in SVG

I have done zooming in SVG chart. Please refer below screenshot.
above screenshot series is zoomed state.i used clipping concept to hide the outside lines from chart area after zooming.
i need to do panning here ? how can i implement like google maps. when i start pan to move the series and see the zoomed chart of another area.
how can i perform "translate" operation for path element in SVG. element in the screenshot is called series (i.e. data points /line).
i need to move the element zoomed area based on mouse movec(i.e. like scrolling the hidden content).
Is "translate" attribute is used to view the other zoomed area ? how can i perform "translate" in path element that will make the panning.
Normal chart screenshot.
Zoomed Screenshot.
Please refer below link.
http://www.cyberz.org/projects/SVGPan/tiger.svg
Thanks,
Siva
First be sure:
Download svgpan.js file in your project location
is must be the right place in your code
You must add this: xmlns:xlink="http://www.w3.org/1999/xlink"

How to Scale SVG rectagle to fit the svg text element

So here is the problem:
I am trying to create dynamic buttons that have text. The text will be generated dynamically so the svg object doesn't know the size of the text. There are two things that I am looking to do and I hope that SVG will do this
First I want the left and right edge of the svg element to stay the same even if I scale the element horizontally
The problem is that I have to set a width on the svg otherwise it doesn't show up when I display the page. Also on the Home and blog buttons you can see that the edge is compressed. I want the edge to stay the same no matter how much text is in the element.
Also I can't seem to set the scale or width properly even with a javascript .getComputedTextLength()
Any help or a point in the right direction would be very helpful
Buttons that are sized to their text content is functionality that can be adressed with Raphael's getBBox()
The use of this js library means that you are implicitly using SVG or VML and this functionality is more easily addressed by referencing this JavaScript library
To see the getBBox() function in action you could visit the Autobox example here:
http://www.irunmywebsite.com/raphael/additionalhelp.php?v=2

Incorrect coordinates retrieved from image using ABBYY OCR SDK

I'm trying to process an image using ABBYY OCR SDK using the sample code placed in this question but I'm not able get the co-ordinates right for a specific word say "OCR" on the screenshot below.
I want to draw an overlay (yellow rectangle over the word "OCR") and sometimes the rectangle is placed very far away from the actual word.
The XML you get is synthesised according to this schema.
For each recognized character it will contain an instance of charParams element as shown in the answer you linked to. The element will contain the coordinates in page pixels - the same XML also contains a page element:
<page width="..." height="..." resolution="..." originalCoords="...">
where the image width and height are stored. So l and r for each charParams element is in range 0..width-1 of the corresponding page and t and b for each charParams element is in range 0..height-1 of the corresponding page.
Also it's worth mentioning explicitly that all coordinates are in pixels - they are completely resolution-agnostic. This is why whenever you try to highlight anything on an image you have to take zoom into account - the image will likely not be always displayed as is by your device software, but will be downscaled and so you have to map page coordinates onto your zoomed-out image coordinates and highlight appropriately.
Have you checked the DPI of the original image and also check the documentation to make sure the OCR engine is using the same DPI and not returning the image in points or some other measurement system.
It could be that rectangle you are drawing in iOS is not based on pixels but on some other measurement system also.
You just need to work through the process, testing as you go, and work out where the problem is coming from. It is most likely a uniform scaling and the distance from the actual word is proportional to the distance of the word from the top left of the page.

foreignobject in svg

How to change the height and width of textarea (or any html element) from javascript which is inside foreign object in svg.Moreover, can I drag an html elelment and drop on svg container by any mean (htm5 any hint) or atleast can I get the coordinates on svg during draging so that I can implement my own drag and drop. Thanks in advance
You appear to my eye to have at least two distinct questions. If I understand correctly, the first one is something like this: how can you write JavaScript within an SVG instance so that you can embed the SVG instance and have the JS control the embedding HTML? Do I have that right?
If so, the answer can be constructed from the parts of http://phaseit.net/examples/SVG4/c1.html and related examples. Briefly, write "window.top" to reach the HTML reference.
The same sort of reference gives access to HTML5 drag-and-drop, if that's what you're after.
Is that the level of answer you're after, or do you need an executable example?
LATER, AFTER MORE DISCUSSION: it appears that http://phaseit.net/examples/SVG5/embedding.svg is more like what you're after. Do I have that right, Arslan Ahson? What you should see when you display the SVG instance there is an SVG-coded elliptical button which, when pushed, toggles the appearance (background color and width) of a nearby embedded HTML textarea.

Resources