Skip to content

Commit 96c93cb

Browse files
mbostockmstade
andauthored
reduce specificity of generated stylesheets to 0 (#1941)
* fix!: reduce specificity of generated stylesheets to 0 By reducing the specificity of selectors in the generated stylesheets to 0, consumers of Plot can much more easily override these styles using their own stylesheets while still enjoying the default styling of Plot. * chore: generate new snapshots Because the change in selector specificity affects every chart, all snapshots will need regenerating. The rendered output should yield no differences however. * chore: add simple test case for style overrides This test renders two categorical legends, one using default Plot styles and the other using styles by setting the `className` option. The styles being overridden have the same selector specificity as those set by Plot, would it not be for the `:where()` selector resetting Plot's specificity to 0. This is easily verified by reverting b2ff68e. --------- Co-authored-by: Marcus Stade <[email protected]>
1 parent f937046 commit 96c93cb

File tree

695 files changed

+3612
-3477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

695 files changed

+3612
-3477
lines changed

src/legends/ramp.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ export function legendRamp(color, options) {
3838
.call((svg) =>
3939
// Warning: if you edit this, change defaultClassName.
4040
svg.append("style").text(
41-
`.${className}-ramp {
41+
`:where(.${className}-ramp) {
4242
display: block;
4343
height: auto;
4444
height: intrinsic;
4545
max-width: 100%;
4646
overflow: visible;
4747
}
48-
.${className}-ramp text {
48+
:where(.${className}-ramp text) {
4949
white-space: pre;
5050
}`
5151
)

src/legends/swatches.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ function legendItems(scale, options = {}, swatch) {
9696
let extraStyle;
9797

9898
if (columns != null) {
99-
extraStyle = `.${className}-swatches-columns .${className}-swatch {
99+
extraStyle = `:where(.${className}-swatches-columns .${className}-swatch) {
100100
display: flex;
101101
align-items: center;
102102
break-inside: avoid;
103103
padding-bottom: 1px;
104104
}
105-
.${className}-swatches-columns .${className}-swatch::before {
105+
:where(.${className}-swatches-columns .${className}-swatch::before) {
106106
flex-shrink: 0;
107107
}
108-
.${className}-swatches-columns .${className}-swatch-label {
108+
:where(.${className}-swatches-columns .${className}-swatch-label) {
109109
white-space: nowrap;
110110
overflow: hidden;
111111
text-overflow: ellipsis;
@@ -123,13 +123,13 @@ function legendItems(scale, options = {}, swatch) {
123123
item.append("div").attr("class", `${className}-swatch-label`).attr("title", tickFormat).text(tickFormat)
124124
);
125125
} else {
126-
extraStyle = `.${className}-swatches-wrap {
126+
extraStyle = `:where(.${className}-swatches-wrap) {
127127
display: flex;
128128
align-items: center;
129129
min-height: 33px;
130130
flex-wrap: wrap;
131131
}
132-
.${className}-swatches-wrap .${className}-swatch {
132+
:where(.${className}-swatches-wrap .${className}-swatch) {
133133
display: inline-flex;
134134
align-items: center;
135135
margin-right: 1em;
@@ -150,12 +150,12 @@ function legendItems(scale, options = {}, swatch) {
150150
return swatches
151151
.call((div) =>
152152
div.insert("style", "*").text(
153-
`.${className}-swatches {
153+
`:where(.${className}-swatches) {
154154
font-family: system-ui, sans-serif;
155155
font-size: 10px;
156156
margin-bottom: 0.5em;
157157
}
158-
.${className}-swatch > svg {
158+
:where(.${className}-swatch > svg) {
159159
margin-right: 0.5em;
160160
overflow: visible;
161161
}

src/plot.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,15 @@ export function plot(options = {}) {
257257
.call((svg) =>
258258
// Warning: if you edit this, change defaultClassName.
259259
svg.append("style").text(
260-
`.${className} {
260+
`:where(.${className}) {
261261
--plot-background: white;
262262
display: block;
263263
height: auto;
264264
height: intrinsic;
265265
max-width: 100%;
266266
}
267-
.${className} text,
268-
.${className} tspan {
267+
:where(.${className} text),
268+
:where(.${className} tspan) {
269269
white-space: pre;
270270
}`
271271
)

test/output/aaplBollinger.svg

Lines changed: 3 additions & 3 deletions
Loading

test/output/aaplBollingerCandlestick.svg

Lines changed: 3 additions & 3 deletions
Loading

test/output/aaplBollingerGridInterval.svg

Lines changed: 3 additions & 3 deletions
Loading

test/output/aaplBollingerGridSpacing.svg

Lines changed: 3 additions & 3 deletions
Loading

test/output/aaplCandlestick.svg

Lines changed: 3 additions & 3 deletions
Loading

test/output/aaplChangeVolume.svg

Lines changed: 3 additions & 3 deletions
Loading

test/output/aaplClose.svg

Lines changed: 3 additions & 3 deletions
Loading

0 commit comments

Comments
 (0)