diff --git a/src/context.d.ts b/src/context.d.ts index d07832af8d..3e23ee0dc0 100644 --- a/src/context.d.ts +++ b/src/context.d.ts @@ -8,6 +8,9 @@ export interface Context { */ document: Document; + /** The Plot’s (typically generated) class name, for custom styles. */ + className: string; + /** The current projection, if any. */ projection?: GeoStreamWrapper; } diff --git a/src/context.js b/src/context.js index be41e6802e..56d83886bf 100644 --- a/src/context.js +++ b/src/context.js @@ -1,9 +1,9 @@ import {creator, select} from "d3"; import {createProjection} from "./projection.js"; -export function createContext(options = {}, dimensions) { +export function createContext(options = {}, dimensions, className) { const {document = typeof window !== "undefined" ? window.document : undefined} = options; - return {document, projection: createProjection(options, dimensions)}; + return {document, className, projection: createProjection(options, dimensions)}; } export function create(name, {document}) { diff --git a/src/legends.js b/src/legends.js index 1fab8f28f0..f1a17d18ce 100644 --- a/src/legends.js +++ b/src/legends.js @@ -39,8 +39,8 @@ export function exposeLegends(scales, context, defaults = {}) { }; } -function legendOptions(context, {label, ticks, tickFormat} = {}, options) { - return inherit(options, context, {label, ticks, tickFormat}); +function legendOptions({className, ...context}, {label, ticks, tickFormat} = {}, options) { + return inherit(options, {className: `${className}-legend`, ...context}, {label, ticks, tickFormat}); } function legendColor(color, {legend = true, ...options}) { diff --git a/src/plot.js b/src/plot.js index 3ade737285..72679681cf 100644 --- a/src/plot.js +++ b/src/plot.js @@ -141,7 +141,7 @@ export function plot(options = {}) { const {fx, fy} = scales; const subdimensions = fx || fy ? innerDimensions(scaleDescriptors, dimensions) : dimensions; const superdimensions = fx || fy ? actualDimensions(scales, dimensions) : dimensions; - const context = createContext(options, subdimensions, scaleDescriptors); + const context = createContext(options, subdimensions, className); // Reinitialize; for deriving channels dependent on other channels. const newByScale = new Set();