Skip to content

Commit f175cc5

Browse files
authored
Merge pull request #5016 from plotly/revert-4904-fix4852-template-tickwidth-tickcolor
Revert PR 4904 i.e. undo the Fix for setting tickwidth, tickcolor, ticklen, linecolor and possibly more attributes via template
2 parents 2a03fcd + fc0ba99 commit f175cc5

File tree

5 files changed

+68
-163
lines changed

5 files changed

+68
-163
lines changed

src/lib/coerce.js

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -361,81 +361,58 @@ exports.valObjectMeta = {
361361
* as a convenience, returns the value it finally set
362362
*/
363363
exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt) {
364-
return _coerce(containerIn, containerOut, attributes, attribute, dflt).val;
365-
};
366-
367-
function _coerce(containerIn, containerOut, attributes, attribute, dflt, opts) {
368-
var shouldValidate = (opts || {}).shouldValidate;
369-
370-
var attr = nestedProperty(attributes, attribute).get();
371-
if(dflt === undefined) dflt = attr.dflt;
372-
var src = false;
373-
364+
var opts = nestedProperty(attributes, attribute).get();
374365
var propIn = nestedProperty(containerIn, attribute);
375366
var propOut = nestedProperty(containerOut, attribute);
376-
var valIn = propIn.get();
367+
var v = propIn.get();
377368

378369
var template = containerOut._template;
379-
if(valIn === undefined && template) {
380-
valIn = nestedProperty(template, attribute).get();
381-
src = (valIn !== undefined);
382-
370+
if(v === undefined && template) {
371+
v = nestedProperty(template, attribute).get();
383372
// already used the template value, so short-circuit the second check
384373
template = 0;
385374
}
386375

376+
if(dflt === undefined) dflt = opts.dflt;
377+
387378
/**
388379
* arrayOk: value MAY be an array, then we do no value checking
389380
* at this point, because it can be more complicated than the
390381
* individual form (eg. some array vals can be numbers, even if the
391382
* single values must be color strings)
392383
*/
393-
if(attr.arrayOk && isArrayOrTypedArray(valIn)) {
394-
propOut.set(valIn);
395-
return {
396-
inp: valIn,
397-
val: valIn,
398-
src: true
399-
};
384+
if(opts.arrayOk && isArrayOrTypedArray(v)) {
385+
propOut.set(v);
386+
return v;
400387
}
401388

402-
var coerceFunction = exports.valObjectMeta[attr.valType].coerceFunction;
403-
coerceFunction(valIn, propOut, dflt, attr);
404-
405-
var valOut = propOut.get();
406-
src = (valOut !== undefined) && shouldValidate && validate(valIn, attr);
389+
var coerceFunction = exports.valObjectMeta[opts.valType].coerceFunction;
390+
coerceFunction(v, propOut, dflt, opts);
407391

392+
var out = propOut.get();
408393
// in case v was provided but invalid, try the template again so it still
409394
// overrides the regular default
410-
if(template && valOut === dflt && !validate(valIn, attr)) {
411-
valIn = nestedProperty(template, attribute).get();
412-
coerceFunction(valIn, propOut, dflt, attr);
413-
valOut = propOut.get();
414-
415-
src = (valOut !== undefined) && shouldValidate && validate(valIn, attr);
395+
if(template && out === dflt && !validate(v, opts)) {
396+
v = nestedProperty(template, attribute).get();
397+
coerceFunction(v, propOut, dflt, opts);
398+
out = propOut.get();
416399
}
417-
418-
return {
419-
inp: valIn,
420-
val: valOut,
421-
src: src
422-
};
423-
}
400+
return out;
401+
};
424402

425403
/**
426404
* Variation on coerce
427-
* useful when setting an attribute to a valid value
428-
* can change the default for another attribute.
429405
*
430406
* Uses coerce to get attribute value if user input is valid,
431407
* returns attribute default if user input it not valid or
432408
* returns false if there is no user input.
433409
*/
434410
exports.coerce2 = function(containerIn, containerOut, attributes, attribute, dflt) {
435-
var out = _coerce(containerIn, containerOut, attributes, attribute, dflt, {
436-
shouldValidate: true
437-
});
438-
return (out.src && out.inp !== undefined) ? out.val : false;
411+
var propIn = nestedProperty(containerIn, attribute);
412+
var propOut = exports.coerce(containerIn, containerOut, attributes, attribute, dflt);
413+
var valIn = propIn.get();
414+
415+
return (valIn !== undefined && valIn !== null) ? propOut : false;
439416
};
440417

441418
/*
-213 Bytes
Loading

test/image/mocks/axes_custom-ticks_log-date.json

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,44 @@
1515
"layout": {
1616
"width": 500,
1717
"height": 300,
18-
"template": {
19-
"layout": {
20-
"title": {
21-
"text": "custom ticks on date & log axes"
22-
},
23-
"paper_bgcolor": "lightblue",
24-
"plot_bgcolor": "#ddd",
25-
"yaxis": {
26-
"type": "log",
27-
"tickmode": "array",
28-
"tickvals": [
29-
1,
30-
10,
31-
100
32-
],
33-
"ticktext": [
34-
"one",
35-
"ten",
36-
"one<br>hundred"
37-
],
38-
"gridwidth": 2,
39-
"tickwidth": 15,
40-
"tickcolor": "green",
41-
"gridcolor": "green"
42-
},
43-
"xaxis": {
44-
"type": "date",
45-
"tickmode": "array",
46-
"tickvals": [
47-
"2010-01-16",
48-
"2010-02-14"
49-
],
50-
"ticktext": [
51-
"Jan 16",
52-
"Feb 14"
53-
],
54-
"gridwidth": 10,
55-
"tickwidth": 50,
56-
"tickcolor": "rgba(255,0,0,0.75)",
57-
"gridcolor": "rgba(255,0,0,0.25)"
58-
}
59-
}
18+
"title": {
19+
"text": "custom ticks on date & log axes"
20+
},
21+
"paper_bgcolor": "lightblue",
22+
"plot_bgcolor": "#ddd",
23+
"yaxis": {
24+
"type": "log",
25+
"tickmode": "array",
26+
"tickvals": [
27+
1,
28+
10,
29+
100
30+
],
31+
"ticktext": [
32+
"one",
33+
"ten",
34+
"one<br>hundred"
35+
],
36+
"gridwidth": 2,
37+
"tickwidth": 15,
38+
"tickcolor": "green",
39+
"gridcolor": "green"
40+
},
41+
"xaxis": {
42+
"type": "date",
43+
"tickmode": "array",
44+
"tickvals": [
45+
"2010-01-16",
46+
"2010-02-14"
47+
],
48+
"ticktext": [
49+
"Jan 16",
50+
"Feb 14"
51+
],
52+
"gridwidth": 10,
53+
"tickwidth": 50,
54+
"tickcolor": "rgba(255,0,0,0.75)",
55+
"gridcolor": "rgba(255,0,0,0.25)"
6056
}
6157
}
6258
}

test/jasmine/tests/axes_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,10 +1803,10 @@ describe('Test axes', function() {
18031803
Plotly.plot(gd, data, layout);
18041804

18051805
var yaxis = gd._fullLayout.yaxis;
1806-
expect(yaxis.ticklen).toBe(undefined);
1807-
expect(yaxis.tickwidth).toBe(undefined);
1808-
expect(yaxis.tickcolor).toBe(undefined);
1809-
expect(yaxis.ticks).toBe('');
1806+
expect(yaxis.ticklen).toBe(5);
1807+
expect(yaxis.tickwidth).toBe(1);
1808+
expect(yaxis.tickcolor).toBe('#444');
1809+
expect(yaxis.ticks).toBe('outside');
18101810
expect(yaxis.showticklabels).toBe(true);
18111811
expect(yaxis.tickfont).toEqual({ family: '"Open Sans", verdana, arial, sans-serif', size: 12, color: '#444' });
18121812
expect(yaxis.tickangle).toBe('auto');

test/jasmine/tests/lib_test.js

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ describe('Test lib.js:', function() {
778778
expect(sizeOut).toBe(outObj.testMarker.testSize);
779779
});
780780

781-
it('should set the default and return false if the user input is not valid', function() {
781+
it('should set and return the default if the user input is not valid', function() {
782782
var colVal = 'r';
783783
var sizeVal = 'aaaaah!';
784784
var attrs = {
@@ -792,80 +792,12 @@ describe('Test lib.js:', function() {
792792
var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor');
793793
var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');
794794

795-
expect(colOut).toBe(false);
796-
expect(outObj.testMarker.testColor).toBe('rgba(0, 0, 0, 0)');
797-
expect(sizeOut).toBe(false);
798-
expect(outObj.testMarker.testSize).toBe(20);
799-
});
800-
801-
it('should set the user input', function() {
802-
var colVal = 'red';
803-
var sizeVal = '1e2';
804-
var attrs = {
805-
testMarker: {
806-
testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
807-
testSize: {valType: 'number', dflt: 20}
808-
}
809-
};
810-
var obj = {testMarker: {testColor: colVal, testSize: sizeVal}};
811-
var outObj = {};
812-
var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor');
813-
var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');
814-
815-
expect(colOut).toBe('red');
816-
expect(colOut).toBe(outObj.testMarker.testColor);
817-
expect(sizeOut).toBe(100);
795+
expect(colOut).toBe('rgba(0, 0, 0, 0)');
818796
expect(sizeOut).toBe(outObj.testMarker.testSize);
819-
});
820-
821-
it('should set to template if the container input is not valid', function() {
822-
var attrs = {
823-
testMarker: {
824-
testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
825-
testSize: {valType: 'number', dflt: 20}
826-
}
827-
};
828-
var obj = {
829-
testMarker: {testColor: 'invalid', testSize: 'invalid'}
830-
};
831-
var outObj = {
832-
_template: {
833-
testMarker: {testColor: 'red', testSize: '1e2'}
834-
}
835-
};
836-
var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor');
837-
var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');
838-
839-
expect(colOut).toBe('red');
840-
expect(colOut).toBe(outObj.testMarker.testColor);
841-
expect(sizeOut).toBe(100);
797+
expect(sizeOut).toBe(20);
842798
expect(sizeOut).toBe(outObj.testMarker.testSize);
843799
});
844800

845-
it('should set to default and return false if the both container and template inputs are not valid', function() {
846-
var attrs = {
847-
testMarker: {
848-
testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
849-
testSize: {valType: 'number', dflt: 20}
850-
}
851-
};
852-
var obj = {
853-
testMarker: {testColor: 'invalid', testSize: 'invalid'}
854-
};
855-
var outObj = {
856-
_template: {
857-
testMarker: {testColor: 'invalid', testSize: 'invalid'}
858-
}
859-
};
860-
var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor');
861-
var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');
862-
863-
expect(colOut).toBe(false);
864-
expect(outObj.testMarker.testColor).toBe('rgba(0, 0, 0, 0)');
865-
expect(sizeOut).toBe(false);
866-
expect(outObj.testMarker.testSize).toBe(20);
867-
});
868-
869801
it('should return false if there is no user input', function() {
870802
var colVal = null;
871803
var sizeVal; // undefined

0 commit comments

Comments
 (0)