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"
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 – <img src='…'/>"/>
13 <c:if test="${svgUvnitrXhtml == null}">
14 <c:set var="svgUvnitrXhtml" value="${true}"/>
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">
24 <style type="text/css">
26 fill: url(#ne_prechod);
30 fill: url(#ano_prechod);
34 a:hover rect.ano, a:hover rect.ne {
35 fill: url(#zvyrazneny_prechod);
49 fill: url(#pozadi_prechod);
59 <!-- pozadí – přechod -->
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"/>
67 <!-- nekuřácký graf – přechod -->
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"/>
75 <!-- zvýrazněný graf – přechod -->
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"/>
83 <!-- kuřácký graf – přechod -->
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"/>
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"/>
96 <text x="60" y="20">Mělo by se tu:</text>
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"/>
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"/>
112 <object data="hlasovani-svg.jsp?podnik=${podnik}&amp;hlasuAno=${hlasuAno}&amp;hlasuNe=${hlasuNe}" type="image/svg+xml"/>