Skip to content

Commit 21a41ea

Browse files
committed
Merge branch 'perf' of github.com:ezequiel/stockindicators into ezequiel-perf
Conflicts: src/gallery-charts-stockindicators/js/CanvasAxis.js src/gallery-charts-stockindicators/js/GridlinesCanvas.js src/gallery-charts-stockindicators/js/MultipleLineCanvasSeries.js src/gallery-charts-stockindicators/js/MultipleLineSeries.js src/gallery-charts-stockindicators/js/StockIndicatorsChart.js src/gallery-charts-stockindicators/js/VolumeColumnCanvas.js modified: CanvasAxis.js modified: Crosshair.js modified: Gridlines.js modified: GridlinesCanvas.js modified: IntradayAxisBase.js modified: MultipleLineSeries.js modified: StockIndicatorsAxisLegend.js modified: StockIndicatorsChart.js modified: StockIndicatorsLegend.js
2 parents 9cd0c57 + 0626e7f commit 21a41ea

9 files changed

+53
-52
lines changed

src/gallery-charts-stockindicators/js/CanvasAxis.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ Y.CanvasAxis = Y.Base.create("canvasAxis", Y.AxisBase, [Y.Renderer], Y.merge(Y.A
8181
explicitLabels = this._labelValuesExplicitlySet ? this.get("labelValues") : null,
8282
direction = (position === "left" || position === "right") ? "vertical" : "horizontal";
8383
if(margin) {
84-
marginLeft = Y.Lang.isNumber(margin.left) ? margin.left : 0;
85-
marginRight = Y.Lang.isNumber(margin.right) ? margin.right : 0;
86-
marginTop = Y.Lang.isNumber(margin.top) ? margin.top : 0;
87-
marginBottom = Y.Lang.isNumber(margin.bottom) ? margin.bottom : 0;
84+
marginLeft = typeof margin.left === "number" ? margin.left : 0;
85+
marginRight = typeof margin.right === "number" ? margin.right : 0;
86+
marginTop = typeof margin.top === "number" ? margin.top : 0;
87+
marginBottom = typeof margin.bottom === "number" ? margin.bottom : 0;
8888
}
8989
//need to defaultMargins method to the layout classes.
9090
for(i in defaultMargins)

src/gallery-charts-stockindicators/js/Crosshair.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,27 @@ Y.Crosshair.prototype = {
9999
graph,
100100
i,
101101
index = Math.floor((x / this.width) * this._xcoords.length),
102-
len = series.length;
102+
len = series.length,
103+
isNumber;
104+
103105
this._yline.set("transform", "translate(" + x + ")");
104106
if(series) {
105107
for(i = 0; i < len; i = i + 1) {
106108
graph = series[i];
107109
y = graph.coords[index];
110+
isNumber = typeof y === "number";
111+
108112
if(graph.marker) {
109-
if(Y.Lang.isNumber(y)) {
110-
graph.marker.set("visible", true);
113+
if(isNumber) {
111114
graph.marker.set("transform", "translate(" + x + ", " + y + ")");
112-
} else {
113-
graph.marker.set("visible", false);
114115
}
116+
graph.marker.set("visible", isNumber);
115117
}
116118
if(graph.line) {
117-
if(Y.Lang.isNumber(y)) {
118-
graph.xLine.set("visible", true);
119+
if(isNumber) {
119120
graph.xLine.set("transform", "translateY(" + y + ")");
120-
} else {
121-
graph.xLine.set("visible", false);
122121
}
122+
graph.xLine.set("visible", isNumber);
123123
}
124124
}
125125
}

src/gallery-charts-stockindicators/js/Gridlines.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ Y.Gridlines = Y.Base.create("gridlines", Y.Base, [Y.Renderer], {
4545
* would result in a solid fill across the area.
4646
* @protected
4747
*/
48-
draw: function()
48+
draw: function(w, h, startIndex, interval)
4949
{
5050
if(this.get("axis") && this.get("graphic"))
5151
{
52-
this._drawGridlines.apply(this, arguments);
52+
this._drawGridlines(w, h, startIndex, interval);
5353
}
5454
},
5555

src/gallery-charts-stockindicators/js/GridlinesCanvas.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ Y.GridlinesCanvas = Y.Base.create("gridlinesCanvas", Y.Gridlines, [], {
5252
* would result in a solid fill across the area.
5353
* @protected
5454
*/
55-
draw: function()
55+
draw: function(w, h, startIndex, interval)
5656
{
5757
if(this.get("axis"))
5858
{
59-
this._drawGridlines.apply(this, arguments);
59+
this._drawGridlines(w, h, startIndex, interval);
6060
}
6161
},
6262

src/gallery-charts-stockindicators/js/IntradayAxisBase.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Y.extend(Y.IntradayAxisBase, Y.CategoryAxisBase, {
2828
last = allData[allData.length - 1].Timestamp;
2929
if(dataGranularity) {
3030
interval = parseFloat(dataGranularity) * 60000;
31-
max = new Date(max).valueOf();
32-
last = new Date(last).valueOf();
31+
max = +new Date(max);
32+
last = +new Date(last);
3333

3434
if(max > last) {
3535
while(max > last) {

src/gallery-charts-stockindicators/js/MultipleLineSeries.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ Y.MultipleLineSeries = Y.Base.create("multipleLineSeries", Y.CartesianSeries, [Y
2727
{
2828
return;
2929
}
30-
var isNumber = Y.Lang.isNumber,
31-
direction = this.get("direction"),
30+
var direction = this.get("direction"),
3231
len,
3332
lastPointValid,
3433
pointValid,
@@ -70,7 +69,7 @@ Y.MultipleLineSeries = Y.Base.create("multipleLineSeries", Y.CartesianSeries, [Y
7069
{
7170
nextX = Math.round(xcoords[i] * 1000)/1000;
7271
nextY = Math.round(ycoords[i] * 1000)/1000;
73-
pointValid = isNumber(nextX) && isNumber(nextY);
72+
pointValid = typeof nextX === "number" && typeof nextY === "number";
7473
if(pointValid) {
7574
thresholdIndex = 0;
7675
if(thresholds) {
@@ -92,7 +91,7 @@ Y.MultipleLineSeries = Y.Base.create("multipleLineSeries", Y.CartesianSeries, [Y
9291
m = Math.round(((nextY - lastValidY) / (nextX - lastValidX)) * 1000)/1000;
9392
intersectX = ((thresholdCoords[thresholdIndex] - nextY)/m) + nextX;
9493
intersectY = thresholdCoords[thresholdIndex];
95-
if(isNumber(lastPathIndex)) {
94+
if(typeof lastPathIndex === "number") {
9695
this._lineTo(graphPaths[lastPathIndex], intersectX, intersectY);
9796
}
9897
this._moveTo(graphPaths[pathIndex], intersectX, intersectY);

src/gallery-charts-stockindicators/js/StockIndicatorsAxisLegend.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ Y.StockIndicatorsAxisLegend.prototype = {
182182
minLabel = DOCUMENT.createElement("span"),
183183
height,
184184
width,
185-
minText = this._labelFunction.apply(this, [this._minimum, this._labelFormat]),
186-
maxText = this._labelFunction.apply(this, [this._maximum, this._labelFormat]),
185+
minText = this._labelFunction(this._minimum, this._labelFormat),
186+
maxText = this._labelFunction(this._maximum, this._labelFormat),
187187
container = DOCUMENT.createElement("div"),
188188
arrow = DOCUMENT.createElement("span"),
189189
key,
@@ -283,7 +283,7 @@ Y.StockIndicatorsAxisLegend.prototype = {
283283
arrow = DOCUMENT.createElement("span"),
284284
label = DOCUMENT.createElement("span"),
285285
key,
286-
text = this._labelFunction.apply(this, [value, this._labelFormat]),
286+
text = this._labelFunction(value, this._labelFormat),
287287
ycoord = previousClose.ycoord ||
288288
axis._getCoordFromValue(this._minimum, this._maximum, this.height, value, this.height, true);
289289
ycoord = ycoord + this._y;
@@ -447,7 +447,7 @@ Y.StockIndicatorsAxisLegend.prototype = {
447447
label.style.background = background;
448448
arrow.style.borderRightColor = background;
449449
}
450-
text = this._labelFunction.apply(this, [value, this._labelFormat]),
450+
text = this._labelFunction(value, this._labelFormat),
451451
ycoord = this._y + axis._getCoordFromValue(this._minimum, this._maximum, this.height, value, this.height, true);
452452
label.appendChild(DOCUMENT.createTextNode(text));
453453
container.style.position = "absolute";

src/gallery-charts-stockindicators/js/StockIndicatorsChart.js

+25-23
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Y.StockIndicatorsChart = Y.Base.create("stockIndicatorsChart", Y.Widget, [Y.Ren
1515
*/
1616
initializer: function() {
1717
var cb = this.get("contentBox");
18-
cb.setStyle("position", "relative");
18+
cb._node.style.position = "relative";
1919
this._axes = [];
2020
this._graphs = [];
2121
this._graphics = [];
@@ -266,7 +266,7 @@ Y.StockIndicatorsChart = Y.Base.create("stockIndicatorsChart", Y.Widget, [Y.Ren
266266
startTimeline: function() {
267267
if(!this._runTimeline) {
268268
this._runTimeline = true;
269-
this._timelineStart = (new Date()).valueOf() - 17;
269+
this._timelineStart = +new Date() - 17;
270270
this.redraw();
271271
}
272272
},
@@ -299,7 +299,7 @@ Y.StockIndicatorsChart = Y.Base.create("stockIndicatorsChart", Y.Widget, [Y.Ren
299299
chart,
300300
i,
301301
len = charts.length,
302-
endTime = (new Date()).valueOf();
302+
endTime = +new Date();
303303
if(endTime >= this._timelineStart + 17) {
304304
for(i = 0; i < len; i = i + 1) {
305305
chart = charts[i];
@@ -312,7 +312,7 @@ Y.StockIndicatorsChart = Y.Base.create("stockIndicatorsChart", Y.Widget, [Y.Ren
312312
legend.redraw();
313313
}
314314
}
315-
this._timelineStart = (new Date()).valueOf();
315+
this._timelineStart = +new Date();
316316
}
317317
if(this._runTimeline && !this._autoDraw) {
318318
this._timelineId = this._onEnterFrame.apply(WINDOW, [function() {
@@ -375,13 +375,19 @@ Y.StockIndicatorsChart = Y.Base.create("stockIndicatorsChart", Y.Widget, [Y.Ren
375375
valueLen,
376376
valueKey,
377377
groupMarkers,
378-
nomarkers = ["candlestick", "line", "ohlc", "volumecolumn", "multipleline"];
378+
nomarkers = {
379+
"candlestick": true,
380+
"line": true,
381+
"ohlc": true,
382+
"volumecolumn": true,
383+
"multipleline": true
384+
};
379385
for(indIter = 0; indIter < indLen; indIter = indIter + 1) {
380386
indicator = indicators[indIter];
381387
valueKey = indicator.valueKey;
382388
indicatorType = indicator.type;
383389
if(indicatorType === "candlestick" || indicatorType === "ohlc" || typeof valueKey === "string") {
384-
groupMarkers = Y.Array.indexOf(nomarkers, indicatorType) === -1 && indicator.groupMarkers;
390+
groupMarkers = !nomarkers[indicatorType] && indicator.groupMarkers;
385391
seriesConfig = {
386392
groupMarkers: groupMarkers,
387393
type: indicator.type,
@@ -398,10 +404,10 @@ Y.StockIndicatorsChart = Y.Base.create("stockIndicatorsChart", Y.Widget, [Y.Ren
398404
yKey: indicator.valueKey[valueIter]
399405
};
400406
if(typeof indicatorType === "string") {
401-
seriesConfig.groupMarkers = Y.Array.indexOf(nomarkers, indicatorType) === -1 && indicator.groupMarkers;
407+
seriesConfig.groupMarkers = !nomarkers[indicatorType] && indicator.groupMarkers;
402408
seriesConfig.type = indicatorType;
403409
} else {
404-
seriesConfig.groupMarkers = Y.Array.indexOf(nomarkers, indicatorType[valueIter]) === -1 && indicator.groupMarkers;
410+
seriesConfig.groupMarkers = !nomarkers[indicatorType] && indicator.groupMarkers;
405411
seriesConfig.type = indicatorType[valueIter];
406412
if(indicatorType[valueIter] === "multipleline" && config.threshold && config.range === "1d") {
407413
seriesConfig.thresholds = [parseFloat(indicator.previousClose)];
@@ -661,11 +667,12 @@ Y.StockIndicatorsChart = Y.Base.create("stockIndicatorsChart", Y.Widget, [Y.Ren
661667
numericAxis = new NumericClass(numericConfig);
662668
dateAxis = new DateClass(dateConfig);
663669
bb = dateAxis.get("boundingBox");
664-
bb.setStyle("left", 0 + "px");
665-
bb.setStyle("top", dateConfig.y + "px");
670+
bb._node.style.left = 0;
671+
bb._node.style.top = dateConfig.y + "px";
672+
666673
bb = numericAxis.get("boundingBox");
667-
bb.setStyle("left", numericConfig.x + "px");
668-
bb.setStyle("top", numericConfig.y + "px");
674+
bb._node.style.left = numericConfig.x + "px";
675+
bb._node.style.top = numericConfig.y + "px";
669676
axes = {
670677
numeric: numericAxis,
671678
date: dateAxis
@@ -843,7 +850,8 @@ Y.StockIndicatorsChart = Y.Base.create("stockIndicatorsChart", Y.Widget, [Y.Ren
843850
key,
844851
color,
845852
crosshairKey,
846-
validKeys = config.keys;
853+
validKeys = Y.Array.hash(config.keys);
854+
847855
for(key in graphs) {
848856
if(graphs.hasOwnProperty(key)){
849857
crosshairKey = key === "quote" ? "close" : key;
@@ -852,7 +860,7 @@ Y.StockIndicatorsChart = Y.Base.create("stockIndicatorsChart", Y.Widget, [Y.Ren
852860
if(color && typeof color === "object" && graph.get("type") === "combo") {
853861
color = color.line;
854862
}
855-
if(Y.Array.indexOf(validKeys, crosshairKey) > -1) {
863+
if(validKeys[crosshairKey]) {
856864
series = {
857865
marker: {
858866
shape: "circle",
@@ -1197,15 +1205,9 @@ Y.StockIndicatorsChart = Y.Base.create("stockIndicatorsChart", Y.Widget, [Y.Ren
11971205
}
11981206
}
11991207
}
1200-
if(this._startHandle) {
1201-
this._startHandle.detach();
1202-
}
1203-
if(this._moveHandle) {
1204-
this._moveHandle.detach();
1205-
}
1206-
if(this._endHandle) {
1207-
this._endHandle.detach();
1208-
}
1208+
this._startHandle.detach();
1209+
this._moveHandle.detach();
1210+
this._endHandle.detach();
12091211
},
12101212

12111213
destructor: function() {

src/gallery-charts-stockindicators/js/StockIndicatorsLegend.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ StockIndicatorsLegend.prototype = {
7373
this.dateLabelFunction = cfg.dateLabelFunction;
7474
this.dateLabelFormat = cfg.dateLabelFormat;
7575
this.dateLabelScope = cfg.dateLabelScope || this;
76-
cfg.render.getDOMNode().appendChild(this.contentDiv);
76+
cfg.render._node.appendChild(this.contentDiv);
7777

7878
len = seriesQueue.length;
7979
myul = Y.DOM.create(
@@ -212,7 +212,7 @@ StockIndicatorsLegend.prototype = {
212212
item.li.style.display = "inline-block";
213213
val = dataItem[key];
214214
item.value.innerHTML = Y.Number.format(parseFloat(val), this.valueLabelFormat);
215-
Y.DOM.setStyle(item.value, "color", val > 0 ? this.priceUpColor : this.priceDownColor);
215+
item.value.style.color = val > 0 ? this.priceUpColor : this.priceDownColor;
216216
} else {
217217
item.li.style.display = "none";
218218
}

0 commit comments

Comments
 (0)