<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import csv
print """&lt;?xml version="1.0" standalone="no"?&gt;
&lt;!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"&gt;
&lt;svg width="740" height="641"
xmlns="http://www.w3.org/2000/svg" onload='Init(evt)'&gt;
&lt;title&gt;votegeek.org.uk&lt;/title&gt;
&lt;desc&gt;&lt;/desc&gt;
"""

#magic tooltip code from http://svg-whiz.com/svg/Tooltip2.svg
print """   &lt;script type="text/ecmascript"&gt;&lt;![CDATA[
      var SVGDocument = null;
      var SVGRoot = null;
      var SVGViewBox = null;
      var svgns = 'http://www.w3.org/2000/svg';
      var xlinkns = 'http://www.w3.org/1999/xlink';
      var toolTip = null;
      var TrueCoords = null;
      var tipBox = null;
      var tipText = null;
      var tipTitle = null;
      var tipDesc = null;

      var lastElement = null;
      var titleText = '';
      var titleDesc = '';


      function Init(evt)
      {
         SVGDocument = evt.target.ownerDocument;
         SVGRoot = SVGDocument.documentElement;
         TrueCoords = SVGRoot.createSVGPoint();

         toolTip = SVGDocument.getElementById('ToolTip');
         tipBox = SVGDocument.getElementById('tipbox');
         tipText = SVGDocument.getElementById('tipText');
         tipTitle = SVGDocument.getElementById('tipTitle');
         tipDesc = SVGDocument.getElementById('tipDesc');
         //window.status = (TrueCoords);

         //create event for object
         SVGRoot.addEventListener('mousemove', ShowTooltip, false);
         SVGRoot.addEventListener('mouseout', HideTooltip, false);
      };


      function GetTrueCoords(evt)
      {
         // find the current zoom level and pan setting, and adjust the reported
         //    mouse position accordingly
         var newScale = SVGRoot.currentScale;
         var translation = SVGRoot.currentTranslate;
         TrueCoords.x = (evt.clientX - translation.x)/newScale;
         TrueCoords.y = (evt.clientY - translation.y)/newScale;
      };


      function HideTooltip( evt )
      {
         toolTip.setAttributeNS(null, 'visibility', 'hidden');
      };


      function ShowTooltip( evt )
      {
         GetTrueCoords( evt );

         var tipScale = 1/SVGRoot.currentScale;
         var textWidth = 0;
         var tspanWidth = 0;
         var boxHeight = 20;

         tipBox.setAttributeNS(null, 'transform', 'scale(' + tipScale + ',' + tipScale + ')' );
         tipText.setAttributeNS(null, 'transform', 'scale(' + tipScale + ',' + tipScale + ')' );

         var titleValue = '';
         var descValue = '';
         var targetElement = evt.target;
         if ( lastElement != targetElement )
         {
            var targetTitle = targetElement.getElementsByTagName('title').item(0);
            if ( targetTitle )
            {
               // if there is a 'title' element, use its contents for the tooltip title
               titleValue = targetTitle.firstChild.nodeValue;
            }

            var targetDesc = targetElement.getElementsByTagName('desc').item(0);
            if ( targetDesc )
            {
               // if there is a 'desc' element, use its contents for the tooltip desc
               descValue = targetDesc.firstChild.nodeValue;

               if ( '' == titleValue )
               {
                  // if there is no 'title' element, use the contents of the 'desc' element for the tooltip title instead
                  titleValue = descValue;
                  descValue = '';
               }
            }

            // if there is still no 'title' element, use the contents of the 'id' attribute for the tooltip title
            if ( '' == titleValue )
            {
               titleValue = targetElement.getAttributeNS(null, 'id');
            }

            // selectively assign the tooltip title and desc the proper values,
            //   and hide those which don't have text values
            //
            var titleDisplay = 'none';
            if ( '' != titleValue )
            {
               tipTitle.firstChild.nodeValue = titleValue;
               titleDisplay = 'inline';
            }
            tipTitle.setAttributeNS(null, 'display', titleDisplay );


            var descDisplay = 'none';
            if ( '' != descValue )
            {
               tipDesc.firstChild.nodeValue = descValue;
               descDisplay = 'inline';
            }
            tipDesc.setAttributeNS(null, 'display', descDisplay );
         }

         // if there are tooltip contents to be displayed, adjust the size and position of the box
         if ( '' != titleValue )
         {
            var xPos = TrueCoords.x + (10 * tipScale);
            var yPos = TrueCoords.y + (10 * tipScale);

            //return rectangle around text as SVGRect object
            var outline = tipText.getBBox();
            tipBox.setAttributeNS(null, 'width', Number(outline.width) + 10);
            tipBox.setAttributeNS(null, 'height', Number(outline.height) + 10);

            // update position
            toolTip.setAttributeNS(null, 'transform', 'translate(' + xPos + ',' + yPos + ')');
            toolTip.setAttributeNS(null, 'visibility', 'visible');
         }
      };

   ]]&gt;&lt;/script&gt;
"""
r=csv.reader(open('uns.csv'))
rad="4"#radius of dots
print '&lt;polygon points="0,0 '+str(float(rad)*90*2)+',0 '+str(float(rad)*90)+','+str(float(rad)*90*.866*2)+'" fill="black"  /&gt;'
for row in r:
    con=float(row[0])
    lab=float(row[1])

    ld=float(row[2])
    outcome=row[7]
    cx=(lab*float(rad)*2)+con*float(rad)
    cy=con*float(rad)*2*.866
    #cx=0.5+(lab/5.0)#experimental right angle triangle layout - didn't like it, distorts the shape.
    #cy=0.5+(con/5.0)
  
    if (con==0 or lab==0 or ld==0):
        False
    elif (con&lt;10 or lab&lt;10 or ld&lt;10 or con&gt;50 or lab&gt;50 or ld&gt;50):
        False
    else:
        print '&lt;circle cx="'+str(cx)+'" cy="'+str(cy)+'" r="'+rad+'" '

        if (con==30 and lab==30):
            print 'fill="white"&gt;'
        elif (con==43 and lab==36):
            print 'fill="green" title="1979 outcome"&gt;'
        elif (con==42 and lab==27):
            print 'fill="green" title="1983 outcome"&gt;'
        elif (con==42 and lab==31):
            print 'fill="green" title="1987 outcome"&gt;'
        elif (con==42 and lab==34):
            print 'fill="green" title="1992 outcome"&gt;'
        elif (con==30 and lab==43):
            print 'fill="green" title="1997 outcome"&gt;'
        elif (con==32 and lab==40):
            print 'fill="green" title="2001 outcome"&gt;'
        elif (con==32 and lab==35):
            print 'fill="green" title="2005 outcome"&gt;'


        
        elif outcome.find('Conservative Majority')==0:
            print 'fill="blue"&gt;'
        elif outcome.find('Labour Majority')==0:
            print 'fill="red"&gt;'
        elif outcome.find('Lib Dem Majority')==0:
            print 'fill="yellow"&gt;'
        elif outcome.find('Lib Dems')&gt;0:
            print 'fill="#AAAA00"&gt;'
        elif outcome.find('Labour')&gt;0:
            print 'fill="#AA0000"&gt;'
        elif outcome.find('Conservatives')&gt;0:
            print 'fill="#0000AA"&gt;'

        else:
            print 'fill="grey"&gt;'
        print '&lt;title&gt;Con:'+str(int(con))+' Lab:'+str(int(lab))+' LD:'+str(int(ld))+'&lt;/title&gt;&lt;desc&gt;'+outcome+'&lt;/desc&gt;&lt;/circle&gt;'
