Gauge
A dial and its needle, drawn in svg at the size of the component. The needle is moved by setPos: it has no prop.
import { Gauge } from "x4js"
setPos
setPos moves the needle; here a Slider gives the position.
export function setPos( ) {
const gauge = new Gauge( { width: 240, height: 130 } );
gauge.setPos( 30 );
return new VBox( { content: [
gauge,
new Slider( { width: 240, value: 30, min: 0, max: 100, change: ( ev ) => gauge.setPos( ev.value ) } ),
] } );
}
Colors
colors: the arcs of the dial, from the left; simpleColorStop is one arc of the color of the theme.
export function colors( ) {
return new HBox( { content: [
new Gauge( { width: 200, height: 110, colors: simpleColorStop } ),
new Gauge( { width: 200, height: 110, colors: [ "#2f9e44", "#f59f00", "#e03131" ] } ),
] } );
}
setRange
The range is from min to max (0 to 100 when missing); setRange changes it, the needle keeps its value.
export function setRange( ) {
const gauge = new Gauge( { width: 240, height: 130, min: -20, max: 40 } );
const label = new Label( { text: "-20 °C to 40 °C, 15 °C" } );
gauge.setPos( 15 );
return new HBox( { content: [
gauge,
new VBox( { content: [
new Button( { label: "-20 to 40", cls: "outline", click: ( ) => {
gauge.setRange( -20, 40 );
label.setText( "-20 °C to 40 °C, 15 °C" );
} } ),
new Button( { label: "0 to 20", cls: "outline", click: ( ) => {
gauge.setRange( 0, 20 );
label.setText( "0 °C to 20 °C, 15 °C" );
} } ),
label,
] } ),
] } );
}
For an assistant: llms.txt, llms-full.txt.