Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/transforms/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ function getAggregateFunction(opts, conversions) {
if(vi !== BADNUM) sortCalc.push(vi);
}
if(!sortCalc.length) return BADNUM;
sortCalc.sort();
sortCalc.sort(Lib.sorterAsc);
var mid = (sortCalc.length - 1) / 2;
return c2d((sortCalc[Math.floor(mid)] + sortCalc[Math.ceil(mid)]) / 2);
};
Expand Down
24 changes: 24 additions & 0 deletions test/jasmine/tests/transform_aggregate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,28 @@ describe('aggregate', function() {
.catch(failTest)
.then(done);
});

it('use numeric sort function for median', function() {
var subject = ['M', 'M', 'M'];
var score = [2, 10, 11];

var data = [{
type: 'scatter',
x: subject,
y: score,
mode: 'markers',
transforms: [{
type: 'aggregate',
groups: subject,
aggregations: [
{ target: 'y', func: 'median' },
]
}]
}];

Plotly.newPlot(gd, data);

var traceOut = gd._fullData[0];
expect(traceOut.y[0]).toBe(10);
});
});