first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,721 @@
YUI.add('axis-numeric-base', function (Y, NAME) {
/**
* Provides functionality for the handling of numeric axis data for a chart.
*
* @module charts
* @submodule axis-numeric-base
*/
var Y_Lang = Y.Lang;
/**
* NumericImpl contains logic for numeric data. NumericImpl is used by the following classes:
* <ul>
* <li>{{#crossLink "NumericAxisBase"}}{{/crossLink}}</li>
* <li>{{#crossLink "NumericAxis"}}{{/crossLink}}</li>
* </ul>
*
* @class NumericImpl
* @constructor
* @submodule axis-numeric-base
*/
function NumericImpl()
{
}
NumericImpl.NAME = "numericImpl";
NumericImpl.ATTRS = {
/**
* Indicates whether 0 should always be displayed.
*
* @attribute alwaysShowZero
* @type Boolean
*/
alwaysShowZero: {
value: true
},
/**
* Method used for formatting a label. This attribute allows for the default label formatting method to overridden.
* The method use would need to implement the arguments below and return a `String` or an `HTMLElement`. The default
* implementation of the method returns a `String`. The output of this method will be rendered to the DOM using
* `appendChild`. If you override the `labelFunction` method and return an html string, you will also need to override
* the Data' `appendLabelFunction` to accept html as a `String`.
* <dl>
* <dt>val</dt><dd>Label to be formatted. (`String`)</dd>
* <dt>format</dt><dd>Object containing properties used to format the label. (optional)</dd>
* </dl>
*
* @attribute labelFunction
* @type Function
*/
/**
* Object containing properties used by the `labelFunction` to format a
* label.
*
* @attribute labelFormat
* @type Object
*/
labelFormat: {
value: {
prefix: "",
thousandsSeparator: "",
decimalSeparator: "",
decimalPlaces: "0",
suffix: ""
}
},
/**
*Indicates how to round unit values.
* <dl>
* <dt>niceNumber</dt><dd>Units will be smoothed based on the number of ticks and data range.</dd>
* <dt>auto</dt><dd>If the range is greater than 1, the units will be rounded.</dd>
* <dt>numeric value</dt><dd>Units will be equal to the numeric value.</dd>
* <dt>null</dt><dd>No rounding will occur.</dd>
* </dl>
*
* @attribute roundingMethod
* @type String
* @default niceNumber
*/
roundingMethod: {
value: "niceNumber"
},
/**
* Indicates the scaling for the chart. The default value is `linear`. For a logarithmic axis, set the value
* to `logarithmic`.
*
* @attribute
* @type String
* @default linear
*/
scaleType: {
value: "linear"
}
};
NumericImpl.prototype = {
/**
* @method initializer
* @private
*/
initializer: function() {
this.after("alwaysShowZeroChange", this._keyChangeHandler);
this.after("roundingMethodChange", this._keyChangeHandler);
this.after("scaleTypeChange", this._keyChangeHandler);
},
/**
* Formats a label based on the axis type and optionally specified format.
*
* @method
* @param {Object} value
* @param {Object} format Pattern used to format the value.
* @return String
*/
formatLabel: function(val, format)
{
if(format)
{
return Y.DataType.Number.format(val, format);
}
return val;
},
/**
* Returns the sum of all values per key.
*
* @method getTotalByKey
* @param {String} key The identifier for the array whose values will be calculated.
* @return Number
*/
getTotalByKey: function(key)
{
var total = 0,
values = this.getDataByKey(key),
i = 0,
val,
len = values ? values.length : 0;
for(; i < len; ++i)
{
val = parseFloat(values[i]);
if(!isNaN(val))
{
total += val;
}
}
return total;
},
/**
* Returns the value corresponding to the origin on the axis.
*
* @method getOrigin
* @return Number
*/
getOrigin: function() {
var origin = 0,
min = this.get("minimum"),
max = this.get("maximum");
origin = Math.max(origin, min);
origin = Math.min(origin, max);
return origin;
},
/**
* Type of data used in `Data`.
*
* @property _type
* @readOnly
* @private
*/
_type: "numeric",
/**
* Helper method for getting a `roundingUnit` when calculating the minimum and maximum values.
*
* @method _getMinimumUnit
* @param {Number} max Maximum number
* @param {Number} min Minimum number
* @param {Number} units Number of units on the axis
* @return Number
* @private
*/
_getMinimumUnit:function(max, min, units)
{
return this._getNiceNumber(Math.ceil((max - min)/units));
},
/**
* Calculates a nice rounding unit based on the range.
*
* @method _getNiceNumber
* @param {Number} roundingUnit The calculated rounding unit.
* @return Number
* @private
*/
_getNiceNumber: function(roundingUnit)
{
var tempMajorUnit = roundingUnit,
order = Math.ceil(Math.log(tempMajorUnit) * 0.4342944819032518),
roundedMajorUnit = Math.pow(10, order),
roundedDiff;
if (roundedMajorUnit / 2 >= tempMajorUnit)
{
roundedDiff = Math.floor((roundedMajorUnit / 2 - tempMajorUnit) / (Math.pow(10,order-1)/2));
tempMajorUnit = roundedMajorUnit/2 - roundedDiff*Math.pow(10,order-1)/2;
}
else
{
tempMajorUnit = roundedMajorUnit;
}
if(!isNaN(tempMajorUnit))
{
return tempMajorUnit;
}
return roundingUnit;
},
/**
* Calculates the maximum and minimum values for the `Data`.
*
* @method _updateMinAndMax
* @private
*/
_updateMinAndMax: function()
{
var data = this.get("data"),
max,
min,
len,
num,
i = 0,
setMax = this.get("setMax"),
setMin = this.get("setMin");
if(!setMax || !setMin)
{
if(data && data.length && data.length > 0)
{
len = data.length;
for(; i < len; i++)
{
num = data[i];
if(isNaN(num))
{
max = setMax ? this._setMaximum : max;
min = setMin ? this._setMinimum : min;
continue;
}
if(setMin)
{
min = this._setMinimum;
}
else if(min === undefined)
{
min = num;
}
else
{
min = Math.min(num, min);
}
if(setMax)
{
max = this._setMaximum;
}
else if(max === undefined)
{
max = num;
}
else
{
max = Math.max(num, max);
}
this._actualMaximum = max;
this._actualMinimum = min;
}
}
if(this.get("scaleType") !== "logarithmic")
{
this._roundMinAndMax(min, max, setMin, setMax);
}
else
{
this._dataMaximum = max;
this._dataMinimum = min;
}
}
},
/**
* Rounds the mimimum and maximum values based on the `roundingUnit` attribute.
*
* @method _roundMinAndMax
* @param {Number} min Minimum value
* @param {Number} max Maximum value
* @private
*/
_roundMinAndMax: function(min, max, setMin, setMax)
{
var roundingUnit,
minimumRange,
minGreaterThanZero = min >= 0,
maxGreaterThanZero = max > 0,
dataRangeGreater,
maxRound,
minRound,
topTicks,
botTicks,
tempMax,
tempMin,
units = this.getTotalMajorUnits() - 1,
alwaysShowZero = this.get("alwaysShowZero"),
roundingMethod = this.get("roundingMethod"),
useIntegers = (max - min)/units >= 1;
if(roundingMethod)
{
if(roundingMethod === "niceNumber")
{
roundingUnit = this._getMinimumUnit(max, min, units);
if(minGreaterThanZero && maxGreaterThanZero)
{
if((alwaysShowZero || min < roundingUnit) && !setMin)
{
min = 0;
roundingUnit = this._getMinimumUnit(max, min, units);
}
else
{
min = this._roundDownToNearest(min, roundingUnit);
}
if(setMax)
{
if(!alwaysShowZero)
{
min = max - (roundingUnit * units);
}
}
else if(setMin)
{
max = min + (roundingUnit * units);
}
else
{
max = this._roundUpToNearest(max, roundingUnit);
}
}
else if(maxGreaterThanZero && !minGreaterThanZero)
{
if(alwaysShowZero)
{
topTicks = Math.round(units/((-1 * min)/max + 1));
topTicks = Math.max(Math.min(topTicks, units - 1), 1);
botTicks = units - topTicks;
tempMax = Math.ceil( max/topTicks );
tempMin = Math.floor( min/botTicks ) * -1;
if(setMin)
{
while(tempMin < tempMax && botTicks >= 0)
{
botTicks--;
topTicks++;
tempMax = Math.ceil( max/topTicks );
tempMin = Math.floor( min/botTicks ) * -1;
}
//if there are any bottom ticks left calcualate the maximum by multiplying by the tempMin value
//if not, it's impossible to ensure that a zero is shown. skip it
if(botTicks > 0)
{
max = tempMin * topTicks;
}
else
{
max = min + (roundingUnit * units);
}
}
else if(setMax)
{
while(tempMax < tempMin && topTicks >= 0)
{
botTicks++;
topTicks--;
tempMin = Math.floor( min/botTicks ) * -1;
tempMax = Math.ceil( max/topTicks );
}
//if there are any top ticks left calcualate the minimum by multiplying by the tempMax value
//if not, it's impossible to ensure that a zero is shown. skip it
if(topTicks > 0)
{
min = tempMax * botTicks * -1;
}
else
{
min = max - (roundingUnit * units);
}
}
else
{
roundingUnit = Math.max(tempMax, tempMin);
roundingUnit = this._getNiceNumber(roundingUnit);
max = roundingUnit * topTicks;
min = roundingUnit * botTicks * -1;
}
}
else
{
if(setMax)
{
min = max - (roundingUnit * units);
}
else if(setMin)
{
max = min + (roundingUnit * units);
}
else
{
min = this._roundDownToNearest(min, roundingUnit);
max = this._roundUpToNearest(max, roundingUnit);
}
}
}
else
{
if(setMin)
{
if(alwaysShowZero)
{
max = 0;
}
else
{
max = min + (roundingUnit * units);
}
}
else if(!setMax)
{
if(alwaysShowZero || max === 0 || max + roundingUnit > 0)
{
max = 0;
roundingUnit = this._getMinimumUnit(max, min, units);
min = max - (roundingUnit * units);
}
else
{
min = this._roundDownToNearest(min, roundingUnit);
max = this._roundUpToNearest(max, roundingUnit);
}
}
else
{
min = max - (roundingUnit * units);
}
}
}
else if(roundingMethod === "auto")
{
if(minGreaterThanZero && maxGreaterThanZero)
{
if((alwaysShowZero || min < (max-min)/units) && !setMin)
{
min = 0;
}
roundingUnit = (max - min)/units;
if(useIntegers)
{
roundingUnit = Math.ceil(roundingUnit);
max = min + (roundingUnit * units);
}
else
{
max = min + Math.ceil(roundingUnit * units * 100000)/100000;
}
}
else if(maxGreaterThanZero && !minGreaterThanZero)
{
if(alwaysShowZero)
{
topTicks = Math.round( units / ( (-1 * min) /max + 1) );
topTicks = Math.max(Math.min(topTicks, units - 1), 1);
botTicks = units - topTicks;
if(useIntegers)
{
tempMax = Math.ceil( max/topTicks );
tempMin = Math.floor( min/botTicks ) * -1;
roundingUnit = Math.max(tempMax, tempMin);
max = roundingUnit * topTicks;
min = roundingUnit * botTicks * -1;
}
else
{
tempMax = max/topTicks;
tempMin = min/botTicks * -1;
roundingUnit = Math.max(tempMax, tempMin);
max = Math.ceil(roundingUnit * topTicks * 100000)/100000;
min = Math.ceil(roundingUnit * botTicks * 100000)/100000 * -1;
}
}
else
{
roundingUnit = (max - min)/units;
if(useIntegers)
{
roundingUnit = Math.ceil(roundingUnit);
}
min = Math.round(this._roundDownToNearest(min, roundingUnit) * 100000)/100000;
max = Math.round(this._roundUpToNearest(max, roundingUnit) * 100000)/100000;
}
}
else
{
roundingUnit = (max - min)/units;
if(useIntegers)
{
roundingUnit = Math.ceil(roundingUnit);
}
if(alwaysShowZero || max === 0 || max + roundingUnit > 0)
{
max = 0;
roundingUnit = (max - min)/units;
if(useIntegers)
{
Math.ceil(roundingUnit);
min = max - (roundingUnit * units);
}
else
{
min = max - Math.ceil(roundingUnit * units * 100000)/100000;
}
}
else
{
min = this._roundDownToNearest(min, roundingUnit);
max = this._roundUpToNearest(max, roundingUnit);
}
}
}
else if(!isNaN(roundingMethod) && isFinite(roundingMethod))
{
roundingUnit = roundingMethod;
minimumRange = roundingUnit * units;
dataRangeGreater = (max - min) > minimumRange;
minRound = this._roundDownToNearest(min, roundingUnit);
maxRound = this._roundUpToNearest(max, roundingUnit);
if(setMax)
{
min = max - minimumRange;
}
else if(setMin)
{
max = min + minimumRange;
}
else if(minGreaterThanZero && maxGreaterThanZero)
{
if(alwaysShowZero || minRound <= 0)
{
min = 0;
}
else
{
min = minRound;
}
max = min + minimumRange;
}
else if(maxGreaterThanZero && !minGreaterThanZero)
{
min = minRound;
max = maxRound;
}
else
{
if(alwaysShowZero || maxRound >= 0)
{
max = 0;
}
else
{
max = maxRound;
}
min = max - minimumRange;
}
}
}
this._dataMaximum = max;
this._dataMinimum = min;
},
/**
* Rounds a Number to the nearest multiple of an input. For example, by rounding
* 16 to the nearest 10, you will receive 20. Similar to the built-in function Math.round().
*
* @method _roundToNearest
* @param {Number} number Number to round
* @param {Number} nearest Multiple to round towards.
* @return Number
* @private
*/
_roundToNearest: function(number, nearest)
{
nearest = nearest || 1;
var roundedNumber = Math.round(this._roundToPrecision(number / nearest, 10)) * nearest;
return this._roundToPrecision(roundedNumber, 10);
},
/**
* Rounds a Number up to the nearest multiple of an input. For example, by rounding
* 16 up to the nearest 10, you will receive 20. Similar to the built-in function Math.ceil().
*
* @method _roundUpToNearest
* @param {Number} number Number to round
* @param {Number} nearest Multiple to round towards.
* @return Number
* @private
*/
_roundUpToNearest: function(number, nearest)
{
nearest = nearest || 1;
return Math.ceil(this._roundToPrecision(number / nearest, 10)) * nearest;
},
/**
* Rounds a Number down to the nearest multiple of an input. For example, by rounding
* 16 down to the nearest 10, you will receive 10. Similar to the built-in function Math.floor().
*
* @method _roundDownToNearest
* @param {Number} number Number to round
* @param {Number} nearest Multiple to round towards.
* @return Number
* @private
*/
_roundDownToNearest: function(number, nearest)
{
nearest = nearest || 1;
return Math.floor(this._roundToPrecision(number / nearest, 10)) * nearest;
},
/**
* Returns a coordinate corresponding to a data values.
*
* @method _getCoordFromValue
* @param {Number} min The minimum for the axis.
* @param {Number} max The maximum for the axis.
* @param {Number} length The distance that the axis spans.
* @param {Number} dataValue A value used to ascertain the coordinate.
* @param {Number} offset Value in which to offset the coordinates.
* @param {Boolean} reverse Indicates whether the coordinates should start from
* the end of an axis. Only used in the numeric implementation.
* @return Number
* @private
*/
_getCoordFromValue: function(min, max, length, dataValue, offset, reverse)
{
var range,
multiplier,
valuecoord,
isNumber = Y_Lang.isNumber;
dataValue = parseFloat(dataValue);
if(isNumber(dataValue))
{
if(this.get("scaleType") === "logarithmic" && min > 0)
{
min = Math.log(min);
max = Math.log(max);
dataValue = Math.log(dataValue);
}
range = max - min;
multiplier = length/range;
valuecoord = (dataValue - min) * multiplier;
valuecoord = reverse ? offset - valuecoord : offset + valuecoord;
}
else
{
valuecoord = NaN;
}
return valuecoord;
},
/**
* Rounds a number to a certain level of precision. Useful for limiting the number of
* decimal places on a fractional number.
*
* @method _roundToPrecision
* @param {Number} number Number to round
* @param {Number} precision Multiple to round towards.
* @return Number
* @private
*/
_roundToPrecision: function(number, precision)
{
precision = precision || 0;
var decimalPlaces = Math.pow(10, precision);
return Math.round(decimalPlaces * number) / decimalPlaces;
}
};
Y.NumericImpl = NumericImpl;
/**
* NumericAxisBase manages numeric data for an axis.
*
* @class NumericAxisBase
* @constructor
* @extends AxisBase
* @uses NumericImpl
* @param {Object} config (optional) Configuration parameters.
* @submodule axis-numeric-base
*/
Y.NumericAxisBase = Y.Base.create("numericAxisBase", Y.AxisBase, [Y.NumericImpl]);
}, '3.18.1', {"requires": ["axis-base"]});
@@ -0,0 +1 @@
YUI.add("axis-numeric-base",function(e,t){function r(){}var n=e.Lang;r.NAME="numericImpl",r.ATTRS={alwaysShowZero:{value:!0},labelFormat:{value:{prefix:"",thousandsSeparator:"",decimalSeparator:"",decimalPlaces:"0",suffix:""}},roundingMethod:{value:"niceNumber"},scaleType:{value:"linear"}},r.prototype={initializer:function(){this.after("alwaysShowZeroChange",this._keyChangeHandler),this.after("roundingMethodChange",this._keyChangeHandler),this.after("scaleTypeChange",this._keyChangeHandler)},formatLabel:function(t,n){return n?e.DataType.Number.format(t,n):t},getTotalByKey:function(e){var t=0,n=this.getDataByKey(e),r=0,i,s=n?n.length:0;for(;r<s;++r)i=parseFloat(n[r]),isNaN(i)||(t+=i);return t},getOrigin:function(){var e=0,t=this.get("minimum"),n=this.get("maximum");return e=Math.max(e,t),e=Math.min(e,n),e},_type:"numeric",_getMinimumUnit:function(e,t,n){return this._getNiceNumber(Math.ceil((e-t)/n))},_getNiceNumber:function(e){var t=e,n=Math.ceil(Math.log(t)*.4342944819032518),r=Math.pow(10,n),i;return r/2>=t?(i=Math.floor((r/2-t)/(Math.pow(10,n-1)/2)),t=r/2-i*Math.pow(10,n-1)/2):t=r,isNaN(t)?e:t},_updateMinAndMax:function(){var e=this.get("data"),t,n,r,i,s=0,o=this.get("setMax"),u=this.get("setMin");if(!o||!u){if(e&&e.length&&e.length>0){r=e.length;for(;s<r;s++){i=e[s];if(isNaN(i)){t=o?this._setMaximum:t,n=u?this._setMinimum:n;continue}u?n=this._setMinimum:n===undefined?n=i:n=Math.min(i,n),o?t=this._setMaximum:t===undefined?t=i:t=Math.max(i,t),this._actualMaximum=t,this._actualMinimum=n}}this.get("scaleType")!=="logarithmic"?this._roundMinAndMax(n,t,u,o):(this._dataMaximum=t,this._dataMinimum=n)}},_roundMinAndMax:function(e,t,n,r){var i,s,o=e>=0,u=t>0,a,f,l,c,h,p,d,v=this.getTotalMajorUnits()-1,m=this.get("alwaysShowZero"),g=this.get("roundingMethod"),y=(t-e)/v>=1;if(g)if(g==="niceNumber"){i=this._getMinimumUnit(t,e,v);if(o&&u)(m||e<i)&&!n?(e=0,i=this._getMinimumUnit(t,e,v)):e=this._roundDownToNearest(e,i),r?m||(e=t-i*v):n?t=e+i*v:t=this._roundUpToNearest(t,i);else if(u&&!o)if(m){c=Math.round(v/(-1*e/t+1)),c=Math.max(Math.min(c,v-1),1),h=v-c,p=Math.ceil(t/c),d=Math.floor(e/h)*-1;if(n){while(d<p&&h>=0)h--,c++,p=Math.ceil(t/c),d=Math.floor(e/h)*-1;h>0?t=d*c:t=e+i*v}else if(r){while(p<d&&c>=0)h++,c--,d=Math.floor(e/h)*-1,p=Math.ceil(t/c);c>0?e=p*h*-1:e=t-i*v}else i=Math.max(p,d),i=this._getNiceNumber(i),t=i*c,e=i*h*-1}else r?e=t-i*v:n?t=e+i*v:(e=this._roundDownToNearest(e,i),t=this._roundUpToNearest(t,i));else n?m?t=0:t=e+i*v:r?e=t-i*v:m||t===0||t+i>0?(t=0,i=this._getMinimumUnit(t,e,v),e=t-i*v):(e=this._roundDownToNearest(e,i),t=this._roundUpToNearest(t,i))}else g==="auto"?o&&u?((m||e<(t-e)/v)&&!n&&(e=0),i=(t-e)/v,y?(i=Math.ceil(i),t=e+i*v):t=e+Math.ceil(i*v*1e5)/1e5):u&&!o?m?(c=Math.round(v/(-1*e/t+1)),c=Math.max(Math.min(c,v-1),1),h=v-c,y?(p=Math.ceil(t/c),d=Math.floor(e/h)*-1,i=Math.max(p,d),t=i*c,e=i*h*-1):(p=t/c,d=e/h*-1,i=Math.max(p,d),t=Math.ceil(i*c*1e5)/1e5,e=Math.ceil(i*h*1e5)/1e5*-1)):(i=(t-e)/v,y&&(i=Math.ceil(i)),e=Math.round(this._roundDownToNearest(e,i)*1e5)/1e5,t=Math.round(this._roundUpToNearest(t,i)*1e5)/1e5):(i=(t-e)/v,y&&(i=Math.ceil(i)),m||t===0||t+i>0?(t=0,i=(t-e)/v,y?(Math.ceil(i),e=t-i*v):e=t-Math.ceil(i*v*1e5)/1e5):(e=this._roundDownToNearest(e,i),t=this._roundUpToNearest(t,i))):!isNaN(g)&&isFinite(g)&&(i=g,s=i*v,a=t-e>s,l=this._roundDownToNearest(e,i),f=this._roundUpToNearest(t,i),r?e=t-s:n?t=e+s:o&&u?(m||l<=0?e=0:e=l,t=e+s):u&&!o?(e=l,t=f):(m||f>=0?t=0:t=f,e=t-s));this._dataMaximum=t,this._dataMinimum=e},_roundToNearest:function(e,t){t=t||1;var n=Math.round(this._roundToPrecision(e/t,10))*t;return this._roundToPrecision(n,10)},_roundUpToNearest:function(e,t){return t=t||1,Math.ceil(this._roundToPrecision(e/t,10))*t},_roundDownToNearest:function(e,t){return t=t||1,Math.floor(this._roundToPrecision(e/t,10))*t},_getCoordFromValue:function(e,t,r,i,s,o){var u,a,f,l=n.isNumber;return i=parseFloat(i),l(i)?(this.get("scaleType")==="logarithmic"&&e>0&&(e=Math.log(e),t=Math.log(t),i=Math.log(i)),u=t-e,a=r/u,f=(i-e)*a,f=o?s-f:s+f):f=NaN,f},_roundToPrecision:function(e,t){t=t||0;var n=Math.pow(10,t);return Math.round(n*e)/n}},e.NumericImpl=r,e.NumericAxisBase=e.Base.create("numericAxisBase",e.AxisBase,[e.NumericImpl])},"3.18.1",{requires:["axis-base"]});
@@ -0,0 +1,721 @@
YUI.add('axis-numeric-base', function (Y, NAME) {
/**
* Provides functionality for the handling of numeric axis data for a chart.
*
* @module charts
* @submodule axis-numeric-base
*/
var Y_Lang = Y.Lang;
/**
* NumericImpl contains logic for numeric data. NumericImpl is used by the following classes:
* <ul>
* <li>{{#crossLink "NumericAxisBase"}}{{/crossLink}}</li>
* <li>{{#crossLink "NumericAxis"}}{{/crossLink}}</li>
* </ul>
*
* @class NumericImpl
* @constructor
* @submodule axis-numeric-base
*/
function NumericImpl()
{
}
NumericImpl.NAME = "numericImpl";
NumericImpl.ATTRS = {
/**
* Indicates whether 0 should always be displayed.
*
* @attribute alwaysShowZero
* @type Boolean
*/
alwaysShowZero: {
value: true
},
/**
* Method used for formatting a label. This attribute allows for the default label formatting method to overridden.
* The method use would need to implement the arguments below and return a `String` or an `HTMLElement`. The default
* implementation of the method returns a `String`. The output of this method will be rendered to the DOM using
* `appendChild`. If you override the `labelFunction` method and return an html string, you will also need to override
* the Data' `appendLabelFunction` to accept html as a `String`.
* <dl>
* <dt>val</dt><dd>Label to be formatted. (`String`)</dd>
* <dt>format</dt><dd>Object containing properties used to format the label. (optional)</dd>
* </dl>
*
* @attribute labelFunction
* @type Function
*/
/**
* Object containing properties used by the `labelFunction` to format a
* label.
*
* @attribute labelFormat
* @type Object
*/
labelFormat: {
value: {
prefix: "",
thousandsSeparator: "",
decimalSeparator: "",
decimalPlaces: "0",
suffix: ""
}
},
/**
*Indicates how to round unit values.
* <dl>
* <dt>niceNumber</dt><dd>Units will be smoothed based on the number of ticks and data range.</dd>
* <dt>auto</dt><dd>If the range is greater than 1, the units will be rounded.</dd>
* <dt>numeric value</dt><dd>Units will be equal to the numeric value.</dd>
* <dt>null</dt><dd>No rounding will occur.</dd>
* </dl>
*
* @attribute roundingMethod
* @type String
* @default niceNumber
*/
roundingMethod: {
value: "niceNumber"
},
/**
* Indicates the scaling for the chart. The default value is `linear`. For a logarithmic axis, set the value
* to `logarithmic`.
*
* @attribute
* @type String
* @default linear
*/
scaleType: {
value: "linear"
}
};
NumericImpl.prototype = {
/**
* @method initializer
* @private
*/
initializer: function() {
this.after("alwaysShowZeroChange", this._keyChangeHandler);
this.after("roundingMethodChange", this._keyChangeHandler);
this.after("scaleTypeChange", this._keyChangeHandler);
},
/**
* Formats a label based on the axis type and optionally specified format.
*
* @method
* @param {Object} value
* @param {Object} format Pattern used to format the value.
* @return String
*/
formatLabel: function(val, format)
{
if(format)
{
return Y.DataType.Number.format(val, format);
}
return val;
},
/**
* Returns the sum of all values per key.
*
* @method getTotalByKey
* @param {String} key The identifier for the array whose values will be calculated.
* @return Number
*/
getTotalByKey: function(key)
{
var total = 0,
values = this.getDataByKey(key),
i = 0,
val,
len = values ? values.length : 0;
for(; i < len; ++i)
{
val = parseFloat(values[i]);
if(!isNaN(val))
{
total += val;
}
}
return total;
},
/**
* Returns the value corresponding to the origin on the axis.
*
* @method getOrigin
* @return Number
*/
getOrigin: function() {
var origin = 0,
min = this.get("minimum"),
max = this.get("maximum");
origin = Math.max(origin, min);
origin = Math.min(origin, max);
return origin;
},
/**
* Type of data used in `Data`.
*
* @property _type
* @readOnly
* @private
*/
_type: "numeric",
/**
* Helper method for getting a `roundingUnit` when calculating the minimum and maximum values.
*
* @method _getMinimumUnit
* @param {Number} max Maximum number
* @param {Number} min Minimum number
* @param {Number} units Number of units on the axis
* @return Number
* @private
*/
_getMinimumUnit:function(max, min, units)
{
return this._getNiceNumber(Math.ceil((max - min)/units));
},
/**
* Calculates a nice rounding unit based on the range.
*
* @method _getNiceNumber
* @param {Number} roundingUnit The calculated rounding unit.
* @return Number
* @private
*/
_getNiceNumber: function(roundingUnit)
{
var tempMajorUnit = roundingUnit,
order = Math.ceil(Math.log(tempMajorUnit) * 0.4342944819032518),
roundedMajorUnit = Math.pow(10, order),
roundedDiff;
if (roundedMajorUnit / 2 >= tempMajorUnit)
{
roundedDiff = Math.floor((roundedMajorUnit / 2 - tempMajorUnit) / (Math.pow(10,order-1)/2));
tempMajorUnit = roundedMajorUnit/2 - roundedDiff*Math.pow(10,order-1)/2;
}
else
{
tempMajorUnit = roundedMajorUnit;
}
if(!isNaN(tempMajorUnit))
{
return tempMajorUnit;
}
return roundingUnit;
},
/**
* Calculates the maximum and minimum values for the `Data`.
*
* @method _updateMinAndMax
* @private
*/
_updateMinAndMax: function()
{
var data = this.get("data"),
max,
min,
len,
num,
i = 0,
setMax = this.get("setMax"),
setMin = this.get("setMin");
if(!setMax || !setMin)
{
if(data && data.length && data.length > 0)
{
len = data.length;
for(; i < len; i++)
{
num = data[i];
if(isNaN(num))
{
max = setMax ? this._setMaximum : max;
min = setMin ? this._setMinimum : min;
continue;
}
if(setMin)
{
min = this._setMinimum;
}
else if(min === undefined)
{
min = num;
}
else
{
min = Math.min(num, min);
}
if(setMax)
{
max = this._setMaximum;
}
else if(max === undefined)
{
max = num;
}
else
{
max = Math.max(num, max);
}
this._actualMaximum = max;
this._actualMinimum = min;
}
}
if(this.get("scaleType") !== "logarithmic")
{
this._roundMinAndMax(min, max, setMin, setMax);
}
else
{
this._dataMaximum = max;
this._dataMinimum = min;
}
}
},
/**
* Rounds the mimimum and maximum values based on the `roundingUnit` attribute.
*
* @method _roundMinAndMax
* @param {Number} min Minimum value
* @param {Number} max Maximum value
* @private
*/
_roundMinAndMax: function(min, max, setMin, setMax)
{
var roundingUnit,
minimumRange,
minGreaterThanZero = min >= 0,
maxGreaterThanZero = max > 0,
dataRangeGreater,
maxRound,
minRound,
topTicks,
botTicks,
tempMax,
tempMin,
units = this.getTotalMajorUnits() - 1,
alwaysShowZero = this.get("alwaysShowZero"),
roundingMethod = this.get("roundingMethod"),
useIntegers = (max - min)/units >= 1;
if(roundingMethod)
{
if(roundingMethod === "niceNumber")
{
roundingUnit = this._getMinimumUnit(max, min, units);
if(minGreaterThanZero && maxGreaterThanZero)
{
if((alwaysShowZero || min < roundingUnit) && !setMin)
{
min = 0;
roundingUnit = this._getMinimumUnit(max, min, units);
}
else
{
min = this._roundDownToNearest(min, roundingUnit);
}
if(setMax)
{
if(!alwaysShowZero)
{
min = max - (roundingUnit * units);
}
}
else if(setMin)
{
max = min + (roundingUnit * units);
}
else
{
max = this._roundUpToNearest(max, roundingUnit);
}
}
else if(maxGreaterThanZero && !minGreaterThanZero)
{
if(alwaysShowZero)
{
topTicks = Math.round(units/((-1 * min)/max + 1));
topTicks = Math.max(Math.min(topTicks, units - 1), 1);
botTicks = units - topTicks;
tempMax = Math.ceil( max/topTicks );
tempMin = Math.floor( min/botTicks ) * -1;
if(setMin)
{
while(tempMin < tempMax && botTicks >= 0)
{
botTicks--;
topTicks++;
tempMax = Math.ceil( max/topTicks );
tempMin = Math.floor( min/botTicks ) * -1;
}
//if there are any bottom ticks left calcualate the maximum by multiplying by the tempMin value
//if not, it's impossible to ensure that a zero is shown. skip it
if(botTicks > 0)
{
max = tempMin * topTicks;
}
else
{
max = min + (roundingUnit * units);
}
}
else if(setMax)
{
while(tempMax < tempMin && topTicks >= 0)
{
botTicks++;
topTicks--;
tempMin = Math.floor( min/botTicks ) * -1;
tempMax = Math.ceil( max/topTicks );
}
//if there are any top ticks left calcualate the minimum by multiplying by the tempMax value
//if not, it's impossible to ensure that a zero is shown. skip it
if(topTicks > 0)
{
min = tempMax * botTicks * -1;
}
else
{
min = max - (roundingUnit * units);
}
}
else
{
roundingUnit = Math.max(tempMax, tempMin);
roundingUnit = this._getNiceNumber(roundingUnit);
max = roundingUnit * topTicks;
min = roundingUnit * botTicks * -1;
}
}
else
{
if(setMax)
{
min = max - (roundingUnit * units);
}
else if(setMin)
{
max = min + (roundingUnit * units);
}
else
{
min = this._roundDownToNearest(min, roundingUnit);
max = this._roundUpToNearest(max, roundingUnit);
}
}
}
else
{
if(setMin)
{
if(alwaysShowZero)
{
max = 0;
}
else
{
max = min + (roundingUnit * units);
}
}
else if(!setMax)
{
if(alwaysShowZero || max === 0 || max + roundingUnit > 0)
{
max = 0;
roundingUnit = this._getMinimumUnit(max, min, units);
min = max - (roundingUnit * units);
}
else
{
min = this._roundDownToNearest(min, roundingUnit);
max = this._roundUpToNearest(max, roundingUnit);
}
}
else
{
min = max - (roundingUnit * units);
}
}
}
else if(roundingMethod === "auto")
{
if(minGreaterThanZero && maxGreaterThanZero)
{
if((alwaysShowZero || min < (max-min)/units) && !setMin)
{
min = 0;
}
roundingUnit = (max - min)/units;
if(useIntegers)
{
roundingUnit = Math.ceil(roundingUnit);
max = min + (roundingUnit * units);
}
else
{
max = min + Math.ceil(roundingUnit * units * 100000)/100000;
}
}
else if(maxGreaterThanZero && !minGreaterThanZero)
{
if(alwaysShowZero)
{
topTicks = Math.round( units / ( (-1 * min) /max + 1) );
topTicks = Math.max(Math.min(topTicks, units - 1), 1);
botTicks = units - topTicks;
if(useIntegers)
{
tempMax = Math.ceil( max/topTicks );
tempMin = Math.floor( min/botTicks ) * -1;
roundingUnit = Math.max(tempMax, tempMin);
max = roundingUnit * topTicks;
min = roundingUnit * botTicks * -1;
}
else
{
tempMax = max/topTicks;
tempMin = min/botTicks * -1;
roundingUnit = Math.max(tempMax, tempMin);
max = Math.ceil(roundingUnit * topTicks * 100000)/100000;
min = Math.ceil(roundingUnit * botTicks * 100000)/100000 * -1;
}
}
else
{
roundingUnit = (max - min)/units;
if(useIntegers)
{
roundingUnit = Math.ceil(roundingUnit);
}
min = Math.round(this._roundDownToNearest(min, roundingUnit) * 100000)/100000;
max = Math.round(this._roundUpToNearest(max, roundingUnit) * 100000)/100000;
}
}
else
{
roundingUnit = (max - min)/units;
if(useIntegers)
{
roundingUnit = Math.ceil(roundingUnit);
}
if(alwaysShowZero || max === 0 || max + roundingUnit > 0)
{
max = 0;
roundingUnit = (max - min)/units;
if(useIntegers)
{
Math.ceil(roundingUnit);
min = max - (roundingUnit * units);
}
else
{
min = max - Math.ceil(roundingUnit * units * 100000)/100000;
}
}
else
{
min = this._roundDownToNearest(min, roundingUnit);
max = this._roundUpToNearest(max, roundingUnit);
}
}
}
else if(!isNaN(roundingMethod) && isFinite(roundingMethod))
{
roundingUnit = roundingMethod;
minimumRange = roundingUnit * units;
dataRangeGreater = (max - min) > minimumRange;
minRound = this._roundDownToNearest(min, roundingUnit);
maxRound = this._roundUpToNearest(max, roundingUnit);
if(setMax)
{
min = max - minimumRange;
}
else if(setMin)
{
max = min + minimumRange;
}
else if(minGreaterThanZero && maxGreaterThanZero)
{
if(alwaysShowZero || minRound <= 0)
{
min = 0;
}
else
{
min = minRound;
}
max = min + minimumRange;
}
else if(maxGreaterThanZero && !minGreaterThanZero)
{
min = minRound;
max = maxRound;
}
else
{
if(alwaysShowZero || maxRound >= 0)
{
max = 0;
}
else
{
max = maxRound;
}
min = max - minimumRange;
}
}
}
this._dataMaximum = max;
this._dataMinimum = min;
},
/**
* Rounds a Number to the nearest multiple of an input. For example, by rounding
* 16 to the nearest 10, you will receive 20. Similar to the built-in function Math.round().
*
* @method _roundToNearest
* @param {Number} number Number to round
* @param {Number} nearest Multiple to round towards.
* @return Number
* @private
*/
_roundToNearest: function(number, nearest)
{
nearest = nearest || 1;
var roundedNumber = Math.round(this._roundToPrecision(number / nearest, 10)) * nearest;
return this._roundToPrecision(roundedNumber, 10);
},
/**
* Rounds a Number up to the nearest multiple of an input. For example, by rounding
* 16 up to the nearest 10, you will receive 20. Similar to the built-in function Math.ceil().
*
* @method _roundUpToNearest
* @param {Number} number Number to round
* @param {Number} nearest Multiple to round towards.
* @return Number
* @private
*/
_roundUpToNearest: function(number, nearest)
{
nearest = nearest || 1;
return Math.ceil(this._roundToPrecision(number / nearest, 10)) * nearest;
},
/**
* Rounds a Number down to the nearest multiple of an input. For example, by rounding
* 16 down to the nearest 10, you will receive 10. Similar to the built-in function Math.floor().
*
* @method _roundDownToNearest
* @param {Number} number Number to round
* @param {Number} nearest Multiple to round towards.
* @return Number
* @private
*/
_roundDownToNearest: function(number, nearest)
{
nearest = nearest || 1;
return Math.floor(this._roundToPrecision(number / nearest, 10)) * nearest;
},
/**
* Returns a coordinate corresponding to a data values.
*
* @method _getCoordFromValue
* @param {Number} min The minimum for the axis.
* @param {Number} max The maximum for the axis.
* @param {Number} length The distance that the axis spans.
* @param {Number} dataValue A value used to ascertain the coordinate.
* @param {Number} offset Value in which to offset the coordinates.
* @param {Boolean} reverse Indicates whether the coordinates should start from
* the end of an axis. Only used in the numeric implementation.
* @return Number
* @private
*/
_getCoordFromValue: function(min, max, length, dataValue, offset, reverse)
{
var range,
multiplier,
valuecoord,
isNumber = Y_Lang.isNumber;
dataValue = parseFloat(dataValue);
if(isNumber(dataValue))
{
if(this.get("scaleType") === "logarithmic" && min > 0)
{
min = Math.log(min);
max = Math.log(max);
dataValue = Math.log(dataValue);
}
range = max - min;
multiplier = length/range;
valuecoord = (dataValue - min) * multiplier;
valuecoord = reverse ? offset - valuecoord : offset + valuecoord;
}
else
{
valuecoord = NaN;
}
return valuecoord;
},
/**
* Rounds a number to a certain level of precision. Useful for limiting the number of
* decimal places on a fractional number.
*
* @method _roundToPrecision
* @param {Number} number Number to round
* @param {Number} precision Multiple to round towards.
* @return Number
* @private
*/
_roundToPrecision: function(number, precision)
{
precision = precision || 0;
var decimalPlaces = Math.pow(10, precision);
return Math.round(decimalPlaces * number) / decimalPlaces;
}
};
Y.NumericImpl = NumericImpl;
/**
* NumericAxisBase manages numeric data for an axis.
*
* @class NumericAxisBase
* @constructor
* @extends AxisBase
* @uses NumericImpl
* @param {Object} config (optional) Configuration parameters.
* @submodule axis-numeric-base
*/
Y.NumericAxisBase = Y.Base.create("numericAxisBase", Y.AxisBase, [Y.NumericImpl]);
}, '3.18.1', {"requires": ["axis-base"]});