Skip to content

Commit 4af1703

Browse files
authored
propagate className option to legends (#1441)
1 parent e11e6e4 commit 4af1703

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

src/context.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export interface Context {
88
*/
99
document: Document;
1010

11+
/** The Plot’s (typically generated) class name, for custom styles. */
12+
className: string;
13+
1114
/** The current projection, if any. */
1215
projection?: GeoStreamWrapper;
1316
}

src/context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {creator, select} from "d3";
22
import {createProjection} from "./projection.js";
33

4-
export function createContext(options = {}, dimensions) {
4+
export function createContext(options = {}, dimensions, className) {
55
const {document = typeof window !== "undefined" ? window.document : undefined} = options;
6-
return {document, projection: createProjection(options, dimensions)};
6+
return {document, className, projection: createProjection(options, dimensions)};
77
}
88

99
export function create(name, {document}) {

src/legends.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export function exposeLegends(scales, context, defaults = {}) {
3939
};
4040
}
4141

42-
function legendOptions(context, {label, ticks, tickFormat} = {}, options) {
43-
return inherit(options, context, {label, ticks, tickFormat});
42+
function legendOptions({className, ...context}, {label, ticks, tickFormat} = {}, options) {
43+
return inherit(options, {className: `${className}-legend`, ...context}, {label, ticks, tickFormat});
4444
}
4545

4646
function legendColor(color, {legend = true, ...options}) {

src/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export function plot(options = {}) {
141141
const {fx, fy} = scales;
142142
const subdimensions = fx || fy ? innerDimensions(scaleDescriptors, dimensions) : dimensions;
143143
const superdimensions = fx || fy ? actualDimensions(scales, dimensions) : dimensions;
144-
const context = createContext(options, subdimensions, scaleDescriptors);
144+
const context = createContext(options, subdimensions, className);
145145

146146
// Reinitialize; for deriving channels dependent on other channels.
147147
const newByScale = new Set();

0 commit comments

Comments
 (0)