Class Index | File Index

Classes


Class slikcalc.FormulaCalc

FormulaCalc
Defined in: FormulaCalc.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Calculator object that calculates based on a given formula and mapped variables.
Field Summary
Field Attributes Field Name and Description
 
Formula used to calculate the total for a row
 
Holds the formula value once it has been parsed, and the equality portion has been removed
 
Property to hold the variable from the formula that specifies where the result goes
 
Array of row objects for the calculator
 
Array of the variables parsed from the formula
 
Regular Expression to find variables in the formula
Method Summary
Method Attributes Method Name and Description
 
addRow(rowConfig)
Adds a row to the calculator to be included in the calculations
 
Processes the rows and applies the formula to each one.
 
Method run on page load to parse the formula, and pull out variables within it.
Class Detail
slikcalc.FormulaCalc(config)
Calculator object that calculates based on a given formula and mapped variables. Calculates across multiple rows as well,updating a single totals value based on a given mathematical operator.
Parameters:
{Object} config
Configuration object, all options of slikcalc.BaseCalc plus the following:
  • formula : Mathematical formula in string form. Variables denoted within the '{}' that map to vars definitions passed in on the addRow method. Example: "{a} + {b} = {c}". "{a} + {b}" is used as the formula, and {c} becomes the position that the eval'd result is placed into.
  • total.vars : Variables configuration object, see slikcalc.FormulaCalc.addRow() for details. If passed in here, an initial row is added
Field Detail
formula
Formula used to calculate the total for a row

formulaParsed
Holds the formula value once it has been parsed, and the equality portion has been removed

resultVar
Property to hold the variable from the formula that specifies where the result goes

rows
Array of row objects for the calculator

variables
Array of the variables parsed from the formula

varMatch
Regular Expression to find variables in the formula
Method Detail
addRow(rowConfig)
Adds a row to the calculator to be included in the calculations
Parameters:
{Object} rowConfig
Configuration object for the row being added to the calculator. It may contain the following options:
  • vars : Object containing one to many variable definitions
  • vars.x : Configuration object for variable 'x' where x represents a variable in the formula
  • vars.x.id : Element id for the input mappted to variable 'x' in formula
  • vars.x.defaultValue : (Optional) Value used in place of empty/null for variable 'x'. Defaults to 0
  • checkbox.id : Element id of checkbox. Required if config[checkbox] included
  • checkbox.invert : Defaults to false. If true, row is included in total calculcation when un-checked, and omitted when checked

calculate()
Processes the rows and applies the formula to each one.

initialize()
Method run on page load to parse the formula, and pull out variables within it.

Documentation generated by JsDoc Toolkit 2.0.2 on Thu Sep 11 2008 15:52:44 GMT-0600 (MDT)