2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('series-curve-util', function (Y, NAME) {
11 * Provides functionality for drawing curves in a series.
14 * @submodule series-curve-util
17 * Utility class used for calculating curve points.
21 * @submodule series-curve-util
27 CurveUtil.prototype = {
29 * Creates an array of start, end and control points for splines.
31 * @method getCurveControlPoints
32 * @param {Array} xcoords Collection of x-coordinates used for calculate the curves
33 * @param {Array} ycoords Collection of y-coordinates used for calculate the curves
37 getCurveControlPoints: function(xcoords, ycoords)
41 l = xcoords.length - 1,
46 // Too few points, need at least two
59 // Special case, the Bezier should be a straight line
62 outpoints[0].ctrlx1 = (2.0*xcoords[0] + xcoords[1])/3.0;
63 outpoints[0].ctrly2 = (2.0*ycoords[0] + ycoords[1])/3.0;
64 outpoints[0].ctrlx2 = 2.0*outpoints[0].ctrlx1 - xcoords[0];
65 outpoints[0].ctrly2 = 2.0*outpoints[0].ctrly1 - ycoords[0];
72 startx: Math.round(xcoords[i]),
73 starty: Math.round(ycoords[i]),
74 endx: Math.round(xcoords[i+1]),
75 endy: Math.round(ycoords[i+1])
77 xvals[i] = 4.0 * xcoords[i] + 2*xcoords[i+1];
78 yvals[i] = 4.0*ycoords[i] + 2*ycoords[i+1];
81 xvals[0] = xcoords[0] + (2.0 * xcoords[1]);
82 xvals[l-1] = (8.0 * xcoords[l-1] + xcoords[l]) / 2.0;
83 xvals = this.getControlPoints(xvals.concat());
84 yvals[0] = ycoords[0] + (2.0 * ycoords[1]);
85 yvals[l-1] = (8.0 * ycoords[l-1] + ycoords[l]) / 2.0;
86 yvals = this.getControlPoints(yvals.concat());
88 for (i = 0; i < l; ++i)
90 outpoints[i].ctrlx1 = Math.round(xvals[i]);
91 outpoints[i].ctrly1 = Math.round(yvals[i]);
95 outpoints[i].ctrlx2 = Math.round(2*xcoords[i+1] - xvals[i+1]);
96 outpoints[i].ctrly2 = Math.round(2*ycoords[i+1] - yvals[i+1]);
100 outpoints[i].ctrlx2 = Math.round((xcoords[l] + xvals[l-1])/2);
101 outpoints[i].ctrly2 = Math.round((ycoords[l] + yvals[l-1])/2);
109 * Gets the control points for the curve.
111 * @method getControlPoints
112 * @param {Array} vals Collection of values coords used to generate control points.
116 getControlPoints: function(vals)
127 b = (i < l-1 ? 4.0 : 3.5) - tmp[i];
128 x[i] = (vals[i] - x[i-1]) / b;
131 for (i = 1; i < l; ++i)
133 x[l-i-1] -= tmp[l-i] * x[l-i];
139 Y.CurveUtil = CurveUtil;