Skip to content

Fix finance trace auto-range #3544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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