Installation

Show a figure together with how it came about (a derivation, a statement of account): the operator before each number, the result above a double rule, and every figure opening into the numbers it came from.

import { Calculation, Given, Difference, Quotient, Ref } from "@umriss-ui/calculation";
npm install @umriss-ui/calculation @umriss-ui/core

The command brings the core package along, a peer dependency: it gives the calculation its formats, its wording and the assessment of targets and limits. React 19 or newer is a peer as well and stays the application's own.

The stylesheet loads itself: the package imports it and marks CSS as a side effect, so a bundler keeps it. @umriss-ui/calculation/styles.css stays exported for setups that link stylesheets by hand.

You write the figure as elements and hand in only the givens; the calculation performs every operation it shows, so the screen cannot disagree with the number. Start with Calculation.

Examples

The availability of a service

Write the figure as elements; the calculation computes every number on the screen and assesses the result against its target.

import { Calculation, Difference, Given, Quotient, Ref } from "@umriss-ui/calculation";

export default function Availability() {
  return (
    <Calculation aria-label="Availability of Checkout, March so far">
      <Quotient label="Availability, Checkout" format="percent" decimals={2} target={0.9995}>
        <Difference label="Minutes up" unit="min">
          <Given id="month" label="Minutes this month" value={23670} unit="min" />
          <Given label="Minutes down" value={34} unit="min" />
        </Difference>
        <Ref to="month" />
      </Quotient>
    </Calculation>
  );
}

Keyboard

The keys of Calculation apply here.

Props on this page

From CalculationProps — the full table stands on Calculation.

NameTypeDefaultDescription
childrenrequiredReactNode—The result: exactly one quantity - a tree (<Sum>, <Difference>, <Product>, <Quotient> with their operands, <Given> as leaves) or a <Chain>, the two mixing freely; <Ref> for a quantity defined elsewhere.

From OperatorProps — the full table stands on Tree.

NameTypeDefaultDescription
childrenReactNode—The operands, in order: quantities, givens and references.
labelrequiredstring—What the quantity is called. It stands on its line, wherever it is an operand, and in the accessible sentence. from QuantityProps
idstring—Makes the quantity referable: <Ref to> stands for it elsewhere. Needed only for a quantity used more than once. from QuantityProps
unitstring—A label written after the number - "min", "pcs", "€". Never converted and never checked; the calculation does no unit algebra. from QuantityProps
format"percent"—percent presents a plain ratio as per cent: 0.916 is shown as 91.6 %. The quantity stays a ratio in every operation. from QuantityProps
decimalsnumberone digit for a percentage, at most two for a derived number, a given as it was givenFixed number of fraction digits as shown. Rounding happens only in presentation; every operation uses the full value. from QuantityProps
targetnumber—The value this quantity is meant to reach - missed, never violated. from QuantityProps

From RefProps — the full table stands on Tree.

NameTypeDefaultDescription
torequiredstring—The id of the quantity this reference stands for.

From ChainOperandProps — the full table stands on Chain.

NameTypeDefaultDescription
idstring—Makes the quantity referable: <Ref to> stands for it elsewhere. Needed only for a quantity used more than once. from QuantityProps
unitstring—A label written after the number - "min", "pcs", "€". Never converted and never checked; the calculation does no unit algebra. from QuantityProps
format"percent"—percent presents a plain ratio as per cent: 0.916 is shown as 91.6 %. The quantity stays a ratio in every operation. from QuantityProps
decimalsnumberone digit for a percentage, at most two for a derived number, a given as it was givenFixed number of fraction digits as shown. Rounding happens only in presentation; every operation uses the full value. from QuantityProps
targetnumber—The value this quantity is meant to reach - missed, never violated. from QuantityProps

From QuantityProps — the full table stands on Chain.

NameTypeDefaultDescription
labelrequiredstring—What the quantity is called. It stands on its line, wherever it is an operand, and in the accessible sentence.
idstring—Makes the quantity referable: <Ref to> stands for it elsewhere. Needed only for a quantity used more than once.
unitstring—A label written after the number - "min", "pcs", "€". Never converted and never checked; the calculation does no unit algebra.
format"percent"—percent presents a plain ratio as per cent: 0.916 is shown as 91.6 %. The quantity stays a ratio in every operation.
decimalsnumberone digit for a percentage, at most two for a derived number, a given as it was givenFixed number of fraction digits as shown. Rounding happens only in presentation; every operation uses the full value.
targetnumber—The value this quantity is meant to reach - missed, never violated.

From GivenProps — the full table stands on Given.

NameTypeDefaultDescription
valuerequired| number
| null
| undefined
| MetricValues
—The number the calculation starts from. Absent (null, undefined, not finite) makes every quantity that depends on it absent, with the reason - never zero. Where the calculation has metrics, an object with a number for each metric id instead; absence then stays in its metric.
labelrequiredstring—What the quantity is called. It stands on its line, wherever it is an operand, and in the accessible sentence. from QuantityProps
idstring—Makes the quantity referable: <Ref to> stands for it elsewhere. Needed only for a quantity used more than once. from QuantityProps
unitstring—A label written after the number - "min", "pcs", "€". Never converted and never checked; the calculation does no unit algebra. from QuantityProps
format"percent"—percent presents a plain ratio as per cent: 0.916 is shown as 91.6 %. The quantity stays a ratio in every operation. from QuantityProps
decimalsnumberone digit for a percentage, at most two for a derived number, a given as it was givenFixed number of fraction digits as shown. Rounding happens only in presentation; every operation uses the full value. from QuantityProps
targetnumber—The value this quantity is meant to reach - missed, never violated. from QuantityProps

Every page of @umriss-ui/calculation

Getting started

Writing a calculation

In practice

API index