Skip to content

Commit 4352dd8

Browse files
committed
ohlc: use all coords on given x-axis to compute min coord diff
- instead of using only per-trace coords - adding a loop over all traces in calcTransform is unfortunate, but is required as transform do not have access to the setPostiions step.
1 parent e4617ac commit 4352dd8

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/traces/ohlc/transform.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ exports.calcTransform = function calcTransform(gd, trace, opts) {
121121

122122
var xa = axisIds.getFromTrace(gd, trace, 'x'),
123123
ya = axisIds.getFromTrace(gd, trace, 'y'),
124-
tickWidth = convertTickWidth(trace.x, xa, trace._fullInput.tickwidth);
124+
tickWidth = convertTickWidth(gd, xa, trace._fullInput.tickwidth);
125125

126126
var open = trace.open,
127127
high = trace.high,
@@ -191,16 +191,23 @@ exports.calcTransform = function calcTransform(gd, trace, opts) {
191191
trace.text = textOut;
192192
};
193193

194-
function convertTickWidth(coords, ax, tickWidth) {
195-
if(coords.length < 2) return tickWidth;
194+
function convertTickWidth(gd, xa, tickWidth) {
195+
var fullData = gd._fullData,
196+
coords = [];
196197

197-
var _coords = coords.map(ax.d2c),
198-
minDTick = Math.abs(_coords[1] - _coords[0]);
198+
// find all coordinates attached to this x-axis
199+
for(var i = 0; i < fullData.length; i++) {
200+
var trace = fullData[i]._fullInput;
199201

200-
for(var i = 1; i < _coords.length - 1; i++) {
201-
var dist = Math.abs(_coords[i + 1] - _coords[i]);
202-
minDTick = Math.min(dist, minDTick);
202+
if(trace.type === 'ohlc' &&
203+
trace.visible === true &&
204+
trace.xaxis === xa._id &&
205+
trace.x
206+
) {
207+
coords = coords.concat(trace.x.map(xa.d2c));
208+
}
203209
}
204210

205-
return minDTick * tickWidth;
211+
var minDiff = Lib.distinctVals(coords).minDiff;
212+
return minDiff * tickWidth;
206213
}

test/jasmine/tests/finance_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ describe('finance charts calc transforms:', function() {
512512

513513
expect(out[2].name).toEqual('trace 0 - increasing');
514514
expect(out[2].x.map(ms2DateTime)).toEqual([
515-
'2016-09-03 23:59:59.999', '2016-09-04', '2016-09-04', '2016-09-04', '2016-09-04', '2016-09-04', null
515+
'2016-09-03 22:48', '2016-09-04', '2016-09-04', '2016-09-04', '2016-09-04', '2016-09-04 01:12', null
516516
]);
517517
expect(out[2].y).toEqual([
518518
32.06, 32.06, 34.25, 31.62, 33.18, 33.18, null

0 commit comments

Comments
 (0)