Built-In Namespace _global_
| Method Attributes | Method Name and Description |
|---|---|
|
calcinterest(event)
Calculates the interest and other results from given inputs.
|
|
|
Determine begin and end date of investment.
|
|
|
checkForUpdates(event)
Checks to see if there is a new version available.
|
|
|
compare(i1, i2)
Compare two items.
|
|
|
compareVersions(v1, i2)
Compare 2 versions of the format n.n.n.
|
|
|
datechange(event)
Called then duration or durationunit changes.
|
|
|
extractNumber(id)
Get a number from a form element and remove ,$%.
|
|
|
formatNumber(n)
Prepare a number for a prettier display.
|
|
|
hide()
Called by when widget is hidden.
|
|
|
Either shows or displays the 2 elements (1 on front, 1 on back)
that indicate a version update is available.
|
|
|
load()
Called by onload when widget start.
|
|
|
remove()
Called when widget is removed from dashboard.
|
|
|
runTest(code, result)
Eval's the given code and tests the result against the
given expected result.
|
|
|
Saves the values in form elements to instance preferences.
|
|
|
setDisplay(elid, dval)
Sets the 'display' attribut of the element specified by the
the given element id to the given value.
|
|
|
shouldCompound(freq, dte, day)
Determines if the give dte is the appropriate one according to the
given frequency to perform compounding or deposits.
|
|
|
show()
Called by onload when widget is shown.
|
|
|
showBack(event)
Shows the back of the widget.
|
|
|
showFront(event)
Shows the front of the widget.
|
|
|
sync()
Called when widget is synchronized with .mac
|
|
|
test()
tests the functions in this file.
|
|
|
updateDates(starttime, endtime)
Update the Dates element of the widget to give dates.
|
|
|
updateResult(elid, promptid, res)
Updates the element associated to the given elid with the
given res number.
|
Method Detail
calcinterest(event)
Calculates the interest and other results from given inputs.
This is the main routine for the widget. It extracts all
of the various inputs and then calculates the accumulated amount and
an inflation adjusted total. It also splits out the interest growth
vs. the deposits and displays the totals. For a more detailed description
of the inputs and outputs see the user documentation, which is generated
from the comments at the top of this file.
This function uses an iterative method to determine the compounding.
It loops through all of the days in the duration of the investment and
calls "shouldCompound" to see if the interest should be compounded and
likewise if the deposit should be applied. If so, the appropriate
amount is added to the totals. Applying the correct interest for the
deposits can be confusing.
In order to allow for long investment periods, time value of
money formulas are used for durations of more than 100 years. This
is to avoid performance issues with the iterative method.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
- Parameters:
- event
- - event that invoked this function call
calculateStartAndEndDate()
Determine begin and end date of investment.
Assumes the starting date is the first day of the current year. Looks
at the duration and duration-unit input elements to determine the
ending date.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
- Returns:
- array of millisecs since epoch - 1st element is start, 2nd is end
checkForUpdates(event)
Checks to see if there is a new version available. It does
this by setting up the XMLRequest for the json object containing
the version info. There is a sub-function that waits until the
request is complete and then checks the retrieved version
against the current version.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
- Parameters:
- event
- - event that invoked this function call
compare(i1, i2)
Compare two items.
Defined in: ghlib.js.
Defined in: ghlib.js.
- Parameters:
- i1
- - first item to compare
- i2
- - second item to compare
- Returns:
- - -1 if i1 < i2 ; 0 if equal ; and 1 if i1 > i2
compareVersions(v1, i2)
Compare 2 versions of the format n.n.n. For example, 10.2.3
is less than 10.11.3. A string compare would not figure this out.
This function just splits the versions by the . segments. It then
makes the resulting array sizes equal and calls compare on each
segment.
Defined in: ghlib.js.
Defined in: ghlib.js.
- Parameters:
- v1
- - first version to compare
- i2
- - second version to compare
- Returns:
- - -1 if v1 < v2 ; 0 if equal ; and 1 if v1 > v2
datechange(event)
Called then duration or durationunit changes. Updates end date
determines the new start and end date and called updateDates
to update them in the view.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
- Parameters:
- event
- - event that invoked this function call
extractNumber(id)
Get a number from a form element and remove ,$%.
Uses the replace function to remove nonnumeric decorations
around a number
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
- Parameters:
- id
- - id of form element to get number from
- Returns:
- - a numeric string with only digits and .
formatNumber(n)
Prepare a number for a prettier display.
Adds commas at appropriate places to a given number in order
to make that number more readable. If number is large enough
to be displayed using exponential notation, then leave it
alone.
Defined in: ghlib.js.
Defined in: ghlib.js.
- Parameters:
- n
- - the floating or int number to format
- Returns:
- - a pretty numeric string (ie. with ,)
hide()
Called by when widget is hidden.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
hideOrShowUpdateAvail(s)
Either shows or displays the 2 elements (1 on front, 1 on back)
that indicate a version update is available.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
- Parameters:
- s
- - string - "hide" or "show" to indicate what to do
load()
Called by onload when widget start. Loads values into fields.
First, calls the setupParts from DashCode to setup various html
elements. Then it retrieves the preferences for deposittime (which
can be at beginning or end of period) and inflation rate and loads
these into the appropriate form elements.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
remove()
Called when widget is removed from dashboard. Cleans up.
Removes the preferences used by this widget. No timers
are used, but if they were, they would need to be removed.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
runTest(code, result)
Eval's the given code and tests the result against the
given expected result. Uses 'alert' to send a message to the
console with either a 'passed' or a 'failed' depending on
where the result matches the expected result.
Defined in: ghlib.js.
Defined in: ghlib.js.
- Parameters:
- code
- - code to run (string)
- result
- - expected result from eval'ing code
savePreferences()
Saves the values in form elements to instance preferences.
The preferences are on the back of the widget. The 2 preference
items are the inflation rate and whether to assume deposits are at
the beginning or end of the period. These are save when the 'Done'
button on the back of the widget is clicked. They are instance
widgets so that multiple instances of compoundeeyo, each with
different values for these preferences, can be placed on the
dashboard.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
setDisplay(elid, dval)
Sets the 'display' attribut of the element specified by the
the given element id to the given value. The values will usually be
'none', or 'block', but any of the valid CSS values can be used.
Defined in: ghlib.js.
Defined in: ghlib.js.
- Parameters:
- elid
- - id of element to set attribute for
- dval
- - value to set 'display' attribute to
{, }
shouldCompound(freq, dte, day)
Determines if the give dte is the appropriate one according to the
given frequency to perform compounding or deposits. If the give day
is beginning of the period than dte will have to be the first day of
the year or month or quarter,... If the give day is 'end' dte needs to
be the last day of the month, year, quarter,...
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
- Parameters:
- freq
- - the compounding or deposit frequency
- dte
- - the date to check
- day
- - apply are beginning or end of period
- Returns:
- 1 if dte is the date to compound
- 0 if dte is NOT the date to compound
show()
Called by onload when widget is shown.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
showBack(event)
Shows the back of the widget.
Sets the front to hide and the back image to show. Calls
timeout to invoke the transition.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
- Parameters:
- event
- - event (onclick) that invoked this function call
showFront(event)
Shows the front of the widget.
Sets the back to hide and the front image to show. Calls
timeout to invoke the transition. Additionally, this function saves
the values from the form fields on the back of the widget to
instance preferences.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
- Parameters:
- event
- - event (onclick) that invoked this function call
sync()
Called when widget is synchronized with .mac
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
test()
tests the functions in this file.
Defined in: ghlib.js.
Defined in: ghlib.js.
updateDates(starttime, endtime)
Update the Dates element of the widget to give dates.
Formats a string with the given information and updates the display
with that string.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
- Parameters:
- starttime
- - msecs-since-epoch of the start time of the investment
- endtime
- - msecs-since-epoch of the ending time of the investment
updateResult(elid, promptid, res)
Updates the element associated to the given elid with the
given res number. The main purpose of this function is to make
sure that the given text will fit on the widget. If it doesn't
the font size of both the label and the element being updated
will be shrunken until it does fit. The first thing this
function does is to call formatNumber on the result. For reallly
large numbers, the exponential format is used.
Defined in: compoundeeyo.js.
Defined in: compoundeeyo.js.
- Parameters:
- elid
- - Id of element to be updated
- promptid
- - Id of element that servers as the label for elid
- res
- - number to update elid to