Skip to content

Commit c4487ed

Browse files
committed
all styles; fix margin
1 parent 1e1ecc7 commit c4487ed

26 files changed

+876
-831
lines changed

src/legends/swatches.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,24 @@ function legendItems(scale, {
9393
--swatchHeight: ${+swatchHeight}px;
9494
`);
9595

96-
const palette = label
97-
? swatches.call(div => div.append("p")
98-
.text(label)
99-
.style("font-weight", "bold")
100-
.style("width", "100%"))
96+
const hasTitle = label != null && label !== "";
97+
const palette = hasTitle
98+
? swatches.call(div => div.append("div")
99+
.attr("class", `${className}-title`)
100+
.text(label))
101101
.append("div")
102102
: swatches;
103+
palette.classed(`${className}-palette`, true);
103104

104-
let extraStyle;
105+
let extraStyle = hasTitle ? `
106+
.${className}-title {
107+
font-weight: bold;
108+
display: block;
109+
margin-bottom: 0.4em;
110+
}` : "";
105111

106112
if (columns != null) {
107-
extraStyle = `
113+
extraStyle += `
108114
.${className}-swatch {
109115
display: flex;
110116
align-items: center;
@@ -134,10 +140,10 @@ function legendItems(scale, {
134140
.attr("title", tickFormat)
135141
.text(tickFormat));
136142
} else {
137-
extraStyle = `
138-
.${className} {
143+
extraStyle += `
144+
.${className}-palette {
139145
display: flex;
140-
align-items: center;
146+
align-items: flex-start;
141147
min-height: 33px;
142148
flex-wrap: wrap;
143149
}

test/output/caltrain.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<figure style="max-width: initial;">
2-
<div class="plot" style="
2+
<div class="plot plot-palette" style="
33
--swatchWidth: 15px;
44
--swatchHeight: 15px;
55
">
@@ -19,9 +19,9 @@
1919
background: var(--color);
2020
}
2121

22-
.plot {
22+
.plot-palette {
2323
display: flex;
24-
align-items: center;
24+
align-items: flex-start;
2525
min-height: 33px;
2626
flex-wrap: wrap;
2727
}

test/output/colorLegendCategorical.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="plot" style="
1+
<div class="plot plot-palette" style="
22
--swatchWidth: 15px;
33
--swatchHeight: 15px;
44
">
@@ -18,9 +18,9 @@
1818
background: var(--color);
1919
}
2020

21-
.plot {
21+
.plot-palette {
2222
display: flex;
23-
align-items: center;
23+
align-items: flex-start;
2424
min-height: 33px;
2525
flex-wrap: wrap;
2626
}

test/output/colorLegendCategoricalColumns.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
background: var(--color);
1919
}
2020

21+
.plot-title {
22+
font-weight: bold;
23+
display: block;
24+
margin-bottom: 0.4em;
25+
}
26+
2127
.plot-swatch {
2228
display: flex;
2329
align-items: center;
@@ -35,8 +41,8 @@
3541
text-overflow: ellipsis;
3642
}
3743
</style>
38-
<p style="font-weight: bold; width: 100%;">Industry</p>
39-
<div style="columns: 180px;">
44+
<div class="plot-title">Industry</div>
45+
<div class="plot-palette" style="columns: 180px;">
4046
<div class="plot-swatch" style="--color: #4e79a7;">
4147
<div class="plot-label" title="Wholesale and Retail Trade">Wholesale and Retail Trade</div>
4248
</div>

test/output/colorLegendCategoricalReverse.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="plot" style="
1+
<div class="plot plot-palette" style="
22
--swatchWidth: 15px;
33
--swatchHeight: 15px;
44
">
@@ -18,9 +18,9 @@
1818
background: var(--color);
1919
}
2020

21-
.plot {
21+
.plot-palette {
2222
display: flex;
23-
align-items: center;
23+
align-items: flex-start;
2424
min-height: 33px;
2525
flex-wrap: wrap;
2626
}

test/output/colorLegendCategoricalScheme.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="plot" style="
1+
<div class="plot plot-palette" style="
22
--swatchWidth: 15px;
33
--swatchHeight: 15px;
44
">
@@ -18,9 +18,9 @@
1818
background: var(--color);
1919
}
2020

21-
.plot {
21+
.plot-palette {
2222
display: flex;
23-
align-items: center;
23+
align-items: flex-start;
2424
min-height: 33px;
2525
flex-wrap: wrap;
2626
}

test/output/colorLegendOrdinal.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="plot" style="
1+
<div class="plot plot-palette" style="
22
--swatchWidth: 15px;
33
--swatchHeight: 15px;
44
">
@@ -18,9 +18,9 @@
1818
background: var(--color);
1919
}
2020

21-
.plot {
21+
.plot-palette {
2222
display: flex;
23-
align-items: center;
23+
align-items: flex-start;
2424
min-height: 33px;
2525
flex-wrap: wrap;
2626
}

test/output/colorLegendOrdinalScheme.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="plot" style="
1+
<div class="plot plot-palette" style="
22
--swatchWidth: 15px;
33
--swatchHeight: 15px;
44
">
@@ -18,9 +18,9 @@
1818
background: var(--color);
1919
}
2020

21-
.plot {
21+
.plot-palette {
2222
display: flex;
23-
align-items: center;
23+
align-items: flex-start;
2424
min-height: 33px;
2525
flex-wrap: wrap;
2626
}

test/output/colorLegendOrdinalTickFormat.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="plot" style="
1+
<div class="plot plot-palette" style="
22
--swatchWidth: 15px;
33
--swatchHeight: 15px;
44
">
@@ -18,9 +18,9 @@
1818
background: var(--color);
1919
}
2020

21-
.plot {
21+
.plot-palette {
2222
display: flex;
23-
align-items: center;
23+
align-items: flex-start;
2424
min-height: 33px;
2525
flex-wrap: wrap;
2626
}

test/output/colorLegendOrdinalTickFormatFunction.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="plot" style="
1+
<div class="plot plot-palette" style="
22
--swatchWidth: 15px;
33
--swatchHeight: 15px;
44
">
@@ -18,9 +18,9 @@
1818
background: var(--color);
1919
}
2020

21-
.plot {
21+
.plot-palette {
2222
display: flex;
23-
align-items: center;
23+
align-items: flex-start;
2424
min-height: 33px;
2525
flex-wrap: wrap;
2626
}

0 commit comments

Comments
 (0)