common functions
functions that are useful everywhere...
- Source:
Methods
-
<static> makeSVGright(tag, attrs) → {SVGElement}
-
Creates an SVGElement of an SVG figure using the correct
document.createElementNS
call.Parameters:
Name Type Argument Default Description tag
string <optional>
'svg' a tag, such as 'rect', 'circle', 'text', or 'svg'
attrs
Object <optional>
attributes to pass to the tag.
- Source:
Returns:
- Type
- SVGElement
-
<static> merge(destination, source) → {Object}
-
concept borrowed from Vex.Flow.Merge, though here the source can be undefined;
http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically
recursive parts used in .clone()Parameters:
Name Type Description destination
Object object to have attributes placed into
source
Object object to take attributes from.
- Source:
Returns:
destination
- Type
- Object
-
<static> ordinalAbbreviation(value, plural) → {string}
-
Take a number such as 32 and return a string such as "nd"
(for "32nd") etc.Parameters:
Name Type Argument Default Description value
int plural
Boolean <optional>
false make plural (note that "21st" plural is "21st")
- Source:
Returns:
- Type
- string
-
<static> rationalize(ql, epsilon, maxDenominator) → {object|undefined}
-
Find a rational number approximation of this floating point.
Parameters:
Name Type Argument Default Description ql
number number to rationalize
epsilon
number <optional>
0.001 how close to get
maxDenominator
int <optional>
50 maximum denominator
- Source:
Returns:
{'numerator: numerator, 'denominator': denominator}
- Type
- object | undefined
-
<static> setWindowVisibilityWatcher(callback)
-
runs a callback with either "visible" or "hidden" as the argument anytime the
window or document state changes.Depending on the browser, may be called multiple times with the same argument
for a single event. For instance, Safari calls once on losing focus completely
but twice for a tab change.Parameters:
Name Type Description callback
function - Source:
-
<static> statisticalMode(a) → {Object}
-
Returns the statistical mode (most commonly appearing element)
in a.In case of tie, returns the first element to reach the maximum
number of occurrences.Parameters:
Name Type Description a
Array.<*> an array to analyze
- Source:
Returns:
element with the highest frequency in a
- Type
- Object
-
<static> stripPx(str) → {number}
-
Change something that could be a string or number and might
end with "px" to a number."400px" -> 400
Parameters:
Name Type Description str
number | string - string that might have 'px' at the end or not
- Source:
Returns:
a number to use
- Type
- number
-
<static> urlParam(name) → {string}
-
Find name in the query string (?name=value) and return value.
Parameters:
Name Type Description name
string url parameter to find
- Source:
Returns:
may be "" if empty.
- Type
- string