Re: Database and SVG file
[email protected] Thu, 14 Nov 2013 14:56:40 +0100 (CET)
| Newsgroups | gmane.text.xml.svg.devel |
|---|---|
| Message-ID | <1747377841.367759636.1384437400605.JavaMail.root@zimbra59-e10.priv.proxad.net> |
Hi,
Here's a short example of a svg file. Colors change after calling a server-side script. No library needed.
<?xml version="1.0" encoding="utf-8"?>
<svg width="500" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<path id="country_1" d="M0,100 L100,0 L200,100"/>
<path id="country_2" d="M100,0 L200,100 L300,0"/>
<path id="country_3" d="M200,100 L300,0 L400,100"/>
<script>
<![CDATA[
(function() {
var req = new XMLHttpRequest();
req.open('GET', 'yourScript.php', true);
req.onreadystatechange = function (e) {
if (req.readyState != 4) return;
if (req.status != 200) { window.alert("error"); return; }
var obj = JSON.parse(req.responseText),
id,shape,value,color;
for (id in obj) {
shape = document.getElementById(id);
value = obj[id];
switch (true) {
case (value < 5) : color = "green"; break;
case (value < 10) : color = "orange"; break;
default : color = "red"; break;
}
shape.setAttribute("fill",color);
}
}
req.send(null);
}());
]]>
</script>
</svg>
All you need is to write "yourScript.php" (php or any server-side language) which queries the database and produces json format like :
{
"country_1" : 3,
"country_2" : 8,
"country_3" : 12
}
Hope it will help.
Yannick
----- Mail original -----
De: "flyfishac" <[email protected]>
À: [email protected]
Envoyé: Mercredi 13 Novembre 2013 15:27:55
Objet: [svg-developers] Database and SVG file
I'm wondering if anyone can make suggestions on learning how to manipulate an SVG file with a database or if anyone has a simple example with source files.
Reasons:
I'm a salesman whose territory consists of 3 states. Within those states are counties. As sales begin to increase per county, the Fill Color of that county is edited by me via Inkscape. It would be nice to drive those colors via database and not have to alter the SVG file every time I make a large sale.
* This can be a very powerful tool for organizations who want to better understand their territories in real time and visualize growth patterns over a period of time.
I really want to learn how to do this!
-Aubrey
------------------------------------
-----
To unsubscribe send a message to: [email protected]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my membership"
----Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/svg-developers/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/svg-developers/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo Groups is subject to:
http://info.yahoo.com/legal/us/yahoo/utos/terms/