Skip to content

Commit 5925c10

Browse files
authored
Merge pull request #3544 from plotly/finance-trailing-badnum-autorange-fix
Fix finance trace auto-range
2 parents 30eaa3a + 8a882de commit 5925c10

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

src/traces/box/cross_trace_calc.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,12 @@ function setPositionOffset(traceType, gd, boxList, posAxis) {
192192
vpadminus = pushminus;
193193
}
194194

195-
// calcdata[i][j] are in ascending order
196-
var firstPos = calcTrace[0].pos;
197-
var lastPos = calcTrace[calcTrace.length - 1].pos;
195+
var pos = new Array(calcTrace.length);
196+
for(j = 0; j < calcTrace.length; j++) {
197+
pos[j] = calcTrace[j].pos;
198+
}
198199

199-
trace._extremes[axId] = Axes.findExtremes(posAxis, [firstPos, lastPos], {
200+
trace._extremes[axId] = Axes.findExtremes(posAxis, pos, {
200201
padded: padded,
201202
vpadminus: vpadminus,
202203
vpadplus: vpadplus,

src/traces/ohlc/calc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function calcCommon(gd, trace, x, ya, ptFunc) {
9090

9191
cd.push(pt);
9292
} else {
93-
cd.push({empty: true});
93+
cd.push({pos: xi, empty: true});
9494
}
9595
}
9696

test/jasmine/tests/finance_test.js

+39-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ describe('finance charts calc', function() {
428428
addJunk(trace1);
429429

430430
var out = _calcRaw([trace0, trace1]);
431-
var indices = [0, 1, 2, 3, 4, 5, 6, 7, undefined, undefined, undefined, undefined];
431+
var indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
432432
var i = 'increasing';
433433
var d = 'decreasing';
434434
var directions = [i, d, d, i, d, i, d, i, undefined, undefined, undefined, undefined];
@@ -646,6 +646,44 @@ describe('finance charts calc', function() {
646646
});
647647
});
648648

649+
describe('finance charts auto-range', function() {
650+
var gd;
651+
652+
beforeEach(function() { gd = createGraphDiv(); });
653+
654+
afterEach(destroyGraphDiv);
655+
656+
describe('should give correct results with trailing nulls', function() {
657+
var base = {
658+
x: ['time1', 'time2', 'time3'],
659+
high: [10, 11, null],
660+
close: [5, 6, null],
661+
low: [3, 3, null],
662+
open: [4, 4, null]
663+
};
664+
665+
it('- ohlc case', function(done) {
666+
var trace = Lib.extendDeep({}, base, {type: 'ohlc'});
667+
668+
Plotly.plot(gd, [trace]).then(function() {
669+
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.5, 2.5], 1);
670+
})
671+
.catch(failTest)
672+
.then(done);
673+
});
674+
675+
it('- candlestick case', function(done) {
676+
var trace = Lib.extendDeep({}, base, {type: 'candlestick'});
677+
678+
Plotly.plot(gd, [trace]).then(function() {
679+
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.5, 2.5], 1);
680+
})
681+
.catch(failTest)
682+
.then(done);
683+
});
684+
});
685+
});
686+
649687
describe('finance charts updates:', function() {
650688
'use strict';
651689

0 commit comments

Comments
 (0)