Skip to content

Commit

Permalink
fix ramp legend font-variant (observablehq#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock authored Jun 2, 2022
1 parent 82e446c commit f00e7cc
Show file tree
Hide file tree
Showing 29 changed files with 104 additions and 102 deletions.
18 changes: 10 additions & 8 deletions src/legends/ramp.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,16 @@ export function legendRamp(color, {
.attr("font-family", null)
.attr("font-variant", impliedString(fontVariant, "normal"))
.call(tickAdjust)
.call(g => g.select(".domain").remove())
.call(label === undefined ? () => {} : g => g.append("text")
.attr("x", marginLeft)
.attr("y", marginTop + marginBottom - height - 6)
.attr("fill", "currentColor") // TODO move to stylesheet?
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text(label));
.call(g => g.select(".domain").remove());

if (label !== undefined) {
svg.append("text")
.attr("x", marginLeft)
.attr("y", marginTop - 6)
.attr("fill", "currentColor") // TODO move to stylesheet?
.attr("font-weight", "bold")
.text(label);
}

return svg.node();
}
Expand Down
4 changes: 2 additions & 2 deletions test/output/carsHexbin.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
</g>
<g class="tick" opacity="1" transform="translate(240.5,0)">
<line stroke="currentColor" y2="6" y1="-10"></line><text fill="currentColor" y="9" dy="0.71em">5,000</text>
</g><text x="0" y="-16" fill="currentColor" text-anchor="start" font-weight="bold">weight (lb)</text>
</g>
</g>
</g><text x="0" y="12" fill="currentColor" font-weight="bold">weight (lb)</text>
</svg><svg class="plot-2" fill="currentColor" font-family="system-ui, sans-serif" font-size="10" text-anchor="middle" width="640" height="400" viewBox="0 0 640 400" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<style>
.plot-2 {
Expand Down
4 changes: 2 additions & 2 deletions test/output/carsJitter.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
</g>
<g class="tick" opacity="1" transform="translate(192.5,0)">
<line stroke="currentColor" y2="6" y1="-10"></line><text fill="currentColor" y="9" dy="0.71em">200</text>
</g><text x="0" y="-16" fill="currentColor" text-anchor="start" font-weight="bold">power (hp)</text>
</g>
</g>
</g><text x="0" y="12" fill="currentColor" font-weight="bold">power (hp)</text>
</svg><svg class="plot-2" fill="currentColor" font-family="system-ui, sans-serif" font-size="10" text-anchor="middle" width="640" height="350" viewBox="0 0 640 350" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<style>
.plot-2 {
Expand Down
4 changes: 2 additions & 2 deletions test/output/colorLegendDiverging.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendDivergingSqrt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendImplicitLabel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendLabelBoth.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendLabelLegend.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendLabelScale.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendMargins.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendOrdinalRampTickSize.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendQuantile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendQuantileImplicit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendQuantize.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendQuantizeDescending.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendQuantizeDescendingReversed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendQuantizeRange.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendQuantizeReverse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendThreshold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/output/colorLegendThresholdTickSize.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f00e7cc

Please sign in to comment.