Skip to content

Commit c1fa966

Browse files
committed
box: map boxlist index to calcdata items
- instead of simply assuming over boxlist.length === gd.calcdata - fixes http://codepen.io/etpinard/pen/EgrKEy
1 parent ecec280 commit c1fa966

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/traces/box/set_positions.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ module.exports = function setPositions(gd, plotinfo) {
7474
Axes.minDtick(posAxis, boxdv.minDiff, boxdv.vals[0], true);
7575

7676
// set the width of all boxes
77-
for(i = 0; i < boxlist.length; ++i) {
78-
gd.calcdata[i][0].t.dPos = dPos;
77+
for(i = 0; i < boxlist.length; i++) {
78+
var boxListIndex = boxlist[i];
79+
gd.calcdata[boxListIndex][0].t.dPos = dPos;
7980
}
8081

8182
// autoscale the x axis - including space for points if they're off the side

test/jasmine/tests/finance_test.js

+49
Original file line numberDiff line numberDiff line change
@@ -780,4 +780,53 @@ describe('finance charts updates:', function() {
780780
done();
781781
});
782782
});
783+
784+
it('Plotly.addTraces + Plotly.relayout should update candlestick box position values', function(done) {
785+
786+
function assertBoxPosFields(dPos) {
787+
expect(gd.calcdata.length).toEqual(dPos.length);
788+
789+
gd.calcdata.forEach(function(calcTrace, i) {
790+
if(dPos[i] === undefined) {
791+
expect(calcTrace[0].t.dPos).toBeUndefined();
792+
}
793+
else {
794+
expect(calcTrace[0].t.dPos).toEqual(dPos[i]);
795+
}
796+
});
797+
}
798+
799+
var trace0 = {
800+
type: 'candlestick',
801+
x: ['2011-01-01'],
802+
open: [0],
803+
high: [3],
804+
low: [1],
805+
close: [3]
806+
};
807+
808+
Plotly.plot(gd, [trace0]).then(function() {
809+
assertBoxPosFields([0.5, undefined]);
810+
811+
return Plotly.addTraces(gd, {});
812+
813+
})
814+
.then(function() {
815+
var update = {
816+
type: 'candlestick',
817+
x: [['2011-02-02']],
818+
open: [[0]],
819+
high: [[3]],
820+
low: [[1]],
821+
close: [[3]]
822+
};
823+
824+
return Plotly.restyle(gd, update);
825+
})
826+
.then(function() {
827+
assertBoxPosFields([0.5, undefined, 0.5, undefined]);
828+
829+
done();
830+
});
831+
});
783832
});

0 commit comments

Comments
 (0)