Skip to content

Commit fb489aa

Browse files
committed
tickformatstops.visible -> enabled
1 parent 4346611 commit fb489aa

File tree

7 files changed

+39
-29
lines changed

7 files changed

+39
-29
lines changed

src/plot_api/make_template.js

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ function mergeTemplates(oldTemplate, newTemplate) {
130130
mergeTemplates(oldVal, newVal);
131131
}
132132
else if(Array.isArray(newVal) && Array.isArray(oldVal)) {
133+
// Note: omitted `inclusionAttr` from arrayTemplater here,
134+
// it's irrelevant as we only want the resulting `_template`.
133135
var templater = Template.arrayTemplater({_template: oldTemplate}, key);
134136
for(j = 0; j < newVal.length; j++) {
135137
var item = newVal[j];

src/plot_api/plot_template.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ var templateAttrs = {
2424
'in addition to any items the figure already has in this array.',
2525
'You can modify these items in the output figure by making your own',
2626
'item with `templateitemname` matching this `name`',
27-
'alongside your modifications (including `visible: false` to hide it).',
27+
'alongside your modifications (including `visible: false` or',
28+
'`enabled: false` to hide it).',
2829
'Has no effect outside of a template.'
2930
].join(' ')
3031
}
@@ -37,8 +38,8 @@ templateAttrs[TEMPLATEITEMNAME] = {
3738
'Used to refer to a named item in this array in the template. Named',
3839
'items from the template will be created even without a matching item',
3940
'in the input figure, but you can modify one by making an item with',
40-
'`templateitemname` matching its `name`, alongside your',
41-
'modifications (including `visible: false` to hide it).',
41+
'`templateitemname` matching its `name`, alongside your modifications',
42+
'(including `visible: false` or `enabled: false` to hide it).',
4243
'If there is no template or no matching item, this item will be',
4344
'hidden unless you explicitly show it with `visible: true`.'
4445
].join(' ')
@@ -148,6 +149,8 @@ exports.newContainer = function(container, name, baseName) {
148149
* @param {string} name: the name of the array to template (ie 'annotations')
149150
* will be used to find default ('annotationdefaults' object) and specific
150151
* ('annotations' array) template specs.
152+
* @param {string} inclusionAttr: the attribute determining this item's
153+
* inclusion in the output, usually 'visible' or 'enabled'
151154
*
152155
* @returns {object}: {newItem, defaultItems}, both functions:
153156
* newItem(itemIn): create an output item, bare except for the correct
@@ -156,7 +159,7 @@ exports.newContainer = function(container, name, baseName) {
156159
* specific template items that have not already beeen included,
157160
* also as bare output items ready for supplyDefaults.
158161
*/
159-
exports.arrayTemplater = function(container, name) {
162+
exports.arrayTemplater = function(container, name, inclusionAttr) {
160163
var template = container._template;
161164
var defaultsTemplate = template && template[arrayDefaultKey(name)];
162165
var templateItems = template && template[name];
@@ -199,7 +202,7 @@ exports.arrayTemplater = function(container, name) {
199202
// to only be modifications it's most likely broken. Hide it unless
200203
// it's explicitly marked visible - in which case it gets NO template,
201204
// not even the default.
202-
out.visible = itemIn.visible || false;
205+
out[inclusionAttr] = itemIn[inclusionAttr] || false;
203206
return out;
204207
}
205208

src/plots/array_container_defaults.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ var Template = require('../plot_api/plot_template');
2525
* options object:
2626
* - name {string}
2727
* name of the key linking the container in question
28+
* - inclusionAttr {string}
29+
* name of the item attribute for inclusion/exclusion. Default is 'visible'.
30+
* Since inclusion is true, use eg 'enabled' instead of 'disabled'.
2831
* - handleItemDefaults {function}
2932
* defaults method to be called on each item in the array container in question
3033
*
@@ -43,12 +46,13 @@ var Template = require('../plot_api/plot_template');
4346
*/
4447
module.exports = function handleArrayContainerDefaults(parentObjIn, parentObjOut, opts) {
4548
var name = opts.name;
49+
var inclusionAttr = opts.inclusionAttr || 'visible';
4650

4751
var previousContOut = parentObjOut[name];
4852

4953
var contIn = Lib.isArrayOrTypedArray(parentObjIn[name]) ? parentObjIn[name] : [];
5054
var contOut = parentObjOut[name] = [];
51-
var templater = Template.arrayTemplater(parentObjOut, name);
55+
var templater = Template.arrayTemplater(parentObjOut, name, inclusionAttr);
5256
var i, itemOut;
5357

5458
for(i = 0; i < contIn.length; i++) {
@@ -57,15 +61,15 @@ module.exports = function handleArrayContainerDefaults(parentObjIn, parentObjOut
5761

5862
if(!Lib.isPlainObject(itemIn)) {
5963
itemOut = templater.newItem({});
60-
itemOut.visible = false;
64+
itemOut[inclusionAttr] = false;
6165
}
6266
else {
6367
itemOut = templater.newItem(itemIn);
6468
}
6569

6670
itemOut._index = i;
6771

68-
if(itemOut.visible !== false) {
72+
if(itemOut[inclusionAttr] !== false) {
6973
opts.handleItemDefaults(itemIn, itemOut, parentObjOut, opts, itemOpts);
7074
}
7175

src/plots/cartesian/axes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ axes.getTickFormat = function(ax) {
13961396
case 'linear': {
13971397
for(i = 0; i < ax.tickformatstops.length; i++) {
13981398
stopi = ax.tickformatstops[i];
1399-
if(stopi.visible && isProperStop(ax.dtick, stopi.dtickrange, convertToMs)) {
1399+
if(stopi.enabled && isProperStop(ax.dtick, stopi.dtickrange, convertToMs)) {
14001400
tickstop = stopi;
14011401
break;
14021402
}
@@ -1406,7 +1406,7 @@ axes.getTickFormat = function(ax) {
14061406
case 'log': {
14071407
for(i = 0; i < ax.tickformatstops.length; i++) {
14081408
stopi = ax.tickformatstops[i];
1409-
if(stopi.visible && isProperLogStop(ax.dtick, stopi.dtickrange)) {
1409+
if(stopi.enabled && isProperLogStop(ax.dtick, stopi.dtickrange)) {
14101410
tickstop = stopi;
14111411
break;
14121412
}

src/plots/cartesian/layout_attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ module.exports = {
512512
].join(' ')
513513
},
514514
tickformatstops: templatedArray('tickformatstop', {
515-
visible: {
515+
enabled: {
516516
valType: 'boolean',
517517
role: 'info',
518518
dflt: true,

src/plots/cartesian/tick_label_defaults.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module.exports = function handleTickLabelDefaults(containerIn, containerOut, coe
4242
if(Array.isArray(tickformatStops) && tickformatStops.length) {
4343
handleArrayContainerDefaults(containerIn, containerOut, {
4444
name: 'tickformatstops',
45+
inclusionAttr: 'enabled',
4546
handleItemDefaults: tickformatstopDefaults
4647
});
4748
}
@@ -89,8 +90,8 @@ function tickformatstopDefaults(valueIn, valueOut) {
8990
return Lib.coerce(valueIn, valueOut, layoutAttributes.tickformatstops, attr, dflt);
9091
}
9192

92-
var visible = coerce('visible');
93-
if(visible) {
93+
var enabled = coerce('enabled');
94+
if(enabled) {
9495
coerce('dtickrange');
9596
coerce('value');
9697
}

test/jasmine/tests/axes_test.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -2820,17 +2820,17 @@ describe('Test Axes.getTickformat', function() {
28202820
it('get proper tickformatstop for linear axis', function() {
28212821
var lineartickformatstops = [
28222822
{
2823-
visible: true,
2823+
enabled: true,
28242824
dtickrange: [null, 1],
28252825
value: '.f2',
28262826
},
28272827
{
2828-
visible: true,
2828+
enabled: true,
28292829
dtickrange: [1, 100],
28302830
value: '.f1',
28312831
},
28322832
{
2833-
visible: true,
2833+
enabled: true,
28342834
dtickrange: [100, null],
28352835
value: 'g',
28362836
}
@@ -2859,7 +2859,7 @@ describe('Test Axes.getTickformat', function() {
28592859
})).toEqual(lineartickformatstops[2].value);
28602860

28612861
// a stop is ignored if it's set invisible, but the others are used
2862-
lineartickformatstops[1].visible = false;
2862+
lineartickformatstops[1].enabled = false;
28632863
expect(Axes.getTickFormat({
28642864
type: 'linear',
28652865
tickformatstops: lineartickformatstops,
@@ -2883,42 +2883,42 @@ describe('Test Axes.getTickformat', function() {
28832883
var YEAR = 'M12'; // or 365.25 * DAY;
28842884
var datetickformatstops = [
28852885
{
2886-
visible: true,
2886+
enabled: true,
28872887
dtickrange: [null, SECOND],
28882888
value: '%H:%M:%S.%L ms' // millisecond
28892889
},
28902890
{
2891-
visible: true,
2891+
enabled: true,
28922892
dtickrange: [SECOND, MINUTE],
28932893
value: '%H:%M:%S s' // second
28942894
},
28952895
{
2896-
visible: true,
2896+
enabled: true,
28972897
dtickrange: [MINUTE, HOUR],
28982898
value: '%H:%M m' // minute
28992899
},
29002900
{
2901-
visible: true,
2901+
enabled: true,
29022902
dtickrange: [HOUR, DAY],
29032903
value: '%H:%M h' // hour
29042904
},
29052905
{
2906-
visible: true,
2906+
enabled: true,
29072907
dtickrange: [DAY, WEEK],
29082908
value: '%e. %b d' // day
29092909
},
29102910
{
2911-
visible: true,
2911+
enabled: true,
29122912
dtickrange: [WEEK, MONTH],
29132913
value: '%e. %b w' // week
29142914
},
29152915
{
2916-
visible: true,
2916+
enabled: true,
29172917
dtickrange: [MONTH, YEAR],
29182918
value: '%b \'%y M' // month
29192919
},
29202920
{
2921-
visible: true,
2921+
enabled: true,
29222922
dtickrange: [YEAR, null],
29232923
value: '%Y Y' // year
29242924
}
@@ -2969,22 +2969,22 @@ describe('Test Axes.getTickformat', function() {
29692969
it('get proper tickformatstop for log axis', function() {
29702970
var logtickformatstops = [
29712971
{
2972-
visible: true,
2972+
enabled: true,
29732973
dtickrange: [null, 'L0.01'],
29742974
value: '.f3',
29752975
},
29762976
{
2977-
visible: true,
2977+
enabled: true,
29782978
dtickrange: ['L0.01', 'L1'],
29792979
value: '.f2',
29802980
},
29812981
{
2982-
visible: true,
2982+
enabled: true,
29832983
dtickrange: ['D1', 'D2'],
29842984
value: '.f1',
29852985
},
29862986
{
2987-
visible: true,
2987+
enabled: true,
29882988
dtickrange: [1, null],
29892989
value: 'g'
29902990
}

0 commit comments

Comments
 (0)