changeset 60:588cb9ba7c9c

display of reffed info via colour minimally working
author Henry S. Thompson <ht@markup.co.uk>
date Fri, 02 Jun 2017 15:50:43 +0100
parents f90bbd38b8f6
children 2da454c30b47
files backref.xsl html.xsl visualise.xpl
diffstat 3 files changed, 72 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/backref.xsl	Fri Jun 02 12:54:54 2017 +0100
+++ b/backref.xsl	Fri Jun 02 15:50:43 2017 +0100
@@ -13,7 +13,7 @@
   <xsl:variable name="ris" select="for $r in e:r/text()
                                     return key('fcell',$r)/@fi"/>
   <xsl:copy>
-   <xsl:attribute name="ri"><xsl:value-of select="string-join($ris,',')"/></xsl:attribute>
+   <xsl:attribute name="ri"><xsl:value-of select="string-join($ris,'_')"/></xsl:attribute>
    <xsl:apply-templates select="node()|@*"/>
   </xsl:copy>
  </xsl:template>
--- a/html.xsl	Fri Jun 02 12:54:54 2017 +0100
+++ b/html.xsl	Fri Jun 02 15:50:43 2017 +0100
@@ -7,29 +7,33 @@
  <xsl:include href="n2a.xsl"/>
  
  <xsl:variable name="colours" select="(
-      '#FFB300', /* Vivid Yellow */
-      '#803E75', /* Strong Purple */
-      '#FF6800', /* Vivid Orange */
-      '#A6BDD7', /* Very Light Blue */
-      '#C10020', /* Vivid Red */
-      '#CEA262', /* Grayish Yellow */
-      '#817066', /* Medium Gray */
-      /* The following don't work well for people with defective color vision */
-      '#007D34', /* Vivid Green */
-      '#F6768E', /* Strong Purplish Pink */
-      '#00538A', /* Strong Blue */
-      '#FF7A5C', /* Strong Yellowish Pink */
-      '#53377A', /* Strong Violet */
-      '#FF8E00', /* Vivid Orange Yellow */
-      '#B32851', /* Strong Purplish Red */
-      '#F4C800', /* Vivid Greenish Yellow */
-      '#7F180D', /* Strong Reddish Brown */
-      '#93AA00', /* Vivid Yellowish Green */
-      '#593315', /* Deep Yellowish Brown */
-      '#F13A13', /* Vivid Reddish Orange */
-      '#232C16'  /* Dark Olive Green */)"><xsl:comment>From http://stackoverflow.com/questions/470690/how-to-automatically-generate-n-distinct-colors</xsl:comment></xsl:variable>
+    (: Thanks to http://stackoverflow.com/questions/470690/how-to-automatically-generate-n-distinct-colors :)
+      '#FFB300', (: Vivid Yellow :)
+      '#803E75', (: Strong Purple :)
+      '#FF6800', (: Vivid Orange :)
+      '#A6BDD7', (: Very Light Blue :)
+      '#C10020', (: Vivid Red :)
+      '#CEA262', (: Grayish Yellow :)
+      '#817066', (: Medium Gray :)
+      (: The following don't work well for people with defective color vision :)
+      '#007D34', (: Vivid Green :)
+      '#F6768E', (: Strong Purplish Pink :)
+      '#00538A', (: Strong Blue :)
+      '#FF7A5C', (: Strong Yellowish Pink :)
+      '#53377A', (: Strong Violet :)
+      '#FF8E00', (: Vivid Orange Yellow :)
+      '#B32851', (: Strong Purplish Red :)
+      '#F4C800', (: Vivid Greenish Yellow :)
+      '#7F180D', (: Strong Reddish Brown :)
+      '#93AA00', (: Vivid Yellowish Green :)
+      '#593315', (: Deep Yellowish Brown :)
+      '#F13A13', (: Vivid Reddish Orange :)
+      '#232C16'  (: Dark Olive Green :))"/>
  <xsl:variable name="nColours" select="count($colours)"/>
- <xsl:variable name="colourClassStyles" select="for $c in colours, $i in (1 to $nColours) return concat('.c',$i,' {background-color: ',$c,'}')"/>
+ <xsl:variable name="colourClassStyles" select="for $i in (1 to $nColours) return concat('.c',$i,' {background-color: ',$colours[$i],'}')"/>
+ 
+ <xsl:variable name="backfi" select="distinct-values(/e:a/e:r/e:c/e:i/@ri)"/>
+ <xsl:variable name="borderClassStyles" select="for $fis in $backfi return e:bcs($fis)"></xsl:variable>
 
  <xsl:template match="/">
   <html>
@@ -44,7 +48,8 @@
        table {table-layout: fixed}
        th {width: 1en}
     </style>
-    <style><xsl:value-of select="string-join($colourClassStyles,'&#10;       "/></style>
+    <style><xsl:value-of select="string-join($colourClassStyles,'&#10;       ')"/></style>
+    <style><xsl:value-of select="string-join($borderClassStyles,'&#10;       ')"/></style>
    </head>
    <body>
     <xsl:apply-templates/>
@@ -99,12 +104,33 @@
  
  <xsl:variable name="borders" select="('left','right','top','bottom')"/>
  
+ <xsl:function name="e:bcs" as="xs:string">
+  <xsl:param name="fiss" as="xs:string"/>
+  <xsl:value-of select="let $fis := tokenize($fiss,'_') return
+                         concat('.b',$fiss,' {',
+                                string-join(for $i in (1 to 4) return
+                                                    e:bfs($fis[$i],
+                                                          $borders[$i]),
+                                             '; '),
+                                '}')"/>
+ </xsl:function>
+ 
+ <xsl:function name="e:bfs" as="xs:string">
+  <xsl:param name="fi" as="xs:string?"/>
+  <xsl:param name="pos" as="xs:string"/>
+  <xsl:value-of select="if (empty($fi)) then
+                         concat('border-',$pos,': solid 1px black') else
+                         concat('border-',$pos,': solid 2px ',
+                                $colours[xs:integer($fi)])"/>
+ </xsl:function>
+ 
  <xsl:function name="e:rf" as="xs:string">
   <xsl:param name="ris" as="attribute(ri)*"/>
-  <xsl:value-of select="let $ff := (for $ri in split($ris,',')
-                                return if ($ri le $nColours) then $ri else ())
-                          return if $ff
-                           then concat('.b',string-join($ff,'b'))
-                           else 'reffed'"/>
+  <xsl:value-of select="let $ff := (for $ri in tokenize(string($ris),'_')
+                                return if (xs:integer($ri) le $nColours) then $ri else ())
+                          return if (empty($ff))
+                           then 'reffed'
+                           else concat('b',
+                                       string-join(subsequence($ff,1,4),'_'))"/>
  </xsl:function>
 </xsl:stylesheet>
