Skip to content

ThermometerNode

ThermometerNode (from scenerystack/scenery-phet) draws a classic bulb-and-tube thermometer whose fluid level tracks a temperature value between a min and max. It handles the glass outline, tick marks, and the clipped fluid shape for you — you only supply the temperature Property and the range it can take.

ts
import { ThermometerNode } from 'scenerystack/scenery-phet';
import { Property } from 'scenerystack/axon';

A minimal example

ts
const temperatureProperty = new Property<number | null>( 20 );

const thermometer = new ThermometerNode( temperatureProperty, 0, 100, {
  bulbDiameter: 50,
  tubeHeight: 150,
  tickSpacingTemperature: 10 // one tick every 10 degrees, instead of every fixed pixel spacing
} );

Constructor

ts
new ThermometerNode(
  temperatureProperty: TReadOnlyProperty<number | null>,
  minTemperature: number,
  maxTemperature: number,
  providedOptions?: ThermometerNodeOptions
)

Options

OptionDefaultEffect
bulbDiameter50Diameter of the bulb at the bottom
tubeWidth30Width of the tube
tubeHeight100Height of the straight part of the tube
lineWidth4Stroke width of the glass outline
outlineStroke'black'Color of the glass outline
glassThickness4Gap between the outline and the fluid inside it
tickSpacing15Pixel spacing between tick marks
tickSpacingTemperaturenullIf set, overrides tickSpacing to space ticks by units of temperature instead of pixels
majorTickLength / minorTickLength15 / 7.5Lengths of alternating major/minor ticks
zeroLevel'bulbCenter'Where the fluid level sits at minTemperature'bulbCenter' or 'bulbTop'
backgroundFillnullIf set, an extra Path is drawn behind the fluid in this color; null leaves the tube background transparent
fluidMainColor / fluidHighlightColor / fluidRightSideColorshades of redColors for the bulb fluid and the tube's gradient

Methods

MethodEffect
temperatureToYPos( temperature )Converts a temperature (or null) to the internal y-coordinate used for tick placement
yPosToTemperature( y )Inverse of the above, useful for mapping a draggable thumb position back to a temperature

A null temperature is treated as the literal value 0, not minTemperature

temperatureProperty accepts number | null. Internally, ThermometerNode substitutes the literal number 0 for null before mapping it through the temperature-to-height function (a legacy requirement carried over from States of Matter) — it does not hide the fluid or throw. This only reads the same as minTemperature when minTemperature happens to be 0; with a non-zero minTemperature (e.g. a negative range), a null reading shows the fluid level for temperature 0, not the bottom of the tube. If you need "no reading" to look visually distinct, handle that in a sibling Node rather than expecting ThermometerNode to do it.