Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 404611d

Browse files
committed
revise bar text transform functions to return reusable raw objects instead of final text - e.g. as required fortreemap transitions
1 parent 76f7652 commit 404611d

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

src/traces/bar/plot.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,22 +340,22 @@ function appendBarText(gd, plotinfo, bar, calcTrace, i, x0, x1, y0, y1, opts) {
340340
trace.constraintext === 'both' ||
341341
trace.constraintext === 'outside';
342342

343-
transform = getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, {
343+
transform = getTransform(toMoveOutsideBar(x0, x1, y0, y1, textBB, {
344344
isHorizontal: isHorizontal,
345345
constrained: constrained,
346346
angle: trace.textangle
347-
});
347+
}));
348348
} else {
349349
constrained =
350350
trace.constraintext === 'both' ||
351351
trace.constraintext === 'inside';
352352

353-
transform = getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, {
353+
transform = getTransform(toMoveInsideBar(x0, x1, y0, y1, textBB, {
354354
isHorizontal: isHorizontal,
355355
constrained: constrained,
356356
angle: trace.textangle,
357357
anchor: trace.insidetextanchor
358-
});
358+
}));
359359
}
360360

361361
textSelection.attr('transform', transform);
@@ -365,7 +365,7 @@ function getRotationFromAngle(angle) {
365365
return (angle === 'auto') ? 0 : angle;
366366
}
367367

368-
function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, opts) {
368+
function toMoveInsideBar(x0, x1, y0, y1, textBB, opts) {
369369
var isHorizontal = !!opts.isHorizontal;
370370
var constrained = !!opts.constrained;
371371
var angle = opts.angle || 0;
@@ -440,10 +440,17 @@ function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, opts) {
440440
// lastly apply auto rotation
441441
if(isAutoRotated) rotation += 90;
442442

443-
return getTransform(textX, textY, targetX, targetY, scale, rotation);
443+
return {
444+
textX: textX,
445+
textY: textY,
446+
targetX: targetX,
447+
targetY: targetY,
448+
scale: scale,
449+
rotation: rotation
450+
};
444451
}
445452

446-
function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, opts) {
453+
function toMoveOutsideBar(x0, x1, y0, y1, textBB, opts) {
447454
var isHorizontal = !!opts.isHorizontal;
448455
var constrained = !!opts.constrained;
449456
var angle = opts.angle || 0;
@@ -491,10 +498,24 @@ function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, opts) {
491498
var textX = (textBB.left + textBB.right) / 2;
492499
var textY = (textBB.top + textBB.bottom) / 2;
493500

494-
return getTransform(textX, textY, targetX, targetY, scale, rotation);
501+
return {
502+
textX: textX,
503+
textY: textY,
504+
targetX: targetX,
505+
targetY: targetY,
506+
scale: scale,
507+
rotation: rotation
508+
};
495509
}
496510

497-
function getTransform(textX, textY, targetX, targetY, scale, rotation) {
511+
function getTransform(opts) {
512+
var textX = opts.textX;
513+
var textY = opts.textY;
514+
var targetX = opts.targetX;
515+
var targetY = opts.targetY;
516+
var scale = opts.scale;
517+
var rotation = opts.rotation;
518+
498519
var transformScale;
499520
var transformRotate;
500521
var transformTranslate;
@@ -610,6 +631,7 @@ function calcTextinfo(calcTrace, index, xa, ya) {
610631

611632
module.exports = {
612633
plot: plot,
613-
getTransformToMoveInsideBar: getTransformToMoveInsideBar,
614-
getTransformToMoveOutsideBar: getTransformToMoveOutsideBar
634+
getTransform: getTransform,
635+
toMoveInsideBar: toMoveInsideBar,
636+
toMoveOutsideBar: toMoveOutsideBar
615637
};

src/traces/funnelarea/plot.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ var Lib = require('../../lib');
1515
var svgTextUtils = require('../../lib/svg_text_utils');
1616

1717
var barPlot = require('../bar/plot');
18-
var getTransformToMoveInsideBar = barPlot.getTransformToMoveInsideBar;
18+
var getTransform = barPlot.getTransform;
19+
var toMoveInsideBar = barPlot.toMoveInsideBar;
1920

2021
var pieHelpers = require('../pie/helpers');
2122
var piePlot = require('../pie/plot');
@@ -113,12 +114,12 @@ module.exports = function plot(gd, cdModule) {
113114
x0 = Math.max(pt.TL[0], pt.BL[0]);
114115
x1 = Math.min(pt.TR[0], pt.BR[0]);
115116

116-
transform = getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, {
117+
transform = getTransform(toMoveInsideBar(x0, x1, y0, y1, textBB, {
117118
isHorizontal: true,
118119
constrained: true,
119120
angle: 0,
120121
anchor: 'middle'
121-
});
122+
}));
122123

123124
sliceText.attr('transform',
124125
'translate(' + cx + ',' + cy + ')' + transform

0 commit comments

Comments
 (0)