Skip to content

Commit 0b7541e

Browse files
committed
fix for box & candlestick together on one subplot
also an image test for #2004 category OHLC and candlestick using box layout attrs
1 parent 71fa112 commit 0b7541e

File tree

7 files changed

+111
-14
lines changed

7 files changed

+111
-14
lines changed

src/plots/cartesian/index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,16 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
211211
var _module = modules[j];
212212

213213
// skip over non-cartesian trace modules
214-
if(_module.basePlotModule.name !== 'cartesian') continue;
214+
if(!_module.plot || _module.basePlotModule.name !== 'cartesian') continue;
215215

216216
// plot all traces of this type on this subplot at once
217-
var cdModule = getModuleCalcData(cdSubplot, _module);
217+
var cdModuleAndOthers = getModuleCalcData(cdSubplot, _module);
218+
var cdModule = cdModuleAndOthers[0];
219+
// don't need to search the found traces again - in fact we need to NOT
220+
// so that if two modules share the same plotter we don't double-plot
221+
cdSubplot = cdModuleAndOthers[1];
218222

219-
if(_module.plot) _module.plot(gd, plotinfo, cdModule, transitionOpts, makeOnCompleteCallback);
223+
_module.plot(gd, plotinfo, cdModule, transitionOpts, makeOnCompleteCallback);
220224
}
221225
}
222226

src/plots/get_data.js

+28-8
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ var Registry = require('../registry');
1212
var SUBPLOT_PATTERN = require('./cartesian/constants').SUBPLOT_PATTERN;
1313

1414
/**
15-
* Get calcdata traces(s) associated with a given subplot
15+
* Get calcdata trace(s) associated with a given subplot
1616
*
17-
* @param {array} calcData (as in gd.calcdata)
18-
* @param {string} type subplot type
19-
* @param {string} subplotId subplot id to look for
17+
* @param {array} calcData: as in gd.calcdata
18+
* @param {string} type: subplot type
19+
* @param {string} subplotId: subplot id to look for
2020
*
2121
* @return {array} array of calcdata traces
2222
*/
@@ -36,20 +36,40 @@ exports.getSubplotCalcData = function(calcData, type, subplotId) {
3636

3737
return subplotCalcData;
3838
};
39-
39+
/**
40+
* Get calcdata trace(s) that can be plotted with a given module
41+
* NOTE: this isn't necessarily just exactly matching trace type,
42+
* if multiple trace types use the same plotting routine, they will be
43+
* collected here.
44+
* In order to not plot the same thing multiple times, we return two arrays,
45+
* the calcdata we *will* plot with this module, and the ones we *won't*
46+
*
47+
* @param {array} calcdata: as in gd.calcdata
48+
* @param {object|string} typeOrModule: the plotting module, or its name
49+
*
50+
* @return {array[array]} [foundCalcdata, remainingCalcdata]
51+
*/
4052
exports.getModuleCalcData = function(calcdata, typeOrModule) {
4153
var moduleCalcData = [];
54+
var remainingCalcData = [];
4255
var _module = typeof typeOrModule === 'string' ? Registry.getModule(typeOrModule) : typeOrModule;
43-
if(!_module) return moduleCalcData;
56+
if(!_module) return [moduleCalcData, calcdata];
4457

4558
for(var i = 0; i < calcdata.length; i++) {
4659
var cd = calcdata[i];
4760
var trace = cd[0].trace;
61+
if(trace.visible !== true) continue;
4862

49-
if((trace._module === _module) && (trace.visible === true)) moduleCalcData.push(cd);
63+
// we use this to find data to plot - so if there's a .plot
64+
if(trace._module.plot === _module.plot) {
65+
moduleCalcData.push(cd);
66+
}
67+
else {
68+
remainingCalcData.push(cd);
69+
}
5070
}
5171

52-
return moduleCalcData;
72+
return [moduleCalcData, remainingCalcData];
5373
};
5474