#now the lines to divide up the regions of interest
print '&lt;line x1="'+str(float(rad)*90)+'" y1="'+str(float(rad)*90*.866*2/3)+'" x2= "'+str(float(rad)*90)+'" y2="0" style="stroke: white;"/&gt;'    
print '&lt;line x1="'+str(float(rad)*90)+'" y1="'+str(float(rad)*90*.866*2/3)+'" x2= "'+str(float(rad)*90*0.5)+'" y2="'+str(float(rad)*90*.866)+'" style="stroke: white;"/&gt;'    
print '&lt;line x1="'+str(float(rad)*90)+'" y1="'+str(float(rad)*90*.866*2/3)+'" x2= "'+str(float(rad)*90*1.5)+'" y2="'+str(float(rad)*90*.866)+'" style="stroke: white;"/&gt;'    

print '&lt;line x1="'+str(float(rad)*90)+'" y1="'+str(float(rad)*90*.866*2/3)+'" x2= "0" y2="0" style="stroke: green;"/&gt;'    
print '&lt;line x1="'+str(float(rad)*90)+'" y1="'+str(float(rad)*90*.866*2/3)+'" x2= "'+str(float(rad)*90*2)+'" y2="0" style="stroke: green;"/&gt;'    
print '&lt;line x1="'+str(float(rad)*90)+'" y1="'+str(float(rad)*90*.866*2/3)+'" x2= "'+str(float(rad)*90)+'" y2="'+str(float(rad)*90*.866*2)+'" style="stroke: green;"/&gt;'    


print """    &lt;g id='ToolTip' opacity='0.8' visibility='hidden' pointer-events='none'&gt;
      &lt;rect id='tipbox' x='0' y='5' width='88' height='20' rx='2' ry='2' fill='white' stroke='black'/&gt;
      &lt;text id='tipText' x='5' y='20' font-family='Arial' font-size='12'&gt;
         &lt;tspan id='tipTitle' x='5' font-weight='bold'&gt;&lt;![CDATA[]]&gt;&lt;/tspan&gt;
         &lt;tspan id='tipDesc' x='5' dy='15' fill='blue'&gt;&lt;![CDATA[]]&gt;&lt;/tspan&gt;
      &lt;/text&gt;
   &lt;/g&gt;

"""


print"&lt;/svg&gt;"

</pre></body></html>