|
|
Consider the set of equal-sized rectangles rendered in Figure 10.1.
Figure 10.1: A bar set.
The SVG document in Listing 10.1 demonstrates how to draw a bar set of rectangles of equal width and height that alternate the colors red and blue.
Listing 10.1 barSet1.svg
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN" "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd"> <svg width="100%" height="100%"> <defs> <rect x="0" y="0" width="40" height="200" stroke="white"/> </defs> <g transform="translate(40,100)"> <use x="0" y="0" fill="blue" xlink:href="#blot1"/> <use x="40" y="0" fill="red" xlink:href="#blot1"/> <use x="80" y="0" fill="blue" xlink:href="#blot1"/> <use x="120" y="0" fill="red" xlink:href="#blot1"/> <use x="160" y="0" fill="blue" xlink:href="#blot1"/> <use x="200" y="0" fill="red" xlink:href="#blot1"/> <use x="240" y="0" fill="blue" xlink:href="#blot1"/> <use x="280" y="0" fill="red" xlink:href="#blot1"/> </g> </svg>
The SVG code in Listing 10.1 is straightforward. The SVG code starts with an SVG defs element that defines an SVG rect element whose id attribute has a value of blot1. Next, the SVG code contains an SVG g element with multiple SVG use elements. Each SVG use element references the SVG rect element defined in the SVG defs element. Notice that the x-coordinate is incremented by 40 pixels, which produces a set of contiguous rectangles. In this book a set of contiguous rectangles that have the same width and height will be informally referred to as a 'homogeneous bar set.'
|
|