Difference between revisions of "Template:ListEdgesWIP"

From AtlasWiki
Jump to: navigation, search
(Preliminary version, handles only "permitted" in edges (both inherited and directly specified))
(Now uses a separate template to generate tables, all tables are being generated for permitted and specified edges, whether inherited or not)
 
Line 7: Line 7:
 
| headers=hide
 
| headers=hide
 
| name=permittedInEdges
 
| name=permittedInEdges
}}{{#ask: [[spedified edge to {{PAGENAME}}::+]]
+
}}{{#ask: [[specified edge to {{PAGENAME}}::+]]
 
| ?specified edge to {{PAGENAME}}
 
| ?specified edge to {{PAGENAME}}
 
| format=array
 
| format=array
 
| headers=hide
 
| headers=hide
 
| name=specifiedInEdges
 
| name=specifiedInEdges
 +
}}{{#ask: [[permitted edge from {{PAGENAME}}::+]]
 +
| ?permitted edge from {{PAGENAME}}
 +
| format=array
 +
| headers=hide
 +
| name=permittedOutEdges
 +
}}{{#ask: [[specified edge from {{PAGENAME}}::+]]
 +
| ?specified edge from {{PAGENAME}}
 +
| format=array
 +
| headers=hide
 +
| name=specifiedOutEdges
 
}}<noinclude><!--
 
}}<noinclude><!--
  
Above, we've stored all the in edges in an arrays named "permittedInEdges" and "specifiedInEdges".
+
Above, we've stored all the in edges in an arrays named "permittedInEdges", "specifiedInEdges", "permittedOutEdges", and "specifiedOutEdges".
  
 
Each entry in each array is in this format:
 
Each entry in each array is in this format:
Line 28: Line 38:
 
...now we want similar information about inherited in edges:
 
...now we want similar information about inherited in edges:
  
