Skip to content

Commit c5fa44b

Browse files
committed
pull 1.3 out into alignment constants
1 parent a68f861 commit c5fa44b

File tree

10 files changed

+26
-19
lines changed

10 files changed

+26
-19
lines changed

src/components/colorbar/draw.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var Drawing = require('../drawing');
2424
var Color = require('../color');
2525
var Titles = require('../titles');
2626
var svgTextUtils = require('../../lib/svg_text_utils');
27+
var LINE_SPACING = require('../../constants/alignment').LINE_SPACING;
2728

2829
var handleAxisDefaults = require('../../plots/cartesian/axis_defaults');
2930
var handleAxisPositionDefaults = require('../../plots/cartesian/position_defaults');
@@ -297,7 +298,7 @@ module.exports = function draw(gd, id) {
297298
lineSize = 15.6;
298299
if(titleText.node()) {
299300
lineSize =
300-
parseInt(titleText.style('font-size'), 10) * 1.3;
301+
parseInt(titleText.style('font-size'), 10) * LINE_SPACING;
301302
}
302303
if(mathJaxNode) {
303304
titleHeight = Drawing.bBox(mathJaxNode).height;

src/components/drawing/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ var Lib = require('../../lib');
2020
var svgTextUtils = require('../../lib/svg_text_utils');
2121

2222
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
23+
var alignment = require('../../constants/alignment');
24+
var LINE_SPACING = alignment.LINE_SPACING;
25+
2326
var subTypes = require('../../traces/scatter/subtypes');
2427
var makeBubbleSizeFn = require('../../traces/scatter/make_bubble_size_func');
2528

@@ -426,8 +429,7 @@ drawing.tryColorscale = function(marker, prefix) {
426429
};
427430

428431
// draw text at points
429-
var TEXTOFFSETSIGN = {start: 1, end: -1, middle: 0, bottom: 1, top: -1},
430-
LINEEXPAND = 1.3;
432+
var TEXTOFFSETSIGN = {start: 1, end: -1, middle: 0, bottom: 1, top: -1};
431433
drawing.textPointStyle = function(s, trace, gd) {
432434
s.each(function(d) {
433435
var p = d3.select(this),
@@ -462,7 +464,7 @@ drawing.textPointStyle = function(s, trace, gd) {
462464
.call(svgTextUtils.convertToTspans, gd);
463465

464466
var pgroup = d3.select(this.parentNode);
465-
var numLines = (svgTextUtils.lineCount(p) - 1) * LINEEXPAND + 1;
467+
var numLines = (svgTextUtils.lineCount(p) - 1) * LINE_SPACING + 1;
466468
var dx = TEXTOFFSETSIGN[h] * r;
467469
var dy = fontSize * 0.75 + TEXTOFFSETSIGN[v] * r +
468470
(TEXTOFFSETSIGN[v] - 1) * numLines * fontSize / 2;

src/components/legend/draw.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ var svgTextUtils = require('../../lib/svg_text_utils');
2222

2323
var constants = require('./constants');
2424
var interactConstants = require('../../constants/interactions');
25+
var LINE_SPACING = require('../../constants/alignment').LINE_SPACING;
26+
2527
var getLegendData = require('./get_legend_data');
2628
var style = require('./style');
2729
var helpers = require('./helpers');
@@ -561,7 +563,7 @@ function computeTextDimensions(g, gd) {
561563
var mathjaxGroup = g.select('g[class*=math-group]');
562564
var mathjaxNode = mathjaxGroup.node();
563565
var opts = gd._fullLayout.legend;
564-
var lineHeight = opts.font.size * 1.3;
566+
var lineHeight = opts.font.size * LINE_SPACING;
565567
var height, width;
566568

567569
if(mathjaxNode) {

src/components/rangeselector/draw.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var svgTextUtils = require('../../lib/svg_text_utils');
1919
var axisIds = require('../../plots/cartesian/axis_ids');
2020
var anchorUtils = require('../legend/anchor_utils');
2121

22+
var LINE_SPACING = require('../../constants/alignment').LINE_SPACING;
23+
2224
var constants = require('./constants');
2325
var getUpdateObject = require('./get_update_object');
2426

@@ -183,7 +185,7 @@ function reposition(gd, buttons, opts, axName) {
183185
var button = d3.select(this);
184186
var text = button.select('.selector-text');
185187

186-
var tHeight = opts.font.size * 1.3;
188+
var tHeight = opts.font.size * LINE_SPACING;
187189
var hEff = Math.max(tHeight * svgTextUtils.lineCount(text), 16) + 3;
188190

189191
opts.height = Math.max(opts.height, hEff);
@@ -195,7 +197,7 @@ function reposition(gd, buttons, opts, axName) {
195197
var text = button.select('.selector-text');
196198

197199
var tWidth = text.node() && Drawing.bBox(text.node()).width;
198-
var tHeight = opts.font.size * 1.3;
200+
var tHeight = opts.font.size * LINE_SPACING;
199201
var tLines = svgTextUtils.lineCount(text);
200202

201203
var wEff = Math.max(tWidth + 10, constants.minButtonWidth);

src/components/sliders/constants.js

-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ module.exports = {
4545
// padding around item text
4646
textPadX: 40,
4747

48-
// font size to height scale
49-
fontSizeToHeight: 1.3,
50-
5148
// arrow offset off right edge
5249
arrowOffsetX: 4,
5350

src/components/sliders/draw.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var svgTextUtils = require('../../lib/svg_text_utils');
1818
var anchorUtils = require('../legend/anchor_utils');
1919

2020
var constants = require('./constants');
21+
var LINE_SPACING = require('../../constants/alignment').LINE_SPACING;
2122

2223

2324
module.exports = function draw(gd) {
@@ -309,7 +310,7 @@ function drawCurrentValue(sliderGroup, sliderOpts, valueOverride) {
309310
var lines = svgTextUtils.lineCount(text);
310311

311312
var y0 = (sliderOpts.currentValueMaxLines + 1 - lines) *
312-
sliderOpts.currentvalue.font.size * constants.fontSizeToHeight;
313+
sliderOpts.currentvalue.font.size * LINE_SPACING;
313314

314315
svgTextUtils.positionText(text, x0, y0);
315316

@@ -381,7 +382,7 @@ function drawLabelGroup(sliderGroup, sliderOpts) {
381382
sliderOpts.ticklen +
382383
// position is the baseline of the top line of text only, even
383384
// if the label spans multiple lines
384-
sliderOpts.font.size * constants.fontSizeToHeight +
385+
sliderOpts.font.size * LINE_SPACING +
385386
constants.labelOffset +
386387
sliderOpts.currentValueTotalHeight
387388
);

src/components/updatemenus/constants.js

-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ module.exports = {
4444
textPadX: 24,
4545
arrowPadX: 16,
4646

47-
// font size to height scale
48-
fontSizeToHeight: 1.3,
49-
5047
// item rect radii
5148
rx: 2,
5249
ry: 2,

src/components/updatemenus/draw.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ var Drawing = require('../drawing');
1717
var svgTextUtils = require('../../lib/svg_text_utils');
1818
var anchorUtils = require('../legend/anchor_utils');
1919

20+
var LINE_SPACING = require('../../constants/alignment').LINE_SPACING;
21+
2022
var constants = require('./constants');
2123
var ScrollBox = require('./scrollbox');
2224

@@ -530,7 +532,7 @@ function findDimensions(gd, menuOpts) {
530532
var wEff = Math.max(tWidth + constants.textPadX, constants.minWidth);
531533

532534
// height is determined by item text
533-
var tHeight = menuOpts.font.size * constants.fontSizeToHeight;
535+
var tHeight = menuOpts.font.size * LINE_SPACING;
534536
var tLines = svgTextUtils.lineCount(text);
535537
var hEff = Math.max(tHeight * tLines, constants.minHeight) + constants.textOffsetY;
536538

@@ -643,7 +645,7 @@ function setItemPosition(item, menuOpts, posOpts, overrideOpts) {
643645
height: finalHeight
644646
});
645647

646-
var tHeight = menuOpts.font.size * constants.fontSizeToHeight;
648+
var tHeight = menuOpts.font.size * LINE_SPACING;
647649
var tLines = svgTextUtils.lineCount(text);
648650
var spanOffset = ((tLines - 1) * tHeight / 2);
649651

src/constants/alignment.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ module.exports = {
2828
bottom: 1,
2929
middle: 0.5,
3030
top: 0
31-
}
31+
},
32+
// multiple of fontSize to get the vertical offset between lines
33+
LINE_SPACING: 1.3
3234
};

src/lib/svg_text_utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var d3 = require('d3');
1616
var Lib = require('../lib');
1717
var xmlnsNamespaces = require('../constants/xmlns_namespaces');
1818
var stringMappings = require('../constants/string_mappings');
19+
var LINE_SPACING = require('../constants/alignment').LINE_SPACING;
1920

2021
// text converter
2122

@@ -326,7 +327,7 @@ function buildSVGText(containerNode, str) {
326327
var lineNode = document.createElementNS(xmlnsNamespaces.svg, 'tspan');
327328
d3.select(lineNode).attr({
328329
class: 'line',
329-
dy: (currentLine * 1.3) + 'em'
330+
dy: (currentLine * LINE_SPACING) + 'em'
330331
});
331332
containerNode.appendChild(lineNode);
332333

0 commit comments

Comments
 (0)