Difference between revisions of "Template:Bartable/doc"
Jump to navigation
Jump to search
imported>Cmglee (→2-column (only positive values): Add link to unit definition) |
imported>Vanisaac m (→See also: clean up per WP:CAT#T and WP:AWBREQ add template:Sandbox other) |
||
| (6 intermediate revisions by 4 users not shown) | |||
| Line 4: | Line 4: | ||
This template adds an inline bar graph to tables with numeric (including negative) values that a reader may wish to compare. | This template adds an inline bar graph to tables with numeric (including negative) values that a reader may wish to compare. | ||
| − | Use this template inside a table. The template generates either two table cells (for cases in which all values are positive) or three (to | + | Use this template inside a table. The template generates either two table cells (for cases in which all values are positive) or three (to accommodate negative bars going off to the left). Thus, your table headers should have '''colspan="2"''' or '''colspan="3"''' (or similar combinations), respectively, to correctly span the columns. |
The template generates two cells if the ''scale'' parameter is positive and three if it is negative. | The template generates two cells if the ''scale'' parameter is positive and three if it is negative. | ||
| Line 13: | Line 13: | ||
; ''value'' (mandatory) : any real number or math expression that evaluates to a number. Commas can be used to [[Digit_grouping|group digits]]. See [[Help:Calculation]] for the syntax for math expressions. | ; ''value'' (mandatory) : any real number or math expression that evaluates to a number. Commas can be used to [[Digit_grouping|group digits]]. See [[Help:Calculation]] for the syntax for math expressions. | ||
| − | ; ''unit'' (default = empty string) : the unit, e.g. "m" for metres. | + | ; ''unit'' (default = empty string) : the unit, e.g. "m" for metres. Prepend a space if you want a space between the value and the unit. If ''unit'' starts with "''/''", the value is converted between units (using the '''[[Template:Convert|convert]]''' template) as follows: |
:: "''/unit1/unit2/round''" converts the value from ''unit1'' to ''unit2'' and rounds it to ''round'' decimal places (using <code><nowiki>{{</nowiki>convert|''value''|''unit1''|''unit2''|''round''|abbr=on<nowiki>}}</nowiki></code>). Unfortunately ''unit1'', ''unit2'' or ''round'' cannot contain a "''/''" or a "=" — if anyone knows how to allow it (or translate other characters to it), please help. | :: "''/unit1/unit2/round''" converts the value from ''unit1'' to ''unit2'' and rounds it to ''round'' decimal places (using <code><nowiki>{{</nowiki>convert|''value''|''unit1''|''unit2''|''round''|abbr=on<nowiki>}}</nowiki></code>). Unfortunately ''unit1'', ''unit2'' or ''round'' cannot contain a "''/''" or a "=" — if anyone knows how to allow it (or translate other characters to it), please help. | ||
; ''scale'' (default = 1) : a factor multiplied by ''value'' to give the width of the bar in pixels. Use the same scale in every row, as otherwise the bar chart won’t be to scale! | ; ''scale'' (default = 1) : a factor multiplied by ''value'' to give the width of the bar in pixels. Use the same scale in every row, as otherwise the bar chart won’t be to scale! | ||
| Line 71: | Line 71: | ||
| Math expression || {{bartable|exp(1)*1e2}} | | Math expression || {{bartable|exp(1)*1e2}} | ||
|- | |- | ||
| − | | Value and unit ( | + | | Value and unit (note added space) || {{bartable|272| km/h}} |
|- | |- | ||
| − | | Value and | + | | Value and unit (link to definition) || {{bartable|272|[[Degree_(angle)|°]]}} |
| + | |- | ||
| + | | Value and unit (with formatting) || align="right"|''θ'' = {{bartable|272|°}} | ||
| + | |- | ||
| + | | Value and unit (with conversion) || {{bartable|272|/km/mi}} | ||
|- | |- | ||
| Value and scale || {{bartable|272||1/(2^0.5)}} | | Value and scale || {{bartable|272||1/(2^0.5)}} | ||
| Line 96: | Line 100: | ||
| Math expression || {{bartable|exp(1)*1e2}} | | Math expression || {{bartable|exp(1)*1e2}} | ||
|- | |- | ||
| − | | Value and unit ( | + | | Value and unit (note added space) || {{bartable|272| km/h}} |
|- | |- | ||
| − | | Value and | + | | Value and unit (link to definition) || {{bartable|272|[[Degree_(angle)|°]]}} |
| + | |- | ||
| + | | Value and unit (with formatting) || align="right"|''θ'' = {{bartable|272|°}} | ||
| + | |- | ||
| + | | Value and unit (with conversion) || {{bartable|272|/km/mi}} | ||
|- | |- | ||
| Value and scale || {{bartable|272||1/(2^0.5)}} | | Value and scale || {{bartable|272||1/(2^0.5)}} | ||
| Line 115: | Line 123: | ||
<pre> | <pre> | ||
{| class="wikitable" | {| class="wikitable" | ||
| − | ! Example | + | ! Example || colspan="3" | Rendering |
|- | |- | ||
| − | | Only value | + | | Only value || {{bartable|272||-1}} |
|- | |- | ||
| − | | Negative value | + | | Negative value || {{bartable|-72||-1}} |
|- | |- | ||
| − | | Math expression | + | | Math expression || {{bartable|exp(1)*1e2||-1}} |
|- | |- | ||
| − | | Value and | + | | Value and unit (note added space) || {{bartable|272| km/h|-1}} |
|- | |- | ||
| − | | Value and | + | | Value and unit (link to definition) || {{bartable|272|[[Degree_(angle)|°]]|-1}} |
|- | |- | ||
| − | | Value and | + | | Value and unit (with formatting) || align="right"|''θ'' = {{bartable|272|°|-1}} |
|- | |- | ||
| − | | Value and | + | | Value and unit (with conversion) || {{bartable|272|/km/mi|-1}} |
|- | |- | ||
| − | | Value and | + | | Value and scale || {{bartable|272||-1/(2^0.5)}} |
|- | |- | ||
| − | | Value | + | | Value and height || {{bartable|272||-1|4px}} |
|- | |- | ||
| − | | The full monty | + | | Value and style || {{bartable|272||-1||background:blue;}} |
| + | |- | ||
| + | | Value with commas, and scale || {{bartable|2,720||-.1}} | ||
| + | |- | ||
| + | | The full monty || {{bartable|18^2|%|sin(-1)|2em|border:ridge red;}} | ||
|- | |- | ||
|} | |} | ||
</pre> | </pre> | ||
{| class="wikitable" | {| class="wikitable" | ||
| − | ! Example | + | ! Example || colspan="3" | Rendering |
| + | |- | ||
| + | | Only value || {{bartable|272||-1}} | ||
| + | |- | ||
| + | | Negative value || {{bartable|-72||-1}} | ||
|- | |- | ||
| − | | | + | | Math expression || {{bartable|exp(1)*1e2||-1}} |
|- | |- | ||
| − | | | + | | Value and unit (note added space) || {{bartable|272| km/h|-1}} |
|- | |- | ||
| − | | | + | | Value and unit (link to definition) || {{bartable|272|[[Degree_(angle)|°]]|-1}} |
|- | |- | ||
| − | | Value and | + | | Value and unit (with formatting) || align="right"|''θ'' = {{bartable|272|°|-1}} |
|- | |- | ||
| − | | Value and | + | | Value and unit (with conversion) || {{bartable|272|/km/mi|-1}} |
|- | |- | ||
| − | | Value and scale | + | | Value and scale || {{bartable|272||-1/(2^0.5)}} |
|- | |- | ||
| − | | Value and height | + | | Value and height || {{bartable|272||-1|4px}} |
|- | |- | ||
| − | | Value and style | + | | Value and style || {{bartable|272||-1||background:blue;}} |
|- | |- | ||
| − | | Value with commas and scale || {{bartable|2,720||-.1}} | + | | Value with commas, and scale || {{bartable|2,720||-.1}} |
|- | |- | ||
| − | | The full monty | + | | The full monty || {{bartable|18^2|%|sin(-1)|2em|border:ridge red;}} |
|- | |- | ||
|} | |} | ||
| − | <includeonly> | + | == See also == |
| + | * {{tl|composition bar}} | ||
| + | * {{tl|bar chart}} | ||
| + | |||
| + | <includeonly>{{Sandbox other|| | ||
<!-- Categories and interwikis go here: --> | <!-- Categories and interwikis go here: --> | ||
| − | [[Category:Table | + | [[Category:Table templates]] |
[[Category:Conversion templates]] | [[Category:Conversion templates]] | ||
| − | </includeonly> | + | }}</includeonly> |
Latest revision as of 23:39, 23 April 2020
| This is a documentation subpage for Template:Bartable. It contains usage information, categories and other content that is not part of the original template page. |
This template adds an inline bar graph to tables with numeric (including negative) values that a reader may wish to compare.
Use this template inside a table. The template generates either two table cells (for cases in which all values are positive) or three (to accommodate negative bars going off to the left). Thus, your table headers should have colspan="2" or colspan="3" (or similar combinations), respectively, to correctly span the columns.
The template generates two cells if the scale parameter is positive and three if it is negative.
Contents
Usage
{{bartable|value|unit|scale|height|style}}
- value (mandatory)
- any real number or math expression that evaluates to a number. Commas can be used to group digits. See Help:Calculation for the syntax for math expressions.
- unit (default = empty string)
- the unit, e.g. "m" for metres. Prepend a space if you want a space between the value and the unit. If unit starts with "/", the value is converted between units (using the convert template) as follows:
- "/unit1/unit2/round" converts the value from unit1 to unit2 and rounds it to round decimal places (using
{{convert|value|unit1|unit2|round|abbr=on}}). Unfortunately unit1, unit2 or round cannot contain a "/" or a "=" — if anyone knows how to allow it (or translate other characters to it), please help.
- "/unit1/unit2/round" converts the value from unit1 to unit2 and rounds it to round decimal places (using
- scale (default = 1)
- a factor multiplied by value to give the width of the bar in pixels. Use the same scale in every row, as otherwise the bar chart won’t be to scale!
- scale can be negative, in which case an additional column (for showing negative values) is created. See example below.
- height (default = "2ex")
- the height of the bar as a CSS measurement e.g. "1em" or "16px".
- style (default = empty string)
- a CSS style string to apply to the bar, e.g. "background:red;".
Examples
Real-world example
{| class="wikitable"
|+ Melting point at 1 atmosphere
! Substance !! Temperature !! colspan="2" | Relative size
|-
| Mercury || {{bartable| -38.72|/C/F|-2|1em|background:silver}}
|-
| Bromine || {{bartable| -7.10|/C/F|-2|1em|background:brown}}
|-
| Water || {{bartable| 0|/C/F|-2|1em}}
|-
| Phosphorus || {{bartable| 44.10|/C/F|-2|1em|background:red}}
|-
| Iodine || {{bartable| 113.50|/C/F|-2|1em|background:indigo}}
|-
| Sulphur || {{bartable| 115.36|/C/F|-2|1em|background:yellow}}
|}
| Substance | Temperature | Relative size | |
|---|---|---|---|
| Mercury | −38.72 °C (−37.70 °F) | ||
| Bromine | −7.10 °C (19.22 °F) | ||
| Water | 0 °C (32 °F) | ||
| Phosphorus | 44.10 °C (111.38 °F) | ||
| Iodine | 113.50 °C (236.30 °F) | ||
| Sulphur | 115.36 °C (239.65 °F) | ||
2-column (only positive values)
{| class="wikitable"
! Example || colspan="2" | Rendering
|-
| Only value || {{bartable|272}}
|-
| Negative value || {{bartable|-72}}
|-
| Math expression || {{bartable|exp(1)*1e2}}
|-
| Value and unit (note added space) || {{bartable|272| km/h}}
|-
| Value and unit (link to definition) || {{bartable|272|[[Degree_(angle)|°]]}}
|-
| Value and unit (with formatting) || align="right"|''θ'' = {{bartable|272|°}}
|-
| Value and unit (with conversion) || {{bartable|272|/km/mi}}
|-
| Value and scale || {{bartable|272||1/(2^0.5)}}
|-
| Value and height || {{bartable|272|||4px}}
|-
| Value and style || {{bartable|272||||background:blue;}}
|-
| Value with commas, and scale || {{bartable|2,720||.1}}
|-
| The full monty || {{bartable|18^2|%|sin(1)|2em|border:ridge red;}}
|-
|}
| Example | Rendering | |
|---|---|---|
| Only value | 272 | |
| Negative value | -72 | |
| Math expression | exp(1)*1e2 | |
| Value and unit (note added space) | 272 km/h | |
| Value and unit (link to definition) | 272° | |
| Value and unit (with formatting) | θ = 272° | |
| Value and unit (with conversion) | 272 km (169 mi) | |
| Value and scale | 272 | |
| Value and height | 272 | |
| Value and style | 272 | |
| Value with commas, and scale | 2,720 | |
| The full monty | 18^2% | |
3-column (positive and negative values)
{| class="wikitable"
! Example || colspan="3" | Rendering
|-
| Only value || {{bartable|272||-1}}
|-
| Negative value || {{bartable|-72||-1}}
|-
| Math expression || {{bartable|exp(1)*1e2||-1}}
|-
| Value and unit (note added space) || {{bartable|272| km/h|-1}}
|-
| Value and unit (link to definition) || {{bartable|272|[[Degree_(angle)|°]]|-1}}
|-
| Value and unit (with formatting) || align="right"|''θ'' = {{bartable|272|°|-1}}
|-
| Value and unit (with conversion) || {{bartable|272|/km/mi|-1}}
|-
| Value and scale || {{bartable|272||-1/(2^0.5)}}
|-
| Value and height || {{bartable|272||-1|4px}}
|-
| Value and style || {{bartable|272||-1||background:blue;}}
|-
| Value with commas, and scale || {{bartable|2,720||-.1}}
|-
| The full monty || {{bartable|18^2|%|sin(-1)|2em|border:ridge red;}}
|-
|}
| Example | Rendering | ||
|---|---|---|---|
| Only value | 272 | ||
| Negative value | -72 | ||
| Math expression | exp(1)*1e2 | ||
| Value and unit (note added space) | 272 km/h | ||
| Value and unit (link to definition) | 272° | ||
| Value and unit (with formatting) | θ = 272° | ||
| Value and unit (with conversion) | 272 km (169 mi) | ||
| Value and scale | 272 | ||
| Value and height | 272 | ||
| Value and style | 272 | ||
| Value with commas, and scale | 2,720 | ||
| The full monty | 18^2% | ||
See also
- {{composition bar}}
- {{bar chart}}