|
1 | 1 | var helpers = require('@src/components/shapes/helpers');
|
2 | 2 | var constants = require('@src/components/shapes/constants');
|
| 3 | +var handleShapeDefaults = require('@src/components/shapes/shape_defaults'); |
3 | 4 |
|
4 | 5 | var Plotly = require('@lib/index');
|
5 | 6 | var PlotlyInternal = require('@src/plotly');
|
6 | 7 | var Lib = require('@src/lib');
|
7 | 8 | var Axes = PlotlyInternal.Axes;
|
| 9 | +var Plots = require('@src/plots/plots'); |
8 | 10 |
|
9 | 11 | var d3 = require('d3');
|
10 | 12 | var createGraphDiv = require('../assets/create_graph_div');
|
11 | 13 | 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 | +}); |
12 | 54 |
|
13 | 55 |
|
14 | 56 | describe('Test shapes:', function() {
|
|
0 commit comments