Skip to content

Commit 597adf9

Browse files
committed
ensure o, h, l, and c are all numeric - or drop the whole point
1 parent 9575ab6 commit 597adf9

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/traces/candlestick/transform.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
'use strict';
1111

12+
var isNumeric = require('fast-isnumeric');
13+
1214
var Lib = require('../../lib');
1315
var helpers = require('../ohlc/helpers');
1416

@@ -115,7 +117,7 @@ exports.calcTransform = function calcTransform(gd, trace, opts) {
115117
};
116118

117119
for(var i = 0; i < len; i++) {
118-
if(filterFn(open[i], close[i])) {
120+
if(filterFn(open[i], close[i]) && isNumeric(high[i]) && isNumeric(low[i])) {
119121
appendX(i);
120122
appendY(open[i], high[i], low[i], close[i]);
121123
}

src/traces/ohlc/helpers.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
'use strict';
1111

12+
var isNumeric = require('fast-isnumeric');
13+
1214
var Lib = require('../../lib');
1315

1416
// This routine gets called during the trace supply-defaults step.
@@ -103,7 +105,7 @@ function _getFilterFn(direction) {
103105
var isPrevIncreasing = true;
104106
var cPrev = null;
105107

106-
function isIncreasing(o, c) {
108+
function _isIncreasing(o, c) {
107109
if(o === c) {
108110
if(c > cPrev) {
109111
isPrevIncreasing = true; // increasing
@@ -117,8 +119,12 @@ function _getFilterFn(direction) {
117119
return isPrevIncreasing;
118120
}
119121

122+
function isIncreasing(o, c) {
123+
return isNumeric(o) && isNumeric(c) && _isIncreasing(+o, +c);
124+
}
125+
120126
function isDecreasing(o, c) {
121-
return !isIncreasing(o, c);
127+
return isNumeric(o) && isNumeric(c) && !_isIncreasing(+o, +c);
122128
}
123129

124130
return direction === 'increasing' ? isIncreasing : isDecreasing;

src/traces/ohlc/transform.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
'use strict';
1111

12+
var isNumeric = require('fast-isnumeric');
13+
1214
var Lib = require('../../lib');
1315
var helpers = require('./helpers');
1416
var Axes = require('../../plots/cartesian/axes');
@@ -195,7 +197,7 @@ exports.calcTransform = function calcTransform(gd, trace, opts) {
195197
};
196198

197199
for(var i = 0; i < len; i++) {
198-
if(filterFn(open[i], close[i])) {
200+
if(filterFn(open[i], close[i]) && isNumeric(high[i]) && isNumeric(low[i])) {
199201
appendX(i);
200202
appendY(open[i], high[i], low[i], close[i]);
201203
appendText(i, open[i], high[i], low[i], close[i]);

test/jasmine/tests/finance_test.js

+14
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,28 @@ describe('finance charts calc transforms:', function() {
395395
return gd.calcdata.map(calcDatatoTrace);
396396
}
397397

398+
// add some points that shouldn't make it into calcdata because
399+
// one of o, h, l, c is not numeric
400+
function addJunk(trace) {
401+
// x filtering happens in other ways
402+
if(trace.x) trace.x.push(1, 1, 1, 1);
403+
404+
trace.open.push('', 1, 1, 1);
405+
trace.high.push(1, null, 1, 1);
406+
trace.low.push(1, 1, [1], 1);
407+
trace.close.push(1, 1, 1, 'close');
408+
}
409+
398410
it('should fill when *x* is not present', function() {
399411
var trace0 = Lib.extendDeep({}, mock0, {
400412
type: 'ohlc',
401413
});
414+
addJunk(trace0);
402415

403416
var trace1 = Lib.extendDeep({}, mock0, {
404417
type: 'candlestick',
405418
});
419+
addJunk(trace1);
406420

407421
var out = _calc([trace0, trace1]);
408422

0 commit comments

Comments
 (0)