Skip to content

Commit

Permalink
Merge pull request #3544 from plotly/finance-trailing-badnum-autorang…
Browse files Browse the repository at this point in the history
…e-fix

Fix finance trace auto-range
  • Loading branch information
etpinard authored Feb 14, 2019
2 parents 30eaa3a + 8a882de commit 5925c10
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/traces/box/cross_trace_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,12 @@ function setPositionOffset(traceType, gd, boxList, posAxis) {
vpadminus = pushminus;
}

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

trace._extremes[axId] = Axes.findExtremes(posAxis, [firstPos, lastPos], {
trace._extremes[axId] = Axes.findExtremes(posAxis, pos, {
padded: padded,
vpadminus: vpadminus,
vpadplus: vpadplus,
Expand Down
2 changes: 1 addition & 1 deletion src/traces/ohlc/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function calcCommon(gd, trace, x, ya, ptFunc) {

cd.push(pt);
} else {
cd.push({empty: true});
cd.push({pos: xi, empty: true});
}
}

Expand Down
40 changes: 39 additions & 1 deletion test/jasmine/tests/finance_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ describe('finance charts calc', function() {
addJunk(trace1);

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

describe('finance charts auto-range', function() {
var gd;

beforeEach(function() { gd = createGraphDiv(); });

afterEach(destroyGraphDiv);

describe('should give correct results with trailing nulls', function() {
var base = {
x: ['time1', 'time2', 'time3'],
high: [10, 11, null],
close: [5, 6, null],
low: [3, 3, null],
open: [4, 4, null]
};

it('- ohlc case', function(done) {
var trace = Lib.extendDeep({}, base, {type: 'ohlc'});

Plotly.plot(gd, [trace]).then(function() {
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.5, 2.5], 1);
})
.catch(failTest)
.then(done);
});

it('- candlestick case', function(done) {
var trace = Lib.extendDeep({}, base, {type: 'candlestick'});

Plotly.plot(gd, [trace]).then(function() {
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([-0.5, 2.5], 1);
})
.catch(failTest)
.then(done);
});
});
});

describe('finance charts updates:', function() {
'use strict';

Expand Down

0 comments on commit 5925c10

Please sign in to comment.