Parameters and Calculations


A parameter is like a variable that can be used in functions. At its simpest, it consists of a name and a value:

params: - {name: a, value: 3} - {name: b, value: 0.5} layout: HTMLLayout: html: "`

The value of $a$ is ${params.a}.

The value of $b$ is ${params.b}.

`"

Fundamentally, a parameter is a variable which the user can adjust, either via a slider or by manipulating something on the graph. The initial value of the parameter is determined by the value attribute on the parameter definition; the range of the slider is determined by the min and max attributes. For example, this sets the initial value of a to 3, and sets it range to be between 0 and 10:

params: - {name: a, value: 3, min: 0, max: 10} layout: HTMLPlusSidebarLayout: html: "`

The value of $a$ is ${params.a}.

`" sidebar: controls: - title: Parameters sliders: - {param: a, label: a}

By default, parameters are integers; you can change the precision of a by creating a round command. Here, we round a to the nearest tenth:

params: - {name: a, value: 3, min: 0, max: 10, round: 0.1} layout: HTMLPlusSidebarLayout: html: "`

The value of $a$ is ${params.a}.

`" sidebar: controls: - title: Rounding Parameters sliders: - {param: a, label: a}

Drag the slider back and forth. Oh no! It displays badly. We can fix this by adding a .toFixed(1) in the HTML:

params: - {name: a, value: 3, min: 0, max: 10, round: 0.1} layout: HTMLPlusSidebarLayout: html: "`

The value of $a$ is ${params.a.toFixed(1)}.

`" sidebar: controls: - title: Nicely Rounding Parameters sliders: - {param: a, label: a}
KGJS
KineticGraphs.org
Getting Started

About the Project

Authoring Sandbox

Graphs & Layouts

Layouts

Sidebars

Graphs

Trees

3D Graphs

Graph Objects

Styling Graph Objects

Points

Lines

Curves

Contours

Shapes and Areas

Segments and Arrows

Angles and Angle Markers

User Interactions

Parameters

Calculations

Dragging

Economics

Econ Schema

Supply and Demand

Consumer Optimization

Exchange