question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SVG Axis Labels align inconsistently across browsers

See original GitHub issue

The align of axis labels in svg is based on the alignment-baseline property, which differs across browsers: https://stackoverflow.com/questions/41822995/inconsistent-svg-text-alignment-in-chrome-and-firefox https://stackoverflow.com/questions/19212498/firefox-support-for-alignment-baseline-property

This is due to the specification not permitting alignment-baseline on text elements: https://www.w3.org/TR/SVG11/text.html#AlignmentBaselineProperty

Therefore, I suggest changing the use of alignment-baseline to dominant-baseline and the valuesbefore-edge to text-before-edges and after-edge to text-after-edge, which appears to resolve the issues for me, but I have not tried to build this from the source.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
plouccommented, Mar 28, 2019

Contributions are welcome 😃

1reaction
mjsarfatticommented, Aug 15, 2018

Ps: a fast CSS fix in the meantime is the following (not tested in IE though):

text {
  alignment-baseline: baseline !important; /* reset since Chrome wrongfully sees it as valid */
  dominant-baseline: middle;
}

It looks like it won’t work in IE though. So maybe something like the following? (untested as well)

text {
  alignment-baseline: baseline !important; /* reset since Chrome wrongfully sees it as valid */
  position: relative;
  top: Npx; /* will need to be chart-based, manually computed */
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent SVG text alignment in Chrome and Firefox
The icons represent weather stations and they are rotated according to the wind direction and show the average wind speed as an overlay....
Read more >
[Solved]-d3.js: Align text labels between ticks on the axis-d3.js
I often do this by stacking multiple axes, each with a custom .tickFormat() . If I'm placing labels in between dates, I'll often...
Read more >
Align y-labels — Matplotlib 3.6.2 documentation
Two methods are shown here, one using a short call to Figure.align_ylabels and the second a manual way to align the labels. ......
Read more >
Balisage Paper: How long is my SVG <text> element?
Under those bar labels we label the X axis itself. ... in browsers is inconsistent, and user-controlled kerning support in SVG and CSS...
Read more >
SVG Animation and CSS Transforms: A Complicated Love Story
In all browsers, px-based origins are measured differently for SVG elements than other DOM elements (see below). Here's a video demonstrating ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found