Skip to content

Commit 9a039bd

Browse files
authoredAug 21, 2023
Merge pull request #6712 from lvlte/allow-default-scaleanchor-removal
Allow default scaleanchor removal
2 parents e38c18b + b55fd06 commit 9a039bd

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed
 

‎draftlogs/6712_add.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Allow to remove a scaleanchor constraint that is set by default [[#6712](https://github.com/plotly/plotly.js/pull/6712)], with thanks to @lvlte for the contribution!

‎src/plots/cartesian/constraints.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ function handleOneAxDefaults(axIn, axOut, opts) {
253253
scaleanchor = Lib.coerce(axIn, axOut, {
254254
scaleanchor: {
255255
valType: 'enumerated',
256-
values: linkableAxes
256+
values: linkableAxes.concat([false])
257257
}
258258
}, 'scaleanchor', scaleanchorDflt);
259259
}

‎src/plots/cartesian/layout_attributes.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,13 @@ module.exports = {
330330
].join(' ')
331331
},
332332
// scaleanchor: not used directly, just put here for reference
333-
// values are any opposite-letter axis id
333+
// values are any opposite-letter axis id, or `false`.
334334
scaleanchor: {
335335
valType: 'enumerated',
336336
values: [
337337
constants.idRegex.x.toString(),
338-
constants.idRegex.y.toString()
338+
constants.idRegex.y.toString(),
339+
false
339340
],
340341
editType: 'plot',
341342
description: [
@@ -353,7 +354,12 @@ module.exports = {
353354
'and the last constraint encountered will be ignored to avoid possible',
354355
'inconsistent constraints via `scaleratio`.',
355356
'Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint',
356-
'is currently forbidden.'
357+
'is currently forbidden.',
358+
'Setting `false` allows to remove a default constraint (occasionally,',
359+
'you may need to prevent a default `scaleanchor` constraint from',
360+
'being applied, eg. when having an image trace `yaxis: {scaleanchor: "x"}`',
361+
'is set automatically in order for pixels to be rendered as squares,',
362+
'setting `yaxis: {scaleanchor: false}` allows to remove the constraint).'
357363
].join(' ')
358364
},
359365
scaleratio: {

‎test/jasmine/tests/image_test.js

+8
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ describe('image smart layout defaults', function() {
209209
expect(gd._fullLayout.yaxis.scaleanchor).toBe('x');
210210
});
211211

212+
it('should NOT set scaleanchor if asked not to', function() {
213+
gd = {};
214+
gd.data = [{type: 'image', z: [[[255, 0, 0]]]}];
215+
gd.layout = {yaxis: {scaleanchor: false}};
216+
supplyAllDefaults(gd);
217+
expect(gd._fullLayout.yaxis.scaleanchor).toBe(false);
218+
});
219+
212220
it('should NOT reset scaleanchor if it\'s already defined', function() {
213221
gd.data = [{type: 'image', z: [[[255, 0, 0]]]}, {y: [5, 3, 2], xaxis: 'x3'}];
214222
gd.layout = {yaxis: {scaleanchor: 'x3'}};

‎test/plot-schema.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -11157,12 +11157,13 @@
1115711157
},
1115811158
"role": "object",
1115911159
"scaleanchor": {
11160-
"description": "If set to another axis id (e.g. `x2`, `y`), the range of this axis changes together with the range of the corresponding axis such that the scale of pixels per unit is in a constant ratio. Both axes are still zoomable, but when you zoom one, the other will zoom the same amount, keeping a fixed midpoint. `constrain` and `constraintoward` determine how we enforce the constraint. You can chain these, ie `yaxis: {scaleanchor: *x*}, xaxis2: {scaleanchor: *y*}` but you can only link axes of the same `type`. The linked axis can have the opposite letter (to constrain the aspect ratio) or the same letter (to match scales across subplots). Loops (`yaxis: {scaleanchor: *x*}, xaxis: {scaleanchor: *y*}` or longer) are redundant and the last constraint encountered will be ignored to avoid possible inconsistent constraints via `scaleratio`. Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint is currently forbidden.",
11160+
"description": "If set to another axis id (e.g. `x2`, `y`), the range of this axis changes together with the range of the corresponding axis such that the scale of pixels per unit is in a constant ratio. Both axes are still zoomable, but when you zoom one, the other will zoom the same amount, keeping a fixed midpoint. `constrain` and `constraintoward` determine how we enforce the constraint. You can chain these, ie `yaxis: {scaleanchor: *x*}, xaxis2: {scaleanchor: *y*}` but you can only link axes of the same `type`. The linked axis can have the opposite letter (to constrain the aspect ratio) or the same letter (to match scales across subplots). Loops (`yaxis: {scaleanchor: *x*}, xaxis: {scaleanchor: *y*}` or longer) are redundant and the last constraint encountered will be ignored to avoid possible inconsistent constraints via `scaleratio`. Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint is currently forbidden. Setting `false` allows to remove a default constraint (occasionally, you may need to prevent a default `scaleanchor` constraint from being applied, eg. when having an image trace `yaxis: {scaleanchor: \"x\"}` is set automatically in order for pixels to be rendered as squares, setting `yaxis: {scaleanchor: false}` allows to remove the constraint).",
1116111161
"editType": "plot",
1116211162
"valType": "enumerated",
1116311163
"values": [
1116411164
"/^x([2-9]|[1-9][0-9]+)?( domain)?$/",
11165-
"/^y([2-9]|[1-9][0-9]+)?( domain)?$/"
11165+
"/^y([2-9]|[1-9][0-9]+)?( domain)?$/",
11166+
false
1116611167
]
1116711168
},
1116811169
"scaleratio": {
@@ -12167,12 +12168,13 @@
1216712168
},
1216812169
"role": "object",
1216912170
"scaleanchor": {
12170-
"description": "If set to another axis id (e.g. `x2`, `y`), the range of this axis changes together with the range of the corresponding axis such that the scale of pixels per unit is in a constant ratio. Both axes are still zoomable, but when you zoom one, the other will zoom the same amount, keeping a fixed midpoint. `constrain` and `constraintoward` determine how we enforce the constraint. You can chain these, ie `yaxis: {scaleanchor: *x*}, xaxis2: {scaleanchor: *y*}` but you can only link axes of the same `type`. The linked axis can have the opposite letter (to constrain the aspect ratio) or the same letter (to match scales across subplots). Loops (`yaxis: {scaleanchor: *x*}, xaxis: {scaleanchor: *y*}` or longer) are redundant and the last constraint encountered will be ignored to avoid possible inconsistent constraints via `scaleratio`. Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint is currently forbidden.",
12171+
"description": "If set to another axis id (e.g. `x2`, `y`), the range of this axis changes together with the range of the corresponding axis such that the scale of pixels per unit is in a constant ratio. Both axes are still zoomable, but when you zoom one, the other will zoom the same amount, keeping a fixed midpoint. `constrain` and `constraintoward` determine how we enforce the constraint. You can chain these, ie `yaxis: {scaleanchor: *x*}, xaxis2: {scaleanchor: *y*}` but you can only link axes of the same `type`. The linked axis can have the opposite letter (to constrain the aspect ratio) or the same letter (to match scales across subplots). Loops (`yaxis: {scaleanchor: *x*}, xaxis: {scaleanchor: *y*}` or longer) are redundant and the last constraint encountered will be ignored to avoid possible inconsistent constraints via `scaleratio`. Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint is currently forbidden. Setting `false` allows to remove a default constraint (occasionally, you may need to prevent a default `scaleanchor` constraint from being applied, eg. when having an image trace `yaxis: {scaleanchor: \"x\"}` is set automatically in order for pixels to be rendered as squares, setting `yaxis: {scaleanchor: false}` allows to remove the constraint).",
1217112172
"editType": "plot",
1217212173
"valType": "enumerated",
1217312174
"values": [
1217412175
"/^x([2-9]|[1-9][0-9]+)?( domain)?$/",
12175-
"/^y([2-9]|[1-9][0-9]+)?( domain)?$/"
12176+
"/^y([2-9]|[1-9][0-9]+)?( domain)?$/",
12177+
false
1217612178
]
1217712179
},
1217812180
"scaleratio": {

0 commit comments

Comments
 (0)
Please sign in to comment.