8000 Revert PR 4904 i.e. "undo the Fix for setting tickwidth, tickcolor, ticklen, linecolor and possibly more attributes via template" by archmoj · Pull Request #5016 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Revert PR 4904 i.e. "undo the Fix for setting tickwidth, tickcolor, ticklen, linecolor and possibly more attributes via template" #5016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Revert "Fix setting tickwidth, tickcolor, ticklen, linecolor and poss…
…ibly more attributes via template"
  • Loading branch information
archmoj authored Jul 23, 2020
commit fc0ba99447a6ed8e2ff86d87e1675eedc3d8a572
69 changes: 23 additions & 46 deletions src/lib/coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,81 +361,58 @@ exports.valObjectMeta = {
* as a convenience, returns the value it finally set
*/
exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt) {
return _coerce(containerIn, containerOut, attributes, attribute, dflt).val;
};

function _coerce(containerIn, containerOut, attributes, attribute, dflt, opts) {
var shouldValidate = (opts || {}).shouldValidate;

var attr = nestedProperty(attributes, attribute).get();
if(dflt === undefined) dflt = attr.dflt;
var src = false;

var opts = nestedProperty(attributes, attribute).get();
var propIn = nestedProperty(containerIn, attribute);
var propOut = nestedProperty(containerOut, attribute);
var valIn = propIn.get();
var v = propIn.get();

var template = containerOut._template;
if(valIn === undefined && template) {
valIn = nestedProperty(template, attribute).get();
src = (valIn !== undefined);

if(v === undefined && template) {
v = nestedProperty(template, attribute).get();
// already used the template value, so short-circuit the second check
template = 0;
}

if(dflt === undefined) dflt = opts.dflt;

/**
* arrayOk: value MAY be an array, then we do no value checking
* at this point, because it can be more complicated than the
* individual form (eg. some array vals can be numbers, even if the
* single values must be color strings)
*/
if(attr.arrayOk && isArrayOrTypedArray(valIn)) {
propOut.set(valIn);
return {
inp: valIn,
val: valIn,
src: true
};
if(opts.arrayOk && isArrayOrTypedArray(v)) {
propOut.set(v);
return v;
}

var coerceFunction = exports.valObjectMeta[attr.valType].coerceFunction;
coerceFunction(valIn, propOut, dflt, attr);

var valOut = propOut.get();
src = (valOut !== undefined) && shouldValidate && validate(valIn, attr);
var coerceFunction = exports.valObjectMeta[opts.valType].coerceFunction;
coerceFunction(v, propOut, dflt, opts);

var out = propOut.get();
// in case v was provided but invalid, try the template again so it still
// overrides the regular default
if(template && valOut === dflt && !validate(valIn, attr)) {
valIn = nestedProperty(template, attribute).get();
coerceFunction(valIn, propOut, dflt, attr);
valOut = propOut.get();

src = (valOut !== undefined) && shouldValidate && validate(valIn, attr);
if(template && out === dflt && !validate(v, opts)) {
v = nestedProperty(template, attribute).get();
coerceFunction(v, propOut, dflt, opts);
out = propOut.get();
}

return {
inp: valIn,
val: valOut,
src: src
};
}
return out;
};

/**
* Variation on coerce
* useful when setting an attribute to a valid value
* can change the default for another attribute.
*
* Uses coerce to get attribute value if user input is valid,
* returns attribute default if user input it not valid or
* returns false if there is no user input.
*/
exports.coerce2 = function(containerIn, containerOut, attributes, attribute, dflt) {
var out = _coerce(containerIn, containerOut, attributes, attribute, dflt, {
shouldValidate: true
});
return (out.src && out.inp !== undefined) ? out.val : false;
var propIn = nestedProperty(containerIn, attribute);
var propOut = exports.coerce(containerIn, containerOut, attributes, attribute, dflt);
var valIn = propIn.get();

return (valIn !== undefined && valIn !== null) ? propOut : false;
};

/*
Expand Down
Binary file modified test/image/baselines/axes_breaks-round-weekdays.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 38 additions & 42 deletions test/image/mocks/axes_custom-ticks_log-date.json
< 8000 tr data-hunk="2efe94652db86aeb8fc2533a88e8052cca314b31976d81d9b00acb7624592beb" class="show-top-border">
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,44 @@
"layout": {
"width": 500,
"height": 300,
"template": {
"layout": {
"title": {
"text": "custom ticks on date & log axes"
},
"paper_bgcolor": "lightblue",
"plot_bgcolor": "#ddd",
"yaxis": {
"type": "log",
"tickmode": "array",
"tickvals": [
1,
10,
100
],
"ticktext": [
"one",
"ten",
"one<br>hundred"
],
"gridwidth": 2,
"tickwidth": 15,
"tickcolor": "green",
"gridcolor": "green"
},
"xaxis": {
"type": "date",
"tickmode": "array",
"tickvals": [
"2010-01-16",
"2010-02-14"
],
"ticktext": [
"Jan 16",
"Feb 14"
],
"gridwidth": 10,
"tickwidth": 50,
"tickcolor": "rgba(255,0,0,0.75)",
"gridcolor": "rgba(255,0,0,0.25)"
}
}
"title": {
"text": "custom ticks on date & log axes"
},
"paper_bgcolor": "lightblue",
"plot_bgcolor": "#ddd",
"yaxis": {
"type": "log",
"tickmode": "array",
"tickvals": [
1,
10,
100
],
"ticktext": [
"one",
"ten",
"one<br>hundred"
],
"gridwidth": 2,
"tickwidth": 15,
"tickcolor": "green",
"gridcolor": "green"
},
"xaxis": {
"type": "date",
"tickmode": "array",
"tickvals": [
"2010-01-16",
"2010-02-14"
],
"ticktext": [
"Jan 16",
"Feb 14"
],
"gridwidth": 10,
"tickwidth": 50,
"tickcolor": "rgba(255,0,0,0.75)",
"gridcolor": "rgba(255,0,0,0.25)"
}
}
}
8 changes: 4 additions & 4 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1803,10 +1803,10 @@ describe('Test axes', function() {
Plotly.plot(gd, data, layout);

var yaxis = gd._fullLayout.yaxis;
expect(yaxis.ticklen).toBe(undefined);
expect(yaxis.tickwidth).toBe(undefined);
expect(yaxis.tickcolor).toBe(undefined);
expect(yaxis.ticks).toBe('');
expect(yaxis.ticklen).toBe(5);
expect(yaxis.tickwidth).toBe(1);
expect(yaxis.tickcolor).toBe('#444');
expect(yaxis.ticks).toBe('outside');
expect(yaxis.showticklabels).toBe(true);
expect(yaxis.tickfont).toEqual({ family: '"Open Sans", verdana, arial, sans-serif', size: 12, color: '#444' });
expect(yaxis.tickangle).toBe('auto');
Expand Down
74 changes: 3 additions & 71 deletions test/jasmine/tests/lib_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ describe('Test lib.js:', function() {
expect(sizeOut).toBe(outObj.testMarker.testSize);
});

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

expect(colOut).toBe(false);
expect(outObj.testMarker.testColor).toBe('rgba(0, 0, 0, 0)');
expect(sizeOut).toBe(false);
expect(outObj.testMarker.testSize).toBe(20);
});

it('should set the user input', function() {
var colVal = 'red';
var sizeVal = '1e2';
var attrs = {
testMarker: {
testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
testSize: {valType: 'number', dflt: 20}
}
};
var obj = {testMarker: {testColor: colVal, testSize: sizeVal}};
var outObj = {};
CCA7 var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor');
var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');

expect(colOut).toBe('red');
expect(colOut).toBe(outObj.testMarker.testColor);
expect(sizeOut).toBe(100);
expect(colOut).toBe('rgba(0, 0, 0, 0)');
expect(sizeOut).toBe(outObj.testMarker.testSize);
});

it('should set to template if the container input is not valid', function() {
var attrs = {
testMarker: {
testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
testSize: {valType: 'number', dflt: 20}
}
};
var obj = {
testMarker: {testColor: 'invalid', testSize: 'invalid'}
};
var outObj = {
_template: {
testMarker: {testColor: 'red', testSize: '1e2'}
}
};
var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor');
var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');

expect(colOut).toBe('red');
expect(colOut).toBe(outObj.testMarker.testColor);
expect(sizeOut).toBe(100);
expect(sizeOut).toBe(20);
expect(sizeOut).toBe(outObj.testMarker.testSize);
});

it('should set to default and return false if the both container and template inputs are not valid', function() {
var attrs = {
testMarker: {
testColor: {valType: 'color', dflt: 'rgba(0, 0, 0, 0)'},
testSize: {valType: 'number', dflt: 20}
}
};
var obj = {
testMarker: {testColor: 'invalid', testSize: 'invalid'}
};
var outObj = {
_template: {
testMarker: {testColor: 'invalid', testSize: 'invalid'}
}
};
var colOut = coerce2(obj, outObj, attrs, 'testMarker.testColor');
var sizeOut = coerce2(obj, outObj, attrs, 'testMarker.testSize');

expect(colOut).toBe(false);
expect(outObj.testMarker.testColor).toBe('rgba(0, 0, 0, 0)');
expect(sizeOut).toBe(false);
expect(outObj.testMarker.testSize).toBe(20);
});

it('should return false if there is no user input', function() {
var colVal = null;
var sizeVal; // undefined
Expand Down
0