BMT45 / Ferdinand-Magellan-Project

XML Code
4 stars 1 forks source link

Still having issues with the SVG timeline #16

Open JustinCampbell9 opened 5 years ago

JustinCampbell9 commented 5 years ago

I attempted to change the xml like @ghbondar recommended and build the svg around that however it still doesn't seem to be working. Also I'm a little confused on how to incorporate several different attributes into the variables in the svg.

JustinCampbell9 commented 5 years ago

@ebeshero

The code

           <xsl:for-each select="0 to $latest - $earliest"> 
              <circle cx="0" cy="{current() ! xs:integer(.) * $spacer}"  r="6" fill="black"/>
             <text x="-50" y="{current() ! xs:integer(.) * $spacer}" text-anchor="middle" style="font   family: Arial;
                    font-size  : 20;
                    stroke     : black;
                    fill       : red;
                    "><xsl:value-of select="$earliest + position() -1"/></text>
            </xsl:for-each>

Doesn't seem to be working correctly. It doesn't give my anything on my output even with the correct variables attached.

ebeshero commented 5 years ago

@JustinCampbell9 Point me to your source code?

ebeshero commented 5 years ago

@JustinCampbell9 This is the file, right? https://github.com/BMT45/Ferdinand-Magellan-Project/blob/master/SVG/magellanTimeline

I see you've got comments for testing the $earliest and $latest variables. Remember how your dates are formatted differently than mine? You've got the year at the end. It looks like your variables are getting the first token, not the last one. (XSLT counts from 1, while JavaScript counts from 0.)

JustinCampbell9 commented 5 years ago

Yes, i have them like this

     <xsl:variable name="latest" select="max(for $i in $allDates return tokenize($i, '-')[3]) ! xs:integer(.)"/>
JustinCampbell9 commented 5 years ago

Having the [3] is how it should be, correct?

ebeshero commented 5 years ago

@JustinCampbell9 Do you have any dates where you don't have the day value? (In my projects, sometimes I only have month and year for some fuzzy dates). Just in case, you're safest to use our friend last() if your year value is always in the end position.

ebeshero commented 5 years ago

@JustinCampbell9 So you can just say [last()] to get the last of a thing if you're not sure it's always going to be the third token.

JustinCampbell9 commented 5 years ago

I guess capturing the dates isn't the issue anymore. The output is just all of the dates in a comment which I'm not sure how to fix.

JustinCampbell9 commented 5 years ago

Changing it to the last(), I believe, left me with the same output

ebeshero commented 5 years ago

Push your latest code? I can take a closer look. You should be able to spit out all the years in one variable, and then send that value to max() to get the latest, and min() to get the earliest.

JustinCampbell9 commented 5 years ago

https://github.com/BMT45/Ferdinand-Magellan-Project/blob/master/SVG/magellanTimeline

ebeshero commented 5 years ago

@JustinCampbell9 Thanks...let me see. It's a number problem: you need to get one and only one value for $earliest and one and only one value for $latest. I'm betting there's a syntax error somewhere.

ebeshero commented 5 years ago

@JustinCampbell9 Can you tell me what your source file is? Is it supposed to be a collection of files? (We can set up a variable to read in a collection if that makes sense.)

ebeshero commented 5 years ago

@JustinCampbell9 Or is it just that journal file I see in the XML directory? Let me know...tinkering with the file now.

ebeshero commented 5 years ago

@JustinCampbell9 Aha! It was a syntax error and I got it working...also I see one fouled-up year date in your journal....But your XSLT is properly plotting an SVG now...

JustinCampbell9 commented 5 years ago

All of the dates are in that single file

ebeshero commented 5 years ago

Okay-- so one year in that Journal file is marked as 15 and it's fouling up the scope. But it's working--you're getting SVG elements in the output. I can't see it on a web browser yet, but I think it's that one bad date in the XML markup. Let me push what I have...

ebeshero commented 5 years ago

Okay-- I pushed the repair. NOTE: You want to delete your original XSLT file: it didn't have a file extension, so I was having trouble opening it. Mine is the file with the .xsl extension, and I had to move your comment tag with your name inside the root elements.

The issue was that we needed to put the xs:integer(.) function inside the parentheses for the for $i... function. You're definitely getting max() and min() dates now, but you want to figure out what's wrong with that one date in the file where the year is coming out as 15. If that's not something you can fix, you can work around it with an xsl:if when you construct your variable to include only properly formed dates in your variable.

ebeshero commented 5 years ago

