| Previous Next Contents References A Simple XY GraphHere is an SVG document for a simple xy graph. The SVG
document is simple_xy.svg.
Simple SVG Document with an XY Graph Again the outer rectangle shows the extent of the SVG drawing. The code for this example is given below.
|
|
The svg tag is the same as the last example. The
title and description tags, used on lines 4
and 5, are not displayed unless the browser has some other problem
displaying the document.
The group element, g,
groups child elements on an imaginary separate canvas. This
introduces several new concepts, highlighted in bold here. The g
element on line 8 translates all child elements to use x=200, y=20 as
the origin, defining a new user
coordinate system. The term SVG
canvas describes an
infinite area for each dimension of the
space. Rendering of the SVG drawing on the canvas is on a finite
rectangular region of the canvas, called the viewport, which is the
area where users sees the SVG content.
The rectangle element is used on line 10 to paint a rectangle 600 pixels wide, 200 pixels high starting at the (newly translated) origin (0, 0). This is a box for our x-y graph.
Lines 13 through 15 draw lines for tick marks along the
y-axis. Here the
style is written as style="stroke: black;". This
uses the same syntax as CSS. However, it could also have been
written as stroke="black". Lines 18 through 20 draw
text to label the tickmarks drawn on lines 13 through 15.
On line 30 group is introduced to group the elements of the line for the electric potential together and translate the graph axis to the middle of the y-axis (0 mV). On line 32 another group is introduced to scale the graph so y runs upwards. We can now use the actual coordinates in electric potential in mV and time in msec to plot the points (except that msec are multiplied by 100), instead of thinking in terms of pixels. For example, on line 33 a line is drawn from t = 0, E = -70 mV to t = 2.4 msec, E = -70 mV. I avoided doing the transformation to actual physical user coordinates before this point because of the effect on the text labels (they would be printed upside down).
The graph curve is
defined by lines and paths. Paths are lines or outlines and are
defined by the commands
The path command has the form <path d="...">,
where d is the path data. The 'M' (moveto) command moves the
current point to the point following it to start drawing the
curve. For example,
on line 34 the current point is set to (240, -70).
The 'C' (curveto) command has the form C x1,y1 x2,y2 x,y.
It draws a cubic Bézier curve from the current point to (x,y) using
(x1,y1) as the control point at the beginning of the curve and (x2,y2)
as the control point at the end of the curve. The points (x1,y1)
and (x2,y2) pull the curve towards them. The entire graph could
have been drawn with a single path element. However, I broke it
up for demonstration of the relation with ion channels and pumps, which
leads into the next example.