<tally>
<tally> is a General Operator
component that renders how many times each category appears among its arguments: a list
of counts, one per category. Where <count> reports how many values there
are in total, <tally> reports how many there are of each kind.
Attributes and Properties
Attributes for <tally>
Highlighted (3)
asListboolean. Default value: true. Whether to render the items separated by commas (true) or with no separator (false).
[ _componentListWithSelectableType ]. The categories to count, in the order the counts are reported. Omit to count the distinct values present, in sorted order.
keyword. Component type to interpret bare string children as. Omit it and they are read as what they look like: every piece naming a number makes the list numeric, anything else makes it text. Also overrides how categories is read, which is otherwise text.
| Value | Description |
|---|---|
number | Read bare strings as numbers, ordered by value. |
math | Read bare strings as math expressions, ordered by value. |
text | Read bare strings as text, ordered alphabetically. |
boolean | Read bare strings as booleans, ordered with false before true. |
Other (5)
avoidScientificNotationWhether to render numbers in full decimal form rather than scientific notation.
displayDecimalsNumber of decimal places to display when rendering this number.
displayDigitsNumber of significant digits to display when rendering this number.
displaySmallAsZeroThreshold below which numbers are displayed as zero.
padZerosWhether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.
Common to all components (9)
copyreference. Create an independent copy of another component by reference. Enter a references a $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedDefault value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. Default value: 1. The style number used to select this component's visual styling from the available style definitions.
Properties for <tally name="t">
Highlighted (1)
$t.categoriesThe categories the counts are counts of, in the same order.
Common to all components (4)
$t.doenetMLtext. The DoenetML source code that produced this component.
$t.hideboolean. Whether to hide this component from the rendered output.
$t.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$t.styleNumberinteger. The style number used to select this component's visual styling from the available style definitions.
Examples
Example: counting the values that are there
With no categories attribute, the categories are whatever distinct values turned up,
in sorted order.
Example: counting a simulation
Three tags do the whole simulation:
<cumulativeSum> accumulates the subpopulation sizes,
<searchSorted> maps every draw onto the subpopulation it landed
in, and <tally> counts them. Because every draw lands in exactly one
subpopulation, the counts always sum to the number of samples.
Example: values outside the declared categories
A value matching none of the declared categories is not counted anywhere, so the counts do not sum to the number of values. This occurrence is reported as an informational message.
Attribute Examples
Attribute Example: categories
Declaring the categories keeps a slot for the ones nothing matched — 2 and 4 here — so
the counts stay lined up with the faces they are counts of. Left to infer its own
categories, <tally> would report only the four values that actually appeared.
Attribute Example: type
Bare strings are read as what they look like, so 007 and 008 count as the numbers 7
and 8, and the leading zeros are gone from the categories. type="text" keeps a numeral
that is a label rather than a quantity — a jersey number, a ZIP code, a room number —
whole.
type="math" is for the other direction. Neither 2x nor 2*x is a number, so both are
read as text and compared letter by letter, which makes them two categories. Read as
maths they are the same expression, and the three values are one category counted three
times.
Property Examples
Property Example: categories
The categories a <tally> inferred are readable back, so a chart or a table is
driven off the same component that did the counting.