LeftAxisLayout.js revision 6aa3a8d9176704373c2e24b0530b508f643fe6a0
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico/**
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * Algorithmic strategy for rendering a left axis.
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @class LeftAxisLayout
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico * @constructor
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoLeftAxisLayout = function() {};
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoLeftAxisLayout.prototype = {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico /**
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * Default margins for text fields.
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico *
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * @private
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * @method _getDefaultMargins
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * @return Object
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico */
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico _getDefaultMargins: function()
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico return {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico top: 0,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico left: 0,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico right: 4,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico bottom: 0
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico };
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico },
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico /**
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * Sets the length of the tick on either side of the axis line.
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico *
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @method setTickOffset
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @protected
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico */
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico setTickOffsets: function()
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico var host = this,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico majorTicks = host.get("styles").majorTicks,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico tickLength = majorTicks.length,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico halfTick = tickLength * 0.5,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico display = majorTicks.display;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico host.set("topTickOffset", 0);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico host.set("bottomTickOffset", 0);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico switch(display)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico case "inside" :
6decd839c5d3aac21faa79519b8f125f3b6e4629cmarqu host.set("rightTickOffset", tickLength);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico host.set("leftTickOffset", 0);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico break;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico case "outside" :
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico host.set("rightTickOffset", 0);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico host.set("leftTickOffset", tickLength);
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico break;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico case "cross":
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico host.set("rightTickOffset", halfTick);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico host.set("leftTickOffset", halfTick);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico break;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico default:
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico host.set("rightTickOffset", 0);
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico host.set("leftTickOffset", 0);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico break;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico },
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico /**
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * Draws a tick
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method drawTick
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param {Object} pt Point on the axis in which the tick will intersect.
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * @param {Object} tickStyle Hash of properties to apply to the tick.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico drawTick: function(pt, tickStyles)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico var host = this,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico style = host.get("styles"),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico padding = style.padding,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico tickLength = tickStyles.length,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico start = {x:padding.left, y:pt.y},
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico end = {x:tickLength + padding.left, y:pt.y};
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico host.drawLine(start, end, tickStyles);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico },
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Calculates the coordinates for the first point on an axis.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * @method getLineStart
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @return {Object}
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @protected
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico getLineStart: function()
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico var style = this.get("styles"),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico padding = style.padding,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico majorTicks = style.majorTicks,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico tickLength = majorTicks.length,
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico display = majorTicks.display,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico pt = {x:padding.left, y:0};
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico if(display === "outside")
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico pt.x += tickLength;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico else if(display === "cross")
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico pt.x += tickLength/2;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico return pt;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico },
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Calculates the point for a label.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method getLabelPoint
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @param {Object} point Point on the axis in which the tick will intersect.
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @return {Object}
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @protected
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico getLabelPoint: function(point)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico return {x:point.x - this.get("leftTickOffset"), y:point.y};
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico },
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico /**
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * Updates the value for the `maxLabelSize` for use in calculating total size.
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico *
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @method updateMaxLabelSize
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @param {HTMLElement} label to measure
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @protected
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico */
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico updateMaxLabelSize: function(label)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico var host = this,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico props = this._labelRotationProps,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico rot = props.rot,
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico absRot = props.absRot,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico sinRadians = props.sinRadians,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico cosRadians = props.cosRadians,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico m11 = props.m11,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico m12 = props.m12,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico m21 = props.m21,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico m22 = props.m22,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico max;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(!DOCUMENT.createElementNS)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
ba93101fe1cf68c34d71b5406224a3e1be4fe6e1JazzyNico label.style.filter = 'progid:DXImageTransform.Microsoft.Matrix(M11=' + m11 + ' M12=' + m12 + ' M21=' + m21 + ' M22=' + m22 + ' sizingMethod="auto expand")';
ba93101fe1cf68c34d71b5406224a3e1be4fe6e1JazzyNico host.set("maxLabelSize", Math.max(host.get("maxLabelSize"), label.offsetWidth));
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
ba93101fe1cf68c34d71b5406224a3e1be4fe6e1JazzyNico else
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico label.style.msTransform = "rotate(0deg)";
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico if(rot === 0)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico max = label.offsetWidth;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico else if(absRot === 90)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico max = label.offsetHeight;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico else
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico max = (cosRadians * label.offsetWidth) + (sinRadians * label.offsetHeight);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico host.set("maxLabelSize", Math.max(host.get("maxLabelSize"), max));
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico },
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico /**
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * Rotate and position title.
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico *
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @method positionTitle
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @param {HTMLElement} label to rotate position
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @protected
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico */
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico positionTitle: function(label)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico var host = this,
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico max,
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico styles = host.get("styles").title,
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico props = this._getTextRotationProps(styles),
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico rot = props.rot,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico absRot = props.absRot,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico sinRadians = props.sinRadians,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico cosRadians = props.cosRadians,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico x = 0,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico y = this.get("height")/2,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico leftOffset = 0,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico topOffset = 0,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico labelWidth = label.offsetWidth,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico labelHeight = label.offsetHeight;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico if(Y.config.doc.createElementNS)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico if(rot === 0)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico max = labelWidth;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico topOffset -= labelHeight * 0.5;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico else if(absRot === 90)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico max = labelHeight;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico if(rot === 90)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico leftOffset += labelHeight;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico topOffset -= labelWidth * 0.5;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico else
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico topOffset += labelWidth * 0.5;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico else
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico max = (cosRadians * labelWidth) + (sinRadians * labelHeight);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(rot > 0)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico topOffset -= ((sinRadians * labelWidth) + (cosRadians * labelHeight))/2;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico leftOffset += Math.min(labelHeight, (sinRadians * labelHeight));
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico else
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico topOffset += (sinRadians * labelWidth)/2 - (cosRadians * labelHeight)/2;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico y += topOffset;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico x += leftOffset;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico props.x = Math.round(x);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico props.y = Math.round(y);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico else
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico if(rot === 0)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico topOffset -= labelHeight * 0.5;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico max = labelWidth;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico else if(rot === 90)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico topOffset -= labelWidth * 0.5;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico max = labelHeight;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico else if(rot === -90)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico topOffset -= labelWidth * 0.5;
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico max = labelHeight;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico else
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico max = (cosRadians * labelWidth) + (sinRadians * labelHeight);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico topOffset -= ((sinRadians * labelWidth) + (cosRadians * labelHeight))/2;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico y += topOffset;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico x += leftOffset;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico label.style.left = Math.round(x) + "px";
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico label.style.top = Math.round(y) + "px";
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._titleSize = max;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico this._rotate(label, props);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico },
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * Rotate and position labels.
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico *
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @method positionLabel
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @param {HTMLElement} label to rotate position
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @param {Object} pt hash containing the x and y coordinates in which the label will be positioned
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * against.
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * @protected
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico positionLabel: function(label, pt)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico var host = this,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico tickOffset = host.get("leftTickOffset"),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico style = host.get("styles").label,
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico margin = 0,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico leftOffset = pt.x + this._titleSize,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico topOffset = pt.y,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico props = this._labelRotationProps,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico rot = props.rot,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico absRot = props.absRot,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico sinRadians = props.sinRadians,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico cosRadians = props.cosRadians,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico maxLabelSize = host.get("maxLabelSize"),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico labelWidth = Math.round(label.offsetWidth),
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico labelHeight = Math.round(label.offsetHeight);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(style.margin && style.margin.right)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico margin = style.margin.right;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico if(!DOCUMENT.createElementNS)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico label.style.filter = null;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico labelWidth = Math.round(label.offsetWidth);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico labelHeight = Math.round(label.offsetHeight);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(rot === 0)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico leftOffset = labelWidth;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico topOffset -= labelHeight * 0.5;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico else if(absRot === 90)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico leftOffset = labelHeight;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico topOffset -= labelWidth * 0.5;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico else if(rot > 0)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico leftOffset = (cosRadians * labelWidth) + (labelHeight * rot/90);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico topOffset -= (sinRadians * labelWidth) + (cosRadians * (labelHeight * 0.5));
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico else
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico leftOffset = (cosRadians * labelWidth) + (absRot/90 * labelHeight);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico topOffset -= cosRadians * (labelHeight * 0.5);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico leftOffset += tickOffset;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico label.style.left = Math.round((pt.x + this._titleSize + maxLabelSize) - leftOffset) + "px";
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico label.style.top = Math.round(topOffset) + "px";
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._rotate(label, this._labelRotationProps);
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico return;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico label.style.msTransform = "rotate(0deg)";
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico labelWidth = Math.round(label.offsetWidth);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico labelHeight = Math.round(label.offsetHeight);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico if(rot === 0)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico leftOffset -= labelWidth;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico topOffset -= labelHeight * 0.5;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico else if(rot === 90)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico topOffset -= labelWidth * 0.5;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico else if(rot === -90)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico leftOffset -= labelHeight;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico topOffset += labelWidth * 0.5;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico else
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(rot < 0)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico leftOffset -= (cosRadians * labelWidth) + (sinRadians * labelHeight);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico topOffset += (sinRadians * labelWidth) - (cosRadians * (labelHeight * 0.6));
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico else
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico leftOffset -= (cosRadians * labelWidth);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico topOffset -= (sinRadians * labelWidth) + (cosRadians * (labelHeight * 0.6));
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico props.x = Math.round(host.get("maxLabelSize") + leftOffset);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico props.y = Math.round(topOffset);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this._rotate(label, this._labelRotationProps);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico },
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Calculates the size and positions the content elements.
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico *
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @method setSizeAndPosition
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico setSizeAndPosition: function()
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico var host = this,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico labelSize = host.get("maxLabelSize"),
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico style = host.get("styles"),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico leftTickOffset = host.get("leftTickOffset"),
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico sz = labelSize + leftTickOffset,
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico graphic = host.get("graphic"),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico margin = style.label.margin;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico if(margin && margin.right)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico {
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico sz += margin.right;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico sz += this._titleSize;
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico sz = Math.round(sz);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico host.set("width", sz);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico host.get("contentBox").setStyle("width", sz);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico graphic.set("x", sz - leftTickOffset);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico },
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * Adjust the position of the Axis widget's content box for internal axes.
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method offsetNodeForTick
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @param {Node} cb Content box of the Axis.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico offsetNodeForTick: function(cb)
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico },
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Sets the width of the axis based on its contents.
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method setCalculatedSize
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @protected
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico setCalculatedSize: function()
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico var host = this,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico style = host.get("styles"),
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico label = style.label,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico tickOffset = host.get("leftTickOffset"),
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico max = host.get("maxLabelSize"),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ttl = Math.round(this._titleSize + tickOffset + max + label.margin.right);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico host.get("contentBox").setStyle("width", ttl);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico host.set("width", ttl);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico};
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNicoY.LeftAxisLayout = LeftAxisLayout;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico