- i++;
- }
-};
-
-// Create the pie charts
-PlotKit.Layout.prototype._evaluatePieCharts = function() {
- var items = PlotKit.Base.items;
- var sum = MochiKit.Iter.sum;
- var getter = MochiKit.Base.itemgetter;
-
- var setCount = items(this.datasets).length;
-
- // we plot the y values of the first dataset
- var dataset = items(this.datasets)[0][1];
- var total = sum(map(getter(1), dataset));
-
- this.slices = new Array();
- var currentAngle = 0.0;
- for (var i = 0; i < dataset.length; i++) {
- var fraction = dataset[i][1] / total;
- var startAngle = currentAngle * Math.PI * 2;
- var endAngle = (currentAngle + fraction) * Math.PI * 2;
-
- var slice = {fraction: fraction,
- xval: dataset[i][0],
- yval: dataset[i][1],
- startAngle: startAngle,
- endAngle: endAngle
- };
- if (dataset[i][1] != 0) {
- this.slices.push(slice);
- }
- currentAngle += fraction;
- }
-};
-
-PlotKit.Layout.prototype._evaluateLineTicksForXAxis = function() {
- var isNil = MochiKit.Base.isUndefinedOrNull;
-
- if (this.options.xTicks) {
- // we use use specified ticks with optional labels
-
- this.xticks = new Array();
- var makeTicks = function(tick) {
- var label = tick.label;
- if (isNil(label))
- label = tick.v.toString();
- var pos = this.xscale * (tick.v - this.minxval);
- if ((pos >= 0.0) && (pos <= 1.0)) {
- this.xticks.push([pos, label]);
- }
- };
- MochiKit.Iter.forEach(this.options.xTicks, bind(makeTicks, this));
- }
- else if (this.options.xNumberOfTicks) {
- // we use defined number of ticks as hint to auto generate
- var xvalues = this._uniqueXValues();
- var roughSeparation = this.xrange / this.options.xNumberOfTicks;
- var tickCount = 0;
-
- this.xticks = new Array();
- for (var i = 0; i <= xvalues.length; i++) {
- if ((xvalues[i] - this.minxval) >= (tickCount * roughSeparation)) {
- var pos = this.xscale * (xvalues[i] - this.minxval);
- if ((pos > 1.0) || (pos < 0.0))
- continue;
- this.xticks.push([pos, xvalues[i]]);
- tickCount++;
- }
- if (tickCount > this.options.xNumberOfTicks)
- break;
- }
- }
-};
-
-PlotKit.Layout.prototype._evaluateLineTicksForYAxis = function() {
- var isNil = MochiKit.Base.isUndefinedOrNull;
-
-
- if (this.options.yTicks) {
- this.yticks = new Array();
- var makeTicks = function(tick) {
- var label = tick.label;
- if (isNil(label))
- label = tick.v.toString();
- var pos = 1.0 - (this.yscale * (tick.v - this.minyval));
- if ((pos >= 0.0) && (pos <= 1.0)) {
- this.yticks.push([pos, label]);
- }
- };
- MochiKit.Iter.forEach(this.options.yTicks, bind(makeTicks, this));
- }
- else if (this.options.yNumberOfTicks) {
- // We use the optionally defined number of ticks as a guide
- this.yticks = new Array();
-
- // if we get this separation right, we'll have good looking graphs
- var roundInt = PlotKit.Base.roundInterval;
- var prec = this.options.yTickPrecision;
- var roughSeparation = roundInt(this.yrange,
- this.options.yNumberOfTicks, prec);
-
- // round off each value of the y-axis to the precision
- // eg. 1.3333 at precision 1 -> 1.3
- for (var i = 0; i <= this.options.yNumberOfTicks; i++) {
- var yval = this.minyval + (i * roughSeparation);
- var pos = 1.0 - ((yval - this.minyval) * this.yscale);
- if ((pos > 1.0) || (pos < 0.0))
- continue;
- this.yticks.push([pos, MochiKit.Format.roundToFixed(yval, prec)]);
- }