Jump to content

User:Fredddie/Graphs

From Wikipedia, the free encyclopedia

This page does the calculations required to create SVG assessment graphs for WP:USRD and for WP:CRWP.

Refresh this page

Coordinate data

[edit]

The coordinate plane is typically 120 pixels high. The B–FA graph is calculated for 240px, but on 120px graph, the result is a 2x magnification.

WP:USRD assessment graphs
Class Count Pie wedge x y Area graph Stat graph B–FA graph Cumulative Relative
 ??? 0 0.00%  0×10−16  −1.0000 0.00 120.00      
Stub 1323 10.66%  62.0688  −78.4058 12.79 106.77
Start 4459 35.92%  21.3453  97.6953 55.89 75.41
C 3762 30.30%  −99.3025  −11.7908 92.26 82.38
B 1582 12.74%  −60.6701  −79.4930 107.55 104.18 −38.2
GA 1183 9.53%  −5.3119  −99.8588 118.99 108.17 1.70
A 21 0.17%  −4.2503  −99.9096 119.19 119.79 117.90
FA 84 0.68%  0×10−14  −100.0000 120.00 119.16 111.60
Total 12414  
  15.17 71.11
[edit]
WP:CRWP assessment graphs
Class Count Pie wedge x y Area graph
 ??? 13 0.78%  0×10−16  −1.0000 0.94
Stub 908 54.53%  −28.1074  95.9686 66.38
Start 415 24.92%  −96.1001  −27.6544 96.29
C 76 4.56%  −84.3518  −53.7101 101.77
B 124 7.45%  −51.0583  −85.9828 110.70
GA 116 6.97%  −9.7958  −99.5191 119.06
A 4 0.24%  −8.2926  −99.6556 119.35
FA 9 0.54%  −4.9038  −99.8797 120.00
Total 1665  
[edit]

Tutorial

[edit]

While SVG may look like a strange language, it is actually pretty easy to update the graphs. The files are all text-editable, which means you can simply download the SVG files and open them in your favorite text editor. Plotting points in SVG is very similar to plotting points on a Cartesian plane. In SVG, however, the origin is the top left corner of the viewing area of your browser and the Y-axis goes down the page. It is possible to translate the origin to another part of the graph.

Pie chart

[edit]

The pie charts are the easiest to edit, so we'll start there. When I created the pie chart, I translated the origin of the circle to (110,110) which made it a lot easier to do the math required to create the wedges. The coordinates listed in the charts above account for this.

There are seven wedges in the graph – one for each assessment class – and the corresponding lines look similar to this:

<!-- stub-class articles -->
<path fill="#f66" d="M0,0 L0,-100 A100,100 0, 0,1 99.7949,-6.4021 Z"/>

This is fancy SVG code telling the renderer that it's part of a circle. We're only really interested in L0,-100 and 99.7949,-6.4021. The L0,-100 is our starting point on the circle and 99.7949,-6.4021 is the ending point. Both coordinates are located on the circle. The L value is always the same as the previous wedge, since the stubs always start the graph, it's starting at the top, which is 0,-100. The other value, 99.7949,-6.4021 can be replaced with the values from the table 99.6374,-8.5083. Remember, the L value on the Start-Class wedge will be L99.6374,-8.5083. Repeat for each wedge.

When you're done with the wedges, don't forget to update the percentages:

<text x="255" y="63">Stub (23.98%)</text>

Preview the graph in your browser before you upload it. My most common mistakes were either forgetting the comma in the ordered pairs or replacing a decimal point with a comma.

Other graphs

[edit]

The other graphs are little trickier, but are nonetheless easy to edit. All of the graphs are a rolling window of the last 5 years. If we were to continue showing every month, the text you see would eventually be narrowed to the point of not being legible. To accomplish this, the line part of the graph is contained within a second SVG document within the main document. To get the graph to "roll", you must change the position of the second SVG's viewBox.

For this part of the tutorial, I'll be looking at the stat graph.

<svg width="360" height="136" x="40" y="0" viewBox="60 0 360 136">

The only number that needs to be changed is the first number, in this case 60. Simply advance that number by 5 (65). Any code that is not within the 360-pixel viewBox will not be visible.

Lengthening the lines is simple. They use polylines, which allow you to define points long which the lines will be drawn. This is in contrast to a line, which only allows you to define the beginning and ending points.

<polyline class="Total"
	points="40,119.98 45,95.30 50,87.51 55,83.65 60,79.99 65,69.49 70,59.64 75,53.75
		...omitted for brevity...
		360,16.04"/>

In this example we would the next point would be at 365,<Y COORDINATE>, which is determined from the table above. Do this for all lines.


The area graph is slightly different. It uses the same polyline to create a polygon, so the line must be closed to render correctly.

<polyline fill="#f66" stroke="#000" stroke-width="0.25"
	points="40,120 40,0 45,44.79 50,50.3 55,47.08 60,40.58 65,23.95 70,0 75,4.33 80,0.02 
		...omitted for brevity...
		270,0 275,0.01 280,0.01 290,0 360,0 360,120"/>

As you can see, the last two coordinates have the same X value. The Y-value of the last ordered pair <X COORDINATE>,120 does not need to be changed.