Skip to content

Commit 781fbe2

Browse files
committed
remove lxFunc and lyFunc
1 parent a2befea commit 781fbe2

File tree

1 file changed

+9
-45
lines changed

1 file changed

+9
-45
lines changed

src/traces/bar/plot.js

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,6 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
276276
var r = (isBar || isHistogram) ? calcCornerRadius(t.cornerradiusvalue, t.cornerradiusform) : 0;
277277
// Construct path string for bar
278278
var path, h;
279-
// Functions which return x-dimension and y-dimension of bar at a given x/y,
280-
// to be used for positioning text
281-
var lxFunc = null;
282-
var lyFunc = null;
283279
// Default rectangular path (used if no rounding)
284280
var rectanglePath = 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z';
285281
var overhead = 0;
@@ -308,11 +304,6 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
308304
'V' + (y0 + r * ydir) +
309305
'A ' + r + ',' + r + ' 0 0 ' + cornersweep + ' ' + (x1 - r * xdir) + ',' + y0 +
310306
'Z';
311-
lyFunc = function(x) {
312-
if(x > r) return Math.abs(y1 - y0);
313-
var _dy2 = (x > 0) ? Math.sqrt(x * (2 * r - x)) : 0;
314-
return Math.abs(y1 - y0) - 2 * (r - _dy2);
315-
};
316307
} else {
317308
// Base on axis: Round 3rd and 4th corners
318309

@@ -329,12 +320,6 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
329320
'V' + (y0 + r * ydir + dy2) +
330321
'A ' + r + ',' + r + ' 0 0 ' + cornersweep + ' ' + xminfunc(x1 - (r - overhead) * xdir, x0) + ',' + (y0 + dy1 * ydir) +
331322
'Z';
332-
lyFunc = function(x) {
333-
var _overhead = overhead + x;
334-
if(_overhead > r) return Math.abs(y1 - y0);
335-
var _dy2 = (_overhead > 0) ? Math.sqrt(_overhead * (2 * r - _overhead)) : 0;
336-
return Math.abs(y1 - y0) - 2 * (r - _dy2);
337-
};
338323
}
339324
} else {
340325
// Vertical bars
@@ -349,11 +334,6 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
349334
'V' + (y0 + r * ydir) +
350335
'A ' + r + ',' + r + ' 0 0 ' + cornersweep + ' ' + (x1 - r * xdir) + ',' + y0 +
351336
'Z';
352-
lxFunc = function(y) {
353-
if(y > r) return Math.abs(x1 - x0);
354-
var _dx2 = (y > 0) ? Math.sqrt(y * (2 * r - y)) : 0;
355-
return Math.abs(x1 - x0) - 2 * (r - _dx2);
356-
};
357337
} else {
358338
// Base on axis: Round 2nd and 3rd corners
359339

@@ -369,12 +349,6 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
369349
'H' + (x1 - r * xdir + dx2) +
370350
'A ' + r + ',' + r + ' 0 0 ' + cornersweep + ' ' + (x1 - dx1 * xdir) + ',' + yminfunc(y1 - (r - overhead) * ydir, y0) +
371351
'V' + y0 + 'Z';
372-
lxFunc = function(y) {
373-
var _overhead = overhead + y;
374-
if(_overhead > r) return Math.abs(x1 - x0);
375-
var _dx2 = (_overhead > 0) ? Math.sqrt(_overhead * (2 * r - _overhead)) : 0;
376-
return Math.abs(x1 - x0) - 2 * (r - _dx2);
377-
};
378352
}
379353
}
380354
} else {
@@ -397,7 +371,7 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
397371
Drawing.singlePointStyle(di, sel, trace, styleFns, gd);
398372
}
399373

400-
appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, lxFunc, lyFunc, r, overhead, opts, makeOnCompleteCallback);
374+
appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, r, overhead, opts, makeOnCompleteCallback);
401375

402376
if(plotinfo.layerClipId) {
403377
Drawing.hideOutsideRangePoint(di, bar.select('text'), xa, ya, trace.xcalendar, trace.ycalendar);
@@ -414,7 +388,7 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
414388
Registry.getComponentMethod('errorbars', 'plot')(gd, bartraces, plotinfo, opts);
415389
}
416390

417-
function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, lxFunc, lyFunc, r, overhead, opts, makeOnCompleteCallback) {
391+
function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, r, overhead, opts, makeOnCompleteCallback) {
418392
var xa = plotinfo.xaxis;
419393
var ya = plotinfo.yaxis;
420394

@@ -453,6 +427,7 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, lxFunc, lyFunc,
453427
var calcBar = cd[i];
454428
var isOutmostBar = !inStackOrRelativeMode || calcBar._outmost;
455429
var hasB = calcBar.hasB;
430+
var barIsRounded = r && (r - overhead) > TEXTPAD;
456431

457432
if(!text ||
458433
textPosition === 'none' ||
@@ -490,17 +465,10 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, lxFunc, lyFunc,
490465
}
491466
}
492467

493-
// Get width and height of bar at text position
494-
var lx, ly, refPos;
495-
if(isHorizontal) {
496-
refPos = (insidetextanchor === 'middle') ? Math.abs(x1 - x0) / 2 : TEXTPAD;
497-
lx = Math.abs(x1 - x0);
498-
ly = lyFunc ? lyFunc(refPos) : Math.abs(y1 - y0);
499-
} else {
500-
refPos = (insidetextanchor === 'middle') ? Math.abs(y1 - y0) / 2 : TEXTPAD;
501-
lx = lxFunc ? lxFunc(refPos) : Math.abs(x1 - x0);
502-
ly = Math.abs(y1 - y0);
503-
}
468+
// Compute width and height of bar
469+
var lx = Math.abs(x1 - x0);
470+
var ly = Math.abs(y1 - y0);
471+
504472
// padding excluded
505473
var barWidth = lx - 2 * TEXTPAD;
506474
var barHeight = ly - 2 * TEXTPAD;
@@ -535,12 +503,10 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, lxFunc, lyFunc,
535503
(barWidth >= textWidth * (barHeight / textHeight)) :
536504
(barHeight >= textHeight * (barWidth / textWidth));
537505

538-
// TODO: Rounding needs to be considered when deciding
539-
// whether text fits inside bar
540-
if(textHasSize && (
506+
if(textHasSize && (barIsRounded || (
541507
fitsInside ||
542508
fitsInsideIfRotated ||
543-
fitsInsideIfShrunk)
509+
fitsInsideIfShrunk))
544510
) {
545511
textPosition = 'inside';
546512
} else {
@@ -595,8 +561,6 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, lxFunc, lyFunc,
595561
constrained: constrained,
596562
angle: angle,
597563
anchor: insidetextanchor,
598-
lxFunc: lxFunc,
599-
lyFunc: lyFunc,
600564
hasB: hasB,
601565
r: r,
602566
overhead: overhead,

0 commit comments

Comments
 (0)