8000 property x0shift, x1shift, y0shift, y1shift for adjusting the shape coordinates by my-tien · Pull Request #7005 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

property x0shift, x1shift, y0shift, y1shift for adjusting the shape coordinates #7005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
aa0cd7a
property shape.x_shift/y_shift for adjusting the shape coordinates
my-tien May 27, 2024
44d1858
Add draftlog for PR 7005
my-tien May 27, 2024
7abea61
Add x_shift/y_shift for selections as well, add selection example to …
my-tien May 27, 2024
a617017
baseline images zzz_shape_shift_horizontal and zzz_shape_shift_vertical
my-tien May 27, 2024
c2f7f27
Update shapes_test after adding shift param to getDataToPixel
my-tien May 27, 2024
fdcaa0c
Rename x_shift/y_shift → xshift/yshift
my-tien May 31, 2024
9921522
Replace xshift and yshift with x0shift and y0shift
my-tien Jun 10, 2024
3ac32f3
Only coerce x0/x1/y0/y1shift if referenced axis is category/multicate…
my-tien Jun 10, 2024
6680745
Fix typo in calc_autorange: x/ysizemode "scale" -> "scaled"
my-tien Jun 10, 2024
ada2289
Add scatter to zzz_shape_shift_vertical mock
my-tien Jun 10, 2024
e11f6f6
Merge remote-tracking branch 'origin-plotly/master' into shape_shift
my-tien Jun 10, 2024
1bfb22d
Updated baseline image after adding scatter to zzz_shape_shift_vertic…
my-tien Jun 10, 2024
04466db
getDataToPixel: If shift is undefined, set it to 0
my-tien Jun 10, 2024
91db7c8
Update draftlog with final property names
my-tien Jun 12, 2024
4bbb669
Adjust attribute descriptions with property formatting and mention of…
my-tien Jun 12, 2024
ab935ac
Move calculation of shape shift into a dedicated function
my-tien Jun 18, 2024
82de6b1
Merge remote-tracking branch 'origin-plotly/master' into shape_shift
my-tien Jun 19, 2024
f9c44bf
Update overlooked test after changing xshift/yshift to x0shift,x1shif…
my-tien Jul 3, 2024
b00d4d8
Remove shift properties from selection for now
my-tien Jul 10, 2024
8cf665a
Merge remote-tracking branch 'origin-plotly/master' into shape_shift
my-tien Jul 10, 2024
78a7e5e
Fix getPixelShift for reversed axes, add reversed axis to mock
my-tien Jul 11, 2024
18e7c84
Update baseline image of zzz_shape_shift_vertical
my-tien Jul 11, 2024
5509ee6
Account for shift when dragging a shape
my-tien Jul 15, 2024
6f8e5a6
Support shape shift in texttemplate as well
my-tien Jul 15, 2024
7de45c3
Update baseline image after updated mock for texttemplate shape
my-tien Jul 15, 2024
9ac970a
Refine description for x0shift/x1shift/y0shift/y1shift
my-tien Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Prev Previous commit
Next Next commit
Rename x_shift/y_shift → xshift/yshift
  • Loading branch information