Let's see...how would we screen for only dates that have 4 digit years at the end? I think you'd need to write a test like this: 1) For each member of the date list, tokenize the date on hyphens, look at the last() part, and use a match() function to match a regex. The regex is 4 digits: \d{4}. ONLY include an @when attribute if it ends in 4 digits. 2) Figure out how to say that in XSLT. I'm going to tinker with that now...

ebeshero commented 5 years ago

@JustinCampbell9 Got it! I used an XPath predicate to filter your dates, and screened out anything that didn't end with 4 digits. That's almost equivalent to a test you'd write in Schematron to help you find and fix badly formed dates... Hint: you and your team might want to write and associate a little Schematron test to help you quickly find errors like this in your markup.

ebeshero commented 5 years ago

@JustinCampbell9 You've got a functioning XSLT and some nice, viewable SVG output with this commit: https://github.com/BMT45/Ferdinand-Magellan-Project/commit/74b9f0783f11d5b55a33736b9e80f50af42e3a16

Next step--can you plot the events? You may want to stretch out this timeline by a much larger spacing factor so you can see them all.

JustinCampbell9 commented 5 years ago

@ebeshero I'm not sure if it's an issue on my end however i'm not getting anything on the output when opening it in safari or chrome. I was attempting to plot the events but it's difficult not being able to see anything.

ebeshero commented 5 years ago

@JustinCampbell9 There are two XSLT files in your repo now. One is your original which lacked a file extension, so make sure you're not using that one. (You should probably delete it on your end rather than me to avoid git merge conflicts.) The OTHER XSLT file is the one I edited last night and is producing visible output. Do a git pull, and you can actually open my output because I saved it in your directory as .svg.

JustinCampbell9 commented 5 years ago

@ebeshero I guess I'm confused about how to plot the actual dates on the timeline. We don't have each event in a variable so I guess I'm going to have to manually enter them. However, I don't really understand how to do that. Using your file, i believe is for already created variables

ebeshero commented 5 years ago

@JustinCampbell9 How are the events coded in your source XML? Can you show me an example here?

ebeshero commented 5 years ago

@JustinCampbell9 I'm sorting through some of your XML files, and I think I understand the problem. Is it that your dates are coded in paragraphs? So you don't have them attached to specific events or headings, or something you'd consider a proper "label." That can still be okay. What you want to do is scope around with the some XPath to see what might be interesting to plot next to a given date. What if it's the entire surrounding paragraph? (There's no harm in putting that inside an SVG <text> element, but you just need to make room for it.) If I remember this right, your team doesn't have a long range of years, but you have many dates, so you want to stretch those years out and accommodate each of many data points in a given year. You could factor in more space to provide whatever information you have associated with a given date that looks interesting.

Do I understand the issue right?

JustinCampbell9 commented 5 years ago

@ebeshero Yes, I wasn't sure if I should try and summarize the event for that date or what. I was more or less confused on how to even do that.

ebeshero commented 5 years ago

@JustinCampbell9 Sorry--and if an extension until Friday or even Saturday night would help, please take one (just let us know). But you should not need to write these entries yourself--it's better to extract something directly from the XML. (And less likely you'll make an interpretive error there, too.)

JustinCampbell9 commented 5 years ago

@ebeshero I guess I could change the xml however the dates correspond with the entire paragraph of information

JustinCampbell9 commented 5 years ago

@ebeshero How would you suggest plotting the points on the line itself? I'm trying to look at examples for reference however none of them are really helping.

ebeshero commented 5 years ago

@JustinCampbell9 Your timeline will likely have a lot of text (if you are pulling in paragraphs). You want to put a lot of space between points—and you have a lot of options—you could plot circles with hash lines pointing to date labels and then set a text element in between. The difficulty is estimating how much space to allow for your entries. I guess you might have to figure that out with some trial and error.

JustinCampbell9 commented 5 years ago

@ebeshero

                     <xsl:variable name="para" select="p"/>                  
                    <circle cx="{150 + position()*50}" cy="{$para}" r="6" fill="black"/> 
                    <line x1="0" x2="{150 + position()*50}" y1="{$para}" y2="{$para}" stroke="black" stroke-width="1.5"/> 
                    <text x="{375 + position()*50}" y="{$para}" text-anchor="middle" style="font-family: Arial;
                        font-size  : 20;
                        stroke     : black;
                        fill       : cyan;"/>

This doesn't actually display any text. Do you know why?

Also it's not on the correct date