Samantha-Mcguigan / newsAnalysis

repository for our newsAnalysis web page
3 stars 0 forks source link

Bar Graphs: Troubleshooting #14

Closed ebeshero closed 6 years ago

ebeshero commented 7 years ago

@ajnewton1 I had a peek in the eXist-db at your XQuery generating one of those troubled bar graphs, and I think I've spotted the stacking problem. Here's a snip of your code generating a couple of bars on the "Comparison Between the Amount of Time each Gender Was Quoted" graph:

    <!-- articles -->
        <rect x="20" y="-238" height="{$articles}" width="20" style="stroke: black ; stroke-width: 2;"/>
        <rect x="20" y="-168" height="{$articlesM}" width="20" style="stroke: blue; stroke-width: 2; fill: blue;"/>
        <rect x="20" y="-47" height="{$articlesF}" width="20" style="stroke: pink; stroke-width: 2; fill: pink;"/>

        <!-- election results -->
        <rect x="60" y="-29" height="{$ERarticles}" width="20" style="stroke: black; stroke-width: 2;"/>
        <rect x="60" y="-28" height="{$ERarticlesM}" width="20" style="stroke: blue; stroke-width: 2; fill: blue;"/>
        <rect x="60" y="-1" height="{$ERarticlesF}" width="20" style="stroke: pink; stroke-width: 2; fill: pink;"/>

Here's what I see, and I'm taking my time reading the variables: 1) I'm not sure how you're determining the value of "y" for each rectangle--it seems like you're doing the stacking by hand? (It's more robust code to write out the variables that are doing the stacking so we can see what's what--use XQuery as your calculator.) 2) Earlier in your XQuery, here's how you've defined these variables:

declare variable $articles := count($news//body//quote[@sex]);
declare variable $articlesM := count($news//body//quote[@sex="m"]);
declare variable $articlesF := count($news//body//quote[@sex="f"]);

What that tells me is: the $articles variable represents a TOTAL COUNT of all the quotes that have an @sex attribute. I have a couple of questions about this:

OK, if we know that $articles (and $ERarticles and other variables like it) represent a TOTAL, that total already contains the male and female quotes. So when you go to stack your bar graphs, this one should not be sitting on top of the others. It should be the first bar you draw and it should extend from 0,0 up to the total. (That's something I'd want to double-check to be sure is happening.)

If each of your bars superimposes over the others, the bars for males and females need to properly stack, and...I think the problem is that the male bar isn't sitting on top of the female bar, but is being obscured under it. If the bars are being plotted from 0,0 upward, you want to set the value of the female count + the male count to determine how high the male bar sits.

Let's tinker with the variables this morning and see if we can make the stacking work and the code more robust and easier to read.