Skip to content

Commit 8e45e2a

Browse files
authored
font-variant for legends (#608)
1 parent 3f4d797 commit 8e45e2a

32 files changed

+38
-32
lines changed

src/axes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,6 @@ function inferLabel(channels = [], scale, axis, key) {
143143
return candidate;
144144
}
145145

146-
function inferFontVariant(scale) {
146+
export function inferFontVariant(scale) {
147147
return isOrdinalScale(scale) ? undefined : "tabular-nums";
148148
}

src/legends/ramp.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {create, quantize, interpolateNumber, piecewise, format, scaleBand, scaleLinear, axisBottom} from "d3";
2+
import {inferFontVariant} from "../axes.js";
23
import {interpolatePiecewise} from "../scales/quantitative.js";
3-
import {applyInlineStyles, maybeClassName} from "../style.js";
4+
import {applyInlineStyles, impliedString, maybeClassName} from "../style.js";
45

56
export function legendRamp(color, {
67
label = color.label,
@@ -14,6 +15,7 @@ export function legendRamp(color, {
1415
style,
1516
ticks = (width - marginLeft - marginRight) / 64,
1617
tickFormat,
18+
fontVariant = inferFontVariant(color),
1719
round = true,
1820
className
1921
}) {
@@ -141,6 +143,7 @@ export function legendRamp(color, {
141143
.tickValues(Array.isArray(ticks) ? ticks : null))
142144
.attr("font-size", null)
143145
.attr("font-family", null)
146+
.attr("font-variant", impliedString(fontVariant, "normal"))
144147
.call(tickAdjust)
145148
.call(g => g.select(".domain").remove())
146149
.call(label === undefined ? () => {} : g => g.append("text")

src/legends/swatches.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {create} from "d3";
2+
import {inferFontVariant} from "../axes.js";
23
import {maybeTickFormat} from "../axis.js";
3-
import {applyInlineStyles, maybeClassName} from "../style.js";
4+
import {applyInlineStyles, impliedString, maybeClassName} from "../style.js";
45

56
export function legendSwatches(color, {
67
columns,
78
tickFormat,
9+
fontVariant = inferFontVariant(color),
810
// TODO label,
911
swatchSize = 15,
1012
swatchWidth = swatchSize,
@@ -96,6 +98,7 @@ export function legendSwatches(color, {
9698
}
9799
${extraStyle}
98100
`))
101+
.style("font-variant", impliedString(fontVariant, "normal"))
99102
.call(applyInlineStyles, style)
100103
.node();
101104
}

test/output/colorLegendDiverging.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/colorLegendDivergingPivot.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/colorLegendDivergingPivotAsymmetric.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/colorLegendDivergingSqrt.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/colorLegendImplicitLabel.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/colorLegendInterpolate.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/colorLegendInterpolateSqrt.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)