From bdbc77be552ef1cbe7c2e37607611f81b5e36503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Fri, 10 Dec 2021 16:59:16 +0100 Subject: [PATCH 1/5] remove font-variant from the global styles; introduce the axis fontVariant option, which defaults to tabular-nums closes #601 --- README.md | 1 + src/axis.js | 8 ++++++++ src/legends/ramp.js | 1 - src/legends/swatches.js | 1 - src/plot.js | 1 - test/output/aaplBollinger.svg | 6 +++--- test/output/aaplCandlestick.svg | 4 ++-- test/output/aaplChangeVolume.svg | 6 +++--- test/output/aaplClose.svg | 6 +++--- test/output/aaplCloseUntyped.svg | 6 +++--- test/output/aaplMonthly.svg | 6 +++--- test/output/aaplVolume.svg | 6 +++--- test/output/aaplVolumeRect.svg | 6 +++--- test/output/anscombeQuartet.svg | 14 +++++++------- test/output/athletesHeightWeight.svg | 6 +++--- test/output/athletesHeightWeightBin.svg | 6 +++--- test/output/athletesHeightWeightBinStroke.svg | 6 +++--- test/output/athletesHeightWeightSex.svg | 6 +++--- test/output/athletesHeightWeightSport.svg | 6 +++--- test/output/athletesNationality.svg | 6 +++--- test/output/athletesSexWeight.svg | 6 +++--- test/output/athletesSportSex.svg | 6 +++--- test/output/athletesSportWeight.svg | 6 +++--- test/output/athletesWeight.svg | 6 +++--- test/output/athletesWeightCumulative.svg | 6 +++--- test/output/availability.svg | 6 +++--- test/output/ballotStatusRace.svg | 6 +++--- test/output/beckerBarley.svg | 18 +++++++++--------- test/output/caltrain.html | 3 +-- test/output/carsMpg.svg | 6 +++--- test/output/carsParcoords.svg | 4 ++-- test/output/collapsedHistogram.svg | 6 +++--- test/output/colorLegendCategorical.html | 1 - test/output/colorLegendCategoricalColumns.html | 1 - test/output/colorLegendCategoricalReverse.html | 1 - test/output/colorLegendCategoricalScheme.html | 1 - test/output/colorLegendDiverging.svg | 2 +- test/output/colorLegendDivergingPivot.svg | 2 +- .../colorLegendDivergingPivotAsymmetric.svg | 2 +- test/output/colorLegendDivergingSqrt.svg | 2 +- test/output/colorLegendInterpolate.svg | 2 +- test/output/colorLegendInterpolateSqrt.svg | 2 +- test/output/colorLegendLabelBoth.svg | 2 +- test/output/colorLegendLabelLegend.svg | 2 +- test/output/colorLegendLabelScale.svg | 2 +- test/output/colorLegendLinear.svg | 2 +- .../colorLegendLinearTruncatedScheme.svg | 2 +- test/output/colorLegendLog.svg | 2 +- test/output/colorLegendLogTicks.svg | 2 +- test/output/colorLegendMargins.svg | 2 +- test/output/colorLegendOrdinal.html | 1 - test/output/colorLegendOrdinalRamp.svg | 2 +- test/output/colorLegendOrdinalRampTickSize.svg | 2 +- test/output/colorLegendOrdinalReverseRamp.svg | 2 +- test/output/colorLegendOrdinalScheme.html | 1 - test/output/colorLegendOrdinalSchemeRamp.svg | 2 +- test/output/colorLegendOrdinalTickFormat.html | 1 - .../colorLegendOrdinalTickFormatFunction.html | 1 - test/output/colorLegendOrdinalTicks.svg | 2 +- test/output/colorLegendQuantile.svg | 2 +- test/output/colorLegendQuantileImplicit.svg | 2 +- test/output/colorLegendQuantitative.svg | 2 +- test/output/colorLegendQuantitativeScheme.svg | 2 +- test/output/colorLegendSqrt.svg | 2 +- test/output/colorLegendSqrtPiecewise.svg | 2 +- test/output/colorLegendThreshold.svg | 2 +- test/output/colorLegendThresholdTickSize.svg | 2 +- test/output/covidIhmeProjectedDeaths.svg | 6 +++--- test/output/crimeanWarOverlapped.svg | 6 +++--- test/output/crimeanWarStacked.svg | 6 +++--- test/output/d3Survey2015Comfort.svg | 6 +++--- test/output/d3Survey2015Why.svg | 6 +++--- test/output/diamondsCaratPrice.svg | 6 +++--- test/output/diamondsCaratPriceDots.svg | 6 +++--- test/output/empty.svg | 6 +++--- test/output/emptyX.svg | 2 +- test/output/figcaption.html | 6 +++--- test/output/figcaptionHtml.html | 6 +++--- test/output/firstLadies.svg | 4 ++-- test/output/footballCoverage.svg | 6 +++--- test/output/fruitSales.svg | 6 +++--- test/output/fruitSalesDate.svg | 6 +++--- test/output/gistempAnomaly.svg | 6 +++--- test/output/gistempAnomalyMoving.svg | 6 +++--- test/output/gistempAnomalyTransform.svg | 6 +++--- test/output/googleTrendsRidgeline.svg | 6 +++--- test/output/gridChoropleth.svg | 2 +- test/output/hadcrutWarmingStripes.svg | 4 ++-- test/output/highCardinalityOrdinal.svg | 4 ++-- test/output/identityScale.svg | 6 +++--- test/output/industryUnemployment.svg | 6 +++--- test/output/industryUnemploymentShare.svg | 6 +++--- test/output/industryUnemploymentStream.svg | 6 +++--- test/output/learningPoverty.svg | 6 +++--- test/output/letterFrequencyBar.svg | 6 +++--- test/output/letterFrequencyCloud.svg | 2 +- test/output/letterFrequencyColumn.svg | 6 +++--- test/output/letterFrequencyDot.svg | 4 ++-- test/output/letterFrequencyLollipop.svg | 6 +++--- test/output/logDegenerate.svg | 4 ++-- test/output/metroInequality.svg | 6 +++--- test/output/metroInequalityChange.svg | 6 +++--- test/output/metroUnemployment.svg | 6 +++--- test/output/metroUnemploymentHighlight.svg | 6 +++--- test/output/metroUnemploymentIndex.svg | 6 +++--- test/output/metroUnemploymentMoving.svg | 6 +++--- test/output/metroUnemploymentNormalize.svg | 6 +++--- test/output/metroUnemploymentRidgeline.svg | 6 +++--- test/output/metroUnemploymentStroke.svg | 6 +++--- test/output/mobyDickFaceted.svg | 14 +++++++------- test/output/mobyDickLetterFrequency.svg | 6 +++--- test/output/mobyDickLetterPairs.svg | 4 ++-- test/output/mobyDickLetterPosition.svg | 6 +++--- .../output/mobyDickLetterRelativeFrequency.svg | 6 +++--- test/output/morleyBoxplot.svg | 6 +++--- test/output/moviesProfitByGenre.svg | 6 +++--- test/output/musicRevenue.svg | 6 +++--- test/output/opacityLegend.svg | 2 +- test/output/opacityLegendColor.svg | 2 +- test/output/opacityLegendLinear.svg | 2 +- test/output/opacityLegendLog.svg | 2 +- test/output/opacityLegendRange.svg | 2 +- test/output/opacityLegendSqrt.svg | 2 +- test/output/ordinalBar.svg | 6 +++--- test/output/penguinCulmen.svg | 18 +++++++++--------- test/output/penguinCulmenArray.svg | 18 +++++++++--------- test/output/penguinIslandUnknown.svg | 6 +++--- test/output/penguinMass.svg | 6 +++--- test/output/penguinMassSex.svg | 12 ++++++------ test/output/penguinMassSexSpecies.svg | 18 +++++++++--------- test/output/penguinMassSpecies.svg | 6 +++--- test/output/penguinSex.svg | 6 +++--- test/output/penguinSexMassCulmenSpecies.svg | 12 ++++++------ test/output/penguinSpeciesGroup.svg | 4 ++-- test/output/penguinSpeciesIsland.svg | 6 +++--- test/output/penguinSpeciesIslandRelative.svg | 6 +++--- test/output/penguinSpeciesIslandSex.svg | 12 ++++++------ test/output/polylinear.svg | 4 ++-- test/output/randomBins.svg | 6 +++--- test/output/randomBinsXY.svg | 6 +++--- test/output/randomQuantile.svg | 6 +++--- test/output/randomWalk.svg | 6 +++--- test/output/seattlePrecipitationRule.svg | 4 ++-- test/output/seattleTemperatureBand.svg | 6 +++--- test/output/seattleTemperatureCell.svg | 6 +++--- test/output/sfCovidDeaths.svg | 6 +++--- test/output/sfTemperatureBand.svg | 6 +++--- test/output/sfTemperatureBandArea.svg | 6 +++--- test/output/simpsonsRatings.svg | 6 +++--- test/output/simpsonsRatingsDots.svg | 6 +++--- test/output/simpsonsViews.svg | 6 +++--- test/output/singleValueBar.svg | 6 +++--- test/output/singleValueBin.svg | 6 +++--- test/output/softwareVersions.svg | 4 ++-- test/output/stackedBar.svg | 4 ++-- test/output/stackedRect.svg | 4 ++-- test/output/stargazers.svg | 6 +++--- test/output/stargazersBinned.svg | 6 +++--- test/output/stargazersHourly.svg | 6 +++--- test/output/stargazersHourlyGroup.svg | 6 +++--- test/output/stocksIndex.svg | 6 +++--- test/output/travelersYearOverYear.svg | 6 +++--- test/output/uniformRandomDifference.svg | 6 +++--- test/output/untypedDateBin.svg | 6 +++--- test/output/usCongressAge.svg | 6 +++--- test/output/usCongressAgeGender.svg | 6 +++--- test/output/usPopulationStateAge.svg | 6 +++--- test/output/usPopulationStateAgeDots.svg | 4 ++-- test/output/usPresidentFavorabilityDots.svg | 6 +++--- test/output/usPresidentialElection2020.svg | 6 +++--- test/output/usPresidentialForecast2016.svg | 6 +++--- test/output/usRetailSales.svg | 6 +++--- test/output/usStatePopulationChange.svg | 6 +++--- test/output/wealthBritainBar.svg | 4 ++-- test/output/wealthBritainProportionPlot.svg | 4 ++-- test/output/wordCloud.svg | 2 +- test/output/wordLengthMobyDick.svg | 6 +++--- test/plots/aapl-candlestick.js | 3 ++- 178 files changed, 451 insertions(+), 453 deletions(-) diff --git a/README.md b/README.md index 3da79153a2..2c53a65400 100644 --- a/README.md +++ b/README.md @@ -273,6 +273,7 @@ Plot automatically generates axes for position scales. You can configure these a * *scale*.**label** - a string to label the axis * *scale*.**labelAnchor** - the label anchor: *top*, *right*, *bottom*, *left*, or *center* * *scale*.**labelOffset** - the label position offset (in pixels; default 0, typically for facet axes) +* *scale*.**fontVariant** - the font-variant attribute for axis ticks; defaults to tabular-nums. Top-level options are also supported as shorthand: **grid** (for *x* and *y* only; see [facet.grid](#facet-options)), **label**, **axis**, **inset**, **round**, **align**, and **padding**. diff --git a/src/axis.js b/src/axis.js index 42a39d7686..54101afae4 100644 --- a/src/axis.js +++ b/src/axis.js @@ -10,6 +10,7 @@ export class AxisX { tickSize = name === "fx" ? 0 : 6, tickPadding = tickSize === 0 ? 9 : 3, tickFormat, + fontVariant = "tabular-nums", grid, label, labelAnchor, @@ -23,6 +24,7 @@ export class AxisX { this.tickSize = number(tickSize); this.tickPadding = number(tickPadding); this.tickFormat = tickFormat; + this.fontVariant = string(fontVariant); this.grid = boolean(grid); this.label = string(label); this.labelAnchor = maybeKeyword(labelAnchor, "labelAnchor", ["center", "left", "right"]); @@ -49,6 +51,7 @@ export class AxisX { ) { const { axis, + fontVariant, grid, label, labelAnchor, @@ -65,6 +68,7 @@ export class AxisX { .call(maybeTickRotate, tickRotate) .attr("font-size", null) .attr("font-family", null) + .attr("font-variant", fontVariant) .call(!line ? g => g.select(".domain").remove() : () => {}) .call(!grid ? () => {} : fy ? gridFacetX(index, fy, -ty) @@ -93,6 +97,7 @@ export class AxisY { tickSize = name === "fy" ? 0 : 6, tickPadding = tickSize === 0 ? 9 : 3, tickFormat, + fontVariant = "tabular-nums", grid, label, labelAnchor, @@ -106,6 +111,7 @@ export class AxisY { this.tickSize = number(tickSize); this.tickPadding = number(tickPadding); this.tickFormat = tickFormat; + this.fontVariant = string(fontVariant); this.grid = boolean(grid); this.label = string(label); this.labelAnchor = maybeKeyword(labelAnchor, "labelAnchor", ["center", "top", "bottom"]); @@ -130,6 +136,7 @@ export class AxisY { ) { const { axis, + fontVariant, grid, label, labelAnchor, @@ -146,6 +153,7 @@ export class AxisY { .call(maybeTickRotate, tickRotate) .attr("font-size", null) .attr("font-family", null) + .attr("font-variant", fontVariant) .call(!line ? g => g.select(".domain").remove() : () => {}) .call(!grid ? () => {} : fx ? gridFacetY(index, fx, -tx) diff --git a/src/legends/ramp.js b/src/legends/ramp.js index cd7555dce4..2172860963 100644 --- a/src/legends/ramp.js +++ b/src/legends/ramp.js @@ -23,7 +23,6 @@ export function legendRamp(color, { .attr("class", className) .attr("font-family", "system-ui, sans-serif") .attr("font-size", 10) - .attr("font-variant", "tabular-nums") .attr("width", width) .attr("height", height) .attr("viewBox", `0 0 ${width} ${height}`) diff --git a/src/legends/swatches.js b/src/legends/swatches.js index 43796c831c..28720d2118 100644 --- a/src/legends/swatches.js +++ b/src/legends/swatches.js @@ -83,7 +83,6 @@ export function legendSwatches(color, { .${className} { font-family: system-ui, sans-serif; font-size: 10px; - font-variant: tabular-nums; margin-bottom: 0.5em;${marginLeft === undefined ? "" : ` margin-left: ${+marginLeft}px;`}${width === undefined ? "" : ` width: ${width}px;`} diff --git a/src/plot.js b/src/plot.js index 3cbe4e5d26..d83e5715e7 100644 --- a/src/plot.js +++ b/src/plot.js @@ -70,7 +70,6 @@ export function plot(options = {}) { .attr("fill", "currentColor") .attr("font-family", "system-ui, sans-serif") .attr("font-size", 10) - .attr("font-variant", "tabular-nums") .attr("text-anchor", "middle") .attr("width", width) .attr("height", height) diff --git a/test/output/aaplBollinger.svg b/test/output/aaplBollinger.svg index 62fe7f700f..812d2fa9a8 100644 --- a/test/output/aaplBollinger.svg +++ b/test/output/aaplBollinger.svg @@ -1,4 +1,4 @@ - + - + 60 @@ -70,7 +70,7 @@ 190 ↑ Close - + 2014 diff --git a/test/output/aaplCandlestick.svg b/test/output/aaplCandlestick.svg index 8f725adc05..37701ca780 100644 --- a/test/output/aaplCandlestick.svg +++ b/test/output/aaplCandlestick.svg @@ -1,4 +1,4 @@ - + ↑ Apple stock price ($) - + December diff --git a/test/output/aaplChangeVolume.svg b/test/output/aaplChangeVolume.svg index d220f03b71..8de5da0360 100644 --- a/test/output/aaplChangeVolume.svg +++ b/test/output/aaplChangeVolume.svg @@ -1,4 +1,4 @@ - + - + 7.1 @@ -70,7 +70,7 @@ 8.4 ↑ Volume (log₁₀) - + −6 diff --git a/test/output/aaplClose.svg b/test/output/aaplClose.svg index eee6e4a057..410cb0b36f 100644 --- a/test/output/aaplClose.svg +++ b/test/output/aaplClose.svg @@ -1,4 +1,4 @@ - + - + 0 @@ -54,7 +54,7 @@ 180 ↑ Close - + 2014 diff --git a/test/output/aaplCloseUntyped.svg b/test/output/aaplCloseUntyped.svg index c4fb512947..c3fbfcf783 100644 --- a/test/output/aaplCloseUntyped.svg +++ b/test/output/aaplCloseUntyped.svg @@ -1,4 +1,4 @@ - + - + 0 @@ -54,7 +54,7 @@ 180 ↑ Close - + 2014 diff --git a/test/output/aaplMonthly.svg b/test/output/aaplMonthly.svg index 0ee551a2f0..5cdd5edb35 100644 --- a/test/output/aaplMonthly.svg +++ b/test/output/aaplMonthly.svg @@ -1,4 +1,4 @@ - + - + 0 @@ -56,7 +56,7 @@ 260 ↑ Daily trade volume (millions) - + 2014 diff --git a/test/output/aaplVolume.svg b/test/output/aaplVolume.svg index 78537e9c0a..ab09cc59f2 100644 --- a/test/output/aaplVolume.svg +++ b/test/output/aaplVolume.svg @@ -1,4 +1,4 @@ - + - + 0 @@ -50,7 +50,7 @@ 16 ↑ Frequency (%) - + 7.0 diff --git a/test/output/aaplVolumeRect.svg b/test/output/aaplVolumeRect.svg index 9f167deed3..c1deac92e1 100644 --- a/test/output/aaplVolumeRect.svg +++ b/test/output/aaplVolumeRect.svg @@ -1,4 +1,4 @@ - + - + 0 @@ -70,7 +70,7 @@ 65 ↑ Daily trade volume (millions) - + Mar 18 diff --git a/test/output/anscombeQuartet.svg b/test/output/anscombeQuartet.svg index 191519eccb..d35e89258a 100644 --- a/test/output/anscombeQuartet.svg +++ b/test/output/anscombeQuartet.svg @@ -1,4 +1,4 @@ - + - + 4 @@ -34,7 +34,7 @@ ↑ y - + 1 @@ -50,7 +50,7 @@ - + 5 @@ -66,7 +66,7 @@ - + 5 @@ -82,7 +82,7 @@ - + 5 @@ -98,7 +98,7 @@ - + 5 diff --git a/test/output/athletesHeightWeight.svg b/test/output/athletesHeightWeight.svg index e577e44c0f..42ecac2e6f 100644 --- a/test/output/athletesHeightWeight.svg +++ b/test/output/athletesHeightWeight.svg @@ -1,4 +1,4 @@ - + - + 1.25 @@ -94,7 +94,7 @@ 2.20 ↑ height - + 40 diff --git a/test/output/athletesHeightWeightBin.svg b/test/output/athletesHeightWeightBin.svg index 42eb3298c7..3f06987e8b 100644 --- a/test/output/athletesHeightWeightBin.svg +++ b/test/output/athletesHeightWeightBin.svg @@ -1,4 +1,4 @@ - + - + 1.2 @@ -58,7 +58,7 @@ 2.2 ↑ height - + 40 diff --git a/test/output/athletesHeightWeightBinStroke.svg b/test/output/athletesHeightWeightBinStroke.svg index 7e37d3c9d5..69262933f1 100644 --- a/test/output/athletesHeightWeightBinStroke.svg +++ b/test/output/athletesHeightWeightBinStroke.svg @@ -1,4 +1,4 @@ - + - + 1.2 @@ -58,7 +58,7 @@ 2.2 ↑ height - + 40 diff --git a/test/output/athletesHeightWeightSex.svg b/test/output/athletesHeightWeightSex.svg index 862baa6590..a14777803f 100644 --- a/test/output/athletesHeightWeightSex.svg +++ b/test/output/athletesHeightWeightSex.svg @@ -1,4 +1,4 @@ - + - + 1.2 @@ -58,7 +58,7 @@ 2.2 ↑ height - + 40 diff --git a/test/output/athletesHeightWeightSport.svg b/test/output/athletesHeightWeightSport.svg index 1327fb6541..406c4b541a 100644 --- a/test/output/athletesHeightWeightSport.svg +++ b/test/output/athletesHeightWeightSport.svg @@ -1,4 +1,4 @@ - + - + 1.25 @@ -94,7 +94,7 @@ 2.20 ↑ height - + 40 diff --git a/test/output/athletesNationality.svg b/test/output/athletesNationality.svg index 4ecf3452d7..fab290b4d2 100644 --- a/test/output/athletesNationality.svg +++ b/test/output/athletesNationality.svg @@ -1,4 +1,4 @@ - + - + USA @@ -74,7 +74,7 @@ COL - + 0 diff --git a/test/output/athletesSexWeight.svg b/test/output/athletesSexWeight.svg index d944071332..4f407d8e95 100644 --- a/test/output/athletesSexWeight.svg +++ b/test/output/athletesSexWeight.svg @@ -1,4 +1,4 @@ - + - + 0 @@ -58,7 +58,7 @@ 1,000 ↑ Frequency - + 40 diff --git a/test/output/athletesSportSex.svg b/test/output/athletesSportSex.svg index 66b1c13e33..a88231cc0c 100644 --- a/test/output/athletesSportSex.svg +++ b/test/output/athletesSportSex.svg @@ -1,4 +1,4 @@ - + - + boxing @@ -98,7 +98,7 @@ gymnastics - + 0 diff --git a/test/output/athletesSportWeight.svg b/test/output/athletesSportWeight.svg index 770f804103..4def8dc3a3 100644 --- a/test/output/athletesSportWeight.svg +++ b/test/output/athletesSportWeight.svg @@ -1,4 +1,4 @@ - + - + aquatics @@ -98,7 +98,7 @@ wrestling sport - + 40 diff --git a/test/output/athletesWeight.svg b/test/output/athletesWeight.svg index d75a4bb0c0..b471bdae26 100644 --- a/test/output/athletesWeight.svg +++ b/test/output/athletesWeight.svg @@ -1,4 +1,4 @@ - + - + 0 @@ -53,7 +53,7 @@ 600 ↑ Frequency - + 40 diff --git a/test/output/athletesWeightCumulative.svg b/test/output/athletesWeightCumulative.svg index c40273fca3..4fc471b2ad 100644 --- a/test/output/athletesWeightCumulative.svg +++ b/test/output/athletesWeightCumulative.svg @@ -1,4 +1,4 @@ - + - + 0 @@ -47,7 +47,7 @@ 10,000 ↑ Frequency - + 40 diff --git a/test/output/availability.svg b/test/output/availability.svg index 8e11d86d8d..849c0d04a1 100644 --- a/test/output/availability.svg +++ b/test/output/availability.svg @@ -1,4 +1,4 @@ - + - + 0 @@ -32,7 +32,7 @@ 5 ↑ value - + 2020 diff --git a/test/output/ballotStatusRace.svg b/test/output/ballotStatusRace.svg index 94a279cf18..24ca6b8625 100644 --- a/test/output/ballotStatusRace.svg +++ b/test/output/ballotStatusRace.svg @@ -1,4 +1,4 @@ - + - + WHITE @@ -38,7 +38,7 @@ NATIVE HAWAIIAN or PACIFIC ISLANDER - + 0 diff --git a/test/output/beckerBarley.svg b/test/output/beckerBarley.svg index 6951867160..1092d7eba1 100644 --- a/test/output/beckerBarley.svg +++ b/test/output/beckerBarley.svg @@ -1,4 +1,4 @@ - + - + Waseca @@ -32,7 +32,7 @@ Grand Rapids site - + 10 @@ -64,7 +64,7 @@ - + Trebi @@ -108,7 +108,7 @@ - + Trebi @@ -152,7 +152,7 @@ - + Trebi @@ -196,7 +196,7 @@ - + Trebi @@ -240,7 +240,7 @@ - + Trebi @@ -284,7 +284,7 @@ - + Trebi diff --git a/test/output/caltrain.html b/test/output/caltrain.html index db8369380e..afceb7844f 100644 --- a/test/output/caltrain.html +++ b/test/output/caltrain.html @@ -7,7 +7,6 @@ .plot { font-family: system-ui, sans-serif; font-size: 10px; - font-variant: tabular-nums; margin-bottom: 0.5em; margin-left: 0px; } @@ -32,7 +31,7 @@ margin-right: 1em; } NLB - +