Graphviz focus on a node - php

I'm creating a scenario where I create a graph from an XML file (nodes+edges). The graph is being generated as an SVG inside an iframe. What I want to do is to be able to click on a node and have that node focused (different colour, scrolled into position).
What I've got is that I'm passing a URL in the attributes passed to graphviz that has the focus node in the query string so my-url.php?focus=2 will focus node id 2. Then, during attribute creation, I change the color of the focus node to bright yellow.
The problem is that I can't find a way to scroll down to this node. I have to manually search for the node by scrolling down. Is there a way I can get the coordinates of the node in focus and pass it to the window hosting the iframe? That way, I would be able to use Javascript to scroll down (or right).
Any ideas? I'm not looking for a complete solution. I can live with a strategy if it's feasible (and would work on the latest browsers. It doesn't have to be backward compatible).
Thanks.

You can retrieve the position of the nodes in the SVG by calling dot without the -T option (it produces the dot file where nodes are annotated with a "pos" attribute indicating where they are drawn. Then, when $_GET['focus'] is 42 (ie. my-url.php?focus=42 is requested), my-url.php should produce Javascript code which will scroll the iframe to the position of node 42, using something like scrollTo (http://stackoverflow.com/questions/1192228/scrolling-an-iframe-with-javascript).
To ensure that this works even if the image has been scaled (it's SVG, right), you would need to multiply the position to which you scroll by the ratio between the total width of the SVG and the width of the dot drawing as set by the "size" graph attribute (same thing for height).

Related

Create dynamic image in PHP

So, here's what I'm attempting to do:
I have an image of a target, and I'd like to dynamically place the location of each arrow on the target. I'd also like to have the shot location be referenceable with a dynamically generated tooltip (JQuery?) so that when the user hovers over the shot location, they can see what the score for that shot is.
So, in the image shown here, the "target" is a standard image and the numbers (in white) are added based upon data in my database and indicate the shot sequence and approximate location of that shot. I'm storing the location in two parts: score and clock position. So, for the second shot, the score is "5" and the clock position is 14:30 (approximately!) For the third shot, the score is "2" and the clock position is 16:15.
What's my best approach? I think I can use the PHP GD libraries to get the shot sequence number added to the base image, but I'm not sure how to get the hover/tooltip to work in conjunction with this.
Update: Mission accomplished: here's the semi-finished product:
If you want JavaScript to be able to interact with it, you might be better just having a <div> with the target as a background-image, then placing more <div>s with position:absolute in the right places, applying the tooltips to these. Much simpler than generating the image in PHP and then implementing tooltips over certain areas.

Get dimension of HTML tag

I'm using PHPQuery parse HTML file and I need the height and width of a given tag, in jQuery it's possible to use something like
height=$("div.content").height();
width=$("div.content").width();
but in PHPQuery there is no such thing as height(), width() functions so is there any way to get the dimensions?
PHPQuery just lets you traverse the document in a manner similar to jQuery. It does not actually render the document and so it has no idea what size each element will actually be when rendered by a browser.
In order to compute the width and height of an element, it would need to parse your stylesheet, apply all of those rules, fetch any images used by that element (and its descendants) and render the element using the appropriate font(s) -- and possibly even render parent elements as well. And there's no guarantee that the resulting dimensions will match some particular client configuration, since the client-side environment may cause the element to render at a different size (DPI being the most obvious example, but even the size of the browser window could affect the size of any given element).

I want to put number on a image dynamically

I want to put number on a image dynamically.
Take two div's. Set backgroung image for one div and put some number on another div. Place the second div on first div by using css properties like position, z-index
There are 2 ways of doing that:
1.) In the client-side:
You can use the HTML5 CANVAS API. This API allows you to draw arbitrary shapes and images inside a canvas element that is rendered into the browser. So to solve your problem you could load an image inside the canvas and after that draw a number on top of it.
2.) In the server-side:
You will load the image and after that draw the number inside of it using a server-side application. Eg. an application developed using PHP, ASP.NET, Python, etc. In PHP you can use the GD library to do that.

Get actual width rather than auto using PHP

How can I determine the explicit width of a HTML element that has width auto using PHP?
JQuery has the ability to do this if width:auto; is used it can compute the actual width.
Get the current computed width for the first element in the set of
matched elements.
JQuery probably does this with the help of the browser as it is client side.
How can I achieve this using PHP? I have the HTML as a string.
Update
All CSS is inline, if the width is auto, the only thing left to determine the width of the element is its immediate parent and/or its contents.
It is not possible. PHP does not know how the HTML/CSS will be rendered (if rendered at all).
The only way this would be possible in PHP is if you have both the HTML and the complete CSS as strings AND the width of the element is defined in absolute pixels or the width of its container (or the parent's container, etc) is defined in absolute pixels. If all these conditions were true, it would still be extremely difficult to figure out. Basically you'd have to code a rendering engine in PHP.
If you were really lucky, the element you needed would have an inline style="width:px" and you could parse for that attribute.
This is possible in Javascript because the browser knows its own size. Under most circumstances, the HTML in a string doesn't have a size until rendered in a browser.

PHP Determining Font Size based off of width

I have static width of an element, and an unknown string length which is inserted by the user. I'm trying to keep javascript out otherwise this problem would be solved via using jQuery method described in other posts.
I'm generating a static page with php that won't change and I'm trying to calculate the size of the text in order to fit inside the div.
Is this possible with only having the following:
- String Length
- Width of Container
- Server side with PHP
and if so could you please lend me a hand in finding the correct solution?
Cheers
If this is about an HTML element, you will not be able to determine the width in PHP with 100% reliability. You would have to actually render the element in the client browser to find it out, and that is possible only using JavaScript.
Plus there are many factors on client side that can play into the result:
The operating system's text size level
The browser's zoom level
The availability of the font used on the client machine
You may be best off manually determining the element's width in an average web browser with normal zoom (or if it's dynamic text, maybe use what #Jared proposes)
This answer (by Pekka, see his response as well):
PHP Accurate Font Width
Suggests imagettfbbox, if you're using a truetype font.

Categories