(findDragger, autoshiftX, autoshiftY, coordScale)
| 1058 | * and for the plot defined above, data-referenced has scale 100 |
| 1059 | */ |
| 1060 | function checkDragging(findDragger, autoshiftX, autoshiftY, coordScale) { |
| 1061 | var bboxInitial = textBox().getBoundingClientRect(); |
| 1062 | // first move it within the same auto-anchor zone |
| 1063 | return dragAndReplot(findDragger(), 30, -30) |
| 1064 | .then(function() { |
| 1065 | var bbox = textBox().getBoundingClientRect(); |
| 1066 | |
| 1067 | // I'm not sure why these calculations aren't exact - they end up |
| 1068 | // being off by a fraction of a pixel, or a full pixel sometimes |
| 1069 | // even though as far as I can see in practice the positioning is |
| 1070 | // exact. In any event, this precision is enough to ensure that |
| 1071 | // anchor: auto is being used. |
| 1072 | expect(bbox.left).toBeWithin(bboxInitial.left + 30, 1); |
| 1073 | expect(bbox.top).toBeWithin(bboxInitial.top - 30, 1); |
| 1074 | |
| 1075 | var ann = gd.layout.annotations[0]; |
| 1076 | expect(ann.x).toBeWithin(0.1 * coordScale, 0.01 * coordScale); |
| 1077 | expect(ann.y).toBeWithin(0.1 * coordScale, 0.01 * coordScale); |
| 1078 | |
| 1079 | // now move it to the center |
| 1080 | // note that we explicitly offset by half the box size because the |
| 1081 | // auto-anchor will move to the center |
| 1082 | return dragAndReplot(findDragger(), 120 - autoshiftX, -120 + autoshiftY); |
| 1083 | }) |
| 1084 | .then(function() { |
| 1085 | var bbox = textBox().getBoundingClientRect(); |
| 1086 | expect(bbox.left).toBeWithin(bboxInitial.left + 150 - autoshiftX, 2); |
| 1087 | expect(bbox.top).toBeWithin(bboxInitial.top - 150 + autoshiftY, 2); |
| 1088 | |
| 1089 | var ann = gd.layout.annotations[0]; |
| 1090 | expect(ann.x).toBeWithin(0.5 * coordScale, 0.01 * coordScale); |
| 1091 | expect(ann.y).toBeWithin(0.5 * coordScale, 0.01 * coordScale); |
| 1092 | |
| 1093 | // next move it near the upper right corner, where the auto-anchor |
| 1094 | // moves to the top right corner |
| 1095 | // we don't move it all the way to the corner, so the annotation will |
| 1096 | // still be entirely on the plot even with an arrow. |
| 1097 | return dragAndReplot(findDragger(), 90 - autoshiftX, -90 + autoshiftY); |
| 1098 | }) |
| 1099 | .then(function() { |
| 1100 | var bbox = textBox().getBoundingClientRect(); |
| 1101 | expect(bbox.left).toBeWithin(bboxInitial.left + 240 - 2 * autoshiftX, 2); |
| 1102 | expect(bbox.top).toBeWithin(bboxInitial.top - 240 + 2 * autoshiftY, 2); |
| 1103 | |
| 1104 | var ann = gd.layout.annotations[0]; |
| 1105 | expect(ann.x).toBeWithin(0.8 * coordScale, 0.01 * coordScale); |
| 1106 | expect(ann.y).toBeWithin(0.8 * coordScale, 0.01 * coordScale); |
| 1107 | |
| 1108 | // finally move it back to 0, 0 |
| 1109 | return dragAndReplot(findDragger(), -240 + 2 * autoshiftX, 240 - 2 * autoshiftY); |
| 1110 | }) |
| 1111 | .then(function() { |
| 1112 | var bbox = textBox().getBoundingClientRect(); |
| 1113 | expect(bbox.left).toBeWithin(bboxInitial.left, 2); |
| 1114 | expect(bbox.top).toBeWithin(bboxInitial.top, 2); |
| 1115 | |
| 1116 | var ann = gd.layout.annotations[0]; |
| 1117 | expect(ann.x).toBeWithin(0 * coordScale, 0.01 * coordScale); |
no test coverage detected
searching dependent graphs…