java/nekurak.net-web/web/WEB-INF/tags/nekurak/hlasovani.tag
author František Kučera <franta-hg@frantovo.cz>
Tue Apr 27 13:14:23 2010 +0200 (2010-04-27)
changeset 106 6209f3d550c5
parent 58 e019dbc42723
child 107 e8371105fcc8
permissions -rw-r--r--
Hlasování: základ SVG grafu, výpočet. TODO: validita SVG vloženého do XHTML.
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
     3 	  xmlns:c="http://java.sun.com/jsp/jstl/core"
     4 	  xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
     5 	  xmlns:fn="http://java.sun.com/jsp/jstl/functions"
     6 	  version="2.0">
     7 
     8     <jsp:directive.attribute name="podnik" type="java.lang.Integer" required="true" description="ID podniku"/>
     9     <jsp:directive.attribute name="hlasuAno" type="java.lang.Integer" required="true" description="počet hlasů pro ano – aby se tu kouřilo"/>
    10     <jsp:directive.attribute name="hlasuNe" type="java.lang.Integer" required="true" description="počet hlasů pro ne – aby se tu nekouřilo"/>
    11     <jsp:directive.attribute name="svgUvnitrXhtml" type="java.lang.Boolean" required="false" description="true = SVG vložené přímo do XHTML (XML) | false = SVG jako externí obrázek – &lt;img src='…'/&gt;"/>
    12 
    13     <c:if test="${svgUvnitrXhtml == null}">
    14 	<c:set var="svgUvnitrXhtml" value="${true}"/>
    15     </c:if>
    16 
    17     <c:choose>
    18 	<c:when test="${svgUvnitrXhtml}">
    19 	    <svg width="200" height="200"
    20 		 xmlns="http://www.w3.org/2000/svg"
    21 		 xmlns:xlink="http://www.w3.org/1999/xlink">
    22 
    23 
    24 		<style type="text/css">
    25 		    rect.ne {
    26 			fill:  url(#ne_prechod);
    27 			stroke: black;
    28 		    }
    29 		    rect.ano {
    30 			fill: url(#ano_prechod);
    31 			stroke: black;
    32 		    }
    33 
    34 		    a:hover rect.ano, a:hover rect.ne {
    35 			fill: url(#zvyrazneny_prechod);
    36 		    }
    37 
    38 		    a:hover text {
    39 			fill: green;
    40 		    }
    41 
    42 		    line.ramecek {
    43 			stroke: black;
    44 			stroke-width: 2;
    45 		    }
    46 
    47 
    48 		    rect.pozadi {
    49 			fill: url(#pozadi_prechod);
    50 		    }
    51 
    52 		    text {
    53 			font-size: 12px;
    54 			font-family: Sans;
    55 		    }
    56 
    57 		</style>
    58 
    59 		<!-- pozadí – přechod -->
    60 		<defs>
    61 		    <linearGradient id="pozadi_prechod" x1="0%" y1="0%" x2="100%" y2="100%">
    62 			<stop offset="0%" style="stop-color:white; stop-opacity:0.5"/>
    63 			<stop offset="100%" style="stop-color:silver; stop-opacity:0.8"/>
    64 		    </linearGradient>
    65 		</defs>
    66 
    67 		<!-- nekuřácký graf – přechod -->
    68 		<defs>
    69 		    <linearGradient id="ne_prechod" x1="0%" y1="0%" x2="100%" y2="100%">
    70 			<stop offset="0%" style="stop-color:white; stop-opacity:1"/>
    71 			<stop offset="100%" style="stop-color:blue; stop-opacity:1"/>
    72 		    </linearGradient>
    73 		</defs>
    74 
    75 		<!-- zvýrazněný graf – přechod -->
    76 		<defs>
    77 		    <linearGradient id="zvyrazneny_prechod" x1="0%" y1="0%" x2="100%" y2="100%">
    78 			<stop offset="0%" style="stop-color:white; stop-opacity:1"/>
    79 			<stop offset="100%" style="stop-color:green; stop-opacity:1"/>
    80 		    </linearGradient>
    81 		</defs>
    82 
    83 		<!-- kuřácký graf – přechod -->
    84 		<defs>
    85 		    <linearGradient id="ano_prechod" x1="0%" y1="0%" x2="100%" y2="100%">
    86 			<stop offset="0%" style="stop-color:white; stop-opacity:1"/>
    87 			<stop offset="100%" style="stop-color:red; stop-opacity:1"/>
    88 		    </linearGradient>
    89 		</defs>
    90 
    91 		<!-- pozadí a linka -->
    92 		<rect x="0" y="0" width="200" height="200" class="pozadi"/>
    93 		<line x1="10" y1="180" x2="190" y2="180" class="ramecek"/>
    94 
    95 		<!-- Nadpis grafu -->
    96 		<text x="60" y="20">Mělo by se tu:</text>
    97 
    98 		<!-- nekuřáci -->
    99 		<a xlink:href="javascript:alert('To čumíš, co? :-)')" xlink:title="Hlasů: ${hlasuNe}">
   100 		    <text x="30" y="195" class="ne">nekouřit</text>
   101 		    <rect x="30" y="${180 - (150*hlasuNe/(hlasuAno+hlasuNe))}" width="50" height="${150*hlasuNe/(hlasuAno+hlasuNe)}" class="ne"/>
   102 		</a>
   103 
   104 		<!-- kuřáci -->
   105 		<a xlink:href="javascript:alert('To čumíš, co? :-)')" xlink:title="Hlasů: ${hlasuAno}">
   106 		    <text x="130" y="195" class="ano">kouřit</text>
   107 		    <rect x="120" y="${180 - (150*hlasuAno/(hlasuAno+hlasuNe))}" width="50" height="${150*hlasuAno/(hlasuAno+hlasuNe)}" class="ano"/>
   108 		</a>
   109 	    </svg>
   110 	</c:when>
   111 	<c:otherwise>
   112 	    <object data="hlasovani-svg.jsp?podnik=${podnik}&amp;amp;hlasuAno=${hlasuAno}&amp;amp;hlasuNe=${hlasuNe}" type="image/svg+xml"/>
   113 	</c:otherwise>
   114     </c:choose>
   115 
   116 </jsp:root>