--></noinclude>{{#arraydefine:parentsArray|{{{parents|}}}|,|}}<noinclude>
+
--></noinclude>{{#arraydefine:parentsArray|{{{parents|}}}|,|}}<noinclude><!--
 
 
</noinclude>{{#arraydefine:inheritedPermittedInEdges|{{#arrayprint:parentsArray|<PARENT_SEP>|@@@@|{{#if:{{EdgesTo|@@@@|permitted}}|@@@@<PARENT>{{EdgesTo|@@@@|permitted}}}} }}|<PARENT_SEP>|}}<noinclude>
+
We gather the information on inherited edges as well, then defer to a helper template to print the actual tables
 
 
</noinclude>{{#arraydefine:inheritedSpecifiedInEdges|{{#arrayprint:parentsArray|<PARENT_SEP>|@@@@|{{#if:{{EdgesTo|@@@@|specified}}|@@@@<PARENT>{{EdgesTo|@@@@|specified}}}} }}|<PARENT_SEP>|}}<noinclude><!--
+
--></noinclude>{{ListEdges.generateTable
+
| title = Specified In Edges
We now have all the information about inherited edges in arrays as well, in the format specified by Template:EdgesTo, with the addition of the parent node name tacked on to the front, followed by <PARENT>.
+
| edgeTitle = In Edge
+
| nodeTitle = <abbr title="The node that the edge comes from">Predecessor</abbr>
So we can now decide whether the tables should exist, and whether they should have the extra cell at left for listing parent nodes that edges were inherited from.
+
| uninheritedEdges = {{#arrayprint:specifiedInEdges|<EDGE_SEP>}}
+
| inheritedEdges = {{#arrayprint:parentsArray|<PARENT_SEP>|@@@@|{{#if:{{EdgesTo|@@@@|specified}}|@@@@<PARENT>{{EdgesTo|@@@@|specified}} }} }}
First, we check whether there are edges in the category at all:
+
}}{{ListEdges.generateTable
+
| title = Specified Out Edges
{{#switch:{{#expr:{{#arraysize:permittedInEdges}}+{{#arraysize:inheritedPermittedInEdges}}}}| 0 = | #default =
+
| edgeTitle = Out Edge
 
+
| nodeTitle = <abbr title="The node that the edge points to">Successor</abbr>
... if there are, we start the table
+
| uninheritedEdges = {{#arrayprint:specifiedOutEdges|<EDGE_SEP>}}
+
| inheritedEdges = {{#arrayprint:parentsArray|<PARENT_SEP>|@@@@|{{#if:{{EdgesFrom|@@@@|specified}}|@@@@<PARENT>{{EdgesFrom|@@@@|specified}} }} }}
{{{!}} class="xcsgtable"
+
}}{{ListEdges.generateTable
+
| title = Known Possible In Edges
... we decide on the width based on whether we'll need a column for our parents
+
| edgeTitle = In Edge
+
| nodeTitle = <abbr title="The node that the edge comes from">Predecessor</abbr>
! colspan="{{#switch:{{#arraysize:inheritedPermittedInEdges}}| 0 = 4 | #default = 5 }}" {{!}} Known Possible In Edges
+
| uninheritedEdges = {{#arrayprint:permittedInEdges|<EDGE_SEP>}}
+
| inheritedEdges = {{#arrayprint:parentsArray|<PARENT_SEP>|@@@@|{{#if:{{EdgesTo|@@@@|permitted}}|@@@@<PARENT>{{EdgesTo|@@@@|permitted}} }} }}
... printing the headers, we add an empty cell if needed, whose height is based on the number of non-inherited edges + 1 (since it needs to cover the header as well).
+
}}{{ListEdges.generateTable
+
| title = Known Possible Out Edges
! {{#switch:{{#arraysize:inheritedPermittedInEdges}}| 0 = | #default = rowspan="{{#expr:1+{{#arrayprint:permittedInEdges|+|####|{{#arraydefine:findSize|####|<MANY>}}{{#arraysize:findSize}}}}}}" {{!}} !!}} In Edge !! <abbr title="comes from">Predecessor</abbr> !! Multiplicity !! Description
+
| edgeTitle = Out Edge
 
+
| nodeTitle = <abbr title="The node that the edge points to">Successor</abbr>
That's a bit involved, so let's just look at the calculation:
+
| uninheritedEdges = {{#arrayprint:permittedOutEdges|<EDGE_SEP>}}
+
| inheritedEdges = {{#arrayprint:parentsArray|<PARENT_SEP>|@@@@|{{#if:{{EdgesFrom|@@@@|permitted}}|@@@@<PARENT>{{EdgesFrom|@@@@|permitted}} }} }}
{{#expr:1+{{#arrayprint:permittedInEdges|+|####|{{#arraydefine:findSize|####|<MANY>}}{{#arraysize:findSize}}}}}}
+
}}
+
...to calculate the height, we use an expression. The expression calculates the size via #arrayprint with + as the delimiter, with each printed element being the number of origins for a particular edge kind, counted using arraysize: with a temporary array.
+
+
Hopefully that's enough to go on to figure out what's going on, I'm not going to take the time to break the whole thing down.
+
+
One other technique worth noting: there are lot of cases where we have to treat the first row of something differently than we treat the later rows, because e.g. we want the name of an edge to span several rows, meaning we must print the row with the name of the edge separately from the rows listing other possible origins/destinations. For this we use arraysplit: to give us a version with the first row removed, so we can treat the rest of the rows identically via arrayprint:.
+
+
--></noinclude>{{#switch:{{#expr:{{#arraysize:permittedInEdges}}+{{#arraysize:inheritedPermittedInEdges}}}}| 0 = | #default =
+
{{{!}} class="xcsgtable"
+
{{!}}-
+
! colspan="{{#switch:{{#arraysize:inheritedPermittedInEdges}}| 0 = 4 | #default = 5 }}" {{!}} Known Possible In Edges
+
{{#switch:{{#arraysize:permittedInEdges}}| 0 = | #default = {{!}}-
+
! {{#switch:{{#arraysize:inheritedPermittedInEdges}}| 0 = | #default = rowspan="{{#expr:1+{{#arrayprint:permittedInEdges|+|####|{{#arraydefine:findSize|####|<MANY>}}{{#arraysize:findSize}}}}}}" {{!}} !!}} In Edge !! <abbr title="comes from">Predecessor</abbr> !! Multiplicity !! Description
+
{{!}}-
+
{{!}}{{#arrayprint:permittedInEdges|&#32;
+
{{!}}-
+
{{!}}|var|{{#arraydefine:edgeRelationships|var|<PROP>|}}{{#arraydefine:relationships|{{#arrayindex:edgeRelationships|1}}|<MANY>|}} rowspan="{{#arraysize:relationships}}" {{!}} [[{{#arrayindex:edgeRelationships|0}}]]  {{!}}{{!}}  [[{{#explode:{{#arrayindex:relationships|0}}|$SEP$|0}}]]  {{!}}{{!}} {{#explode:{{#arrayindex:relationships|0}}|$SEP$|1}} {{!}}{{!}} rowspan="{{#arraysize:relationships}}" {{!}} {{ReconstructLinks|{{#explode:{{#arrayindex:relationships|0}}|$SEP$|2}}}} {{#arrayslice:relationships|relationships|1}} {{#arrayprint:relationships||@@@@|&#32;
+
{{!}}-
+
{{!}} [[{{#explode:@@@@|$SEP$|0}}]] {{!}}{{!}} {{#explode:@@@@|$SEP$|1}} }} }} }}
+
{{#switch:{{#arraysize:inheritedPermittedInEdges}}| 0 = | #default =
+
{{!}}-
+
! Inherited From !! In Edge !! <abbr title="comes from">Predecessor</abbr> !! Multiplicity !! Description
+
{{!}}-
+
{{!}}{{#arrayprint:inheritedPermittedInEdges|&#32;
+
{{!}}-
+
{{!}} |@@@@| {{#arraydefine:edges|{{#explode:@@@@|<PARENT>|1}}|<EDGE_SEP>|}} rowspan="{{#expr:{{#arrayprint:edges|+|####|{{#arraydefine:findSize|####|<MANY>}}{{#arraysize:findSize}}}}}}" {{!}} {{#explode:@@@@|<PARENT>|0}} {{!}}{{!}} {{#arraydefine:firstEdge|{{#arrayindex:edges|0}}|<EDGE_PROP>}} {{#arraydefine:firstOrigins|{{#arrayindex:firstEdge|2}}|<MANY>}} rowspan="{{#arraysize:firstOrigins}}" {{!}} {{#arrayindex:firstEdge|0}} {{!}}{{!}} {{#explode:{{#arrayindex:firstOrigins|0}}|<VAL>|0}} {{!}}{{!}} {{#explode:{{#arrayindex:firstOrigins|0}}|<VAL>|1}} {{!}}{{!}} rowspan="{{#arraysize:firstOrigins}}" {{!}} {{#arrayindex:firstEdge|1}} {{#arrayslice:restOfFirstOrigins|firstOrigins|1}} {{#arrayprint:restOfFirstOrigins||$$$$|&#32;
+
{{!}}-
+
{{!}} {{#explode:$$$$|<VAL>|0}} {{!}}{{!}} {{#explode:$$$$|<VAL>|1}} }} {{#arrayslice:restOfEdges|edges|1}}
+
{{#arrayprint:restOfEdges||####|&#32;
+
{{!}}-
+
{{!}}{{#arraydefine:edge|####|<EDGE_PROP>}} {{#arraydefine:origins|{{#arrayindex:edge|2}}|<MANY>}} rowspan="{{#arraysize:origins}}" {{!}} {{#arrayIndex:edge|0}} {{!}}{{!}} {{#explode:{{#arrayindex:origins|0}}|<VAL>|0}} {{!}}{{!}} {{#explode:{{#arrayindex:origins|0}}|<VAL>|1}} {{!}}{{!}} rowspan="{{#arraysize:origins}}" {{!}} {{#arrayIndex:edge|1}}
+
{{#arrayslice:restOfOrigins|origins|1}} {{#arrayprint:restOfOrigins||$$$$|{{!}}-
+
{{!}} {{#explode:$$$$|<VAL>|0}} {{!}}{{!}} {{#explode:$$$$|<VAL>|1}} }} }} }} }}
+
{{!}}}
+
}}<!--
+
+
The rest of this template still needs updating, we need stuff like the above for specified in edges, permitted out edges, and specified out edges...but first, to test it...
+
 
+
Next we get the out edges:
+
 
+
--></noinclude>{{#ask: [[edge from {{PAGENAME}}::+]]
+
| ?edge from {{PAGENAME}}
+
| format=array
+
| headers=hide
+
| name=outEdges
+
}}<noinclude><!--
+
 
+
If both arrays have values, then we need to add the whitespace that goes between the two tables.
+
 
+
--></noinclude>{{#switch:{{#arraysize:inEdges}}| 0 = | #default = {{#switch:{{#arraysize:outEdges}}| 0 = |
+
 
+
}} }}<noinclude><!--
+
 
+
We print the out edges table:
+
 
+
--></noinclude>{{#switch:{{#arraysize:outEdges}}| 0 = | #default =
+
{{{!}} class="xcsgtable"
+
! Out Edge !! Successor (Points To) !! Multiplicity !! Description
+
{{!}}-
+
{{!}}{{#arrayprint:outEdges|&#32;
+
{{!}}-
+
{{!}}|var|{{#arraydefine:edgeRelationships|var|<PROP>|}}{{#arraydefine:relationships|{{#arrayindex:edgeRelationships|1}}|<MANY>|}}{{#arrayprint:relationships|&#32;
+
{{!}}-
+
{{!}}|@@@@|[[{{#arrayindex:edgeRelationships|0}}]] {{!}}{{!}} [[{{#explode:@@@@|$SEP$|0}}]] {{!}}{{!}} {{#explode:@@@@|$SEP$|1}} {{!}}{{!}} {{ReconstructLinks|{{#explode:@@@@|$SEP$|2}}}} }} }}
+
{{!}}}
+
}}<noinclude><!--
+
 
+
And the inherited out edges table:
+
 
+
--></noinclude>{{#if:{{{parents|}}}|{{#if:{{#arrayprint:parents||@@@@|{{InheritEdgesFrom|@@@@}}}}|
+
{{{!}} class="xcsgtable"
+
{{!}}-
+
! colspan="5" {{!}} Inherited Out Edges
+
{{!}}-
+
! Inherited From !! Out Edge  !! Successor (Points To) !! Multiplicity !! Description
+
{{#arrayprint:parents||@@@@|&#32;
+
{{InheritEdgesFrom|@@@@}}}}
+
{{!}}} }} }}
+

Latest revision as of 12:12, 12 May 2014

For use on node kind pages, automatically lists edges declared on the current page.

If the parameter "parents" is given a comma-separated list of the parents of the node, inherited edges will also be listed.