For this assignment, choose one of the following options:
declare variable $dataColl := doc('/db/Assignments/electionData/popElectoralData.xml');. We have saved a starter XQuery file in the database at
/db/2021-Dig400-Examples/bubblePlotSVGstarter.xql.
for loop, but otherwise the form your plot takes is entirely up to you. Whatever you plot must involve some use of XQuery variables and calculations to pull information from the XML code and output it as SVG. Use SVG
<text>
elements to title and label your plot.It may help you to watch my recorded video on how to plot hash marks along X and Y axes on an SVG plot working with XQuery:
You should update your project files into our eXist database to work on for this assignment.
Before you start coding the XQuery, spend a few minutes studying your XML code. Look for something interesting to count and plot. Because the XML texts that we are using here are under development, they may be inconsistently or incompletely marked up. They are all well formed, however, which means that they can be explored with XML tools, including XQuery.
The dimensions and style of your plot are up to you, though we recommend a bar graph be used for most plots of counts. Save your SVG output in eXist, but paste a copy of your XQuery script in a text file, save it according to our usual homework file naming conventions, and upload it to Coursweb.
Work out your maximum values for X and Y and set a view port with a width and a height, and then a viewBox attribute to scale your output if you wish.
Look at examples of how we prepared SVG Viewports in class, and check out Sara Soueidan’s excellent detailed explanation. Here is a brief summary overview of how to set the Viewport attributes on the SVG root element:
width="{largest X value for the ENTIRE plot + something with some wiggle room}"
height="{largest Y for the ENTIRE plot + wiggle room}"
Now, if I want to define how the image behaves on a screen, I define the viewBox
attribute. viewBox
takes four values: viewBox="(x1,y1,x2,y2)"
which define a new coordinate system to use in rendering our output image.
x1,y1
defines starting top-left part of the image, and x2,y2
defines the number that represents the bottom right of the user’s screen.x1,y1
does not start at 0,0
the viewBox
will select the part of your image that starts where you say as the top left of the viewable SVG. (Notice what happens to the output SVG if you set x1,y1 to 200,200)x2,y2
is SMALLER than the total width and height you defined for your image, you’ll be zooming and cropping, because the viewBox
defines what you can see on the visible screen. (Notice what happens if you set x2,y2
to the width div 2
and height div 2
).x2,y2
is LARGER than the total width and height, the result effectively zooms out, making the output image take up LESS space on the screen. Think of x2,y2
as defining a ratio with your width and height attribute values.To plot your graph in SVG from XQuery, apply what you have been learning about SVG in the previous assignments. Keep in mind the following:
<g>
.transform="translate(x, y)": to shift the x dimension over to the right and your y down the screen, so that you can plot your coordinates from x=0 and y=0 so that your plot is visible in the SVG coordinate space,
, and follow our advice in the section above on setting a viewBox.for $i in (0 to 10)
Here, $i is a range variable that we can use to loop over the numbers 0 to 10 in sequence. You can set an XQuery variable that subtracts your min()
from your max()
value in place of the number 10 in our model sequence above.
@stroke-width
attribute is easier than working with the @height
attribute on the rectangle, but this is up to you. If you work with @height
, note that this is a positive absolute value, and the x and y coordinates are set at the top of the rectangle, not the bottom. You draw down the screen based on the positive value of the height you set. If you work with line elements, you set the start and end points of the lines.).