my-tien committed May 31, 2024
commit fdcaa0c8c02f67dc54386c49fd998f2df45fa956
6 changes: 4 additions & 2 deletions src/components/selections/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ module.exports = overrideAll(templatedArray('selection', {
valType: 'any',
description: 'Sets the selection\'s end y position.'
},
x_shift: {

xshift: {
valType: 'number',
dflt: 0,
min: -0.5,
Expand All @@ -64,7 +65,7 @@ module.exports = overrideAll(templatedArray('selection', {
'the reference unit.'
].join(' ')
},
y_shift: {
yshift: {
valType: 'number',
dflt: 0,
min: -0.5,
Expand All @@ -75,6 +76,7 @@ module.exports = overrideAll(templatedArray('selection', {
'the reference unit.'
].join(' ')
},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add these to newselection and test it.

path: {
valType: 'string',
editType: 'arraydraw',
Expand Down
4 changes: 2 additions & 2 deletions src/components/selections/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function handleSelectionDefaults(selectionIn, selectionOut, fullLayout) {
coerce('line.color');
coerce('line.width');
coerce('line.dash');
coerce('x_shift');
coerce('y_shift');
coerce('xshift');
coerce('yshift');

// positioning
var axLetters = ['x', 'y'];
Expand Down
25 changes: 12 additions & 13 deletions src/components/shapes/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,17 @@ module.exports = templatedArray('shape', {
'See `type` and `xsizemode` for more info.'
].join(' ')
},

xshift: {
valType: 'number',
dflt: 0,
min: -0.5,
max: 0.5,
editType: 'calc',
description: [
'Only relevant if xref is a (multi-)category axes. Shifts x0 and x1 by a fraction of',
'the reference unit.'
].join(' ')
},
yref: extendFlat({}, annAttrs.yref, {
description: [
'Sets the shape\'s y coordinate axis.',
Expand Down Expand Up @@ -220,18 +230,7 @@ module.exports = templatedArray('shape', {
'See `type` and `ysizemode` for more info.'
].join(' ')
},
x_shift: {
valType: 'number',
dflt: 0,
min: -0.5,
max: 0.5,
editType: 'calc',
description: [
'Only relevant if xref is a (multi-)category axes. Shifts x0 and x1 by a fraction of',
'the reference unit.'
].join(' ')
},
y_shift: {
yshift: {
valType: 'number',
dflt: 0,
min: -0.5,
Expand Down
4 changes: 2 additions & 2 deletions src/components/shapes/calc_autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function calcAutorange(gd) {
var vx1 = shape.xsizemode === 'pixel' ? shape.xanchor : shape.x1;
ax = Axes.getFromId(gd, shape.xref);

bounds = shapeBounds(ax, vx0, vx1, shape.path, shape.x_shift, constants.paramIsX);
bounds = shapeBounds(ax, vx0, vx1, shape.path, shape.xshift, constants.paramIsX);
if(bounds) {
shape._extremes[ax._id] = Axes.findExtremes(ax, bounds, calcXPaddingOptions(shape));
}
Expand All @@ -38,7 +38,7 @@ module.exports = function calcAutorange(gd) {
var vy1 = shape.ysizemode === 'pixel' ? shape.yanchor : shape.y1;
ax = Axes.getFromId(gd, shape.yref);

bounds = shapeBounds(ax, vy0, vy1, shape.path, shape.y_shift, constants.paramIsY);
bounds = shapeBounds(ax, vy0, vy1, shape.path, shape.yshift, constants.paramIsY);
if(bounds) {
shape._extremes[ax._id] = Axes.findExtremes(ax, bounds, calcYPaddingOptions(shape));
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/shapes/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
var pos2r;
var r2pos;

coerce('x_shift');
coerce('y_shift');
coerce('xshift');
coerce('yshift');

// xref, yref
var axRef = Axes.coerceRef(shapeIn, shapeOut, gdMock, axLetter, undefined,
Expand Down
4 changes: 2 additions & 2 deletions src/components/shapes/display_labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ module.exports = function drawLabel(gd, index, options, shapeGroup) {
// Setup conversion functions
var xa = Axes.getFromId(gd, options.xref);
var xRefType = Axes.getRefType(options.xref);
var xShift = options.x_shift;
var xShift = options.xshift;
var ya = Axes.getFromId(gd, options.yref);
var yRefType = Axes.getRefType(options.yref);
var yShift = options.y_shift;
var yShift = options.yshift;
var x2p = helpers.getDataToPixel(gd, xa, xShift, false, xRefType);
var y2p = helpers.getDataToPixel(gd, ya, yShift, true, yRefType);
shapex0 = x2p(options.x0);
Expand Down
4 changes: 2 additions & 2 deletions src/components/shapes/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer, editHe
// setup conversion functions
var xa = Axes.getFromId(gd, shapeOptions.xref);
var xRefType = Axes.getRefType(shapeOptions.xref);
var xShift = shapeOptions.x_shift;
var xShift = shapeOptions.xshift;
var ya = Axes.getFromId(gd, shapeOptions.yref);
var yRefType = Axes.getRefType(shapeOptions.yref);
var yShift = shapeOptions.y_shift;
var yShift = shapeOptions.yshift;
var x2p = helpers.getDataToPixel(gd, xa, xShift, false, xRefType);
var y2p = helpers.getDataToPixel(gd, ya, yShift, true, yRefType);
var p2x = helpers.getPixelToData(gd, xa, false, xRefType);
Expand Down
16 changes: 8 additions & 8 deletions src/components/shapes/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,20 @@ exports.getPathString = function(gd, options) {
}
if(options.xsizemode === 'pixel') {
var xAnchorPos = x2p(options.xanchor);
x0 = xAnchorPos + options.x0 + shiftUnitX * options.x_shift;
x1 = xAnchorPos + options.x1 + shiftUnitX * options.x_shift;
x0 = xAnchorPos + options.x0 + shiftUnitX * options.xshift;
x1 = xAnchorPos + options.x1 + shiftUnitX * options.xshift;
} else {
x0 = x2p(options.x0) + shiftUnitX * options.x_shift;
x1 = x2p(options.x1) + shiftUnitX * options.x_shift;
x0 = x2p(options.x0) + shiftUnitX * options.xshift;
x1 = x2p(options.x1) + shiftUnitX * options.xshift;
}

if(options.ysizemode === 'pixel') {
var yAnchorPos = y2p(options.yanchor);
y0 = yAnchorPos - options.y0 - shiftUnitY * options.y_shift;
y1 = yAnchorPos - options.y1 - shiftUnitY * options.y_shift;
y0 = yAnchorPos - options.y0 - shiftUnitY * options.yshift;
y1 = yAnchorPos - options.y1 - shiftUnitY * options.yshift;
} else {
y0 = y2p(options.y0) - shiftUnitY * options.y_shift;
y1 = y2p(options.y1) - shiftUnitY * options.y_shift;
y0 = y2p(options.y0) - shiftUnitY * options.yshift;
y1 = y2p(options.y1) - shiftUnitY * options.yshift;
}

if(type === 'line') return 'M' + x0 + ',' + y0 + 'L' + x1 + ',' + y1;
Expand Down
4 changes: 2 additions & 2 deletions test/image/mocks/zzz_shape_shift_horizontal.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"y1": ["A", "D"],
"x0": 0,
"x1": 0.25,
"y_shift": 0.5,
"yshift": 0.5,
"xref": "paper"
},
{
Expand Down Expand Up @@ -79,7 +79,7 @@
"y1": ["B", "D"],
"x0": 0,
"x1": 0.25,
"y_shift": -0.5,
"yshift": -0.5,
"xref": "paper"
}
]
Expand Down
6 changes: 3 additions & 3 deletions test/image/mocks/zzz_shape_shift_vertical.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"x1": "A",
"y0": 0,
"y1": 0.5,
"x_shift": 0.5,
"xshift": 0.5,
"yref": "paper"
},
{
Expand All @@ -48,7 +48,7 @@
"x1": 3,
"y0": 0,
"y1": 0.5,
"x_shift": -0.25,
"xshift": -0.25,
"yref": "paper"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this also working for a path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this should only do something when using x0, x1, y0, y1

],
Expand All @@ -58,7 +58,7 @@
"x1": 4,
"y0": 1,
"y1": 3,
"x_shift": -0.5
"xshift": -0.5
}
]
}
Expand Down
16 changes: 8 additions & 8 deletions test/jasmine/tests/shapes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,8 +1487,8 @@ describe('Test shapes', function() {
function testShapeDrag(dx, dy, layoutShape, node) {
var xa = Axes.getFromId(gd, layoutShape.xref);
var ya = Axes.getFromId(gd, layoutShape.yref);
var x2p = helpers.getDataToPixel(gd, xa, layoutShape.x_shift);
var y2p = helpers.getDataToPixel(gd, ya, layoutShape.y_shift, true);
var x2p = helpers.getDataToPixel(gd, xa, layoutShape.xshift);
var y2p = helpers.getDataToPixel(gd, ya, layoutShape.yshift, true);

var initialCoordinates = getShapeCoordinates(layoutShape, x2p, y2p);

Expand All @@ -1514,8 +1514,8 @@ describe('Test shapes', function() {
function testPathDrag(dx, dy, layoutShape, node) {
var xa = Axes.getFromId(gd, layoutShape.xref);
var ya = Axes.getFromId(gd, layoutShape.yref);
var x2p = helpers.getDataToPixel(gd, xa, layoutShape.x_shift);
var y2p = helpers.getDataToPixel(gd, ya, layoutShape.y_shift, true);
var x2p = helpers.getDataToPixel(gd, xa, layoutShape.xshift);
var y2p = helpers.getDataToPixel(gd, ya, layoutShape.yshift, true);

var initialPath = layoutShape.path;
var initialCoordinates = getPathCoordinates(initialPath, x2p, y2p);
Expand Down Expand Up @@ -1546,8 +1546,8 @@ describe('Test shapes', function() {
function testShapeResize(direction, dx, dy, layoutShape, node) {
var xa = Axes.getFromId(gd, layoutShape.xref);
var ya = Axes.getFromId(gd, layoutShape.yref);
var x2p = helpers.getDataToPixel(gd, xa, layoutShape.x_shift);
var y2p = helpers.getDataToPixel(gd, ya, layoutShape.y_shift, true);
var x2p = helpers.getDataToPixel(gd, xa, layoutShape.xshift);
var y2p = helpers.getDataToPixel(gd, ya, layoutShape.yshift, true);

var initialCoordinates = getShapeCoordinates(layoutShape, x2p, y2p);

Expand Down Expand Up @@ -1590,8 +1590,8 @@ describe('Test shapes', function() {

var xa = Axes.getFromId(gd, layoutShape.xref);
var ya = Axes.getFromId(gd, layoutShape.yref);
var x2p = helpers.getDataToPixel(gd, xa, layoutShape.x_shift);
var y2p = helpers.getDataToPixel(gd, ya, layoutShape.y_shift, true);
var x2p = helpers.getDataToPixel(gd, xa, layoutShape.xshift);
var y2p = helpers.getDataToPixel(gd, ya, layoutShape.yshift, true);

promise = promise.then(function() {
var dragHandle = pointToMove === 'start' ?
Expand Down
52 changes: 26 additions & 26 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9550,14 +9550,6 @@
"path"
]
},
"x_shift": {
"description": "Only relevant if xref is a (multi-)category axes. Shifts x0 and x1 by a fraction of the reference unit.",
"dflt": 0,
"editType": "arraydraw",
"max": 0.5,
"min": -0.5,
"valType": "number"
},
"x0": {
"description": "Sets the selection's starting x position.",
"editType": "arraydraw",
Expand All @@ -9577,8 +9569,8 @@
"/^x([2-9]|[1-9][0-9]+)?( domain)?$/"
]
},
"y_shift": {
"description": "Only relevant if yref is a (multi-)category axes. Shifts y0 and y1 by a fraction of the reference unit.",
"xshift": {
"description": "Only relevant if xref is a (multi-)category axes. Shifts x0 and x1 by a fraction of the reference unit.",
"dflt": 0,
"editType": "arraydraw",
"max": 0.5,
Expand All @@ -9603,6 +9595,14 @@
"paper",
"/^y([2-9]|[1-9][0-9]+)?( domain)?$/"
]
},
"yshift": {
"description": "Only relevant if yref is a (multi-)category axes. Shifts y0 and y1 by a fraction of the reference unit.",
"dflt": 0,
"editType": "arraydraw",
"max": 0.5,
"min": -0.5,
"valType": "number"
}
}
},
Expand Down Expand Up @@ -10016,14 +10016,6 @@
"legendonly"
]
},
"x_shift": {
"description": "Only relevant if xref is a (multi-)category axes. Shifts x0 and x1 by a fraction of the reference unit.",
"dflt": 0,
"editType": "calc",
"max": 0.5,
"min": -0.5,
"valType": "number"
},
"x0": {
"description": "Sets the shape's starting x position. See `type` and `xsizemode` for more info.",
"editType": "calc+arraydraw",
Expand All @@ -10048,6 +10040,14 @@
"/^x([2-9]|[1-9][0-9]+)?( domain)?$/"
]
},
"xshift": {
"description": "Only relevant if xref is a (multi-)category axes. Shifts x0 and x1 by a fraction of the reference unit.",
"dflt": 0,
"editType": "calc",
"max": 0.5,
"min": -0.5,
"valType": "number"
},
"xsizemode": {
"description": "Sets the shapes's sizing mode along the x axis. If set to *scaled*, `x0`, `x1` and x coordinates within `path` refer to data values on the x axis or a fraction of the plot area's width (`xref` set to *paper*). If set to *pixel*, `xanchor` specifies the x position in terms of data or plot fraction but `x0`, `x1` and x coordinates within `path` are pixels relative to `xanchor`. This way, the shape can have a fixed width while maintaining a position relative to data or plot fraction.",
"dflt": "scaled",
Expand All @@ -10058,14 +10058,6 @@
"pixel"
]
},
"y_shift": {
"description": "Only relevant if yref is a (multi-)category axes. Shifts y0 and y1 by a fraction of the reference unit.",
"dflt": 0,
"editType": "calc",
"max": 0.5,
"min": -0.5,
"valType": "number"
},
"y0": {
"description": "Sets the shape's starting y position. See `type` and `ysizemode` for more info.",
"editType": "calc+arraydraw",
Expand All @@ -10090,6 +10082,14 @@
"/^y([2-9]|[1-9][0-9]+)?( domain)?$/"
]
},
"yshift": {
"description": "Only relevant if yref is a (multi-)category axes. Shifts y0 and y1 by a fraction of the reference unit.",
"dflt": 0,
"editType": "calc",
"max": 0.5,
"min": -0.5,
"valType": "number"
},
"ysizemode": {
"description": "Sets the shapes's sizing mode along the y axis. If set to *scaled*, `y0`, `y1` and y coordinates within `path` refer to data values on the y axis or a fraction of the plot area's height (`yref` set to *paper*). If set to *pixel*, `yanchor` specifies the y position in terms of data or plot fraction but `y0`, `y1` and y coordinates within `path` are pixels relative to `yanchor`. This way, the shape can have a fixed height while maintaining a position relative to data or plot fraction.",
"dflt": "scaled",
Expand Down
0