Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
aa0cd7a44d18587abea61a617017c2f7f27fdcaa0c99215223ac32f36680745ada2289e11f6f61bfb22d04466db91db7c84bbb669ab935ac82de6b1f9c44bfb00d4d88cf665a78a7e5e18e7c845509ee66f8e5a67de45c39ac970aFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Add property x0shift, x1shift, y0shift, y1shift for shapes referencing (multi-)category axes, with thanks to @my-tien for the contribution! [[#7005](https://github.com/plotly/plotly.js/pull/7005)] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -23,22 +23,18 @@ module.exports = function calcAutorange(gd) { | ||
| // paper and axis domain referenced shapes don't affect autorange | ||
| if(shape.xref !== 'paper' && xRefType !== 'domain') { | ||
| var vx0 = shape.xsizemode === 'pixel' ? shape.xanchor : shape.x0; | ||
| var vx1 = shape.xsizemode === 'pixel' ? shape.xanchor : shape.x1; | ||
| ax = Axes.getFromId(gd, shape.xref); | ||
| bounds = shapeBounds(ax, vx0, vx1, shape.path, constants.paramIsX); | ||
| bounds = shapeBounds(ax, shape, constants.paramIsX); | ||
| if(bounds) { | ||
| shape._extremes[ax._id] = Axes.findExtremes(ax, bounds, calcXPaddingOptions(shape)); | ||
| } | ||
| } | ||
| if(shape.yref !== 'paper' && yRefType !== 'domain') { | ||
| var vy0 = shape.ysizemode === 'pixel' ? shape.yanchor : shape.y0; | ||
| var vy1 = shape.ysizemode === 'pixel' ? shape.yanchor : shape.y1; | ||
| ax = Axes.getFromId(gd, shape.yref); | ||
| bounds = shapeBounds(ax, vy0, vy1, shape.path, constants.paramIsY); | ||
| bounds = shapeBounds(ax, shape, constants.paramIsY); | ||
| if(bounds) { | ||
| shape._extremes[ax._id] = Axes.findExtremes(ax, bounds, calcYPaddingOptions(shape)); | ||
| } | ||
| @@ -77,15 +73,35 @@ function calcPaddingOptions(lineWidth, sizeMode, v0, v1, path, isYAxis) { | ||
| } | ||
| } | ||
| function shapeBounds(ax, v0, v1, path, paramsToUse) { | ||
| var convertVal = (ax.type === 'category' || ax.type === 'multicategory') ? ax.r2c : ax.d2c; | ||
| function shapeBounds(ax, shape, paramsToUse) { | ||
| var dim = ax._id.charAt(0) === 'x' ? 'x' : 'y'; | ||
| var isCategory = ax.type === 'category' || ax.type === 'multicategory'; | ||
| var v0; | ||
| var v1; | ||
| var shiftStart = 0; | ||
| var shiftEnd = 0; | ||
| var convertVal = isCategory ? ax.r2c : ax.d2c; | ||
archmoj marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| var isSizeModeScale = shape[dim + 'sizemode'] === 'scaled'; | ||
| if(isSizeModeScale) { | ||
| v0 = shape[dim + '0']; | ||
| v1 = shape[dim + '1']; | ||
| if(isCategory) { | ||
| shiftStart = shape[dim + '0shift']; | ||
| shiftEnd = shape[dim + '1shift']; | ||
| } | ||
| } else { | ||
| v0 = shape[dim + 'anchor']; | ||
| v1 = shape[dim + 'anchor']; | ||
| } | ||
| if(v0 !== undefined) return [convertVal(v0), convertVal(v1)]; | ||
| if(!path) return; | ||
| if(v0 !== undefined) return [convertVal(v0) + shiftStart, convertVal(v1) + shiftEnd]; | ||
| if(!shape.path) return; | ||
| var min = Infinity; | ||
| var max = -Infinity; | ||
| var segments = path.match(constants.segmentRE); | ||
| var segments = shape.path.match(constants.segmentRE); | ||
| var i; | ||
| var segment; | ||
| var drawnParam; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -53,7 +53,7 @@ exports.extractPathCoords = function(path, paramsToUse, isRaw) { | ||
| return extractedCoordinates; | ||
| }; | ||
| exports.getDataToPixel = function(gd, axis, isVertical, refType) { | ||
| exports.getDataToPixel = function(gd, axis, shift, isVertical, refType) { | ||
archmoj marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| var gs = gd._fullLayout._size; | ||
| var dataToPixel; | ||
| @@ -66,7 +66,8 @@ exports.getDataToPixel = function(gd, axis, isVertical, refType) { | ||
| var d2r = exports.shapePositionToRange(axis); | ||
| dataToPixel = function(v) { | ||
| return axis._offset + axis.r2p(d2r(v, true)); | ||
| var shiftPixels = getPixelShift(axis, shift); | ||
| return axis._offset + axis.r2p(d2r(v, true)) + shiftPixels; | ||
| }; | ||
| if(axis.type === 'date') dataToPixel = exports.decodeDate(dataToPixel); | ||
| @@ -179,6 +180,10 @@ exports.getPathString = function(gd, options) { | ||
| var ya = Axes.getFromId(gd, options.yref); | ||
| var gs = gd._fullLayout._size; | ||
| var x2r, x2p, y2r, y2p; | ||
| var xShiftStart = getPixelShift(xa, options.x0shift); | ||
| var xShiftEnd = getPixelShift(xa, options.x1shift); | ||
| var yShiftStart = getPixelShift(ya, options.y0shift); | ||
| var yShiftEnd = getPixelShift(ya, options.y1shift); | ||
| var x0, x1, y0, y1; | ||
| if(xa) { | ||
| @@ -208,23 +213,22 @@ exports.getPathString = function(gd, options) { | ||
| if(ya && ya.type === 'date') y2p = exports.decodeDate(y2p); | ||
| return convertPath(options, x2p, y2p); | ||
| } | ||
| if(options.xsizemode === 'pixel') { | ||
| var xAnchorPos = x2p(options.xanchor); | ||
| x0 = xAnchorPos + options.x0; | ||
| x1 = xAnchorPos + options.x1; | ||
| x0 = xAnchorPos + options.x0 + xShiftStart; | ||
archmoj marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| x1 = xAnchorPos + options.x1 + xShiftEnd; | ||
| } else { | ||
| x0 = x2p(options.x0); | ||
| x1 = x2p(options.x1); | ||
| x0 = x2p(options.x0) + xShiftStart; | ||
| x1 = x2p(options.x1) + xShiftEnd; | ||
| } | ||
| if(options.ysizemode === 'pixel') { | ||
| var yAnchorPos = y2p(options.yanchor); | ||
| y0 = yAnchorPos - options.y0; | ||
| y1 = yAnchorPos - options.y1; | ||
| y0 = yAnchorPos - options.y0 + yShiftStart; | ||
| y1 = yAnchorPos - options.y1 + yShiftEnd; | ||
| } else { | ||
| y0 = y2p(options.y0); | ||
| y1 = y2p(options.y1); | ||
| y0 = y2p(options.y0) + yShiftStart; | ||
| y1 = y2p(options.y1) + yShiftEnd; | ||
| } | ||
| if(type === 'line') return 'M' + x0 + ',' + y0 + 'L' + x1 + ',' + y1; | ||
| @@ -279,3 +283,12 @@ function convertPath(options, x2p, y2p) { | ||
| return segmentType + paramString; | ||
| }); | ||
| } | ||
| function getPixelShift(axis, shift) { | ||
| shift = shift || 0; | ||
| var shiftPixels = 0; | ||
| if(shift && axis && (axis.type === 'category' || axis.type === 'multicategory')) { | ||
| shiftPixels = (axis.r2p(1) - axis.r2p(0)) * shift; | ||
| } | ||
| return shiftPixels; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.