82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp/**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * The PieChart class creates a pie chart
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp * @module charts
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @class PieChart
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @extends ChartBase
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @constructor
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippY.PieChart = Y.Base.create("pieChart", Y.Widget, [Y.ChartBase], {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * Calculates and returns a `seriesCollection`.
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp *
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @method _getSeriesCollection
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @return Array
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @private
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _getSeriesCollection: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(this._seriesCollection)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return this._seriesCollection;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var axes = this.get("axes"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp sc = [],
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp seriesKeys,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp i = 0,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp l,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp type = this.get("type"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp key,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp catAxis = "categoryAxis",
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp catKey = "categoryKey",
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp valAxis = "valueAxis",
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp seriesKey = "valueKey";
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(axes)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
a00d11bb8925157bd9fcc0e0fb5fc697c53726eaTripp seriesKeys = axes.values.get("keyCollection");
a00d11bb8925157bd9fcc0e0fb5fc697c53726eaTripp key = axes.category.get("keyCollection")[0];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp l = seriesKeys.length;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for(; i < l; ++i)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp sc[i] = {type:type};
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp sc[i][catAxis] = "category";
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp sc[i][valAxis] = "values";
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp sc[i][catKey] = key;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp sc[i][seriesKey] = seriesKeys[i];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._seriesCollection = sc;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return sc;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * Creates `Axis` instances.
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp *
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @method _parseAxes
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @param {Object} val Object containing `Axis` instances or objects in which to construct `Axis` instances.
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @return Object
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @private
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _parseAxes: function(hash)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(!this._axes)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._axes = {};
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var i, pos, axis, dh, config, axisClass,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp type = this.get("type"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp w = this.get("width"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp h = this.get("height"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp node = Y.Node.one(this._parentNode);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(!w)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.set("width", node.get("offsetWidth"));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp w = this.get("width");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(!h)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.set("height", node.get("offsetHeight"));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp h = this.get("height");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for(i in hash)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(hash.hasOwnProperty(i))
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp dh = hash[i];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp pos = type == "pie" ? "none" : dh.position;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp axisClass = this._getAxisClass(dh.type);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp config = {dataProvider:this.get("dataProvider")};
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(dh.hasOwnProperty("roundingUnit"))
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp config.roundingUnit = dh.roundingUnit;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp config.keys = dh.keys;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp config.width = w;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp config.height = h;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp config.position = pos;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp config.styles = dh.styles;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp axis = new axisClass(config);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp axis.on("axisRendered", Y.bind(this._itemRendered, this));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._axes[i] = axis;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * Adds axes to the chart.
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp *
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @method _addAxes
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @private
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _addAxes: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var axes = this.get("axes"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp i,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp axis,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp p;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(!axes)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.set("axes", this._getDefaultAxes());
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp axes = this.get("axes");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(!this._axesCollection)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._axesCollection = [];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for(i in axes)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(axes.hasOwnProperty(i))
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp axis = axes[i];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp p = axis.get("position");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(!this.get(p + "AxesCollection"))
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.set(p + "AxesCollection", [axis]);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp else
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.get(p + "AxesCollection").push(axis);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._axesCollection.push(axis);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * Renders the Graph.
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp *
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @method _addSeries
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @private
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _addSeries: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var graph = this.get("graph"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp seriesCollection = this.get("seriesCollection");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._parseSeriesAxes(seriesCollection);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp graph.set("showBackground", false);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp graph.set("width", this.get("width"));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp graph.set("height", this.get("height"));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp graph.set("seriesCollection", seriesCollection);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._seriesCollection = graph.get("seriesCollection");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp graph.render(this.get("contentBox"));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * Parse and sets the axes for the chart.
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp *
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @method _parseSeriesAxes
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @param {Array} c A collection `PieSeries` instance.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @private
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _parseSeriesAxes: function(c)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var i = 0,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp len = c.length,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp s,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp axes = this.get("axes"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp axis;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for(; i < len; ++i)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp s = c[i];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(s)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp //If series is an actual series instance,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp //replace axes attribute string ids with axes
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(s instanceof Y.PieSeries)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp axis = s.get("categoryAxis");
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if(axis && !(axis instanceof Y.Axis))
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp s.set("categoryAxis", axes[axis]);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp axis = s.get("valueAxis");
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if(axis && !(axis instanceof Y.Axis))
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp s.set("valueAxis", axes[axis]);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp continue;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp s.categoryAxis = axes.category;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp s.valueAxis = axes.values;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(!s.type)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp s.type = this.get("type");
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * Generates and returns a key-indexed object containing `Axis` instances or objects used to create `Axis` instances.
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp *
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @method _getDefaultAxes
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @return Object
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @private
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _getDefaultAxes: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var catKey = this.get("categoryKey"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp seriesKeys = this.get("seriesKeys") || [],
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp seriesAxis = "numeric",
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp i,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp dv = this.get("dataProvider")[0];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(seriesKeys.length < 1)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for(i in dv)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(i != catKey)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp seriesKeys.push(i);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(seriesKeys.length > 0)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.set("seriesKeys", seriesKeys);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp values:{
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp keys:seriesKeys,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp type:seriesAxis
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp category:{
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp keys:[catKey],
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp type:this.get("categoryType")
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp };
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Returns an object literal containing a categoryItem and a valueItem for a given series index.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method getSeriesItem
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param series Reference to a series.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param index Index of the specified item within a series.
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @return Object
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp getSeriesItems: function(series, index)
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp var categoryItem = {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp axis: series.get("categoryAxis"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp key: series.get("categoryKey"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp displayName: series.get("categoryDisplayName")
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp valueItem = {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp axis: series.get("valueAxis"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp key: series.get("valueKey"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp displayName: series.get("valueDisplayName")
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp };
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp categoryItem.value = categoryItem.axis.getKeyValueAt(categoryItem.key, index);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp valueItem.value = valueItem.axis.getKeyValueAt(valueItem.key, index);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp return {category:categoryItem, value:valueItem};
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /**
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * Handler for sizeChanged event.
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp *
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @method _sizeChanged
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @param {Object} e Event object.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @private
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _sizeChanged: function(e)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._redraw();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /**
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * Redraws the chart instance.
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp *
8209f3939e32e0e5bde64192267fdaf9db6f4fbcTripp * @method _redraw
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @private
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _redraw: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var graph = this.get("graph"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp w = this.get("width"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp h = this.get("height"),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp dimension;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(graph)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp dimension = Math.min(w, h);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp graph.set("width", dimension);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp graph.set("height", dimension);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp },
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp /**
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * Formats tooltip text for a pie chart.
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp *
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * @method _tooltipLabelFunction
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * @param {Object} categoryItem An object containing the following:
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * <dl>
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * <dt>axis</dt><dd>The axis to which the category is bound.</dd>
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * <dt>displayName</dt><dd>The display name set to the category (defaults to key if not provided)</dd>
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * <dt>key</dt><dd>The key of the category.</dd>
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * <dt>value</dt><dd>The value of the category</dd>
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * </dl>
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * @param {Object} valueItem An object containing the following:
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * <dl>
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * <dt>axis</dt><dd>The axis to which the item's series is bound.</dd>
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * <dt>displayName</dt><dd>The display name of the series. (defaults to key if not provided)</dd>
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * <dt>key</dt><dd>The key for the series.</dd>
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * <dt>value</dt><dd>The value for the series item.</dd>
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * </dl>
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * @param {Number} itemIndex The index of the item within the series.
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * @param {CartesianSeries} series The `PieSeries` instance of the item.
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * @param {Number} seriesIndex The index of the series in the `seriesCollection`.
d79066bfa31eec6909a20ccabb5227cc1e1ea2d0Tripp * @return {HTML}
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp * @private
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp */
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp _tooltipLabelFunction: function(categoryItem, valueItem, itemIndex, series, seriesIndex)
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp {
d79066bfa31eec6909a20ccabb5227cc1e1ea2d0Tripp var msg = DOCUMENT.createElement("div"),
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp total = series.getTotalValues(),
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp pct = Math.round((valueItem.value / total) * 10000)/100;
d79066bfa31eec6909a20ccabb5227cc1e1ea2d0Tripp msg.appendChild(DOCUMENT.createTextNode(categoryItem.displayName +
d79066bfa31eec6909a20ccabb5227cc1e1ea2d0Tripp ": " + categoryItem.axis.get("labelFunction").apply(this, [categoryItem.value, categoryItem.axis.get("labelFormat")])));
d79066bfa31eec6909a20ccabb5227cc1e1ea2d0Tripp msg.appendChild(DOCUMENT.createElement("br"));
d79066bfa31eec6909a20ccabb5227cc1e1ea2d0Tripp msg.appendChild(DOCUMENT.createTextNode(valueItem.displayName +
d79066bfa31eec6909a20ccabb5227cc1e1ea2d0Tripp ": " + valueItem.axis.get("labelFunction").apply(this, [valueItem.value, valueItem.axis.get("labelFormat")])));
d79066bfa31eec6909a20ccabb5227cc1e1ea2d0Tripp msg.appendChild(DOCUMENT.createElement("br"));
d79066bfa31eec6909a20ccabb5227cc1e1ea2d0Tripp msg.appendChild(DOCUMENT.createTextNode(pct + "%"));
5c85869b71e935c40b7f7fbcdc2a7977348f786aTripp return msg;
e03e2775537690229fec4bc156e946f851d2cdfdTripp },
e03e2775537690229fec4bc156e946f851d2cdfdTripp
e03e2775537690229fec4bc156e946f851d2cdfdTripp /**
e03e2775537690229fec4bc156e946f851d2cdfdTripp * Returns the appropriate message based on the key press.
e03e2775537690229fec4bc156e946f851d2cdfdTripp *
e03e2775537690229fec4bc156e946f851d2cdfdTripp * @method _getAriaMessage
e03e2775537690229fec4bc156e946f851d2cdfdTripp * @param {Number} key The keycode that was pressed.
e03e2775537690229fec4bc156e946f851d2cdfdTripp * @return String
e03e2775537690229fec4bc156e946f851d2cdfdTripp */
e03e2775537690229fec4bc156e946f851d2cdfdTripp _getAriaMessage: function(key)
e03e2775537690229fec4bc156e946f851d2cdfdTripp {
e03e2775537690229fec4bc156e946f851d2cdfdTripp var msg = "",
e03e2775537690229fec4bc156e946f851d2cdfdTripp categoryItem,
edafb57ad91cdcd90ca3cb67d2cbe9aa31ff9077Tripp items,
edafb57ad91cdcd90ca3cb67d2cbe9aa31ff9077Tripp series,
e03e2775537690229fec4bc156e946f851d2cdfdTripp valueItem,
e03e2775537690229fec4bc156e946f851d2cdfdTripp seriesIndex = 0,
e03e2775537690229fec4bc156e946f851d2cdfdTripp itemIndex = this._itemIndex,
e03e2775537690229fec4bc156e946f851d2cdfdTripp seriesCollection = this.get("seriesCollection"),
e03e2775537690229fec4bc156e946f851d2cdfdTripp len,
e03e2775537690229fec4bc156e946f851d2cdfdTripp total,
e03e2775537690229fec4bc156e946f851d2cdfdTripp pct,
e03e2775537690229fec4bc156e946f851d2cdfdTripp markers;
e03e2775537690229fec4bc156e946f851d2cdfdTripp series = this.getSeries(parseInt(seriesIndex, 10));
e03e2775537690229fec4bc156e946f851d2cdfdTripp markers = series.get("markers");
e03e2775537690229fec4bc156e946f851d2cdfdTripp len = markers && markers.length ? markers.length : 0;
e03e2775537690229fec4bc156e946f851d2cdfdTripp if(key === 37)
e03e2775537690229fec4bc156e946f851d2cdfdTripp {
e03e2775537690229fec4bc156e946f851d2cdfdTripp itemIndex = itemIndex > 0 ? itemIndex - 1 : len - 1;
e03e2775537690229fec4bc156e946f851d2cdfdTripp }
e03e2775537690229fec4bc156e946f851d2cdfdTripp else if(key === 39)
e03e2775537690229fec4bc156e946f851d2cdfdTripp {
e03e2775537690229fec4bc156e946f851d2cdfdTripp itemIndex = itemIndex >= len - 1 ? 0 : itemIndex + 1;
e03e2775537690229fec4bc156e946f851d2cdfdTripp }
e03e2775537690229fec4bc156e946f851d2cdfdTripp this._itemIndex = itemIndex;
e03e2775537690229fec4bc156e946f851d2cdfdTripp items = this.getSeriesItems(series, itemIndex);
e03e2775537690229fec4bc156e946f851d2cdfdTripp categoryItem = items.category;
e03e2775537690229fec4bc156e946f851d2cdfdTripp valueItem = items.value;
e03e2775537690229fec4bc156e946f851d2cdfdTripp total = series.getTotalValues();
e03e2775537690229fec4bc156e946f851d2cdfdTripp pct = Math.round((valueItem.value / total) * 10000)/100;
e03e2775537690229fec4bc156e946f851d2cdfdTripp if(categoryItem && valueItem)
e03e2775537690229fec4bc156e946f851d2cdfdTripp {
a0bc19798c6a993799cde08b90c1aa2f54147792Tripp msg += categoryItem.displayName + ": " + categoryItem.axis.formatLabel.apply(this, [categoryItem.value, categoryItem.axis.get("labelFormat")]) + ", ";
a0bc19798c6a993799cde08b90c1aa2f54147792Tripp msg += valueItem.displayName + ": " + valueItem.axis.formatLabel.apply(this, [valueItem.value, valueItem.axis.get("labelFormat")]) + ", ";
a0bc19798c6a993799cde08b90c1aa2f54147792Tripp msg += "Percent of total " + valueItem.displayName + ": " + pct + "%,";
e03e2775537690229fec4bc156e946f851d2cdfdTripp }
e03e2775537690229fec4bc156e946f851d2cdfdTripp else
e03e2775537690229fec4bc156e946f851d2cdfdTripp {
a0bc19798c6a993799cde08b90c1aa2f54147792Tripp msg += "No data available,";
e03e2775537690229fec4bc156e946f851d2cdfdTripp }
a0bc19798c6a993799cde08b90c1aa2f54147792Tripp msg += (itemIndex + 1) + " of " + len + ". ";
e03e2775537690229fec4bc156e946f851d2cdfdTripp return msg;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp}, {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ATTRS: {
4e6fa831be0e594628556cb4a51e1cede308701cTripp /**
4e6fa831be0e594628556cb4a51e1cede308701cTripp * Sets the aria description for the chart.
4e6fa831be0e594628556cb4a51e1cede308701cTripp *
4e6fa831be0e594628556cb4a51e1cede308701cTripp * @attribute ariaDescription
4e6fa831be0e594628556cb4a51e1cede308701cTripp * @type String
4e6fa831be0e594628556cb4a51e1cede308701cTripp */
4e6fa831be0e594628556cb4a51e1cede308701cTripp ariaDescription: {
a0bc19798c6a993799cde08b90c1aa2f54147792Tripp value: "Use the left and right keys to navigate through items.",
4e6fa831be0e594628556cb4a51e1cede308701cTripp
4e6fa831be0e594628556cb4a51e1cede308701cTripp setter: function(val)
4e6fa831be0e594628556cb4a51e1cede308701cTripp {
4e6fa831be0e594628556cb4a51e1cede308701cTripp if(this._description)
4e6fa831be0e594628556cb4a51e1cede308701cTripp {
4e6fa831be0e594628556cb4a51e1cede308701cTripp this._description.setContent("");
4e6fa831be0e594628556cb4a51e1cede308701cTripp this._description.appendChild(DOCUMENT.createTextNode(val));
4e6fa831be0e594628556cb4a51e1cede308701cTripp }
4e6fa831be0e594628556cb4a51e1cede308701cTripp return val;
4e6fa831be0e594628556cb4a51e1cede308701cTripp }
4e6fa831be0e594628556cb4a51e1cede308701cTripp },
4e6fa831be0e594628556cb4a51e1cede308701cTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Axes to appear in the chart.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute axes
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type Object
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp axes: {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp getter: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return this._axes;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp setter: function(val)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._parseAxes(val);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Collection of series to appear on the chart. This can be an array of Series instances or object literals
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * used to describe a Series instance.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute seriesCollection
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type Array
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp seriesCollection: {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp getter: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return this._getSeriesCollection();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp setter: function(val)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return this._setSeriesCollection(val);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Type of chart when there is no series collection specified.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute type
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type String
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp type: {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp value: "pie"
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp});