Skip to content

Commit b91f073

Browse files
committed
const, g, url
1 parent 3ffc838 commit b91f073

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/legend.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class ColorLegend {
2424
height: canvasHeight
2525
}
2626
) {
27-
let { color: {
27+
const { color: {
2828
legend: {
2929
title,
3030
tickSize = 6,
@@ -48,7 +48,8 @@ export class ColorLegend {
4848
}
4949
}
5050

51-
function legend(svg, {
51+
// https://observablehq.com/@d3/color-legend
52+
function legend(g, {
5253
color,
5354
title,
5455
tickSize,
@@ -72,7 +73,7 @@ function legend(svg, {
7273

7374
x = color.copy().rangeRound(quantize(interpolate(marginLeft, width - marginRight), n));
7475

75-
svg.append("image")
76+
g.append("image")
7677
.attr("x", marginLeft)
7778
.attr("y", marginTop)
7879
.attr("width", width - marginLeft - marginRight)
@@ -87,7 +88,7 @@ function legend(svg, {
8788
.interpolator(interpolateRound(marginLeft, width - marginRight)),
8889
{range() { return [marginLeft, width - marginRight]; }});
8990

90-
svg.append("image")
91+
g.append("image")
9192
.attr("x", marginLeft)
9293
.attr("y", marginTop)
9394
.attr("width", width - marginLeft - marginRight)
@@ -123,7 +124,7 @@ function legend(svg, {
123124
.domain([-1, color.range().length - 1])
124125
.rangeRound([marginLeft, width - marginRight]);
125126

126-
svg.append("g")
127+
g.append("g")
127128
.selectAll("rect")
128129
.data(color.range())
129130
.join("rect")
@@ -143,7 +144,7 @@ function legend(svg, {
143144
.domain(color.domain())
144145
.rangeRound([marginLeft, width - marginRight]);
145146

146-
svg.append("g")
147+
g.append("g")
147148
.selectAll("rect")
148149
.data(color.domain())
149150
.join("rect")
@@ -156,7 +157,7 @@ function legend(svg, {
156157
tickAdjust = () => {};
157158
}
158159

159-
svg.append("g")
160+
g.append("g")
160161
.attr("transform", `translate(0,${height - marginBottom})`)
161162
.call(axisBottom(x)
162163
.ticks(ticks, typeof tickFormat === "string" ? tickFormat : undefined)
@@ -174,7 +175,7 @@ function legend(svg, {
174175
.attr("class", "title")
175176
.text(title));
176177

177-
return svg.node();
178+
return g.node();
178179
}
179180

180181

0 commit comments

Comments
 (0)