5575
/**

src/traces/parcoords/base_plot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var PARCOORDS = 'parcoords';
1818
exports.name = PARCOORDS;
1919

2020
exports.plot = function(gd) {
21-
var calcData = getModuleCalcData(gd.calcdata, PARCOORDS);
21+
var calcData = getModuleCalcData(gd.calcdata, PARCOORDS)[0];
2222
if(calcData.length) parcoordsPlot(gd, calcData);
2323
};
2424

src/traces/sankey/base_plot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ exports.baseLayoutAttrOverrides = overrideAll({
2222
}, 'plot', 'nested');
2323

2424
exports.plot = function(gd) {
25-
var calcData = getModuleCalcData(gd.calcdata, SANKEY);
25+
var calcData = getModuleCalcData(gd.calcdata, SANKEY)[0];
2626
plot(gd, calcData);
2727
};
2828

src/traces/table/base_plot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var TABLE = 'table';
1616
exports.name = TABLE;
1717

1818
exports.plot = function(gd) {
19-
var calcData = getModuleCalcData(gd.calcdata, TABLE);
19+
var calcData = getModuleCalcData(gd.calcdata, TABLE)[0];
2020
if(calcData.length) tablePlot(gd, calcData);
2121
};
2222

Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"data": [{
3+
"type": "ohlc",
4+
"x": [
5+
"2018-04-17", "2018-04-18", "2018-04-19", "2018-04-20",
6+
"2018-04-23", "2018-04-24", "2018-04-25", "2018-04-26", "2018-04-27"
7+
],
8+
"open": [10, 11, 12, 13, 12, 13, 14, 15, 16],
9+
"high": [15, 16, 17, 18, 17, 18, 19, 20, 21],
10+
"low": [7, 8, 9, 10, 9, 10, 11, 12, 13],
11+
"close": [9, 10, 12, 13, 13, 12, 14, 14, 17],
12+
"name": "Date OHLC"
13+
}, {
14+
"type": "candlestick",
15+
"x": [
16+
"2018-04-17", "2018-04-18", "2018-04-19", "2018-04-20",
17+
"2018-04-23", "2018-04-24", "2018-04-25", "2018-04-26", "2018-04-27"
18+
],
19+
"open": [20, 21, 22, 23, 22, 23, 24, 25, 26],
20+
"high": [25, 26, 27, 28, 27, 28, 29, 30, 31],
21+
"low": [17, 18, 19, 20, 19, 20, 21, 22, 23],
22+
"close": [19, 20, 22, 23, 23, 22, 24, 24, 27],
23+
"name": "Date Candlestick"
24+
}, {
25+
"type": "ohlc",
26+
"xaxis": "x2",
27+
"x": [
28+
"2018-04-17", "2018-04-18", "2018-04-19", "2018-04-20",
29+
"2018-04-23", "2018-04-24", "2018-04-25", "2018-04-26", "2018-04-27"
30+
],
31+
"open": [10, 11, 12, 13, 12, 13, 14, 15, 16],
32+
"high": [15, 16, 17, 18, 17, 18, 19, 20, 21],
33+
"low": [7, 8, 9, 10, 9, 10, 11, 12, 13],
34+
"close": [9, 10, 12, 13, 13, 12, 14, 14, 17],
35+
"increasing": {"line": {"color": "orange"}},
36+
"decreasing": {"line": {"color": "blue"}},
37+
"name": "Category OHLC"
38+
}, {
39+
"type": "candlestick",
40+
"xaxis": "x2",
41+
"x": [
42+
"2018-04-17", "2018-04-18", "2018-04-19", "2018-04-20",
43+
"2018-04-23", "2018-04-24", "2018-04-25", "2018-04-26", "2018-04-27"
44+
],
45+
"open": [20, 21, 22, 23, 22, 23, 24, 25, 26],
46+
"high": [25, 26, 27, 28, 27, 28, 29, 30, 31],
47+
"low": [17, 18, 19, 20, 19, 20, 21, 22, 23],
48+
"close": [19, 20, 22, 23, 23, 22, 24, 24, 27],
49+
"increasing": {"line": {"color": "orange"}},
50+
"decreasing": {"line": {"color": "blue"}},
51+
"name": "Category Candlestick"
52+
}, {
53+
"type": "box",
54+
"x": [
55+
"2018-04-23", "2018-04-23", "2018-04-23", "2018-04-23", "2018-04-23",
56+
"2018-04-23", "2018-04-23", "2018-04-23", "2018-04-23", "2018-04-23",
57+
"2018-04-24", "2018-04-24", "2018-04-24", "2018-04-24", "2018-04-24",
58+
"2018-04-24", "2018-04-24", "2018-04-24", "2018-04-24", "2018-04-24"
59+
],
60+
"y": [
61+
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
62+
20, 21, 22, 23, 24, 25, 26, 27, 28, 29
63+
],
64+
"name": "Box"
65+
}],
66+
"layout": {
67+
"xaxis": {"domain": [0, 0.45], "title": "Date"},
68+
"xaxis2": {"domain": [0.55, 1], "title": "Category", "type": "category"},
69+
"width": 800,
70+
"height": 500,
71+
"boxgroupgap": 0
72+
}
73+
}

0 commit comments

Comments
 (0)