Skip to content

Commit

Permalink
Merge pull request #6712 from lvlte/allow-default-scaleanchor-removal
Browse files Browse the repository at this point in the history
Allow default scaleanchor removal
  • Loading branch information
archmoj authored Aug 21, 2023
2 parents e38c18b + b55fd06 commit 9a039bd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions draftlogs/6712_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +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!
2 changes: 1 addition & 1 deletion src/plots/cartesian/constraints.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function handleOneAxDefaults(axIn, axOut, opts) {
scaleanchor = Lib.coerce(axIn, axOut, {
scaleanchor: {
valType: 'enumerated',
values: linkableAxes
values: linkableAxes.concat([false])
}
}, 'scaleanchor', scaleanchorDflt);
}
Expand Down
12 changes: 9 additions & 3 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,13 @@ module.exports = {
].join(' ')
},
// scaleanchor: not used directly, just put here for reference
// values are any opposite-letter axis id
// values are any opposite-letter axis id, or `false`.
scaleanchor: {
valType: 'enumerated',
values: [
constants.idRegex.x.toString(),
constants.idRegex.y.toString()
constants.idRegex.y.toString(),
false
],
editType: 'plot',
description: [
Expand All @@ -353,7 +354,12 @@ module.exports = {
'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.'
'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).'
].join(' ')
},
scaleratio: {
Expand Down
8 changes: 8 additions & 0 deletions test/jasmine/tests/image_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ describe('image smart layout defaults', function() {
expect(gd._fullLayout.yaxis.scaleanchor).toBe('x');
});

it('should NOT set scaleanchor if asked not to', function() {
gd = {};
gd.data = [{type: 'image', z: [[[255, 0, 0]]]}];
gd.layout = {yaxis: {scaleanchor: false}};
supplyAllDefaults(gd);
expect(gd._fullLayout.yaxis.scaleanchor).toBe(false);
});

it('should NOT reset scaleanchor if it\'s already defined', function() {
gd.data = [{type: 'image', z: [[[255, 0, 0]]]}, {y: [5, 3, 2], xaxis: 'x3'}];
gd.layout = {yaxis: {scaleanchor: 'x3'}};
Expand Down
10 changes: 6 additions & 4 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11157,12 +11157,13 @@
},
"role": "object",
"scaleanchor": {
"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.",
"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).",
"editType": "plot",
"valType": "enumerated",
"values": [
"/^x([2-9]|[1-9][0-9]+)?( domain)?$/",
"/^y([2-9]|[1-9][0-9]+)?( domain)?$/"
"/^y([2-9]|[1-9][0-9]+)?( domain)?$/",
false
]
},
"scaleratio": {
Expand Down Expand Up @@ -12167,12 +12168,13 @@
},
"role": "object",
"scaleanchor": {
"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.",
"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).",
"editType": "plot",
"valType": "enumerated",
"values": [
"/^x([2-9]|[1-9][0-9]+)?( domain)?$/",
"/^y([2-9]|[1-9][0-9]+)?( domain)?$/"
"/^y([2-9]|[1-9][0-9]+)?( domain)?$/",
false
]
},
"scaleratio": {
Expand Down

0 comments on commit 9a039bd

Please sign in to comment.