Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Constrain axes by domain #1767

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 23 commits into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d0af01b
axis.constrain and axis.constraintoward
alexcjohnson Jun 1, 2017
cc705c3
robustify plot_test
alexcjohnson Jun 1, 2017
b3a3bb7
simplify plot_test
alexcjohnson Jun 1, 2017
27fc2a9
robustify plot_api_test
alexcjohnson Jun 1, 2017
d937732
simplify hover_label_test
alexcjohnson Jun 2, 2017
1570274
no really, initInteractions! fix #1044... again
alexcjohnson Jun 2, 2017
72896ec
robustify drawing_test
alexcjohnson Jun 2, 2017
ee3211a
robustify gl_plot_interact_test
alexcjohnson Jun 2, 2017
f12ff73
streamline gl2d_click_test
alexcjohnson Jun 2, 2017
5f5214e
fix bug with unhover in gl2d
alexcjohnson Jun 2, 2017
9df6903
robustify mapbox_test
alexcjohnson Jun 2, 2017
d0b15c8
tests of axis domain constraints
alexcjohnson Jun 2, 2017
d67829e
create constraints.clean to get it out of the main Plotly.plot code
alexcjohnson Jun 8, 2017
b1c6b24
more robust way to generate relayout args during axis drag
alexcjohnson Jun 8, 2017
59a092a
update constraints.js to handle some more editing edge cases
alexcjohnson Jun 8, 2017
51fc2c6
put range 0,1 parts separately into GUI relayout calls
alexcjohnson Jun 8, 2017
3931973
rm unused `attrs` variable
alexcjohnson Jun 8, 2017
1271382
axes.expand: ensure domain constraint before adjusting extrappad
alexcjohnson Jun 8, 2017
6d3a48a
add special validateFunction for enumerated valType
etpinard Jun 8, 2017
3b0d829
add special handler in Plotly.validate for enumerated w/ dynamic values
etpinard Jun 8, 2017
4002fc1
Merge pull request #1769 from plotly/validate-dynamic-enumerated
etpinard Jun 8, 2017
fa78376
:hocho: debug cruft
alexcjohnson Jun 9, 2017
67ea3a8
test axis constraints (range & domain) with log and category axes
alexcjohnson Jun 9, 2017
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
14 changes: 14 additions & 0 deletions 14 src/lib/coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ exports.valObjects = {
if(opts.coerceNumber) v = +v;
if(opts.values.indexOf(v) === -1) propOut.set(dflt);
else propOut.set(v);
},
validateFunction: function(v, opts) {
if(opts.coerceNumber) v = +v;

var values = opts.values;
for(var i = 0; i < values.length; i++) {
var k = String(values[i]);

if((k.charAt(0) === '/' && k.charAt(k.length - 1) === '/')) {
var regex = new RegExp(k.substr(1, k.length - 2));
if(regex.test(v)) return true;
} else if(v === values[i]) return true;
}
return false;
}
},
'boolean': {
Expand Down
21 changes: 18 additions & 3 deletions 21 src/plot_api/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ function crawl(objIn, objOut, schema, list, base, path) {
else if(!Lib.validate(valIn, nestedSchema)) {
list.push(format('value', base, p, valIn));
}
else if(nestedSchema.valType === 'enumerated' &&
((nestedSchema.coerceNumber && valIn !== +valOut) || valIn !== valOut)
) {
list.push(format('dynamic', base, p, valIn, valOut));
}
}

return list;
Expand Down Expand Up @@ -267,6 +272,16 @@ var code2msgFunc = {

return inBase(base) + target + ' ' + astr + ' did not get coerced';
},
dynamic: function(base, astr, valIn, valOut) {
return [
inBase(base) + 'key',
astr,
'(set to \'' + valIn + '\')',
'got reset to',
'\'' + valOut + '\'',
'during defaults.'
].join(' ');
},
invisible: function(base) {
return 'Trace ' + base[1] + ' got defaulted to be not visible';
},
Expand All @@ -284,7 +299,7 @@ function inBase(base) {
return 'In ' + base + ', ';
}

function format(code, base, path, valIn) {
function format(code, base, path, valIn, valOut) {
path = path || '';

var container, trace;
Expand All @@ -301,8 +316,8 @@ function format(code, base, path, valIn) {
trace = null;
}

var astr = convertPathToAttributeString(path),
msg = code2msgFunc[code](base, astr, valIn);
var astr = convertPathToAttributeString(path);
var msg = code2msgFunc[code](base, astr, valIn, valOut);

// log to console if logger config option is enabled
Lib.log(msg);
Expand Down
6 changes: 6 additions & 0 deletions 6 test/jasmine/tests/lib_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,12 @@ describe('Test lib.js:', function() {
arrayOk: true,
dflt: 'a'
});

assert(['x', 'x2'], ['xx', 'x0', undefined], {
valType: 'enumerated',
values: ['/^x([2-9]|[1-9][0-9]+)?$/'],
dflt: 'x'
});
});

it('should work for valType \'boolean\' where', function() {
Expand Down
41 changes: 41 additions & 0 deletions 41 test/jasmine/tests/validate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,45 @@ describe('Plotly.validate', function() {
'In data trace 2, key transforms[0].type is set to an invalid value (no gonna work)'
);
});

it('should catch input errors for attribute with dynamic defaults', function() {
var out = Plotly.validate([], {
xaxis: {
constrain: 'domain',
constraintoward: 'bottom'
},
yaxis: {
constrain: 'domain',
constraintoward: 'left'
},
xaxis2: {
anchor: 'x3'
},
yaxis2: {
overlaying: 'x'
}
});

expect(out.length).toBe(4);
assertErrorContent(
out[0], 'dynamic', 'layout', null,
['xaxis', 'constraintoward'], 'xaxis.constraintoward',
'In layout, key xaxis.constraintoward (set to \'bottom\') got reset to \'center\' during defaults.'
);
assertErrorContent(
out[1], 'dynamic', 'layout', null,
['yaxis', 'constraintoward'], 'yaxis.constraintoward',
'In layout, key yaxis.constraintoward (set to \'left\') got reset to \'middle\' during defaults.'
);
assertErrorContent(
out[2], 'dynamic', 'layout', null,
['xaxis2', 'anchor'], 'xaxis2.anchor',
'In layout, key xaxis2.anchor (set to \'x3\') got reset to \'y\' during defaults.'
);
assertErrorContent(
out[3], 'dynamic', 'layout', null,
['yaxis2', 'overlaying'], 'yaxis2.overlaying',
'In layout, key yaxis2.overlaying (set to \'x\') got reset to \'false\' during defaults.'
);
});
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.