Skip to content

Commit 80fb6a2

Browse files
authored
Merge pull request #1348 from plotly/finance-no-data
Don't try adding rangeslider to visible: false finance traces
2 parents 49f2137 + 66c1b01 commit 80fb6a2

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

src/traces/candlestick/transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ exports.transform = function transform(dataIn, state) {
4242
);
4343
}
4444

45-
helpers.addRangeSlider(state.layout);
45+
helpers.addRangeSlider(dataOut, state.layout);
4646

4747
return dataOut;
4848
};

src/traces/ohlc/helpers.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,18 @@ exports.getFilterFn = function(direction) {
104104
}
105105
};
106106

107-
exports.addRangeSlider = function(layout) {
108-
if(!layout.xaxis) layout.xaxis = {};
109-
if(!layout.xaxis.rangeslider) layout.xaxis.rangeslider = {};
107+
exports.addRangeSlider = function(data, layout) {
108+
var hasOneVisibleTrace = false;
109+
110+
for(var i = 0; i < data.length; i++) {
111+
if(data[i].visible === true) {
112+
hasOneVisibleTrace = true;
113+
break;
114+
}
115+
}
116+
117+
if(hasOneVisibleTrace) {
118+
if(!layout.xaxis) layout.xaxis = {};
119+
if(!layout.xaxis.rangeslider) layout.xaxis.rangeslider = {};
120+
}
110121
};

src/traces/ohlc/transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ exports.transform = function transform(dataIn, state) {
4444
);
4545
}
4646

47-
helpers.addRangeSlider(state.layout);
47+
helpers.addRangeSlider(dataOut, state.layout);
4848

4949
return dataOut;
5050
};

test/jasmine/tests/finance_test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,4 +962,44 @@ describe('finance charts updates:', function() {
962962
done();
963963
});
964964
});
965+
966+
it('Plotly.plot with data-less trace and adding with Plotly.restyle', function(done) {
967+
var data = [
968+
{ type: 'candlestick' },
969+
{ type: 'ohlc' },
970+
{ type: 'bar', y: [2, 1, 2] }
971+
];
972+
973+
Plotly.plot(gd, data).then(function() {
974+
expect(countScatterTraces()).toEqual(0);
975+
expect(countBoxTraces()).toEqual(0);
976+
expect(countRangeSliders()).toEqual(0);
977+
978+
return Plotly.restyle(gd, {
979+
open: [mock0.open],
980+
high: [mock0.high],
981+
low: [mock0.low],
982+
close: [mock0.close]
983+
}, [0]);
984+
})
985+
.then(function() {
986+
expect(countScatterTraces()).toEqual(0);
987+
expect(countBoxTraces()).toEqual(2);
988+
expect(countRangeSliders()).toEqual(1);
989+
990+
return Plotly.restyle(gd, {
991+
open: [mock0.open],
992+
high: [mock0.high],
993+
low: [mock0.low],
994+
close: [mock0.close]
995+
}, [1]);
996+
})
997+
.then(function() {
998+
expect(countScatterTraces()).toEqual(2);
999+
expect(countBoxTraces()).toEqual(2);
1000+
expect(countRangeSliders()).toEqual(1);
1001+
})
1002+
.then(done);
1003+
});
1004+
9651005
});

0 commit comments

Comments
 (0)