Skip to content

Commit 16bae9c

Browse files
committed
make a constant for font midline alignment
1 parent 274526a commit 16bae9c

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/constants/alignment.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,13 @@ module.exports = {
3030
top: 0
3131
},
3232
// multiple of fontSize to get the vertical offset between lines
33-
LINE_SPACING: 1.3
33+
LINE_SPACING: 1.3,
34+
35+
// multiple of fontSize to shift from the baseline to the midline
36+
// (to use when we don't calculate this shift from Drawing.bBox)
37+
// To be precise this should be half the cap height (capital letter)
38+
// of the font, and according to wikipedia:
39+
// an "average" font might have a cap height of 70% of the em
40+
// https://en.wikipedia.org/wiki/Em_(typography)#History
41+
MID_SHIFT: 0.35
3442
};

src/plots/cartesian/axes.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ var ONEHOUR = constants.ONEHOUR;
2828
var ONEMIN = constants.ONEMIN;
2929
var ONESEC = constants.ONESEC;
3030

31+
var MID_SHIFT = require('../../constants/alignment').MID_SHIFT;
32+
3133
var axes = module.exports = {};
3234

3335
axes.layoutAttributes = require('./layout_attributes');
@@ -1796,7 +1798,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
17961798
else {
17971799
flipit = (axside === 'right') ? 1 : -1;
17981800
labely = function(d) {
1799-
return d.dy + d.fontSize * 0.35 - labelShift * flipit;
1801+
return d.dy + d.fontSize * MID_SHIFT - labelShift * flipit;
18001802
};
18011803
labelx = function(d) {
18021804
return d.dx + position + (labelStandoff + pad +

src/plots/polar/micropolar.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
var d3 = require('d3');
1010
var Lib = require('../../lib');
1111
var extendDeepAll = Lib.extendDeepAll;
12+
var MID_SHIFT = require('../../constants/alignment').MID_SHIFT;
1213

1314
var µ = module.exports = { version: '0.2.2' };
1415

@@ -295,7 +296,7 @@ var µ = module.exports = { version: '0.2.2' };
295296
angularAxisEnter.append('text').classed('axis-text', true).style(fontStyle);
296297
var ticksText = angularAxis.select('text.axis-text').attr({
297298
x: radius + axisConfig.labelOffset,
298-
dy: '.35em',
299+
dy: MID_SHIFT + 'em',
299300
transform: function(d, i) {
300301
var angle = currentAngle(d, i);
301302
var rad = radius + axisConfig.labelOffset;

0 commit comments

Comments
 (0)