Skip to content

Commit 1dd93bb

Browse files
committed
PR feedback: comment and test case updates
1 parent 392844d commit 1dd93bb

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

src/plot_api/crawler.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@ crawler.DEPRECATED = '_deprecated';
2020
// list of underscore attributes to keep in schema as is
2121
crawler.UNDERSCORE_ATTRS = [crawler.IS_SUBPLOT_OBJ, crawler.IS_LINKED_TO_ARRAY, crawler.DEPRECATED];
2222

23+
/**
24+
* Crawl the attribute tree, recursively calling a callback function
25+
*
26+
* @param {object} attrs
27+
* The node of the attribute tree (e.g. the root) from which recursion originates
28+
* @param {Function} callback
29+
* A callback function with the signature:
30+
* @callback callback
31+
* @param {object} attr an attribute
32+
* @param {String} attrName name string
33+
* @param {object[]} attrs all the attributes
34+
* @param {Number} level the recursion level, 0 at the root
35+
* @param {Number} [specifiedLevel]
36+
* The level in the tree, in order to let the callback function detect descend or backtrack,
37+
* typically unsupplied (implied 0), just used by the self-recursive call.
38+
* The necessity arises because the tree traversal is not controlled by callback return values.
39+
* The decision to not use callback return values for controlling tree pruning arose from
40+
* the goal of keeping the crawler backwards compatible. Observe that one of the pruning conditions
41+
* precedes the callback call.
42+
*
43+
* @return {object} transformOut
44+
* copy of transformIn that contains attribute defaults
45+
*/
2346
crawler.crawl = function(attrs, callback, specifiedLevel) {
2447
var level = specifiedLevel || 0;
2548
Object.keys(attrs).forEach(function(attrName) {

src/plots/plots.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,18 @@ function applyTransforms(fullTrace, fullData, layout) {
793793

794794
var stack = [];
795795

796+
/**
797+
* A closure that gathers attribute paths into its enclosed arraySplitAttributes
798+
* Attribute paths are collected iff their leaf node is a splittable attribute
799+
* @callback callback
800+
* @param {object} attr an attribute
801+
* @param {String} attrName name string
802+
* @param {object[]} attrs all the attributes
803+
* @param {Number} level the recursion level, 0 at the root
804+
* @closureVariable {String[][]} arraySplitAttributes the set of gathered attributes
805+
* Example of filled closure variable (expected to be initialized to []):
806+
* [["marker","size"],["marker","line","width"],["marker","line","color"]]
807+
*/
796808
function callback(attr, attrName, attrs, level) {
797809

798810
stack = stack.slice(0, level).concat([attrName]);

test/jasmine/tests/transform_groupby_test.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ describe('groupby', function() {
261261
});
262262
});
263263

264-
// passes; maybe not for the good reasons (see fixme comments)
265264
it('Plotly.plot should plot the transform traces', function(done) {
266265
var data = Lib.extendDeep([], mockData0);
267266

@@ -285,7 +284,6 @@ describe('groupby', function() {
285284
});
286285
});
287286

288-
// passes; looks OK
289287
it('Plotly.plot should plot the transform traces', function(done) {
290288
var data = Lib.extendDeep([], mockData1);
291289

@@ -306,7 +304,6 @@ describe('groupby', function() {
306304
});
307305
});
308306

309-
// passes OK; see todo comments
310307
it('Plotly.plot should plot the transform traces', function(done) {
311308
var data = Lib.extendDeep([], mockData2);
312309

@@ -317,18 +314,17 @@ describe('groupby', function() {
317314
expect(gd.data[0].x).toEqual([1, -1, -2, 0, 1, 2, 3]);
318315
expect(gd.data[0].y).toEqual([1, 2, 3, 1, 2, 3, 1]);
319316

320-
expect(gd._fullData.length).toEqual(1); // todo: confirm this result is OK
317+
expect(gd._fullData.length).toEqual(1);
321318

322319
expect(gd._fullData[0].x).toEqual([1, -1, -2, 0, 1, 2, 3]);
323320
expect(gd._fullData[0].y).toEqual([1, 2, 3, 1, 2, 3, 1]);
324321

325-
assertDims([7]); // todo: confirm this result is OK
322+
assertDims([7]);
326323

327324
done();
328325
});
329326
});
330327

331-
// passes OK; see todo comments
332328
it('Plotly.plot should plot the transform traces', function(done) {
333329
var data = Lib.extendDeep([], mockData3);
334330

@@ -339,12 +335,12 @@ describe('groupby', function() {
339335
expect(gd.data[0].x).toEqual([1, -1, -2, 0, 1, 2, 3]);
340336
expect(gd.data[0].y).toEqual([1, 2, 3, 1, 2, 3, 1]);
341337

342-
expect(gd._fullData.length).toEqual(1); // todo: confirm this result is OK
338+
expect(gd._fullData.length).toEqual(1);
343339

344340
expect(gd._fullData[0].x).toEqual([1, -1, -2, 0, 1, 2, 3]);
345341
expect(gd._fullData[0].y).toEqual([1, 2, 3, 1, 2, 3, 1]);
346342

347-
assertDims([7]); // todo: confirm this result is OK
343+
assertDims([7]);
348344

349345
done();
350346
});
@@ -354,7 +350,7 @@ describe('groupby', function() {
354350
describe('grouping with basic, heterogenous and overridden attributes', function() {
355351
'use strict';
356352

357-
afterEach(destroyGraphDiv);
353+
//afterEach(destroyGraphDiv);
358354

359355
function test(mockData) {
360356

@@ -453,8 +449,7 @@ describe('groupby', function() {
453449
color: 'darkred', // general 'default' color
454450
line: {
455451
width: [4, 2, 4, 2, 2, 3, 3],
456-
// a general, not overridden array will be interpreted per group
457-
color: ['orange', 'red', 'green', 'cyan']
452+
color: ['orange', 'red', 'green', 'cyan', 'magenta', 'blue', 'pink']
458453
}
459454
},
460455
line: {color: 'red'},
@@ -464,7 +459,7 @@ describe('groupby', function() {
464459
style: {
465460
a: {marker: {size: 30}},
466461
// override general color:
467-
b: {marker: {size: 15, color: 'lightblue'}, line: {color: 'purple'}}
462+
b: {marker: {size: 15, line: {color: 'yellow'}}, line: {color: 'purple'}}
468463
}
469464
}]
470465
}];
@@ -512,10 +507,17 @@ describe('groupby', function() {
512507
}];
513508

514509
it('`data` preserves user supplied input but `gd._fullData` reflects the grouping', test(mockData1));
510+
515511
it('passes with lots of attributes and heterogenous attrib presence', test(mockData2));
512+
516513
it('passes with group styles partially overriding top level aesthetics', test(mockData3));
514+
expect(gd._fullData[0].marker.line.color).toEqual(['orange', 'red', 'cyan', 'pink']);
515+
expect(gd._fullData[1].marker.line.color).toEqual('yellow');
516+
517517
it('passes with no explicit styling for the individual group', test(mockData4));
518+
518519
it('passes with no explicit styling in the group transform at all', test(mockData5));
520+
519521
it('passes with no explicit styling in the group transform at all', test(mockData6));
520522

521523
});

0 commit comments

Comments
 (0)