Created
October 19, 2011 19:39
-
-
Save tripp/1299428 to your computer and use it in GitHub Desktop.
Patches#2531314
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Y_CartesianChart = Y.CartesianChart, | |
| Y_Lang = Y.Lang; | |
| Y_CartesianChart.prototype._getAllKeys = function(dp) | |
| { | |
| var i = 0, | |
| len = dp.length, | |
| item, | |
| key, | |
| keys = {}; | |
| for(; i < len; ++i) | |
| { | |
| item = dp[i]; | |
| for(key in item) | |
| { | |
| if(item.hasOwnProperty(key)) | |
| { | |
| keys[key] = true; | |
| } | |
| } | |
| } | |
| return keys; | |
| }; | |
| Y_CartesianChart.prototype._getDefaultAxes = function(axes) | |
| { | |
| var catKey = this.get("categoryKey"), | |
| axis, | |
| attr, | |
| keys, | |
| newAxes = {}, | |
| claimedKeys = [], | |
| categoryAxisName = this.get("categoryAxisName") || this.get("categoryKey"), | |
| valueAxisName = this.get("valueAxisName"), | |
| seriesKeys = this.get("seriesKeys") || [], | |
| i, | |
| l, | |
| ii, | |
| ll, | |
| cIndex, | |
| dv, | |
| dp = this.get("dataProvider"), | |
| direction = this.get("direction"), | |
| seriesPosition, | |
| categoryPosition, | |
| valueAxes = [], | |
| seriesAxis = this.get("stacked") ? "stacked" : "numeric"; | |
| if(direction == "vertical") | |
| { | |
| seriesPosition = "bottom"; | |
| categoryPosition = "left"; | |
| } | |
| else | |
| { | |
| seriesPosition = "left"; | |
| categoryPosition = "bottom"; | |
| } | |
| if(axes) | |
| { | |
| for(i in axes) | |
| { | |
| if(axes.hasOwnProperty(i)) | |
| { | |
| axis = axes[i]; | |
| keys = this._getBaseAttribute(axis, "keys"); | |
| attr = this._getBaseAttribute(axis, "type"); | |
| if(attr == "time" || attr == "category") | |
| { | |
| categoryAxisName = i; | |
| this.set("categoryAxisName", i); | |
| if(Y_Lang.isArray(keys) && keys.length > 0) | |
| { | |
| catKey = keys[0]; | |
| this.set("categoryKey", catKey); | |
| } | |
| newAxes[i] = axis; | |
| } | |
| else if(i == categoryAxisName) | |
| { | |
| newAxes[i] = axis; | |
| } | |
| else | |
| { | |
| newAxes[i] = axis; | |
| if(i != valueAxisName && keys && Y_Lang.isArray(keys)) | |
| { | |
| ll = keys.length; | |
| for(ii = 0; ii < ll; ++ii) | |
| { | |
| claimedKeys.push(keys[ii]); | |
| } | |
| valueAxes.push(newAxes[i]); | |
| } | |
| if(!(this._getBaseAttribute(newAxes[i], "type"))) | |
| { | |
| this._setBaseAttribute(newAxes[i], "type", seriesAxis); | |
| } | |
| if(!(this._getBaseAttribute(newAxes[i], "position"))) | |
| { | |
| this._setBaseAttribute(newAxes[i], "position", this._getDefaultAxisPosition(newAxes[i], valueAxes, seriesPosition)); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| if(seriesKeys.length < 1) | |
| { | |
| dv = this._getAllKeys(dp); | |
| for(i in dv) | |
| { | |
| if(dv.hasOwnProperty(i) && i != catKey && Y.Array.indexOf(claimedKeys, i) == -1) | |
| { | |
| seriesKeys.push(i); | |
| } | |
| } | |
| } | |
| cIndex = Y.Array.indexOf(seriesKeys, catKey); | |
| if(cIndex > -1) | |
| { | |
| seriesKeys.splice(cIndex, 1); | |
| } | |
| l = claimedKeys.length; | |
| for(i = 0; i < l; ++i) | |
| { | |
| cIndex = Y.Array.indexOf(seriesKeys, claimedKeys[i]); | |
| if(cIndex > -1) | |
| { | |
| seriesKeys.splice(cIndex, 1); | |
| } | |
| } | |
| if(!newAxes.hasOwnProperty(categoryAxisName)) | |
| { | |
| newAxes[categoryAxisName] = {}; | |
| } | |
| if(!(this._getBaseAttribute(newAxes[categoryAxisName], "keys"))) | |
| { | |
| this._setBaseAttribute(newAxes[categoryAxisName], "keys", [catKey]); | |
| } | |
| if(!(this._getBaseAttribute(newAxes[categoryAxisName], "position"))) | |
| { | |
| this._setBaseAttribute(newAxes[categoryAxisName], "position", categoryPosition); | |
| } | |
| if(!(this._getBaseAttribute(newAxes[categoryAxisName], "type"))) | |
| { | |
| this._setBaseAttribute(newAxes[categoryAxisName], "type", this.get("categoryType")); | |
| } | |
| if(!newAxes.hasOwnProperty(valueAxisName) && seriesKeys && seriesKeys.length > 0) | |
| { | |
| newAxes[valueAxisName] = {keys:seriesKeys}; | |
| valueAxes.push(newAxes[valueAxisName]); | |
| } | |
| if(claimedKeys.length > 0) | |
| { | |
| if(seriesKeys.length > 0) | |
| { | |
| seriesKeys = claimedKeys.concat(seriesKeys); | |
| } | |
| else | |
| { | |
| seriesKeys = claimedKeys; | |
| } | |
| } | |
| if(newAxes.hasOwnProperty(valueAxisName)) | |
| { | |
| if(!(this._getBaseAttribute(newAxes[valueAxisName], "position"))) | |
| { | |
| this._setBaseAttribute(newAxes[valueAxisName], "position", this._getDefaultAxisPosition(newAxes[valueAxisName], valueAxes, seriesPosition)); | |
| } | |
| if(!(this._getBaseAttribute(newAxes[valueAxisName], "type"))) | |
| { | |
| this._setBaseAttribute(newAxes[valueAxisName], "type", seriesAxis); | |
| } | |
| if(!(this._getBaseAttribute(newAxes[valueAxisName], "keys"))) | |
| { | |
| this._setBaseAttribute(newAxes[valueAxisName], "keys", seriesKeys); | |
| } | |
| } | |
| this.set("seriesKeys", seriesKeys); | |
| return newAxes; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment