Skip to content

Commit 3925975

Browse files
committed
hover labe test OK - todo candlestick y axis multicategory
1 parent 7c8506c commit 3925975

File tree

4 files changed

+93
-8
lines changed

4 files changed

+93
-8
lines changed

devtools/test_dashboard/index.html

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<section id="mocks-list"></section>
2525
<div id="plots">
2626
<div id="graph">
27-
<div id="tester" style="width: 600px; height: 250px"></div>
27+
<div id="tester" style="width: 600px; height: 450px"></div>
2828
</div>
2929
</div>
3030
<div id="snapshot"></div>
@@ -173,7 +173,69 @@
173173
},
174174
];
175175

176-
Plotly.newPlot("tester", data);
176+
// Plotly.newPlot("tester", data);
177+
</script>
178+
<script>
179+
let data2 = [
180+
{
181+
name: "ohlc",
182+
type: "ohlc",
183+
open: [10, 11, 12, 13, 12, 13, 14, 15, 16],
184+
high: [15, 16, 17, 18, 17, 18, 19, 20, 21],
185+
low: [7, 8, 9, 10, 9, 10, 11, 12, 13],
186+
close: [9, 10, 12, 13, 13, 12, 14, 14, 17],
187+
x: [
188+
[
189+
"Group 1",
190+
"Group 1",
191+
"Group 1",
192+
"Group 2",
193+
"Group 2",
194+
"Group 2",
195+
"Group 3",
196+
"Group 3",
197+
"Group 3",
198+
],
199+
["a", "b", "c", "a", "b", "c", "a", "b", "c"],
200+
],
201+
},
202+
{
203+
name: "candlestick",
204+
type: "candlestick",
205+
open: [20, 21, 22, 23, 22, 23, 24, 25, 26],
206+
high: [25, 26, 27, 28, 27, 28, 29, 30, 31],
207+
low: [17, 18, 19, 20, 19, 20, 21, 22, 23],
208+
close: [19, 20, 22, 23, 23, 22, 24, 24, 27],
209+
x: [
210+
[
211+
"Group 1",
212+
"Group 1",
213+
"Group 1",
214+
"Group 2",
215+
"Group 2",
216+
"Group 2",
217+
"Group 3",
218+
"Group 3",
219+
"Group 3",
220+
],
221+
["a", "b", "c", "a", "b", "c", "a", "b", "c"],
222+
],
223+
},
224+
];
225+
let layout = {
226+
title: {
227+
text: "Finance traces on multicategory x-axis",
228+
xref: "paper",
229+
x: 0,
230+
},
231+
legend: {
232+
x: 1,
233+
xanchor: "right",
234+
y: 1,
235+
yanchor: "bottom",
236+
},
237+
};
238+
Plotly.newPlot("tester", data2);
177239
</script>
178240
</body>
179241
</html>

src/plots/cartesian/axes.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,6 +2514,12 @@ axes.drawOne = function(gd, ax, opts) {
25142514
var tickNames = ['tick'];
25152515

25162516
if(ax.type === 'multicategory') {
2517+
// TODO ax.levels is not beeing set for y axis for candlestick plot, because ax.setupMultiCategory is not called for y axis (should not be multicategory)
2518+
if(!ax.levels) {
2519+
ax.levelNr = 2;
2520+
ax.levels = [0, 1];
2521+
}
2522+
// debugger;
25172523
ax.levels.slice().reverse().slice(0, ax.levelNr - 1).forEach(function(_lvl) {
25182524
var pad = {x: 0 * _lvl, y: 10}[axLetter];
25192525

@@ -2772,7 +2778,8 @@ function getDividerVals(ax, vals) {
27722778
}
27732779
};
27742780

2775-
if(ax.showdividers && vals.length) {
2781+
// debugger
2782+
if(ax.showdividers && vals.length && ax.levels) {
27762783
ax.levels.forEach(function(_lvl) {
27772784
current = undefined;
27782785
for(i = 0; i < vals.length; i++) {

src/plots/cartesian/set_convert.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,13 @@ module.exports = function setConvert(ax, fullLayout) {
395395
var arrays = arrayIn.map(function(x) {
396396
return x;
397397
});
398-
399398
var valLetter;
400-
401-
if(trace.z) {
399+
if(trace.type === 'ohlc' | trace.type === 'candlestick') {
400+
var t = trace;
401+
var valsTransform = sortLib.transpose([t.open, t.high, t.low, t.close]);
402+
arrays.push(valsTransform);
403+
}
404+
else if(trace.z) {
402405
if(axLetter === 'x') {
403406
arrays.push(sortLib.transpose(trace.z));
404407
} else {
@@ -424,19 +427,31 @@ module.exports = function setConvert(ax, fullLayout) {
424427
if(valLetter === 'z' & axLetter === 'x') {
425428
axVals = sortLib.transpose(axVals);
426429
}
430+
431+
if(trace.type === 'ohlc' | trace.type === 'candlestick') {
432+
var sortedValsTransform = sortLib.transpose(axVals);
433+
// debugger;
434+
gd._fullData[i].open = sortedValsTransform[0];
435+
gd._fullData[i].high = sortedValsTransform[1];
436+
gd._fullData[i].low = sortedValsTransform[2];
437+
gd._fullData[i].close = sortedValsTransform[3];
438+
}
427439
// Could/should set sorted y axis values for each trace as the sorted values are already available.
428440
// Need write access to gd._fullData, bad? Should probably be done right at newPlot, or on setting gd._fullData
429441
// debugger;
442+
430443
var transposedAxLabels = sortLib.transpose(axLabels);
431444
gd._fullData[i][axLetter] = transposedAxLabels;
432-
gd._fullData[i][valLetter] = axVals;
445+
if(valLetter) {
446+
gd._fullData[i][valLetter] = axVals;
447+
}
433448
}
434449
}
435450
}
436451
ax.levelNr = axLabels[0].length;
437452
ax.levels = axLabels[0].map(function(_, idx) {return idx;});
438453

439-
454+
// debugger
440455
var fullSortedObjectList = sortLib.sortObjectList(cols, fullObjectList.slice());
441456
var fullList = sortLib.objectListToList(fullSortedObjectList);
442457
var fullSortedMatrix = sortLib.sortedMatrix(fullList);

test/jasmine/tests/hover_label_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5863,6 +5863,7 @@ describe('hovermode: (x|y)unified', function() {
58635863
var mockOhlc = require('@mocks/finance_multicategory.json');
58645864
var mockCopy = Lib.extendDeep({}, mockOhlc);
58655865
mockCopy.layout.hovermode = 'x unified';
5866+
debugger;
58665867
Plotly.newPlot(gd, mockCopy)
58675868
.then(function(gd) {
58685869
_hover(gd, {curveNumber: 0, pointNumber: 0});

0 commit comments

Comments
 (0)