<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: svg code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 08 Aug 2008 15:34:56 GMT</pubDate>
    <description>DZone Snippets: svg code</description>
    <item>
      <title>Drawing with RMagick</title>
      <link>http://snippets.dzone.com/posts/show/5840</link>
      <description>This Ruby code creates a &lt;a href="http://twitxr.com/image/81824/"&gt;shape.gif&lt;/a&gt; [twitxr.com] file which shows an oval line with dimensions on a graph paper background.&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="http://rmagick.rubyforge.org/portfolio3.html"&gt;RMagick Portfolio - Drawings&lt;/a&gt; [rubyforge.org]&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'RMagick'&lt;br /&gt;&lt;br /&gt;canvas = Magick::Image.new(240, 300,&lt;br /&gt;              Magick::HatchFill.new('white','lightcyan2'))&lt;br /&gt;gc = Magick::Draw.new&lt;br /&gt;&lt;br /&gt;# Draw ellipse&lt;br /&gt;gc.stroke('red')&lt;br /&gt;gc.stroke_width(3)&lt;br /&gt;gc.fill_opacity(0)&lt;br /&gt;gc.ellipse(120, 150, 80, 120, 0, 270)&lt;br /&gt;&lt;br /&gt;# Draw endpoints&lt;br /&gt;gc.stroke('gray50')&lt;br /&gt;gc.stroke_width(1)&lt;br /&gt;gc.circle(120, 150, 124, 150)&lt;br /&gt;gc.circle(200, 150, 204, 150)&lt;br /&gt;gc.circle(120,  30, 124,  30)&lt;br /&gt;&lt;br /&gt;# Draw lines&lt;br /&gt;gc.line(120, 150, 200, 150)&lt;br /&gt;gc.line(120, 150, 120,  30)&lt;br /&gt;&lt;br /&gt;# Annotate&lt;br /&gt;gc.stroke('transparent')&lt;br /&gt;gc.fill('black')&lt;br /&gt;gc.text(130, 35, "End")&lt;br /&gt;gc.text(188, 135, "Start")&lt;br /&gt;gc.text(130, 95, "'Height=120'")&lt;br /&gt;gc.text(55, 155, "'Width=80'")&lt;br /&gt;&lt;br /&gt;gc.draw(canvas)&lt;br /&gt;canvas.write('shapes.png')&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The above was executed within an IRB session on Ubuntu which had Imagemagick and librmagick-ruby apt-get installed.&lt;br /&gt;The code was found while browsing RMagick's site for examples on how to convert SVG to PNG for creating a video animation in OGG Theora format. </description>
      <pubDate>Wed, 30 Jul 2008 10:48:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5840</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Animate a shape using SVG</title>
      <link>http://snippets.dzone.com/posts/show/5838</link>
      <description>The animation of a rectangle using SVG was tested using Firefox.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;br /&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" version="1.1"&lt;br /&gt;     onclick="moveRectangle(evt, document.getElementById('r1'));"&gt; &lt;br /&gt;  &lt;title&gt;click to animate the rectangle&lt;/title&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;script type="text/ecmascript"&gt;&lt;br /&gt;    &lt;![CDATA[&lt;br /&gt;             var count = 5;&lt;br /&gt;             var rectangle = '';&lt;br /&gt;             var animation = '';&lt;br /&gt;             &lt;br /&gt;              function moveRectangle (evt, element) {&lt;br /&gt;                rectangle = element;&lt;br /&gt;                rectangle.setAttribute('fill','orange');&lt;br /&gt;                moveIt();&lt;br /&gt;                animation = setInterval("moveIt()",20 );&lt;br /&gt;              }&lt;br /&gt;              &lt;br /&gt;              function moveIt() {&lt;br /&gt;                sLeft = rectangle.getAttribute('x');&lt;br /&gt;                iLeft = parseInt(sLeft) + 5;&lt;br /&gt;                rectangle.setAttribute('x', iLeft);&lt;br /&gt;                if (iLeft &gt; 600) {&lt;br /&gt;                  clearTimeout(animation);&lt;br /&gt;                  rectangle.setAttribute('fill','blue');&lt;br /&gt;                }&lt;br /&gt;              }&lt;br /&gt;              ]]&gt;&lt;br /&gt;  &lt;/script&gt; &lt;br /&gt;  &lt;rect id="r1" x="120" y="20" width="60" height="200"  fill="blue"/&gt;&lt;br /&gt;&lt;br /&gt;&lt;/svg&gt; &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 29 Jul 2008 23:05:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5838</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Externally reference ECMAScript in an SVG file</title>
      <link>http://snippets.dzone.com/posts/show/5408</link>
      <description>source: &lt;a href="http://www.it.rit.edu/~jxs/svg/tutorials/scripting.html"&gt;Using Internal &amp; External Scripts,&lt;/a&gt; [rit.edu]&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;script type="text/ecmascript" xlink:href="scripts/changeCircle.js"/&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 20 Apr 2008 19:21:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5408</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Adding style to SVG</title>
      <link>http://snippets.dzone.com/posts/show/5392</link>
      <description>To reference a CSS file within an SVG file refer to the following example code.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml-stylesheet href="styles_austria_1.css" type="text/css"?&gt; &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here's what an SVG CSS file looks like.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;.str1 {stroke:#0093DD;stroke-width:16;color:#0093DD}&lt;br /&gt;.str2 {stroke:#0093DD;stroke-width:12}&lt;br /&gt;.str3 {stroke:#0093DD;stroke-width:10}&lt;br /&gt;.str4 {stroke:#0093DD;stroke-width:6}&lt;br /&gt;&lt;br /&gt;.str0 {stroke:#DA251D;stroke-width:55;color:#DA251D}&lt;br /&gt;.str6 {stroke:#BB90BB;stroke-width:44;color:#BB90BB}&lt;br /&gt;.str5 {stroke:#0093DD;stroke-width:4}&lt;br /&gt;.str7 {stroke:#1F1A17;stroke-width:13}&lt;br /&gt;&lt;br /&gt;.fil0 {fill:none}&lt;br /&gt;.fil2 {fill:#1F1A17}&lt;br /&gt;.fil1 {fill:#C4E5FA}&lt;br /&gt;.fil3 {fill:#FFFFFF}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Source: &lt;a href="http://www.carto.net/papers/svg/samples/styles.shtml"&gt;Example for using CSS-Styles&lt;/a&gt; [carto.net]&lt;br /&gt;Reference: &lt;a href="http://www.w3.org/TR/SVG/styling.html#StylingWithCSS"&gt;Styling - SVG 1.1 - 20030114&lt;/a&gt; [w3.org]</description>
      <pubDate>Fri, 18 Apr 2008 21:37:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5392</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Converting text to SVG</title>
      <link>http://snippets.dzone.com/posts/show/5388</link>
      <description>First of all the Ruby code reads the text, splits it into an array and then saves it in XML format.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;a = "Open source is a development method for software that harnesses the power of distributed peer &lt;br /&gt;review and transparency of process. The promise of open source is better quality, higher reliability, &lt;br /&gt;more flexibility, lower cost, and an end to predatory vendor lock-in.".split(' ') &lt;br /&gt;&lt;br /&gt;doc = Document.new&lt;br /&gt;doc.add_element('text')&lt;br /&gt;oline = Element.new('line')&lt;br /&gt;&lt;br /&gt;char_count = 0&lt;br /&gt;a.each do |word|&lt;br /&gt;  &lt;br /&gt;  oword = Element.new('word')&lt;br /&gt;  oword.text = word.to_s&lt;br /&gt;  oword.add_attribute('length',char_count)&lt;br /&gt;  oline &lt;&lt; oword &lt;br /&gt;  char_count += word.length&lt;br /&gt;  &lt;br /&gt;  if char_count &gt; 50&lt;br /&gt;    doc.root &lt;&lt; oline&lt;br /&gt;    oline = Element.new('line')&lt;br /&gt;    char_count = 0&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;doc.root &lt;&lt; oline&lt;br /&gt;puts char_count&lt;br /&gt;puts doc&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here's a sample of the XML created&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;text&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;Open&lt;/word&gt;&lt;word length='4'&gt;source&lt;/word&gt;&lt;word length='10'&gt;is&lt;/word&gt;&lt;br /&gt;    &lt;word length='12'&gt;a&lt;/word&gt;&lt;word length='13'&gt;development&lt;/word&gt;&lt;word length='24'&gt;method&lt;/word&gt;&lt;br /&gt;    &lt;word length='30'&gt;for&lt;/word&gt;&lt;word length='33'&gt;software&lt;/word&gt;&lt;word length='41'&gt;that&lt;/word&gt;&lt;br /&gt;    &lt;word length='45'&gt;harnesses&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;the&lt;/word&gt;&lt;word length='3'&gt;power&lt;/word&gt;&lt;br /&gt;    &lt;word length='8'&gt;of&lt;/word&gt;&lt;word length='10'&gt;distributed&lt;/word&gt;&lt;word length='21'&gt;peer&lt;/word&gt;&lt;br /&gt;    &lt;word length='25'&gt;review&lt;/word&gt;&lt;word length='31'&gt;and&lt;/word&gt;&lt;word length='34'&gt;transparency&lt;/word&gt;&lt;br /&gt;    &lt;word length='46'&gt;of&lt;/word&gt;&lt;word length='48'&gt;process.&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;The&lt;/word&gt;&lt;br /&gt;    &lt;word length='3'&gt;promise&lt;/word&gt;&lt;word length='10'&gt;of&lt;/word&gt;&lt;word length='12'&gt;open&lt;/word&gt;&lt;br /&gt;    &lt;word length='16'&gt;source&lt;/word&gt;&lt;word length='22'&gt;is&lt;/word&gt;&lt;word length='24'&gt;better&lt;/word&gt;&lt;br /&gt;    &lt;word length='30'&gt;quality,&lt;/word&gt;&lt;word length='38'&gt;higher&lt;/word&gt;&lt;word length='44'&gt;reliability,&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;more&lt;/word&gt;&lt;word length='4'&gt;flexibility,&lt;/word&gt;&lt;word length='16'&gt;lower&lt;/word&gt;&lt;br /&gt;    &lt;word length='21'&gt;cost,&lt;/word&gt;&lt;word length='26'&gt;and&lt;/word&gt;&lt;word length='29'&gt;an&lt;/word&gt;&lt;br /&gt;    &lt;word length='31'&gt;end&lt;/word&gt;&lt;word length='34'&gt;to&lt;/word&gt;&lt;word length='36'&gt;predatory&lt;/word&gt;&lt;br /&gt;    &lt;word length='45'&gt;vendor&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;  &lt;line&gt;&lt;br /&gt;    &lt;word length='0'&gt;lock-in.&lt;/word&gt;&lt;br /&gt;  &lt;/line&gt;&lt;br /&gt;&lt;/text&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The XML is then transformed to SVG using the following XSL file&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:output encoding="UTF-8"&lt;br /&gt;            method="xml"&lt;br /&gt;            indent="yes"/&gt;&lt;br /&gt;            &lt;br /&gt;  &lt;xsl:template match="text"&gt;&lt;br /&gt;    &lt;svg xmlns="http://www.w3.org/2000/svg" width="100%"&lt;br /&gt;                  xmlns:xlink="http://www.w3.org/1999/xlink" &gt;&lt;br /&gt;      &lt;g id="sketch" class="sketch"&gt;&lt;br /&gt;        &lt;xsl:apply-templates select="line"/&gt;&lt;br /&gt;      &lt;/g&gt;&lt;br /&gt;    &lt;/svg&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;xsl:template match="line"&gt;&lt;br /&gt;    &lt;xsl:variable name="xfactor"&gt;12&lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="yfactor"&gt;20&lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:variable name="pos" select="position()"&gt;&lt;/xsl:variable&gt;&lt;br /&gt;    &lt;xsl:apply-templates select="word"&gt;&lt;br /&gt;      &lt;xsl:with-param name="xfactor" select="$xfactor"&gt;&lt;/xsl:with-param&gt;&lt;br /&gt;      &lt;xsl:with-param name="y" select="$pos * $yfactor + 10"&gt;&lt;/xsl:with-param&gt;&lt;br /&gt;    &lt;/xsl:apply-templates&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;br /&gt;  &lt;xsl:template match="word"&gt;&lt;br /&gt;    &lt;xsl:param name="xfactor"/&gt;&lt;br /&gt;    &lt;xsl:param name="y"/&gt;&lt;br /&gt;    &lt;text xmlns="http://www.w3.org/2000/svg" font-size="12pt" x="{@length * $xfactor +10}" y="{$y}" id="t1"&gt;&lt;xsl:value-of select="."/&gt;&lt;/text&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The final &lt;a href="http://www.twitxr.com/image/31865/"&gt;SVG output&lt;/a&gt; [twitxr.com] shows 5 lines of text with each word as a separate SVG text element.</description>
      <pubDate>Fri, 18 Apr 2008 18:14:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5388</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Using XSLT to generate SVG</title>
      <link>http://snippets.dzone.com/posts/show/5375</link>
      <description>This XSL file is intended to be used as an SVG XSL template file which displays SVG content using Gorg (XSLT back-end processor).&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;&lt;br /&gt;&lt;br /&gt;&lt;xsl:output encoding="UTF-8"&lt;br /&gt;            method="xml"&lt;br /&gt;            indent="yes"/&gt;&lt;br /&gt;            &lt;br /&gt;  &lt;xsl:template match="mainpage"&gt;&lt;br /&gt;  &lt;svg xmlns="http://www.w3.org/2000/svg" width="100%"&lt;br /&gt;                xmlns:xlink="http://www.w3.org/1999/xlink" &gt;&lt;br /&gt;&lt;br /&gt;    &lt;g&gt;&lt;br /&gt;    &lt;text font-size="12pt" x="50" y="50" id="t2" stroke="olive"&gt;&lt;xsl:value-of select="title"/&gt;&lt;/text&gt;&lt;br /&gt;    &lt;/g&gt;&lt;br /&gt;&lt;br /&gt;  &lt;/svg&gt;&lt;br /&gt;  &lt;/xsl:template&gt;&lt;br /&gt;&lt;/xsl:stylesheet&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Reference: 'using XSLT to generate SVG' http://snurl.com/24pwo [carto.net] </description>
      <pubDate>Thu, 17 Apr 2008 10:45:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5375</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Zoom into SVG</title>
      <link>http://snippets.dzone.com/posts/show/5336</link>
      <description>This code is a complete SVG document which can be copied and pasted into a file saved as an SVG document (eg. makeZoom.svg) and run locally within your SVG compliant web browser. When the user clicks on the yellow rectangle the shape will increase in size giving the appearance that the document has just been zoomed in.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;svg	xmlns="http://www.w3.org/2000/svg" width="100%"&lt;br /&gt;		xmlns:xlink="http://www.w3.org/1999/xlink" id="cont" viewBox="0 0 300 100"&gt;&lt;br /&gt;  &lt;g&gt;	&lt;br /&gt;    &lt;g id="sketch" class="sketch"&gt;&lt;br /&gt;      &lt;rect x="130"&lt;br /&gt;  y="6" width="20px" height="10px" fill="yellow" onclick="zoomIn()" /&gt;&lt;br /&gt;    &lt;/g&gt;&lt;br /&gt;  &lt;/g&gt;&lt;br /&gt;&lt;br /&gt;  &lt;script&gt;&lt;br /&gt;  &lt;![CDATA[&lt;br /&gt;  function zoomIn(){&lt;br /&gt;&lt;br /&gt;    document.getElementById('sketch').parentNode.setAttribute('transform','translate(-70  ,-6)')&lt;br /&gt;    document.getElementById('sketch').setAttribute('transform','scale(1.5)')&lt;br /&gt;  }&lt;br /&gt;  ]]&gt;&lt;br /&gt;  &lt;/script&gt;&lt;br /&gt;&lt;/svg&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;I started off experimenting with viewBox however for simplicity, transform seems better suited for zoom, and panning.&lt;br /&gt;&lt;br /&gt;Reference:&lt;br /&gt;&lt;a href="http://www.w3.org/TR/SVG11/coords.html"&gt;Coordinate Systems, Transformations and Units - SVG 1.1 - 20030114&lt;/a&gt; [w3.org]&lt;br /&gt;&lt;a href="http://www.carto.net/papers/svg/samples/viewbox.shtml"&gt;Example for viewbox control&lt;/a&gt; [carto.net]</description>
      <pubDate>Tue, 08 Apr 2008 15:31:05 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5336</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Undo the last shape stored in the whiteboard message buffer</title>
      <link>http://snippets.dzone.com/posts/show/5335</link>
      <description>This ECMAScript implements an undo feature for the SVG whiteboard. When the user presses CTRL+Z the last shape in the message_buffer variable is removed.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  function undoLast() {&lt;br /&gt;    ipos = getLastMethodPos(message_buffer,-1)&lt;br /&gt;    if (ipos &gt; 0)&lt;br /&gt;      message_buffer = message_buffer.substring(0, ipos)&lt;br /&gt;    else&lt;br /&gt;      message_buffer = ''    &lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  function getLastMethodPos(message, pos) {&lt;br /&gt;    i = message.indexOf('&lt;method', pos+1)&lt;br /&gt;    if (i &gt;= 0) &lt;br /&gt;      result = getLastMethodPos(message, i)&lt;br /&gt;    else&lt;br /&gt;      result = pos &lt;br /&gt;    return result;&lt;br /&gt;  }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here's an example of the messages (containing shapes) stored in the message_buffer&lt;br /&gt;&lt;code&gt;&lt;br /&gt;"&lt;method name='create'&gt;&lt;params&gt;&lt;param var='type'&gt;shape&lt;/param&gt;&lt;param var='body'&gt;&lt;br /&gt;polyline%20x%3D%27524%27%20y%3D%27198%27%20fill%3D%27none%27%20stroke%3D%27red%27%20id%3D&lt;br /&gt;%27348553%27%20stroke-width%3D%272%27%20points%3D%27524%2C198%20523%2C198%20522%2C198%20521%2C198%20&lt;br /&gt;513%2C198%20511%2C198%20503%2C198%20495%2C200%20493%2C200%20485%2C204%20483%2C205%20475%2C207%20474%&lt;br /&gt;2C208%20470%2C212%20466%2C216%20465%2C217%20464%2C219%20463%2C220%20463%2C222%20463%2C223%20463%2C22&lt;br /&gt;5%20463%2C226%20463%2C228%20464%2C230%20465%2C231%20466%2C233%20467%2C234%20471%2C238%20472%2C238%20&lt;br /&gt;478%2C242%20484%2C246%20485%2C247%20488%2C247%20489%2C248%20491%2C248%20493%2C249%20496%2C249%20497%&lt;br /&gt;2C249%20505%2C249%20515%2C249%20521%2C247%20531%2C245%20533%2C245%20539%2C243%20547%2C243%20548%2C24&lt;br /&gt;3%20550%2C242%20555%2C237%20556%2C237%20557%2C235%20558%2C234%20558%2C233%20559%2C231%20559%2C230%20&lt;br /&gt;560%2C228%20560%2C226%20560%2C222%20559%2C221%20559%2C220%20559%2C219%20559%2C217%20559%2C216%20558%&lt;br /&gt;2C215%20558%2C214%20556%2C208%20555%2C206%20555%2C205%20553%2C199%20549%2C191%20547%2C185%20546%2C18&lt;br /&gt;4%20544%2C176%20540%2C170%20539%2C168%20535%2C162%20534%2C161%20528%2C155%20528%2C154%20524%2C148%20&lt;br /&gt;518%2C144%20517%2C143%20511%2C139%20509%2C138%20501%2C134%20499%2C133%20491%2C129%20489%2C129%20479%&lt;br /&gt;2C129%20469%2C129%20467%2C129%20459%2C129%20457%2C129%20454%2C129%20452%2C129%20446%2C131%20438%2C13&lt;br /&gt;1%20437%2C132%20435%2C132%20435%2C133%20434%2C133%20434%2C134%20433%2C134%20433%2C135%27%23%3A&lt;br /&gt;&lt;/param&gt;&lt;param var='sender'&gt;34855&lt;/param&gt;&lt;/params&gt;&lt;/method&gt;&lt;method name='create'&gt;&lt;params&gt;&lt;param &lt;br /&gt;var='type'&gt;shape&lt;/param&gt;&lt;param var='body'&gt;polyline%20x%3D%27457%27%20y%3D%27175%27%20fill%3D%27none&lt;br /&gt;%27%20stroke%3D%27red%27%20id%3D&lt;br /&gt;%27348554%27%20stroke-width%3D%272%27%20points%3D%27457%2C175%20456%2C175%20455%2C176%20454%2C176%20&lt;br /&gt;453%2C177%20452%2C177%20451%2C177%20449%2C178%20448%2C179%20442%2C181%20440%2C183%20438%2C184%20438%&lt;br /&gt;2C185%20437%2C186%20436%2C187%20435%2C189%20435%2C191%20434%2C193%20434%2C194%20433%2C195%20433%2C19&lt;br /&gt;6%20431%2C200%20431%2C201%20431%2C203%20431%2C205%20431%2C206%20431%2C207%20431%2C208%20431%2C209%20&lt;br /&gt;431%2C210%20431%2C211%20431%2C212%20431%2C213%20431%2C214%20431%2C215%20431%2C216%20431%2C217%20432%&lt;br /&gt;2C223%20432%2C224%20432%2C225%20432%2C226%20433%2C226%20433%2C227%20433%2C228%20433%2C229%20434%2C22&lt;br /&gt;9%20434%2C230%20435%2C231%20435%2C233%20435%2C234%20436%2C235%20437%2C236%20437%2C237%20438%2C237%20&lt;br /&gt;438%2C238%20438%2C239%20438%2C240%20439%2C240%20439%2C241%20443%2C245%20444%2C246%20444%2C247%20445%&lt;br /&gt;2C247%20446%2C248%20447%2C248%20448%2C248%20448%2C249%20449%2C249%20450%2C250%20451%2C251%20452%2C25&lt;br /&gt;2%20454%2C253%20455%2C253%20461%2C255%20462%2C255%20464%2C256%20466%2C256%20467%2C257%20469%2C257%20&lt;br /&gt;469%2C258%20471%2C259%20472%2C259%20474%2C260%20475%2C260%20477%2C261%20478%2C261%20480%2C262%20481%&lt;br /&gt;2C262%20481%2C263%20482%2C263%20483%2C263%20484%2C263%20485%2C263%20486%2C263%20489%2C263%20491%2C26&lt;br /&gt;3%20492%2C263%20495%2C263%20496%2C263%20502%2C261%20504%2C261%20507%2C261%20509%2C261%20510%2C261%20&lt;br /&gt;511%2C261%20512%2C261%20513%2C261%20515%2C261%20517%2C261%20518%2C261%20520%2C260%20523%2C260%20524%&lt;br /&gt;2C260%20526%2C259%20528%2C259%20529%2C259%20534%2C258%20535%2C258%20536%2C257%20537%2C257%20538%2C25&lt;br /&gt;7%20540%2C257%27%23%3A&lt;/param&gt;&lt;param var='sender'&gt;34855&lt;/param&gt;&lt;/params&gt;&lt;/method&gt;"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In the above example there are 2 methods calls ready to be sent to the server, the 2nd method would be removed after the undoLast() function had executed.&lt;br /&gt;&lt;br /&gt;The methods are ready to be passed to the function getLatestMessages which passes the request through the ProjectX API, which then returns the results. &lt;br /&gt;&lt;br /&gt;This code only removes the shape before it's sent to the server, I still need to write the code to delete a shape which is in the server whiteboardqueue, and remove the shape element from the web browser display (SVG DOM).</description>
      <pubDate>Mon, 07 Apr 2008 23:42:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5335</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Retrieve the color from an SVG shape</title>
      <link>http://snippets.dzone.com/posts/show/5291</link>
      <description>&lt;code&gt;&lt;br /&gt;    &lt;rect id="c1" x="510"&lt;br /&gt;y="120" width="20px" height="20px" fill="pink" stroke="blue" onclick="setPenColour(evt)"/&gt;&lt;br /&gt;  &lt;![CDATA[&lt;br /&gt;  function setPenColour(evt) {&lt;br /&gt;    m_pen_colour = evt.target.getAttribute('fill');&lt;br /&gt;  }&lt;br /&gt;  ]]&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Reference: &lt;br /&gt;&lt;a href="http://www.kevlindev.com/tutorials/basics/index.htm"&gt;Tutorials - SVG&lt;/a&gt; [kevlindev.com]&lt;br /&gt;&lt;a href="http://www.kevlindev.com/tutorials/basics/events/mouse/svg_js/index.htm"&gt;Tutorials - SVG - Events&lt;/a&gt; [kevlindev.com]</description>
      <pubDate>Sun, 30 Mar 2008 14:37:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5291</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Drawing a single Polyline using SVG</title>
      <link>http://snippets.dzone.com/posts/show/5270</link>
      <description>This code is very similar to &lt;a href="http://snippets.dzone.com/posts/show/5269"&gt;Draw a series of lines using SVG&lt;/a&gt; [dzone.com] but now we can draw a series of points at the same time the mouse button is pressed and is moving. Here's an &lt;a href="http://twitxr.com/image/18451/"&gt;example of the SVG squiggle output&lt;/a&gt; [twitxr.com].&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;svg	xmlns="http://www.w3.org/2000/svg" width="100%"&lt;br /&gt;		xmlns:xlink="http://www.w3.org/1999/xlink" &gt;&lt;br /&gt;  &lt;g id="sketch" class="sketch"&gt;&lt;br /&gt;&lt;br /&gt;    &lt;rect x="0"&lt;br /&gt;y="0" width="100%" height="100%" fill="yellow" /&gt;&lt;br /&gt;  &lt;/g&gt;&lt;br /&gt;&lt;br /&gt;  &lt;script&gt;&lt;br /&gt;  &lt;![CDATA[&lt;br /&gt;  var	xmlns="http://www.w3.org/2000/svg"&lt;br /&gt;  Root=document.documentElement&lt;br /&gt;  on_start(Root)&lt;br /&gt;&lt;br /&gt;  function mouseUp(evt) {&lt;br /&gt;	  on_pen_up(Root);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  function on_start(R){&lt;br /&gt;	  var Attr={&lt;br /&gt;	    "onmousemove":"mouseMove",&lt;br /&gt;      "onmousedown":"add_line(evt)",	&lt;br /&gt;      "onmouseup":"mouseUp"&lt;br /&gt;	  }&lt;br /&gt;	  assignAttr(R,Attr)&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  function on_pen_down(R){&lt;br /&gt;	  var Attr={&lt;br /&gt;	    "onmousemove":"addPoint(evt)",&lt;br /&gt;	    "onmouseup":"on_pen_up(Root)"&lt;br /&gt;	  }&lt;br /&gt;	  assignAttr(R,Attr)&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  function on_pen_up(R){&lt;br /&gt;	  var Attr={&lt;br /&gt;	    "onmousemove":"null"&lt;br /&gt;	  }&lt;br /&gt;	  assignAttr(R,Attr)&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  function add_line(evt){&lt;br /&gt;	  //if (evt.target.nodeName!="rect") return&lt;br /&gt;	  var C=document.createElementNS(xmlns,"polyline") &lt;br /&gt;	&lt;br /&gt;	  var Attr={&lt;br /&gt;		  "x":30,&lt;br /&gt;		  "y":180,&lt;br /&gt;		  "fill":'none',&lt;br /&gt;		  "stroke": '#44a',&lt;br /&gt;		  "id":'pl1',&lt;br /&gt;		  "stroke-width":2&lt;br /&gt;	  }&lt;br /&gt;    &lt;br /&gt;	  assignAttr(C,Attr)&lt;br /&gt;	  Root.appendChild(C)&lt;br /&gt;    &lt;br /&gt;	  on_pen_down(Root)&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  function addPoint (evt) {&lt;br /&gt;    element = document.getElementById('pl1') 	&lt;br /&gt;    var point = element.ownerDocument.documentElement.createSVGPoint(); &lt;br /&gt;    point.x = evt.clientX; &lt;br /&gt;    point.y = evt.clientY;&lt;br /&gt;    &lt;br /&gt;    element.points.appendItem(point);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  function assignAttr(O,A){&lt;br /&gt;	  for (i in A) O.setAttributeNS(null,i, A[i])&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  ]]&gt;&lt;br /&gt;  &lt;/script&gt;&lt;br /&gt;&lt;br /&gt;  &lt;text font-size="12pt" x="50" y="20" id="t1"&gt;Click something to move it&lt;/text&gt;&lt;br /&gt;  &lt;text font-size="12pt" x="80" y="40" id="t2"&gt;Click nothing to add something&lt;/text&gt;&lt;br /&gt;&lt;/svg&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;*update 7:44pm*&lt;br /&gt;By simply making the id unique using a global variable count it was possible to draw &lt;a href="http://www.twitxr.com/image/18474/"&gt;multiple polylines&lt;/a&gt; [twitxr.com].</description>
      <pubDate>Sat, 22 Mar 2008 19:15:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5270</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
  </channel>
</rss>
