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

Function drawGraphicalElements

src/components/annotations/draw.js:261–735  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

259 }
260
261 function drawGraphicalElements() {
262 // if the text has *only* a link, make the whole box into a link
263 var anchor3 = annText.selectAll('a');
264 if(anchor3.size() === 1 && anchor3.text() === annText.text()) {
265 var wholeLink = annTextGroupInner.insert('a', ':first-child').attr({
266 'xlink:xlink:href': anchor3.attr('xlink:href'),
267 'xlink:xlink:show': anchor3.attr('xlink:show')
268 })
269 .style({cursor: 'pointer'});
270
271 wholeLink.node().appendChild(annTextBG.node());
272 }
273
274 var mathjaxGroup = annTextGroupInner.select('.annotation-text-math-group');
275 var hasMathjax = !mathjaxGroup.empty();
276 var anntextBB = Drawing.bBox(
277 (hasMathjax ? mathjaxGroup : annText).node());
278 var textWidth = anntextBB.width;
279 var textHeight = anntextBB.height;
280 var annWidth = options.width || textWidth;
281 var annHeight = options.height || textHeight;
282 var outerWidth = Math.round(annWidth + 2 * borderfull);
283 var outerHeight = Math.round(annHeight + 2 * borderfull);
284
285 function shiftFraction(v, anchor) {
286 if(anchor === 'auto') {
287 if(v < 1 / 3) anchor = 'left';
288 else if(v > 2 / 3) anchor = 'right';
289 else anchor = 'center';
290 }
291 return {
292 center: 0,
293 middle: 0,
294 left: 0.5,
295 bottom: -0.5,
296 right: -0.5,
297 top: 0.5
298 }[anchor];
299 }
300
301 var annotationIsOffscreen = false;
302 var letters = ['x', 'y'];
303
304 for(var i = 0; i < letters.length; i++) {
305 var axLetter = letters[i];
306 var axRef = options[axLetter + 'ref'] || axLetter;
307 var tailRef = options['a' + axLetter + 'ref'];
308 var ax = {x: xa, y: ya}[axLetter];
309 var dimAngle = (textangle + (axLetter === 'x' ? 0 : -90)) * Math.PI / 180;
310 // note that these two can be either positive or negative
311 var annSizeFromWidth = outerWidth * Math.cos(dimAngle);
312 var annSizeFromHeight = outerHeight * Math.sin(dimAngle);
313 // but this one is the positive total size
314 var annSize = Math.abs(annSizeFromWidth) + Math.abs(annSizeFromHeight);
315 var anchor = options[axLetter + 'anchor'];
316 var overallShift = options[axLetter + 'shift'] * (axLetter === 'x' ? 1 : -1);
317 var posPx = annPosPx[axLetter];
318 var basePx;

Callers

nothing calls this directly

Calls 6

shiftFractionFunction · 0.85
drawArrowFunction · 0.85
modifyItemFunction · 0.85
shiftPositionFunction · 0.85
getUpdateObjFunction · 0.85
makeEventDataFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…