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

Function plotTextLines

src/traces/pie/plot.js:328–378  ·  view source on GitHub ↗
(slices, trace)

Source from the content-addressed store, hash-verified

326
327// TODO add support for transition
328function plotTextLines(slices, trace) {
329 slices.each(function (pt) {
330 var sliceTop = d3.select(this);
331
332 if (!pt.labelExtraX && !pt.labelExtraY) {
333 sliceTop.select('path.textline').remove();
334 return;
335 }
336
337 // first move the text to its new location
338 var sliceText = sliceTop.select('g.slicetext text');
339
340 pt.transform.targetX += pt.labelExtraX;
341 pt.transform.targetY += pt.labelExtraY;
342
343 Lib.setTransormAndDisplay(sliceText, pt.transform);
344
345 // then add a line to the new location
346 var lineStartX = pt.cxFinal + pt.pxmid[0];
347 var lineStartY = pt.cyFinal + pt.pxmid[1];
348 var textLinePath = 'M' + lineStartX + ',' + lineStartY;
349 var finalX = ((pt.yLabelMax - pt.yLabelMin) * (pt.pxmid[0] < 0 ? -1 : 1)) / 4;
350
351 if (pt.labelExtraX) {
352 var yFromX = (pt.labelExtraX * pt.pxmid[1]) / pt.pxmid[0];
353 var yNet = pt.yLabelMid + pt.labelExtraY - (pt.cyFinal + pt.pxmid[1]);
354
355 if (Math.abs(yFromX) > Math.abs(yNet)) {
356 textLinePath +=
357 'l' +
358 (yNet * pt.pxmid[0]) / pt.pxmid[1] +
359 ',' +
360 yNet +
361 'H' +
362 (lineStartX + pt.labelExtraX + finalX);
363 } else {
364 textLinePath += 'l' + pt.labelExtraX + ',' + yFromX + 'v' + (yNet - yFromX) + 'h' + finalX;
365 }
366 } else {
367 textLinePath += 'V' + (pt.yLabelMid + pt.labelExtraY) + 'h' + finalX;
368 }
369
370 Lib.ensureSingle(sliceTop, 'path', 'textline')
371 .call(Color.stroke, trace.outsidetextfont.color)
372 .attr({
373 'stroke-width': Math.min(2, trace.outsidetextfont.size / 8),
374 d: textLinePath,
375 fill: 'none'
376 });
377 });
378}
379
380function attachFxHandlers(sliceTop, gd, cd) {
381 var cd0 = cd[0];

Callers 1

plotFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…