--- a/visualise.xpl	Fri Jun 02 12:54:54 2017 +0100
+++ b/visualise.xpl	Fri Jun 02 15:50:43 2017 +0100
@@ -169,6 +169,21 @@
     </p:input>
  </p:xslt>
  
+ <p:load name="ssb">
+  <p:with-option name="href" select="concat($elabDir,'/backref.xsl')"/>
+  <p:documentation>
+   <div>Add backref info</div>
+  </p:documentation>
+ </p:load>
+ 
+ <p:xslt name="backref">
+  <p:input port="source">
+   <p:pipe step="merge" port="result"/>
+  </p:input>
+  <p:input port="stylesheet">
+     <p:pipe step="ssb" port="result"/>
+    </p:input>
+ </p:xslt>
  <p:choose> 
   <p:when test="p:value-available('format')">
    <p:load name="ss3">
@@ -176,7 +191,7 @@
    </p:load>
    <p:xslt name="fmt">
     <p:input port="source">
-     <p:pipe step="merge" port="result"/>
+     <p:pipe step="backref" port="result"/>
     </p:input>
     <p:input port="stylesheet">
      <p:pipe step="ss3" port="result"/>
@@ -186,7 +201,7 @@
   <p:otherwise>
    <p:identity>
     <p:input port="source">
-     <p:pipe step="merge" port="result"/>
+     <p:pipe step="backref" port="result"/>
     </p:input>
    </p:identity>
   </p:otherwise>