MCPcopy Index your code
hub / github.com/plotly/plotly.js / setClipPath

Function setClipPath

src/components/shapes/draw.js:229–256  ·  view source on GitHub ↗
(shapePath, gd, shapeOptions)

Source from the content-addressed store, hash-verified

227}
228
229function setClipPath(shapePath, gd, shapeOptions) {
230 // note that for layer="below" the clipAxes can be different from the
231 // subplot we're drawing this in. This could cause problems if the shape
232 // spans two subplots. See https://github.com/plotly/plotly.js/issues/1452
233 //
234 // if axis is 'paper' or an axis with " domain" appended, then there is no
235 // clip axis
236
237 const xref = shapeOptions.xref;
238 const yref = shapeOptions.yref;
239
240 // For multi-axis shapes, create a custom clip path from axis bounds
241 if (Array.isArray(xref) || Array.isArray(yref)) {
242 const clipId = 'clip' + gd._fullLayout._uid + 'shape' + shapeOptions._index;
243 const rect = getMultiAxisClipRect(gd, xref, yref);
244
245 Lib.ensureSingleById(gd._fullLayout._clips, 'clipPath', clipId, function (s) {
246 s.append('rect');
247 })
248 .select('rect')
249 .attr(rect);
250
251 Drawing.setClipUrl(shapePath, clipId, gd);
252 } else {
253 const clipAxes = (xref + yref).replace(/paper/g, '').replace(/[xyz][0-9]* *domain/g, '');
254 Drawing.setClipUrl(shapePath, clipAxes ? 'clip' + gd._fullLayout._uid + clipAxes : null, gd);
255 }
256}
257
258function getMultiAxisClipRect(gd, xref, yref) {
259 const gs = gd._fullLayout._size;

Callers 2

drawShapeFunction · 0.70
endDragFunction · 0.70

Calls 1

getMultiAxisClipRectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…