Skip to content

Commit c75cda8

Browse files
committed
swap and 🔒 'calcIfAutorange' -> 'calc' for shapes
1 parent 4e8ff28 commit c75cda8

File tree

2 files changed

+57
-28
lines changed

2 files changed

+57
-28
lines changed

src/components/shapes/attributes.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = templatedArray('shape', {
1919
valType: 'boolean',
2020
role: 'info',
2121
dflt: true,
22-
editType: 'calcIfAutorange+arraydraw',
22+
editType: 'calc+arraydraw',
2323
description: [
2424
'Determines whether or not this shape is visible.'
2525
].join(' ')
@@ -29,7 +29,7 @@ module.exports = templatedArray('shape', {
2929
valType: 'enumerated',
3030
values: ['circle', 'rect', 'path', 'line'],
3131
role: 'info',
32-
editType: 'calcIfAutorange+arraydraw',
32+
editType: 'calc+arraydraw',
3333
description: [
3434
'Specifies the shape type to be drawn.',
3535

@@ -79,7 +79,7 @@ module.exports = templatedArray('shape', {
7979
values: ['scaled', 'pixel'],
8080
dflt: 'scaled',
8181
role: 'info',
82-
editType: 'calcIfAutorange+arraydraw',
82+
editType: 'calc+arraydraw',
8383
description: [
8484
'Sets the shapes\'s sizing mode along the x axis.',
8585
'If set to *scaled*, `x0`, `x1` and x coordinates within `path` refer to',
@@ -95,7 +95,7 @@ module.exports = templatedArray('shape', {
9595
xanchor: {
9696
valType: 'any',
9797
role: 'info',
98-
editType: 'calcIfAutorange+arraydraw',
98+
editType: 'calc+arraydraw',
9999
description: [
100100
'Only relevant in conjunction with `xsizemode` set to *pixel*.',
101101
'Specifies the anchor point on the x axis to which `x0`, `x1`',
@@ -107,7 +107,7 @@ module.exports = templatedArray('shape', {
107107
x0: {
108108
valType: 'any',
109109
role: 'info',
110-
editType: 'calcIfAutorange+arraydraw',
110+
editType: 'calc+arraydraw',
111111
description: [
112112
'Sets the shape\'s starting x position.',
113113
'See `type` and `xsizemode` for more info.'
@@ -116,7 +116,7 @@ module.exports = templatedArray('shape', {
116116
x1: {
117117
valType: 'any',
118118
role: 'info',
119-
editType: 'calcIfAutorange+arraydraw',
119+
editType: 'calc+arraydraw',
120120
description: [
121121
'Sets the shape\'s end x position.',
122122
'See `type` and `xsizemode` for more info.'
@@ -138,7 +138,7 @@ module.exports = templatedArray('shape', {
138138
values: ['scaled', 'pixel'],
139139
dflt: 'scaled',
140140
role: 'info',
141-
editType: 'calcIfAutorange+arraydraw',
141+
editType: 'calc+arraydraw',
142142
description: [
143143
'Sets the shapes\'s sizing mode along the y axis.',
144144
'If set to *scaled*, `y0`, `y1` and y coordinates within `path` refer to',
@@ -154,7 +154,7 @@ module.exports = templatedArray('shape', {
154154
yanchor: {
155155
valType: 'any',
156156
role: 'info',
157-
editType: 'calcIfAutorange+arraydraw',
157+
editType: 'calc+arraydraw',
158158
description: [
159159
'Only relevant in conjunction with `ysizemode` set to *pixel*.',
160160
'Specifies the anchor point on the y axis to which `y0`, `y1`',
@@ -166,7 +166,7 @@ module.exports = templatedArray('shape', {
166166
y0: {
167167
valType: 'any',
168168
role: 'info',
169-
editType: 'calcIfAutorange+arraydraw',
169+
editType: 'calc+arraydraw',
170170
description: [
171171
'Sets the shape\'s starting y position.',
172172
'See `type` and `ysizemode` for more info.'
@@ -175,7 +175,7 @@ module.exports = templatedArray('shape', {
175175
y1: {
176176
valType: 'any',
177177
role: 'info',
178-
editType: 'calcIfAutorange+arraydraw',
178+
editType: 'calc+arraydraw',
179179
description: [
180180
'Sets the shape\'s end y position.',
181181
'See `type` and `ysizemode` for more info.'
@@ -185,7 +185,7 @@ module.exports = templatedArray('shape', {
185185
path: {
186186
valType: 'string',
187187
role: 'info',
188-
editType: 'calcIfAutorange+arraydraw',
188+
editType: 'calc+arraydraw',
189189
description: [
190190
'For `type` *path* - a valid SVG path with the pixel values',
191191
'replaced by data values in `xsizemode`/`ysizemode` being *scaled*',
@@ -224,10 +224,10 @@ module.exports = templatedArray('shape', {
224224
},
225225
line: {
226226
color: extendFlat({}, scatterLineAttrs.color, {editType: 'arraydraw'}),
227-
width: extendFlat({}, scatterLineAttrs.width, {editType: 'calcIfAutorange+arraydraw'}),
227+
width: extendFlat({}, scatterLineAttrs.width, {editType: 'calc+arraydraw'}),
228228
dash: extendFlat({}, dash, {editType: 'arraydraw'}),
229229
role: 'info',
230-
editType: 'calcIfAutorange+arraydraw'
230+
editType: 'calc+arraydraw'
231231
},
232232
fillcolor: {
233233
valType: 'color',

test/jasmine/tests/shapes_test.js

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,17 @@ describe('shapes edge cases', function() {
529529
});
530530

531531
describe('shapes autosize', function() {
532-
'use strict';
533-
534532
var gd;
535533

536534
afterEach(destroyGraphDiv);
537535

536+
function assertRanges(msg, x, y) {
537+
var fullLayout = gd._fullLayout;
538+
var PREC = 1;
539+
expect(fullLayout.xaxis.range).toBeCloseToArray(x, PREC, msg + ' - xaxis');
540+
expect(fullLayout.yaxis.range).toBeCloseToArray(y, PREC, msg + ' - yaxis');
541+
}
542+
538543
it('should adapt to relayout calls', function(done) {
539544
gd = createGraphDiv();
540545

@@ -557,31 +562,55 @@ describe('shapes autosize', function() {
557562
}
558563
};
559564

560-
function assertRanges(x, y) {
561-
var fullLayout = gd._fullLayout;
562-
var PREC = 1;
563-
564-
expect(fullLayout.xaxis.range).toBeCloseToArray(x, PREC, '- xaxis');
565-
expect(fullLayout.yaxis.range).toBeCloseToArray(y, PREC, '- yaxis');
566-
}
567-
568565
Plotly.plot(gd, mock).then(function() {
569-
assertRanges([0, 2], [0, 2]);
570-
566+
assertRanges('base', [0, 2], [0, 2]);
571567
return Plotly.relayout(gd, { 'shapes[1].visible': false });
572568
})
573569
.then(function() {
574-
assertRanges([0, 1], [0, 1]);
570+
assertRanges('shapes[1] not visible', [0, 1], [0, 1]);
575571

576572
return Plotly.relayout(gd, { 'shapes[1].visible': true });
577573
})
578574
.then(function() {
579-
assertRanges([0, 2], [0, 2]);
575+
assertRanges('back to base', [0, 2], [0, 2]);
580576

581577
return Plotly.relayout(gd, { 'shapes[0].x1': 3 });
582578
})
583579
.then(function() {
584-
assertRanges([0, 3], [0, 2]);
580+
assertRanges('stretched shapes[0]', [0, 3], [0, 2]);
581+
})
582+
.catch(failTest)
583+
.then(done);
584+
});
585+
586+
it('should propagate axis autorange changes when axis ranges are set', function(done) {
587+
gd = createGraphDiv();
588+
589+
Plotly.plot(gd, [{y: [1, 2]}], {
590+
xaxis: {range: [0, 2]},
591+
yaxis: {range: [0, 2]},
592+
shapes: [{
593+
x0: 2, y0: 2,
594+
x1: 3, y1: 3
595+
}]
596+
})
597+
.then(function() {
598+
assertRanges('set rng / narrow shape', [0, 2], [0, 2]);
599+
return Plotly.relayout(gd, 'shapes[0].x1', 10);
600+
})
601+
.then(function() {
602+
assertRanges('set rng / large shape', [0, 2], [0, 2]);
603+
return Plotly.relayout(gd, {
604+
'xaxis.autorange': true,
605+
'yaxis.autorange': true
606+
});
607+
})
608+
.then(function() {
609+
assertRanges('auto rng / large shape', [-0.61, 10], [0.86, 3]);
610+
return Plotly.relayout(gd, 'shapes[0].x1', 3);
611+
})
612+
.then(function() {
613+
assertRanges('auto rng / small shape', [-0.18, 3], [0.86, 3]);
585614
})
586615
.catch(failTest)
587616
.then(done);

0 commit comments

Comments
 (0)