/**
* Copyright (c) 2015, Oracle and/or its affiliates.
* All rights reserved.
*/
/*jslint browser: true*/
/**
* @class oj.CubeAxis
* @classdesc Represents an axis (a collection of levels) in a cube. There is a set of [oj.CubeAxisValues]{@link oj.CubeAxisValue} at each index within an axis, up to one per [oj.CubeLevel]{@link oj.CubeLevel} on the axis
* @since 1.1.0
*/
/**
* Represents an axis (a collection of levels) in a cube. There is a set of oj.CubeAxisValues at each index within an axis,
* up to one per oj.CubeLevel on the axis
* @param {Array} levels array of levels, slowest to fastest, to put in this axis
* @param {Number} axis the number of this axis
* @param {oj.Cube} cube the cube on which to generate levels
*
* @constructor
* @export
* @private
*/
oj.CubeAxis = function(levels, axis, cube) {
this.Init();
this['axis'] = axis;
this._levels = [];
for (var i = 0; i < levels.length; i++) {
this._levels.push(cube.GenerateLevel(levels[i], this));
}
this._cube = cube;
// Set up a root for the tree of axis values
this._values = new oj.CubeAxisValue(null, null, null, null);
};
// Subclass from oj.Object
oj.Object.createSubclass(oj.CubeAxis, oj.Object, "oj.CubeAxis");
/**
* Initializes instance with the set options
* @private
*/
oj.CubeAxis.prototype.Init = function()
{
oj.CubeAxis.superclass.Init.call(this);
};
/**
* Gets an ordered list (slowest to fastest varying) of all the levels represented within the axis. Some indices along the axis may not be represented by
* every level
* @return {Array} an ordered array of {@link oj.CubeLevel}
* @export
*/
oj.CubeAxis.prototype.getLevels = function() {
return this._levels;
};
/**
* Gets the total number of indices (data value locations) along this axis
* @return {number} the total number of indices along the axis
* @export
*/
oj.CubeAxis.prototype.getExtent = function() {
return this._values.getExtent();
};
/**
* Get the {@link oj.CubeAxisValue} objects at the given index, one for each level represented at this index within the axis. Note that the number of oj.CubeAxisValues
* returned may not match the overall oj.CubeLevel count on the axis
* @param index {number} index for which to get the oj.CubeAxisValues
* @return {Array} the ordered list of oj.CubeAxisValues at this index (slowest to fastest varying).
* @export
*/
oj.CubeAxis.prototype.getValues = function(index) {
var values = [];
var node = this._values;
while (node) {
node = node.GetChildAt(index);
if (node) {
values.push(node);
}
}
return values;
};
/**
* Return the index of the given key within the axis. Return -1 if not found.
*
* @param {string} key
* @returns {number} index of value found using key, -1 if not found
* @export
*/
oj.CubeAxis.prototype.getIndex = function(key) {
var keyVal = key ? JSON.parse(key) : {};
var node = this._values;
var lastNode = null;
while (node) {
lastNode = node;
node = node.GetChild(keyVal);
}
return lastNode ? lastNode.getStart() : -1;
};
/**
* @desc This axis' number
*
* @type Number
* @export
*/
oj.CubeAxis.prototype.axis;
// Retrieve the hash code for the values at a given index
oj.CubeAxis.prototype.GetCubeKeys = function(index, keys) {
return this.GetPartialCubeKeys(index, this.getLevels().length-1, keys);
};
// Get the cube keys down to a particular level
oj.CubeAxis.prototype.GetPartialCubeKeys = function(index, level, keys) {
var values = this.getValues(index);
var stopLevel = this.getLevels()[level];
for (var v = 0; v < values.length; v++) {
var val = values[v];
if (val.getLevel().isDataValue()) {
keys.AddDataValue(val.getValue());
}
else {
keys.UpdateKeys(val);
}
// Have we hit the stop level?
if (val.getLevel() === stopLevel) {
break;
}
}
return keys;
};
// Distribute contents of row to this axis according to the layout, etc.
oj.CubeAxis.prototype.ProcessRow = function(row, keys) {
// Go over the levels--obtain a set of keys representing cell locations and data values of those intersections
return this._cube.ProcessLevel(this, 0, this._values, row, keys, true);
};
Source: src/main/javascript/oracle/oj/ojcube/CubeAxis.js
Oracle® JavaScript Extension Toolkit (JET)
1.1.2
E65298-01