2
YUI 3.10.3 (build 2fb5187)
3
Copyright 2013 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
8
YUI.add('series-line-util', function (Y, NAME) {
11
* Provides functionality for drawing lines in a series.
14
* @submodule series-line-util
17
* Utility class used for drawing lines.
21
* @submodule series-line-util
28
* @property _lineDefaults
35
* Creates a graphic in which to draw a series.
41
_getGraphic: function()
43
var graphic = this.get("graphic") || this.get("graph").get("graphic");
44
if(!this._lineGraphic)
46
this._lineGraphic = graphic.addShape({type: "path"});
48
this._lineGraphic.clear();
49
return this._lineGraphic;
55
* @method _toggleVisible
56
* @param {Boolean} visible indicates visibilitye
59
_toggleVisible: function(visible)
63
this._lineGraphic.set("visible", visible);
68
* Draws lines for the series.
75
if(this.get("xcoords").length < 1)
79
var isNumber = Y_Lang.isNumber,
82
direction = this.get("direction"),
86
noPointsRendered = true,
92
styles = this.get("styles").line,
93
lineType = styles.lineType,
94
lc = styles.color || this._getDefaultColor(this.get("graphOrder"), "line"),
95
lineAlpha = styles.alpha,
96
dashLength = styles.dashLength,
97
gapSpace = styles.gapSpace,
98
connectDiscontinuousPoints = styles.connectDiscontinuousPoints,
99
discontinuousType = styles.discontinuousType,
100
discontinuousDashLength = styles.discontinuousDashLength,
101
discontinuousGapSpace = styles.discontinuousGapSpace,
102
path = this._getGraphic();
105
xcoords = this.get("stackedXCoords");
106
ycoords = this.get("stackedYCoords");
110
xcoords = this.get("xcoords");
111
ycoords = this.get("ycoords");
113
len = direction === "vertical" ? ycoords.length : xcoords.length;
115
weight: styles.weight,
119
for(i = 0; i < len; i = ++i)
123
pointValid = isNumber(nextX) && isNumber(nextY);
126
lastPointValid = pointValid;
131
noPointsRendered = false;
132
path.moveTo(nextX, nextY);
134
else if(lastPointValid)
136
if(lineType !== "dashed")
138
path.lineTo(nextX, nextY);
142
this.drawDashedLine(path, lastValidX, lastValidY, nextX, nextY,
147
else if(!connectDiscontinuousPoints)
149
path.moveTo(nextX, nextY);
153
if(discontinuousType !== "solid")
155
this.drawDashedLine(path, lastValidX, lastValidY, nextX, nextY,
156
discontinuousDashLength,
157
discontinuousGapSpace);
161
path.lineTo(nextX, nextY);
166
lastPointValid = true;
172
* Connects data points with a consistent curve for a series.
177
drawSpline: function()
179
if(this.get("xcoords").length < 1)
183
var xcoords = this.get("xcoords"),
184
ycoords = this.get("ycoords"),
185
curvecoords = this.getCurveControlPoints(xcoords, ycoords),
186
len = curvecoords.length,
194
styles = this.get("styles").line,
195
path = this._getGraphic(),
196
lineAlpha = styles.alpha,
197
color = styles.color || this._getDefaultColor(this.get("graphOrder"), "line");
199
weight: styles.weight,
203
path.moveTo(xcoords[0], ycoords[0]);
204
for(; i < len; i = ++i)
206
x = curvecoords[i].endx;
207
y = curvecoords[i].endy;
208
cx1 = curvecoords[i].ctrlx1;
209
cx2 = curvecoords[i].ctrlx2;
210
cy1 = curvecoords[i].ctrly1;
211
cy2 = curvecoords[i].ctrly2;
212
path.curveTo(cx1, cy1, cx2, cy2, x, y);
218
* Draws a dashed line between two points.
220
* @method drawDashedLine
221
* @param {Number} xStart The x position of the start of the line
222
* @param {Number} yStart The y position of the start of the line
223
* @param {Number} xEnd The x position of the end of the line
224
* @param {Number} yEnd The y position of the end of the line
225
* @param {Number} dashSize the size of dashes, in pixels
226
* @param {Number} gapSize the size of gaps between dashes, in pixels
229
drawDashedLine: function(path, xStart, yStart, xEnd, yEnd, dashSize, gapSize)
231
dashSize = dashSize || 10;
232
gapSize = gapSize || 10;
233
var segmentLength = dashSize + gapSize,
234
xDelta = xEnd - xStart,
235
yDelta = yEnd - yStart,
236
delta = Math.sqrt(Math.pow(xDelta, 2) + Math.pow(yDelta, 2)),
237
segmentCount = Math.floor(Math.abs(delta / segmentLength)),
238
radians = Math.atan2(yDelta, xDelta),
242
xDelta = Math.cos(radians) * segmentLength;
243
yDelta = Math.sin(radians) * segmentLength;
245
for(i = 0; i < segmentCount; ++i)
247
path.moveTo(xCurrent, yCurrent);
248
path.lineTo(xCurrent + Math.cos(radians) * dashSize, yCurrent + Math.sin(radians) * dashSize);
253
path.moveTo(xCurrent, yCurrent);
254
delta = Math.sqrt((xEnd - xCurrent) * (xEnd - xCurrent) + (yEnd - yCurrent) * (yEnd - yCurrent));
258
path.lineTo(xCurrent + Math.cos(radians) * dashSize, yCurrent + Math.sin(radians) * dashSize);
262
path.lineTo(xCurrent + Math.cos(radians) * delta, yCurrent + Math.sin(radians) * delta);
265
path.moveTo(xEnd, yEnd);
269
* Default values for `styles` attribute.
271
* @method _getLineDefaults
275
_getLineDefaults: function()
283
connectDiscontinuousPoints:true,
284
discontinuousType:"solid",
285
discontinuousDashLength:10,
286
discontinuousGapSpace:10
290
Y.augment(Lines, Y.Attribute);