Skip to content

Commit 8f37fc7

Browse files
committed
Make groupby nameformat dependent on number of traces
1 parent 952e4ea commit 8f37fc7

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/plots/plots.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
798798

799799
for(i = 0; i < dataIn.length; i++) {
800800
trace = dataIn[i];
801-
fullTrace = plots.supplyTraceDefaults(trace, cnt, fullLayout, i);
801+
fullTrace = plots.supplyTraceDefaults(trace, cnt, fullLayout, i, dataIn.length);
802802

803803
fullTrace.index = i;
804804
fullTrace._input = trace;
@@ -809,7 +809,7 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
809809

810810
for(var j = 0; j < expandedTraces.length; j++) {
811811
var expandedTrace = expandedTraces[j];
812-
var fullExpandedTrace = plots.supplyTraceDefaults(expandedTrace, cnt, fullLayout, i);
812+
var fullExpandedTrace = plots.supplyTraceDefaults(expandedTrace, cnt, fullLayout, i, dataIn.length);
813813

814814
// The group key gets cleared. If set, pass it forward
815815
if(expandedTrace._group) {
@@ -945,7 +945,7 @@ plots.supplyFrameDefaults = function(frameIn) {
945945
return frameOut;
946946
};
947947

948-
plots.supplyTraceDefaults = function(traceIn, traceOutIndex, layout, traceInIndex) {
948+
plots.supplyTraceDefaults = function(traceIn, traceOutIndex, layout, traceInIndex, inputTraceCount) {
949949
var traceOut = {},
950950
defaultColor = Color.defaults[traceOutIndex % Color.defaults.length];
951951

@@ -1018,13 +1018,13 @@ plots.supplyTraceDefaults = function(traceIn, traceOutIndex, layout, traceInInde
10181018
traceOut.visible = !!traceOut.visible;
10191019
}
10201020

1021-
plots.supplyTransformDefaults(traceIn, traceOut, layout);
1021+
plots.supplyTransformDefaults(traceIn, traceOut, layout, inputTraceCount);
10221022
}
10231023

10241024
return traceOut;
10251025
};
10261026

1027-
plots.supplyTransformDefaults = function(traceIn, traceOut, layout) {
1027+
plots.supplyTransformDefaults = function(traceIn, traceOut, layout, inputTraceCount) {
10281028
var globalTransforms = layout._globalTransforms || [];
10291029
var transformModules = layout._transformModules || [];
10301030

@@ -1043,7 +1043,7 @@ plots.supplyTransformDefaults = function(traceIn, traceOut, layout) {
10431043
if(!_module) Lib.warn('Unrecognized transform type ' + type + '.');
10441044

10451045
if(_module && _module.supplyDefaults) {
1046-
transformOut = _module.supplyDefaults(transformIn, traceOut, layout, traceIn);
1046+
transformOut = _module.supplyDefaults(transformIn, traceOut, layout, traceIn, inputTraceCount);
10471047
transformOut.type = type;
10481048
transformOut._module = _module;
10491049

src/transforms/groupby.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ exports.attributes = {
3737
},
3838
nameformat: {
3939
valType: 'string',
40-
dflt: '%g (%t)',
4140
description: [
42-
'Pattern by which grouped traces are named. Available special escape',
43-
'sequences are `%g`, which inserts the group name, and `%t`, which',
44-
'inserts the trace name. If grouping GDP data by country, for example',
45-
'The default "%g (%t)" would return "Monaco (GDP per capita)".'
41+
'Pattern by which grouped traces are named. If only one trace is present,',
42+
'defaults to the group name (`"%g"`), otherwise defaults to the group name',
43+
'with trace name (`"%g (%t)"`). Available escape sequences are `%g`, which',
44+
'inserts the group name, and `%t`, which inserts the trace name. If grouping',
45+
'GDP data by country when more than one trace is present, for example, the',
46+
'default "%g (%t)" would return "Monaco (GDP per capita)".'
4647
].join(' ')
4748
},
4849
groupnames: {
@@ -99,7 +100,7 @@ exports.attributes = {
99100
* @return {object} transformOut
100101
* copy of transformIn that contains attribute defaults
101102
*/
102-
exports.supplyDefaults = function(transformIn) {
103+
exports.supplyDefaults = function(transformIn, traceOut, layout, traceIn, inputTraceCount) {
103104
var i;
104105
var transformOut = {};
105106

@@ -112,7 +113,7 @@ exports.supplyDefaults = function(transformIn) {
112113
if(!enabled) return transformOut;
113114

114115
coerce('groups');
115-
coerce('nameformat');
116+
coerce('nameformat', inputTraceCount > 1 ? '%g (%t)' : '%g');
116117

117118
var nameFormatIn = transformIn.groupnames;
118119
var nameFormatOut = transformOut.groupnames = [];

0 commit comments

Comments
 (0)