[SVG] Relative Positionierung von <symbol> mit <use>
Verfasst: 05.06.2010 08:57
Moin!
Mit SVGs wollte ich gerne schon einmal arbeiten. Also habe ich mir einen Widerstand gezeichnet und ein paar mal ausgegeben - klappt. Nun will ich aber gern das Zentrum des Widerstandes als Positionsreferenz haben und schrieb deshalb:
Leider wird mit #R und #W nur das rechte untere Viertel des Widerstandskörpers angezeigt. Ich habe schon mit viewBox() sowohl in <symbol> als auch in <use> herumgespielt, aber das bringt nichts. Wie geht's, den ganzen Widerstand mit Text anzuzeigen, ihn aber mit <use> an seinem Zentrum zu referenzieren?
Gruß - WPö
Mit SVGs wollte ich gerne schon einmal arbeiten. Also habe ich mir einen Widerstand gezeichnet und ein paar mal ausgegeben - klappt. Nun will ich aber gern das Zentrum des Widerstandes als Positionsreferenz haben und schrieb deshalb:
Code: Alles auswählen
<?xml version="1.0" encoding="ISO-8859-15"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ev="http://www.w3.org/2001/xml-events"
version="1.1" baseProfile="full"
width="4000px" height="2000px" viewBox="0 0 4000 2000">
<defs>
<symbol id="Widerstand" style="font-family: Arial, sans serif; font-size: 50px; font-weight: bold;">
<line x1="0" y1="125" x2="400" y2="125" stroke="red" stroke-width="11.81px" />
<rect x="100" y="75" width="200" height="100" fill="white" stroke="black" stroke-width="11.81px" />
<text x="50" y="50">R1</text>
<text x="350" y="50" text-anchor="end">75</text>
</symbol>
<symbol id="W" style="font-family: Arial, sans serif; font-size: 50px; font-weight: bold;">
<line x1="-200" y1="0" x2="200" y2="0" stroke="red" stroke-width="11.81px" />
<rect x="-100" y="-50" width="200" height="100" fill="white" stroke="black" stroke-width="11.81px" />
<text x="-150" y="-75">R1</text>
<text x="150" y="-75" text-anchor="end">75</text>
</symbol>
<symbol id="R">
<use xlink:href="#Widerstand" viewBox="-200 -125 400 375" transform="translate(-200,-125)" />
</symbol>
</defs>
<line x1="0" y1="100" x2="4000" y2="100" stroke="black" stroke-width="1" />
<line x1="0" y1="200" x2="4000" y2="200" stroke="black" stroke-width="1" />
<line x1="0" y1="300" x2="4000" y2="300" stroke="black" stroke-width="1" />
<line x1="0" y1="400" x2="4000" y2="400" stroke="black" stroke-width="1" />
<line x1="0" y1="500" x2="4000" y2="500" stroke="black" stroke-width="1" />
<line x1="0" y1="600" x2="4000" y2="600" stroke="black" stroke-width="1" />
<line x1="100" y1="0" x2="100" y2="2000" stroke="black" stroke-width="1" />
<line x1="200" y1="0" x2="200" y2="2000" stroke="black" stroke-width="1" />
<line x1="300" y1="0" x2="300" y2="2000" stroke="black" stroke-width="1" />
<line x1="400" y1="0" x2="400" y2="2000" stroke="black" stroke-width="1" />
<line x1="500" y1="0" x2="500" y2="2000" stroke="black" stroke-width="1" />
<line x1="600" y1="0" x2="600" y2="2000" stroke="black" stroke-width="1" />
<use x="250" y="0" xlink:href="#Widerstand" />
<use x="250" y="200" xlink:href="#R" />
<use x="350" y="400" xlink:href="#W" />
<use x="250" y="600" xlink:href="#R" />
<use x="250" y="800" xlink:href="#R" />
</svg>
Gruß - WPö