Skip to content

Commit c8a2607

Browse files
committed
Reorganize clearExpandedTraceDefaultColors code
1 parent 5f346e4 commit c8a2607

File tree

4 files changed

+38
-37
lines changed

4 files changed

+38
-37
lines changed

src/plots/plots.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -659,12 +659,15 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa
659659
}
660660
};
661661

662-
// This function clears defaults between the first and second pass of
663-
// supplyDefaults. It exists because otherwise null attributes are
664-
// supplyDefault'd and inherited as *colors* instead of an actual null
665-
// attribute which needs to be supplydefaulted by the individual
666-
// expanded traces.
667-
plots.clearTraceDefaultColors = function(trace) {
662+
// This function clears any attributes with useExpandedTraceDefaultColor
663+
// set to true in the plot schema. This is needed because groupby (which
664+
// is the only transform for which this currently applies) supplies parent
665+
// trace defaults, then expanded trace defaults. The result is that `null`
666+
// colors are default-supplied and inherited as a color instead of a null.
667+
// The result is that expanded trace default colors have no effect, with
668+
// the final result that groups are indistinguishable. This function clears
669+
// those colors so that individual groupby groups get unique colors.
670+
plots.clearExpandedTraceDefaultColors = function(trace) {
668671
var colorAttrs, path, i;
669672

670673
// This uses weird closure state in order to satisfy the linter rule

src/transforms/groupby.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function transformOne(trace, state) {
173173

174174
newTrace.name = groupName;
175175

176-
Plots.clearTraceDefaultColors(newTrace);
176+
Plots.clearExpandedTraceDefaultColors(newTrace);
177177

178178
// there's no need to coerce styleLookup[groupName] here
179179
// as another round of supplyDefaults is done on the transformed traces

test/jasmine/tests/transform_expanded_trace_test.js

-30
This file was deleted.

test/jasmine/tests/transform_groupby_test.js

+28
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,34 @@ describe('groupby', function() {
692692
it('passes with no groups', test(mockData0));
693693
it('passes with empty groups', test(mockData1));
694694
it('passes with falsey groups', test(mockData2));
695+
});
696+
697+
describe('expanded trace coloring', function() {
698+
it('assigns unique colors to each group', function() {
699+
var uniqueColors = {};
700+
var dataOut = [];
701+
var dataIn = [{
702+
y: [1, 2, 3],
703+
transforms: [
704+
{type: 'filter', operation: '<', value: 4},
705+
{type: 'groupby', groups: ['a', 'b', 'c']}
706+
]
707+
}, {
708+
y: [4, 5, 6],
709+
transforms: [
710+
{type: 'filter', operation: '<', value: 4},
711+
{type: 'groupby', groups: ['a', 'b', 'b']}
712+
]
713+
}];
695714

715+
Plots.supplyDataDefaults(dataIn, dataOut, {}, {});
716+
717+
for(var i = 0; i < dataOut.length; i++) {
718+
uniqueColors[dataOut[i].marker.color] = true;
719+
}
720+
721+
// Confirm that five total colors exist:
722+
expect(Object.keys(uniqueColors).length).toEqual(5);
723+
});
696724
});
697725
});

0 commit comments

Comments
 (0)