Skip to content

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
Changes from 1 commit
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
81 changes: 46 additions & 35 deletions test/jasmine/tests/gl2d_click_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var fail = require('../assets/fail_test.js');
// a click event on mouseup
var click = require('../assets/timed_click');
var hover = require('../assets/hover');
var delay = require('../assets/delay');

// contourgl is not part of the dist plotly.js bundle initially
Plotly.register([
Expand Down Expand Up @@ -62,13 +63,6 @@ var mock4 = {
describe('Test hover and click interactions', function() {
var gd;

// need to wait a little bit before canvas can properly catch mouse events
function wait() {
return new Promise(function(resolve) {
setTimeout(resolve, 100);
});
}

function makeHoverFn(gd, x, y) {
return function() {
return new Promise(function(resolve) {
Expand All @@ -90,26 +84,27 @@ describe('Test hover and click interactions', function() {
function makeUnhoverFn(gd, x0, y0) {
return function() {
return new Promise(function(resolve) {
var eventData = null;

gd.on('plotly_unhover', function() {
eventData = 'emitted plotly_unhover';
});

// fairly realistic simulation of moving with the cursor
var canceler = setInterval(function() {
hover(x0--, y0--);
x0 -= 2;
y0 -= 2;
hover(x0, y0);
}, 10);

gd.on('plotly_unhover', function() {
clearInterval(canceler);
resolve('emitted plotly_unhover');
});

setTimeout(function() {
clearInterval(canceler);
resolve(eventData);
resolve(null);
}, 350);
});
};
}

function assertEventData(actual, expected) {
function assertEventData(actual, expected, msg) {
expect(actual.points.length).toEqual(1, 'points length');

var pt = actual.points[0];
Expand All @@ -119,30 +114,30 @@ describe('Test hover and click interactions', function() {
'data', 'fullData', 'xaxis', 'yaxis'
], 'event data keys');

expect(typeof pt.data.uid).toEqual('string', 'uid');
expect(pt.xaxis.domain.length).toEqual(2, 'xaxis');
expect(pt.yaxis.domain.length).toEqual(2, 'yaxis');
expect(typeof pt.data.uid).toBe('string', msg + ' - uid');
expect(pt.xaxis.domain.length).toBe(2, msg + ' - xaxis');
expect(pt.yaxis.domain.length).toBe(2, msg + ' - yaxis');

expect(pt.x).toEqual(expected.x, 'x');
expect(pt.y).toEqual(expected.y, 'y');
expect(pt.curveNumber).toEqual(expected.curveNumber, 'curve number');
expect(pt.pointNumber).toEqual(expected.pointNumber, 'point number');
expect(pt.x).toBe(expected.x, msg + ' - x');
expect(pt.y).toBe(expected.y, msg + ' - y');
expect(pt.curveNumber).toBe(expected.curveNumber, msg + ' - curve number');
expect(String(pt.pointNumber)).toBe(String(expected.pointNumber), msg + ' - point number');
}

function assertHoverLabelStyle(sel, expected) {
function assertHoverLabelStyle(sel, expected, msg) {
if(sel.node() === null) {
expect(expected.noHoverLabel).toBe(true);
return;
}

var path = sel.select('path');
expect(path.style('fill')).toEqual(expected.bgColor, 'bgcolor');
expect(path.style('stroke')).toEqual(expected.borderColor, 'bordercolor');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too bad that toEqual can't print a failure msg. Oh jasmine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for those test tweaks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, didn't it used to be able to do that? super annoying.

expect(path.style('fill')).toBe(expected.bgColor, msg + ' - bgcolor');
expect(path.style('stroke')).toBe(expected.borderColor, msg + ' - bordercolor');

var text = sel.select('text.nums');
expect(parseInt(text.style('font-size'))).toEqual(expected.fontSize, 'font.size');
expect(text.style('font-family').split(',')[0]).toEqual(expected.fontFamily, 'font.family');
expect(text.style('fill')).toEqual(expected.fontColor, 'font.color');
expect(parseInt(text.style('font-size'))).toBe(expected.fontSize, msg + ' - font.size');
expect(text.style('font-family').split(',')[0]).toBe(expected.fontFamily, msg + ' - font.family');
expect(text.style('fill')).toBe(expected.fontColor, msg + ' - font.color');
}

function assertHoveLabelContent(expected) {
Expand Down Expand Up @@ -176,20 +171,20 @@ describe('Test hover and click interactions', function() {
makeUnhoverFn(gd, pos[0], pos[1]);

return function() {
return wait()
return delay(100)()
.then(_hover)
.then(function(eventData) {
assertEventData(eventData, expected);
assertHoverLabelStyle(d3.select('g.hovertext'), expected);
assertHoverLabelStyle(d3.select('g.hovertext'), expected, opts.msg);
assertHoveLabelContent(expected);
})
.then(_click)
.then(function(eventData) {
assertEventData(eventData, expected);
assertEventData(eventData, expected, opts.msg);
})
.then(_unhover)
.then(function(eventData) {
expect(eventData).toEqual('emitted plotly_unhover');
expect(eventData).toBe('emitted plotly_unhover', opts.msg);
});
};
}
Expand Down Expand Up @@ -233,6 +228,8 @@ describe('Test hover and click interactions', function() {
fontSize: 20,
fontFamily: 'Arial',
fontColor: 'rgb(255, 255, 0)'
}, {
msg: 'scattergl'
});

Plotly.plot(gd, _mock)
Expand All @@ -251,6 +248,8 @@ describe('Test hover and click interactions', function() {
curveNumber: 0,
pointNumber: 33,
noHoverLabel: true
}, {
msg: 'scattergl with hoverinfo'
});

Plotly.plot(gd, _mock)
Expand All @@ -277,6 +276,8 @@ describe('Test hover and click interactions', function() {
fontSize: 8,
fontFamily: 'Arial',
fontColor: 'rgb(255, 255, 255)'
}, {
msg: 'pointcloud'
});

Plotly.plot(gd, _mock)
Expand Down Expand Up @@ -308,7 +309,8 @@ describe('Test hover and click interactions', function() {
fontFamily: 'Roboto',
fontColor: 'rgb(255, 255, 255)'
}, {
noUnHover: true
noUnHover: true,
msg: 'heatmapgl'
});

Plotly.plot(gd, _mock)
Expand All @@ -330,6 +332,8 @@ describe('Test hover and click interactions', function() {
fontSize: 13,
fontFamily: 'Arial',
fontColor: 'rgb(255, 255, 255)'
}, {
msg: 'scattergl before visibility restyle'
});

// after the restyle, autorange changes the y range
Expand All @@ -343,6 +347,8 @@ describe('Test hover and click interactions', function() {
fontSize: 13,
fontFamily: 'Arial',
fontColor: 'rgb(68, 68, 68)'
}, {
msg: 'scattergl after visibility restyle'
});

Plotly.plot(gd, _mock)
Expand Down Expand Up @@ -371,6 +377,8 @@ describe('Test hover and click interactions', function() {
fontSize: 13,
fontFamily: 'Arial',
fontColor: 'rgb(255, 255, 255)'
}, {
msg: 'scattergl fancy before visibility restyle'
});

// after the restyle, autorange changes the x AND y ranges
Expand All @@ -387,6 +395,8 @@ describe('Test hover and click interactions', function() {
fontSize: 13,
fontFamily: 'Arial',
fontColor: 'rgb(68, 68, 68)'
}, {
msg: 'scattergl fancy after visibility restyle'
});

Plotly.plot(gd, _mock)
Expand Down Expand Up @@ -417,7 +427,8 @@ describe('Test hover and click interactions', function() {
fontFamily: 'Arial',
fontColor: 'rgb(255, 255, 255)'
}, {
noUnHover: true
noUnHover: true,
msg: 'contourgl'
});

Plotly.plot(gd, _mock)
Expand Down