Skip to content

Commit 165b5bf

Browse files
committed
add tests for aggregate functions change and range
1 parent 0f99934 commit 165b5bf

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

test/jasmine/tests/transform_aggregate_test.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('aggregate', function() {
1515
Plotly.newPlot(gd, [{
1616
x: [1, 2, 3, 4, 'fail'],
1717
y: [1.1, 2.2, 3.3, 'nope', 5.5],
18+
customdata: [4, 'nope', 3, 2, 1],
1819
marker: {
1920
size: ['2001-01-01', 0.2, 0.1, 0.4, 0.5],
2021
color: [2, 4, '', 10, 8],
@@ -34,6 +35,7 @@ describe('aggregate', function() {
3435
{target: 'x', func: 'sum'},
3536
// non-numerics will not count toward numerator or denominator for avg
3637
{target: 'y', func: 'avg'},
38+
{target: 'customdata', func: 'change'},
3739
{target: 'marker.size', func: 'min'},
3840
{target: 'marker.color', func: 'max'},
3941
// marker.opacity doesn't have an entry, but it will default to first
@@ -54,6 +56,7 @@ describe('aggregate', function() {
5456

5557
expect(traceOut.x).toEqual([8, 2]);
5658
expect(traceOut.y).toBeCloseToArray([3.3, 2.2], 5);
59+
expect(traceOut.customdata).toEqual([-3, undefined]);
5760
expect(traceOut.marker.size).toEqual([0.1, 0.2]);
5861
expect(traceOut.marker.color).toEqual([10, 4]);
5962
expect(traceOut.marker.opacity).toEqual([0.6, 'boo']);
@@ -221,15 +224,17 @@ describe('aggregate', function() {
221224
expect(inverseMapping).toEqual({0: [0, 1, 4], 1: [2, 3]});
222225
});
223226

224-
it('handles median, mode, rms, & stddev for numeric data', function() {
227+
it('handles median, mode, rms, stddev, change & range for numeric data', function() {
225228
// again, nothing is going to barf with non-numeric data, but sometimes it
226229
// won't make much sense.
227230

228231
Plotly.newPlot(gd, [{
229232
x: [1, 1, 2, 2, 1],
230233
y: [1, 2, 3, 4, 5],
234+
customdata: [5, 4, 3, 2, 1],
231235
marker: {
232236
size: [1, 2, 3, 4, 5],
237+
opacity: [0.6, 0.5, 0.2, 0.8, 1.0],
233238
line: {width: [1, 1, 2, 2, 1]},
234239
color: [1, 1, 2, 2, 1]
235240
},
@@ -239,7 +244,9 @@ describe('aggregate', function() {
239244
aggregations: [
240245
{target: 'x', func: 'mode'},
241246
{target: 'y', func: 'median'},
247+
{target: 'customdata', func: 'change'},
242248
{target: 'marker.size', func: 'rms'},
249+
{target: 'marker.opacity', func: 'range'},
243250
{target: 'marker.line.width', func: 'stddev', funcmode: 'population'},
244251
{target: 'marker.color', func: 'stddev'}
245252
]
@@ -252,7 +259,9 @@ describe('aggregate', function() {
252259
// but 2 gets to that count first
253260
expect(traceOut.x).toEqual([2, 1]);
254261
expect(traceOut.y).toBeCloseToArray([3.5, 2], 5);
262+
expect(traceOut.customdata).toEqual([-4, 0]);
255263
expect(traceOut.marker.size).toBeCloseToArray([Math.sqrt(51 / 4), 2], 5);
264+
expect(traceOut.marker.opacity).toEqual([0.8, 0]);
256265
expect(traceOut.marker.line.width).toBeCloseToArray([0.5, 0], 5);
257266
expect(traceOut.marker.color).toBeCloseToArray([Math.sqrt(1 / 3), 0], 5);
258267
});

0 commit comments

Comments
 (0)