Skip to content

Commit e63ea3b

Browse files
committed
test and fix shape default positioning
1 parent 5ccd083 commit e63ea3b

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/components/shapes/shape_defaults.js

-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ module.exports = function handleShapeDefaults(shapeIn, fullLayout) {
5252
ax = Axes.getFromId(gdMock, axRef);
5353
r2pos = helpers.rangeToShapePosition(ax);
5454
pos2r = helpers.shapePositionToRange(ax);
55-
56-
dflt0 = r2pos(ax.fraction2r(dflt0));
57-
dflt1 = r2pos(ax.fraction2r(dflt1));
5855
}
5956
else {
6057
pos2r = r2pos = Lib.identity;

test/jasmine/tests/shapes_test.js

+42
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,56 @@
11
var helpers = require('@src/components/shapes/helpers');
22
var constants = require('@src/components/shapes/constants');
3+
var handleShapeDefaults = require('@src/components/shapes/shape_defaults');
34

45
var Plotly = require('@lib/index');
56
var PlotlyInternal = require('@src/plotly');
67
var Lib = require('@src/lib');
78
var Axes = PlotlyInternal.Axes;
9+
var Plots = require('@src/plots/plots');
810

911
var d3 = require('d3');
1012
var createGraphDiv = require('../assets/create_graph_div');
1113
var destroyGraphDiv = require('../assets/destroy_graph_div');
14+
var customMatchers = require('../assets/custom_matchers');
15+
16+
17+
describe('shape supplyDefaults', function() {
18+
beforeAll(function() {
19+
jasmine.addMatchers(customMatchers);
20+
});
21+
22+
it('should provide the right defaults on all axis types', function() {
23+
var fullLayout = {
24+
xaxis: {type: 'linear', range: [0, 20]},
25+
yaxis: {type: 'log', range: [1, 5]},
26+
xaxis2: {type: 'date', range: ['2006-06-05', '2006-06-09']},
27+
yaxis2: {type: 'category', range: [-0.5, 7.5]}
28+
};
29+
fullLayout._has = Plots._hasPlotType.bind(fullLayout);
30+
Axes.setConvert(fullLayout.xaxis);
31+
Axes.setConvert(fullLayout.yaxis);
32+
Axes.setConvert(fullLayout.xaxis2);
33+
Axes.setConvert(fullLayout.yaxis2);
34+
35+
var shape1In = {type: 'rect'},
36+
shape1Out = handleShapeDefaults(shape1In, fullLayout),
37+
shape2In = {type: 'circle', xref: 'x2', yref: 'y2'},
38+
shape2Out = handleShapeDefaults(shape2In, fullLayout);
39+
40+
// default positions are 1/4 and 3/4 of the full range of that axis
41+
expect(shape1Out.x0).toBe(5);
42+
expect(shape1Out.x1).toBe(15);
43+
// shapes use data values for log axes (like everyone will in V2.0)
44+
expect(shape1Out.y0).toBeWithin(100, 0.001);
45+
expect(shape1Out.y1).toBeWithin(10000, 0.001);
46+
// date strings also interpolate
47+
expect(shape2Out.x0).toBe('2006-06-06');
48+
expect(shape2Out.x1).toBe('2006-06-08');
49+
// categories must use serial numbers to get continuous values
50+
expect(shape2Out.y0).toBeWithin(1.5, 0.001);
51+
expect(shape2Out.y1).toBeWithin(5.5, 0.001);
52+
});
53+
});
1254

1355

1456
describe('Test shapes:', function() {

0 commit comments

Comments
 (0)