XML technologies / SVG / Interactive graphics / Manipulating graphic elements / Manipulating the visible property / Creating the necessary symbols

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

For easier definition, create the boxes, buttons and tooltips as symbols and instantiate them with the <use> tag, also specifying gradients and filters. The following listing defines the symbols and stylesheets required. The table explains the symbols’ purposes.

Stylesheets format text. To define custom formats instead of general tag formatting, first name the tag where the format applies, here text, followed by a period and the format name, assigned through the tag’s class attribute. The listing defines the formats titel and info for the <text> tag, formatting the boxes’ titles and texts.

The symbols use only familiar techniques and should be straightforward. To adapt them, you need to know how each is used, as shown in the table.

Table: Purpose of each symbol.

Symbol

Use

smKasten

Creates the gray information box with rounded corners, defining its gradient and shadow.

smButton

Defines the red close button. Its code largely matches the file button.svg from the previous chapter.

smTooltipp

Defines the small gray tooltip with the text “Schließen” (“Close”).

smKastenHor

Creates the circles used as windows for horizontal navigation.

<?xml version="1.0" encoding="iso-8859-1"?>
...
<svg width="800" height="600" viewBox="0 0 800 600">
  <defs>
    <style type="text/css">
      <![CDATA[
       a {fill:rgb(255,110,110);}
         a.weiss {fill:white;}
         a.schwarz {fill:black;}
         text.titel {fill:rgb(255,110,110);font-family:Arial,Helvetica;font-size:16px;font-stretch:ultra-expanded;font-weight:bold}
         text.info {fill:black;font-family:Arial,Helvetica;font-size:11px;kerning:0.18;font-weight:normal;opacity:1}
      ]]>
    </style>
    <symbol id="smKasten">
      <defs>
        <filter id="3D" filterUnits="objectBoundingBox">
          <feGaussianBlur in="SourceAlpha" stdDeviation="8" result="Schatten"/>
          <feOffset dx="+8" dy="+8" in="Schatten" result="Schatten"/>
          <feComposite in="SourceGraphic" in2="Schatten" operator="normal"/>
        </filter>
      </defs>
      <rect x="0" y="0" width="400" height="400" rx="15" ry="15" style="fill:url(#verlaufgrauKasten);stroke:rgb(0,0,0);stroke-width:1;filter:url(#3D)"/>
    </symbol>
    <symbol id="smKastenHor">
      <defs>
        <filter id="3Dh" filterUnits="objectBoundingBox">
          <feGaussianBlur in="SourceAlpha" stdDeviation="4" result="Schatten"/>
          <feOffset dx="+4" dy="+4" in="Schatten" result="Schatten"/>
          <feComposite in="SourceGraphic" in2="Schatten" operator="normal"/>
        </filter>
      </defs>
      <circle cx="100" cy="100" r="100" style="fill:url(#runderVerlauf);stroke:rgb(0,0,0);stroke-width:1;filter:url(#3Dh);"/>
    </symbol>
    <symbol id="smTooltipp">
      <g id="tooltipp" transfer="translate(25,25)">
        <rect x="0" y="0" width="60" height="16" style="fill:url(#verlaufgrauKasten);stroke:black"/>
        <text class="info" x="5" y="12">Schließen</text>  
      </g>
    </symbol>
    <symbol id="smButton">
      <defs>
        <g id="Bttn">
          <desc>Der Button</desc>
          <circle cx="25" cy="25" r="25" style="stroke-width:1;stroke-opacity:0.8;stroke:rgb(222,0,0);fill-opacity:1;opacity:1;fill:url(#runderVerlauf)"/>
          <ellipse cx="25" cy="15" rx="20" ry="12" style="stroke-width:1;stroke:none;fill-opacity:1;opacity:1;fill:url(#linearerVerlauf)"/>
        </g>
        <filter id="SVGObjekt" filterUnits="userSpaceOnUse" width="150" heigth="150">
          <feGaussianBlur id="Schatten" in="SourceAlpha" stdDeviation="12 6" result="Schatten">
            <animate attributeName="stdDeviation" begin="2s" dur="0.5s" values="6,3"/>
          </feGaussianBlur>
          <feImage xlink:href="#Bttn" result="Button"/>
          <feMerge>
            <feMergeNode in="Schatten"/>
            <feMergeNode in="Button"/>
          </feMerge>
        </filter>
        <desc>Es folgen die Farbverläufe</desc>
        <radialGradient id="runderVerlauf" cx="50%" cy="90%" r="60%" fx="60%" fy="80%">
          <stop offset="0%" style="stop-color:rgb(255,150,150);stop-opacity:1"/>
          <stop offset="1%" style="stop-color:rgb(255,128,128);stop-opacity:1"/>
          <stop offset="50%" style="stop-color:rgb(255,0,0);stop-opacity:1"/>
        </radialGradient>
        <linearGradient id="linearerVerlauf" gradientTransform="rotate(90)">
          <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/>
          <stop offset="90%" style="stop-color:rgb(255,1,1);stop-opacity:1"/>
        </linearGradient>
      </defs>
      <g transform="translate(0,0)">
        <g transform="translate(20,20), scale(0.7)" style="filter:url(#SVGObjekt)" id="roterButton">
          <desc>Der Button</desc>
          <circle cx="25" cy="25" r="25" style="stroke-width:1;stroke-opacity:0.8;stroke:rgb(222,0,0);fill-opacity:1;opacity:1;fill:url(#runderVerlauf)"/>
          <ellipse cx="25" cy="15" rx="20" ry="12" style="stroke-width:1;stroke:none;fill-opacity:1;opacity:1;fill:url(#linearerVerlauf)"/>
        </g>
      </g>
    </symbol>
    <linearGradient id="verlaufgrauKasten" spreadMethod="reflect" gradientTransform="">
      <stop offset="0%" style="stop-color:darkgray;stop-opacity:1"/>
      <stop offset="100%" style="stop-color:white;stop-opacity:1"/>
    </linearGradient>

   

 

 

 

back to top