Skip to content

Commit ec12eab

Browse files
committed
clear - and test - TODOs we're not going to address now
also fixed a typo in the test that means... we were actually already sort of supposed to be testing the TODO about start/size interactions
1 parent 11821c2 commit ec12eab

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

src/traces/histogram/calc.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,6 @@ function calcAllAutoBins(gd, trace, pa, maindata) {
233233
// But manually binned traces won't be adjusted, even if the auto values
234234
// are inconsistent with the manual ones (or the manual ones are inconsistent
235235
// with each other).
236-
//
237-
// TODO: there's probably a weird case here where a larger bin pushes the
238-
// start/end out, then it gets shrunk and doesn't make sense with the smaller bin.
239-
// Need to look for cases like this and see if the results are acceptable
240-
// or we need to think harder about it.
241236
minSize = getMinSize(minSize, binspec.size);
242237
minStart = Math.min(minStart, pa.r2c(binspec.start, 0, calendar));
243238
maxEnd = Math.max(maxEnd, pa.r2c(binspec.end, 0, calendar));
@@ -283,10 +278,10 @@ function calcAllAutoBins(gd, trace, pa, maindata) {
283278
}
284279

285280
/*
286-
* return an array of traces that are all stacked or grouped together
287-
* TODO: only considers histograms. Should we also harmonize with bars?
288-
* in principle people can mix and match these, but bars always
289-
* specify their positions explicitly...
281+
* Return an array of traces that are all stacked or grouped together
282+
* Only considers histograms. In principle we could include them in a
283+
* similar way to how we do manually binned histograms, though this
284+
* would have tons of edge cases and value judgments to make.
290285
*/
291286
function getConnectedHistograms(gd, trace) {
292287
if(gd._fullLayout.barmode === 'overlay') return [trace];

test/jasmine/tests/histogram_test.js

+38-3
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,49 @@ describe('Test histogram', function() {
282282
var trace1 = {x: [1, 2, 3, 4]};
283283
var trace2 = {x: [5, 5.5, 6, 6.5]};
284284

285-
expect(calcPositions(trace1)).toEqual([0.5, 2.5, 4.5]);
285+
expect(calcPositions(trace1)).toBeCloseToArray([0.5, 2.5, 4.5], 5);
286286

287-
expect(calcPositions(trace2)).toEqual[5, 6, 7];
287+
expect(calcPositions(trace2)).toBeCloseToArray([5.5, 6.5], 5);
288288

289289
expect(calcPositions(trace1, [trace2])).toEqual([1, 2, 3, 4]);
290+
// huh, turns out even this one is an example of "unexpected bin positions"
291+
// (see another example below) - in this case it's because trace1 gets
292+
// autoshifted to keep integers off the bin edges, whereas trace2 doesn't
293+
// because there are as many integers as half-integers.
294+
// In this case though, it's unexpected but arguably better than the
295+
// "expected" result.
290296
expect(calcPositions(trace2, [trace1])).toEqual([5, 6, 7]);
291297
});
292298

299+
it('can sometimes give unexpected bin positions', function() {
300+
// documenting an edge case that might not be desirable but for now
301+
// we've decided to ignore: a larger bin sets the bin start, but then it
302+
// doesn't quite make sense with the smaller bin we end up with
303+
// we *could* fix this by ensuring that the bin start is based on the
304+
// same bin spec that gave the minimum bin size, but incremented down to
305+
// include the minimum start... but that would have awkward edge cases
306+
// involving month bins so for now we're ignoring it.
307+
308+
// all integers, so all autobins should get shifted to start 0.5 lower
309+
// than they otherwise would.
310+
var trace1 = {x: [1, 2, 3, 4]};
311+
var trace2 = {x: [-2, 1, 4, 7]};
312+
313+
// as above... size: 2
314+
expect(calcPositions(trace1)).toBeCloseToArray([0.5, 2.5, 4.5], 5);
315+
316+
// {size: 5, start: -5.5}: -5..-1, 0..4, 5..9
317+
expect(calcPositions(trace2)).toEqual([-3, 2, 7]);
318+
319+
// unexpected behavior when we put these together,
320+
// because 2 and 5 are mutually prime. Normally you could never get
321+
// groupings 1&2, 3&4... you'd always get 0&1, 2&3...
322+
expect(calcPositions(trace1, [trace2])).toBeCloseToArray([1.5, 3.5], 5);
323+
expect(calcPositions(trace2, [trace1])).toBeCloseToArray([
324+
-2.5, -0.5, 1.5, 3.5, 5.5, 7.5
325+
], 5);
326+
});
327+
293328
it('harmonizes autobins with smaller manual bins', function() {
294329
var trace1 = {x: [1, 2, 3, 4]};
295330
var trace2 = {x: [5, 6, 7, 8], xbins: {start: 4.3, end: 7.1, size: 0.4}};
@@ -315,7 +350,7 @@ describe('Test histogram', function() {
315350
var trace4 = {x: [1, 1.2, 1.4, 1.6], yaxis: 'y2'};
316351

317352
expect(calcPositions(trace1, [trace2, trace3, trace4])).toEqual([1, 2, 3, 4]);
318-
expect(calcPositions(trace3)).toBeCloseToArray([0.9, 1.1, 1.3]);
353+
expect(calcPositions(trace3)).toBeCloseToArray([0.9, 1.1, 1.3], 5);
319354
});
320355

321356
describe('cumulative distribution functions', function() {

0 commit comments

Comments
 (0)