Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Add axisTop example #56

Closed
GCHQDeveloper500 opened this issue Apr 15, 2019 · 1 comment
Closed

Suggestion: Add axisTop example #56

GCHQDeveloper500 opened this issue Apr 15, 2019 · 1 comment

Comments

@GCHQDeveloper500
Copy link

GCHQDeveloper500 commented Apr 15, 2019

A recent version of chrome appears to have delivered a change to their default user agent specification that implements the following rule;

https://www.w3.org/TR/SVG/styling.html#UAStyleSheet

Specifically the following appears to be new (not sure exactly when but last couple of chrome versions at least);

svg:not(:root), image, marker, pattern, symbol { overflow: hidden; }

Specifically the part that is interesting to this library is that svgs that are not at the root will now have their overflow hidden by default.

What this means is that the axisTop function will now no longer display unless you override that style because it works by using negative values for y which takes causes it to overflow (and therefore not display because of this new rule).

The following hopefully illustrates this better;

var scale = d3.scaleLinear().domain([0, 100]).range([0, 400]);

var axis = d3.axisBottom(scale);

d3.select("#axis-demo")
  .append("svg")
    .style('overflow', 'inherit') // previously you didn't need to do this, but now you do
    .attr("width", 400)
    .attr("height", 30)
  .append("g")
    .attr("transform", "translate(0,30)")
    .call(axis);

I don't think this is necessarily something to "fix" but I was wondering if you thought it was worth putting a quick note in the docs about this to save anyone else running into this? Happy to provide the PR if you agree.

@mbostock
Copy link
Member

I don’t generally recommend using overflow: visible to draw the axis outside the normal bounds of the SVG element. Instead, I recommend using a transform to translate the axis into the desired position, as is shown in most of the example charts.

https://observablehq.com/collection/@d3/d3-shape

We’re working on more dedicated d3-axis examples on Observable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants